X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FManual%2FAttributes.pod;h=66d9364718db5ffe9e43f50889e805b5b58ff2f4;hb=1a1774e160f46ec32feca591ee76790955b56f03;hp=98bfd446663add1cb14db5f7ff670ffe1e6cdbd0;hpb=c460adf158d4b2736a8fe137b84a44ccb6d0da94;p=gitmo%2FMoose.git diff --git a/lib/Moose/Manual/Attributes.pod b/lib/Moose/Manual/Attributes.pod index 98bfd44..66d9364 100644 --- a/lib/Moose/Manual/Attributes.pod +++ b/lib/Moose/Manual/Attributes.pod @@ -1,8 +1,10 @@ -=pod +package Moose::Manual::Attributes; + +# ABSTRACT: Object attributes with Moose -=head1 NAME +__END__ -Moose::Manual::Attributes - Object attributes with Moose +=pod =head1 INTRODUCTION @@ -59,7 +61,7 @@ read and write the value of that attribute for an object. By default, the accessor method has the same name as the attribute. If you declared your attribute as C then your accessor will be -read-only. If you declared it read-write, you get a read-write +read-only. If you declared it as C, you get a read-write accessor. Simple. Given our C example above, we now have a single C @@ -394,6 +396,15 @@ C whenever the attribute is set: This is very useful when you're building objects that may contain circular references. +When the object in a weak references goes out of scope, the attribute's value +will become C "behind the scenes". This is done by the Perl interpreter +directly, so Moose does not see this change. This means that triggers don't +fire, coercions aren't applied, etc. + +The attribute is not cleared, so a predicate method for that attribute will +still return true. Similarly, when the attribute is next accessed, a default +value will not be generated. + =head2 Triggers A C is a subroutine that is called whenever the attribute is @@ -414,7 +425,7 @@ set: } $msg .= " - size is now $size"; - warn $msg. + warn $msg; } The trigger is called I an attribute's value is set. It is @@ -430,7 +441,7 @@ 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 +from a C or C. =head2 Attribute types @@ -497,10 +508,10 @@ attribute metaclasses and traits. See L for some examples. You can also write your own metaclasses and traits. See the "Meta" and "Extending" recipes in L for examples. -=head2 Native Traits +=head2 Native Delegations -The Native Traits feature allows standard Perl data structures to be treated -as if they were objects for the purposes of delegation. +Native delegations allow you to delegate to standard Perl data structures as +if they were objects. For example, we can pretend that an array reference has methods like C, C, C, C, and more. @@ -519,25 +530,7 @@ C, C, C, C, and more. }, ); -Moose includes the following native traits: - -=over 4 - -=item * L - -=item * L - -=item * L - -=item * L - -=item * L - -=item * L - -=item * L - -=back +See L for more details. =head1 ATTRIBUTE INHERITANCE @@ -613,16 +606,18 @@ it. If your attribute is an array reference or hash reference, the C option will make Moose dereference the value when it is -returned from the reader method: +returned from the reader method I: my %map = $object->mapping; This option only works if your attribute is explicitly typed as an -C or C. +C or C. When the reader is called in I context, +the reference itself is returned. However, we recommend that you use L traits for these types of attributes, which gives you much more control over how -they are accessed and manipulated. +they are accessed and manipulated. See also +L. =head2 Initializer @@ -630,17 +625,4 @@ Moose provides an attribute option called C. This is called when the attribute's value is being set in the constructor, and lets you change the value before it is set. -=head1 AUTHOR - -Dave Rolsky Eautarch@urth.orgE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - =cut