From: Robin V Date: Mon, 22 Mar 2010 23:02:00 +0000 (+0100) Subject: Added documentation for available parameters in BUILD sub X-Git-Tag: 1.00~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=241108c4887cfbc14a427e05e9488243d591a1fa;p=gitmo%2FMoose.git Added documentation for available parameters in BUILD sub --- diff --git a/lib/Moose/Manual/Construction.pod b/lib/Moose/Manual/Construction.pod index 60e7cfb..5048657 100644 --- a/lib/Moose/Manual/Construction.pod +++ b/lib/Moose/Manual/Construction.pod @@ -25,7 +25,8 @@ you're ready to start creating objects! =head1 OBJECT CONSTRUCTION HOOKS Moose lets you hook into object construction. You can validate an -object's state, do logging, or maybe allow non-hash(ref) constructor +object's state, do logging, customize construction from parameters which +do not match your attributes, or maybe allow non-hash(ref) constructor arguments. You can do this by creating C and/or C methods. @@ -92,12 +93,24 @@ object creation. debug( 'Made a new person - SSN = ', $self->ssn, ); } -Note that while it is not shown here, the C method receives -not only the created object, but also a hashref of the original -arguments passed to new (or the results of your C, -if you have overridden the default C.) This can be -useful if you need to venture beyond what the default -initialization behavior and coercions can accomplish. + +As C is called with the original hashref passed to new (or the +results of your C, if you have overridden the default +C.) it can also use be used to create a custom constructor +using parameters that weren't consumed by attributes. This can be +useful if you need to venture beyond what the default initialization +behavior and coercions can accomplish. + + sub BUILD { + my $self = shift; + my $params_hashref = shift; + + $self->addFriend( My::User->new ($params_hashref->{friendId}, + $params_hashref->{activationCode}) ); + + } + + =head3 BUILD and parent classes