in reply to Re^2: Moose: return null object
in thread Moose: return null object

Using constructor without the class parameter
my $x = Object::new();

instead of the canonical

my $x = 'Object'->new;

means it doesn't bless to its first parameter as usually

sub new { bless {}, shift }

which in turn means it doesn't work in child classes, because it always creates the object of the parent class.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^4: Moose: return null object
by Anonymous Monk on Jul 02, 2015 at 14:46 UTC
    Superdoc, yes indeed thats true. A typo on my part. Slap wrist!!

    But it doesn't affect the point I was making about a way to (apparently) achieve this simple null return from the new constructor as originally requested.

Re^4: Moose: return null object
by Anonymous Monk on Oct 16, 2015 at 09:59 UTC
    Yes, that was a typo and irrelevant to the discussion which is can moose classes return null from constructors? I made my classes have a valid flag, and stringify to "" if this is false, catch all exceptions within moose and this way I am able to use this idiom, in fact it works well. I think Moose should not be so prescriptive, exceptions have their place, and I'll respect your judgement that its a better way to do things, but Moose should not force you to do everything the best way, your best may not be the same as mine. That's my humble opinion in any case.