in reply to Re: Moose: return null object
in thread Moose: return null object
Are you saying you can't return undef from BUILDARGS?
That would be nice. Unfortunately, it's a fatal exception that requires catching:
#!/usr/bin/perl -w use strict; package test; use Mouse; sub BUILDARGS { return undef } __PACKAGE__->meta->make_immutable(); my $eg = test->new(); print "All good!"; # nope...
BUILDARGS did not return a HASH reference at ./test.pl line 11.
..then return undef from new.
Yer not suppose to use your own "new", but I did try defining one and having it return undef. No errors, however, the object returned is still a hash ref, not undef:
package test; use Mouse; sub new { return undef } __PACKAGE__->meta->make_immutable(); my $eg = test->new(); print $eg;
test=HASH(0x2208f08)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Moose: return null object
by lamprecht (Friar) on Apr 18, 2011 at 16:05 UTC | |
|
Re^3: Moose: return null object
by ikegami (Patriarch) on Apr 18, 2011 at 16:28 UTC | |
by halfcountplus (Hermit) on Apr 18, 2011 at 17:11 UTC |