On Wed, Mar 03, 2010 at 12:52:56PM -0800, Darren Duncan wrote:
> Now, perhaps a bigger question that one might ask, is why wouldn't Moose
> use MooseX::StrictConstructor's semantics by default?
>
> The main reason I can think of for the current behavior is that you may
> want objects to have constructor parameters that don't correspond to
> attributes, and you would be using BUILD to map them.
I've wondered this myself. I don't want arbitrary fields springing into
existence in my object, even if they don't have the overhead of a
full-blown attribute. For that matter, I don't want a field on my object
without the attribute interface -- one of the reasons for attribute
accessors is so I never have to type $obj->{fieldname} again. So I don't
want data being put there in a plain old hash key; if I wanted it, I'd have
made an attribute for it, wouldn't I?
FWIW, I also really like the approach used in MooseX::SlurpyConstructor,
where all "extra" constructor arguments are stored together in a slurpy
attribute. I see a strict constructor as a simple extension of a slurpy
one, using the base case of zero slurpy fields being allowed.
tl;dr version: I'm all in favour of strict construction being the default,
and slurpiness being the next best thing for the remaining cases.
--
Statistics are used as a drunk uses
lampposts - for support, not for illumination.
. . . . .
Karen Etheridge, [email protected] GCS C+++$ USL+++$ P+++$ w--- M++
http://etheridge.ca/ PS++ PE-- b++ DI++++ e++ h(-)