So all that's fine, just it seems (very) silly (as in: pointlessly silly, silly oversight kind of silly) that you cannot return undef from a "new" call, and thot perhaps I'd missed something. But I'm not here to pick on Moose either ;)
Well, basically it is not an oversight at all, it is *very* deliberate. This is basically a variant of the "return value" vs. "exception" debate which happens any time you lock a C programmer and Java programmer together in a room for a long enough period of time. We (myself and the other core Moose devs) believe that exceptions are the way to go, so therefore Moose reflects this opinion. But it also goes a little deeper then that, to the philosophy of what is a "Class".
In non-Moose Perl OO, new was simply a method that you could make do whatever you wanted, convention said it was the method that constructed a new instance, but that was simply just convention. There was nothing special about new either, in fact it was a common idiom for a while to do $instance->new as a sort of cloning technique. But in the end, a "Class" in non-Moose Perl OO is not really a rigorously defined concept, but instead really just a loose set of conventions accumulated over time and borrowed from other languages. Now, there is nothing at all wrong with this, it is very powerful and extremely flexible, however it also suffers from the common "dark-side" of TIMTOWTDI.
In contrast, Moose defines "Class" much more rigorously, in particular it thinks that one of the primary functions of a "Class" is as an instance construction factory. So much so that new in Moose will eventually call $class->meta->new_object to get the instance (delegating up to the Class meta-object). So keeping with this philosophy, new should *always* return an instance, and if it cannot for whatever reason return an instance, it should explode loudly with an exception.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||