1Moose::Meta::Attribute(U3s)er Contributed Perl DocumentatMiooonse::Meta::Attribute(3)
2
3
4

NAME

6       Moose::Meta::Attribute - The Moose attribute metaclass
7

DESCRIPTION

9       This is a subclass of Class::MOP::Attribute with Moose specific exten‐
10       sions.
11
12       For the most part, the only time you will ever encounter an instance of
13       this class is if you are doing some serious deep introspection. To
14       really understand this class, you need to refer to the
15       Class::MOP::Attribute documentation.
16

METHODS

18       Overridden methods
19
20       These methods override methods in Class::MOP::Attribute and add Moose
21       specific features. You can safely assume though that they will behave
22       just as Class::MOP::Attribute does.
23
24       new
25       initialize_instance_slot
26       install_accessors
27       accessor_metaclass
28       get_value
29       set_value
30             eval { $point->meta->get_attribute('x')->set_value($point, 'fourty-two') };
31             if($@) {
32               print "Oops: $@\n";
33             }
34
35           Attribute (x) does not pass the type constraint (Int) with
36           'fourty-two'
37
38           Before setting the value, a check is made on the type constraint of
39           the attribute, if it has one, to see if the value passes it. If the
40           value fails to pass, the set operation dies with a "confess" in
41           Carp.
42
43           Any coercion to convert values is done before checking the type
44           constraint.
45
46           To check a value against a type constraint before setting it, fetch
47           the attribute instance using "find_attribute_by_name" in
48           Moose::Meta::Attribute, fetch the type_constraint from the
49           attribute using "type_constraint" in Moose::Meta::Attribute and
50           call "check" in Moose::Meta::TypeConstraint. See Moose::Cook‐
51           book::RecipeX for an example.
52
53       Additional Moose features
54
55       Moose attributes support type-constraint checking, weak reference cre‐
56       ation and type coercion.
57
58       clone_and_inherit_options
59           This is to support the "has '+foo'" feature, it clones an attribute
60           from a superclass and allows a very specific set of changes to be
61           made to the attribute.
62
63       has_type_constraint
64           Returns true if this meta-attribute has a type constraint.
65
66       type_constraint
67           A read-only accessor for this meta-attribute's type constraint. For
68           more information on what you can do with this, see the documenta‐
69           tion for Moose::Meta::TypeConstraint.
70
71       has_handles
72           Returns true if this meta-attribute performs delegation.
73
74       handles
75           This returns the value which was passed into the handles option.
76
77       is_weak_ref
78           Returns true if this meta-attribute produces a weak reference.
79
80       is_required
81           Returns true if this meta-attribute is required to have a value.
82
83       is_lazy
84           Returns true if this meta-attribute should be initialized lazily.
85
86           NOTE: lazy attributes, must have a "default" or "builder" field
87           set.
88
89       is_lazy_build
90           Returns true if this meta-attribute should be initialized lazily
91           through the builder generated by lazy_build. Using "lazy_build =>
92           1" will make your attribute required and lazy. In addition it will
93           set the builder, clearer and predicate options for you using the
94           following convention.
95
96              #If your attribute name starts with an underscore:
97              has '_foo' => (lazy_build => 1);
98              #is the same as
99              has '_foo' => (lazy => 1, required => 1, predicate => '_has_foo', clearer => '_clear_foo', builder => '_build__foo);
100              # or
101              has '_foo' => (lazy => 1, required => 1, predicate => '_has_foo', clearer => '_clear_foo', default => sub{shift->_build__foo});
102
103              #If your attribute name does not start with an underscore:
104              has 'foo' => (lazy_build => 1);
105              #is the same as
106              has 'foo' => (lazy => 1, required => 1, predicate => 'has_foo', clearer => 'clear_foo', builder => '_build_foo);
107              # or
108              has 'foo' => (lazy => 1, required => 1, predicate => 'has_foo', clearer => 'clear_foo', default => sub{shift->_build_foo});
109
110           The reason for the different naming of the "builder" is that the
111           "builder" method is a private method while the "clearer" and "pred‐
112           icate" methods are public methods.
113
114           NOTE: This means your class should provide a method whose name
115           matches the value of the builder part, in this case _build__foo or
116           _build_foo.
117
118       should_coerce
119           Returns true if this meta-attribute should perform type coercion.
120
121       should_auto_deref
122           Returns true if this meta-attribute should perform automatic
123           auto-dereferencing.
124
125           NOTE: This can only be done for attributes whose type constraint is
126           either ArrayRef or HashRef.
127
128       has_trigger
129           Returns true if this meta-attribute has a trigger set.
130
131       trigger
132           This is a CODE reference which will be executed every time the
133           value of an attribute is assigned. The CODE ref will get two val‐
134           ues, the invocant and the new value. This can be used to handle
135           basic bi-directional relations.
136
137       documentation
138           This is a string which contains the documentation for this
139           attribute.  It serves no direct purpose right now, but it might in
140           the future in some kind of automated documentation system perhaps.
141
142       has_documentation
143           Returns true if this meta-attribute has any documentation.
144

BUGS

146       All complex software has bugs lurking in it, and this module is no
147       exception. If you find a bug please either email me, or add the bug to
148       cpan-RT.
149

AUTHOR

151       Stevan Little <stevan@iinteractive.com>
152
153       Yuval Kogman <nothingmuch@woobling.com>
154
156       Copyright 2006, 2007 by Infinity Interactive, Inc.
157
158       <http://www.iinteractive.com>
159
160       This library is free software; you can redistribute it and/or modify it
161       under the same terms as Perl itself.
162
163
164
165perl v5.8.8                       2007-09-06         Moose::Meta::Attribute(3)
Impressum