X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FManual%2FAttributes.pod;h=174c62413fb4e62139ce3aad56fe15099306eb4d;hb=73f70bdfcd04d03ffbfa91aa795f51ffebfc6d9d;hp=61d10ffd65da8cedec4905a670f0623e4da973c3;hpb=f977e77696c15153006677e6c864776190a38185;p=gitmo%2FMoose.git diff --git a/lib/Moose/Manual/Attributes.pod b/lib/Moose/Manual/Attributes.pod index 61d10ff..174c624 100644 --- a/lib/Moose/Manual/Attributes.pod +++ b/lib/Moose/Manual/Attributes.pod @@ -36,10 +36,10 @@ Use the C function to declare an attribute: This says that all C objects have an optional read-write "first_name" attribute. -=head2 Read-write Vs read-only +=head2 Read-write vs. read-only The options passed to C define the properties of the -attribute. There are a many options, but in the simplest form you just +attribute. There are many options, but in the simplest form you just need to set C, which can be either C (read-write) or C (read-only). @@ -67,12 +67,12 @@ particularly handy when you'd like an attribute to be publicly readable, but only privately settable. For example: has 'weight' => ( - is => 'rw', + is => 'ro', writer => '_set_weight', ); -This might be useful if weight is calculated based on other methods, -for example every time the C method is called, we might adjust +This might be useful if weight is calculated based on other methods. +For example, every time the C method is called, we might adjust weight. This lets us hide the implementation details of weight changes, but still provide the weight value to users of the class. @@ -91,7 +91,7 @@ C methods: If you're thinking that doing this over and over would be insanely tedious, you're right! Fortunately, Moose provides a powerful -extension system that lets override the default naming +extension system that lets you override the default naming conventions. See L for more details. =head2 Predicate and clearer methods @@ -102,8 +102,9 @@ you want to access this information, you must define clearer and predicate methods for an attribute. A predicate method tells you whether or not a given attribute is -currently set. Note an attribute can be explicitly set to C or -some other false value, but the predicate will return true. +currently set. Note that an attribute can be explicitly set to +C or some other false value, but the predicate will return +true. The clearer method unsets the attribute. This is I the same as setting the value to C, but you can only distinguish @@ -159,9 +160,9 @@ required, simply set the C option to true: There are a couple caveats worth mentioning in regards to what "required" actually means. -Basically, all it says is that this attribute (C) must be provided -to the constructor. It does not say anything about its value, so it -could be C. +Basically, all it says is that this attribute (C) must be provided to +the constructor, or be lazy with either a default or a builder. It does not +say anything about its value, so it could be C. If you define a clearer method on a required attribute, the clearer I work, so even a required attribute can be unset after object @@ -299,7 +300,7 @@ consuming class provide the C: has 'size' => ( is => 'ro', lazy => 1, - builder => '_build_animal', + builder => '_build_size', ); package Lilliputian; @@ -448,20 +449,19 @@ set: ); sub _size_set { - my ( $self, $size, $meta_attr ) = @_; + my ( $self, $size ) = @_; warn $self->name, " size is now $size\n"; } -The trigger is called as a method, and receives the new value as well -as the L object for the attribute. The trigger -is called I the value is set. +The trigger is called as a method, and receives the new value as its argument. +The trigger is called I the value is set. This differs from an after method modifier in two ways. First, a trigger is only called when the attribute is set, as opposed to whenever the accessor method is called (for reading or -writing). Second, it is also called if the when an attribute's value -is passed to the constructor. +writing). Second, it is also called when an attribute's value is +passed to the constructor. However, triggers are I called when an attribute is populated from a C or C @@ -600,9 +600,9 @@ of an inherited attribute. =head1 MORE ON ATTRIBUTES Moose attributes are a big topic, and this document glosses over a few -aspects of their aspects. We recommend that you read the -L and L documents to -get a more complete understanding of attribute features. +aspects. We recommend that you read the L +and L documents to get a more complete +understanding of attribute features. =head1 A FEW MORE OPTIONS