in reply to Moose: return null object
Hmm. Seems to me that the purpose of new is to create an object. I would expect any object creation that failed would throw an exception, so I would think that the previously suggested:
would be the way to go. Obviously, there are different opinions, or this question would not have arisen.my $obj = eval { Class->new($whatever) }; if (not $obj) { do_something_else(); }
Another possibility would be to define another class method, say maybe_create(), which would wrap up an eval'd new(). That way you could have your optional object creation without violating the sanctity of the "new() returns an object or dies" idea.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Moose: return null object
by Anonymous Monk on Jul 02, 2015 at 11:43 UTC | |
by choroba (Cardinal) on Jul 02, 2015 at 11:58 UTC | |
by Anonymous Monk on Jul 02, 2015 at 14:46 UTC | |
by Anonymous Monk on Oct 16, 2015 at 09:59 UTC |