From: Dave Rolsky Date: Thu, 11 Dec 2008 21:55:05 +0000 (+0000) Subject: More polishing of this doc X-Git-Tag: 0.66~27^2~34 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5384dda8d35229c2b3bd86e1ee4e368ef8a1c18a;p=gitmo%2FMoose.git More polishing of this doc --- diff --git a/lib/Moose/Manual/Construction.pod b/lib/Moose/Manual/Construction.pod index 219d4a3..36416f7 100644 --- a/lib/Moose/Manual/Construction.pod +++ b/lib/Moose/Manual/Construction.pod @@ -6,14 +6,13 @@ Moose::Manual::Classes - Object construction (and destruction) with Moose =head1 WHERE'S THE CONSTRUCTOR? -The first question about object construction with Moose might be how -it happens. B method for your -classes!> +B method for your classes!> When you C in your class, you will become a subclass of C, which provides a C method for you. And if you -follow our recommendations and make your class immutable, then you -actually get a class-specific C method genreated in your class. +follow L and make +your class immutable, then you actually get a class-specific C +method genreated in your class. The Moose-provided constructor accepts a hash or hash reference of named parameters matching your attributes (actually, matching their @@ -21,7 +20,7 @@ Cs). This is just another way in which Moose keeps you from worrying I classes are implemented. Simply define a class and you're ready to start creating objects! -=head1 DOING "STUFF" WHEN AN OBJECT IS CONSTRUCTED +=head1 OBJECT CONSTRUCTION HOOKS Sometimes you need to hook into object construction. Some common needs are validating an object's state, logging, and allowing non-hash(ref) @@ -45,9 +44,9 @@ calling style. For example, we might want to allow our Person class to be called with a single argument of a social security number, C<< Person->new($ssn) >>. -Without a C method, Moose will complain, because this is -clearly not a hash reference. With a C method we can easily -accomodate this: +Without a C method, Moose will complain, because it expects +a hash or hash reference. We can use the C method to +accomodate this calling style: sub BUILDARGS { my $class = shift; @@ -87,7 +86,7 @@ object creation. sub BUILD { my $self = shift; - log_debug( 'Made a new person - SSN = ', $self->ssn, ); + debug( 'Made a new person - SSN = ', $self->ssn, ); } =head3 BUILD and Parent Classes @@ -105,7 +104,7 @@ The theory behind this is that C methods can only be used for increasing specialization of a class's constraints, so it makes sense to call the least specific first (also, this is how Perl 6 does it). -=head OBJECT DESTRUCTION +=head1 OBJECT DESTRUCTION Moose provides a hook for object destruction with the C method. As with C, you should never explicitly call C<< @@ -113,6 +112,9 @@ $self->SUPER::DEMOLISH >>. Moose will arrange for all of the C methods in your hierarchy to be called, from most to least specific. +In most cases, Perl's built-in garbage collection is sufficient, and +you won't need ot provide a C method. + =head1 AUTHOR Dave Rolsky Eautarch@urth.orgE