1Moose::Meta::Role(3) User Contributed Perl Documentation Moose::Meta::Role(3)
2
3
4
6 Moose::Meta::Role - The Moose Role metaclass
7
9 version 2.2011
10
12 This class is a subclass of Class::MOP::Module that provides additional
13 Moose-specific functionality.
14
15 Its API looks a lot like Moose::Meta::Class, but internally it
16 implements many things differently. This may change in the future.
17
19 "Moose::Meta::Role" is a subclass of Class::MOP::Module.
20
22 Construction
23 Moose::Meta::Role->initialize($role_name)
24
25 This method creates a new role object with the provided name.
26
27 Moose::Meta::Role->combine( [ $role => { ... } ], [ $role ], ... )
28
29 This method accepts a list of array references. Each array reference
30 should contain a role name or Moose::Meta::Role object as its first
31 element. The second element is an optional hash reference. The hash
32 reference can contain "-excludes" and "-alias" keys to control how
33 methods are composed from the role.
34
35 The return value is a new Moose::Meta::Role::Composite that represents
36 the combined roles.
37
38 $metarole->composition_class_roles
39
40 When combining multiple roles using "combine", this method is used to
41 obtain a list of role names to be applied to the
42 Moose::Meta::Role::Composite instance returned by "combine". The
43 default implementation returns an empty list. Extensions that need to
44 hook into role combination may wrap this method to return additional
45 role names.
46
47 Moose::Meta::Role->create($name, %options)
48
49 This method is identical to the Moose::Meta::Class "create" method.
50
51 Moose::Meta::Role->create_anon_role
52
53 This method is identical to the Moose::Meta::Class "create_anon_class"
54 method.
55
56 $metarole->is_anon_role
57
58 Returns true if the role is an anonymous role.
59
60 $metarole->consumers
61
62 Returns a list of names of classes and roles which consume this role.
63
64 Role application
65 $metarole->apply( $thing, @options )
66
67 This method applies a role to the given $thing. That can be another
68 Moose::Meta::Role, object, a Moose::Meta::Class object, or a (non-meta)
69 object instance.
70
71 The options are passed directly to the constructor for the appropriate
72 Moose::Meta::Role::Application subclass.
73
74 Note that this will apply the role even if the $thing in question
75 already "does" this role. "does_role" in Moose::Util is a convenient
76 wrapper for finding out if role application is necessary.
77
78 Roles and other roles
79 $metarole->get_roles
80
81 This returns an array reference of roles which this role does. This
82 list may include duplicates.
83
84 $metarole->calculate_all_roles
85
86 This returns a unique list of all roles that this role does, and all
87 the roles that its roles do.
88
89 $metarole->does_role($role)
90
91 Given a role name or Moose::Meta::Role object, returns true if this
92 role does the given role.
93
94 $metarole->add_role($role)
95
96 Given a Moose::Meta::Role object, this adds the role to the list of
97 roles that the role does.
98
99 $metarole->get_excluded_roles_list
100
101 Returns a list of role names which this role excludes.
102
103 $metarole->excludes_role($role_name)
104
105 Given a role name, returns true if this role excludes the named role.
106
107 $metarole->add_excluded_roles(@role_names)
108
109 Given one or more role names, adds those roles to the list of excluded
110 roles.
111
112 Methods
113 The methods for dealing with a role's methods are all identical in API
114 and behavior to the same methods in Class::MOP::Class.
115
116 $metarole->method_metaclass
117
118 Returns the method metaclass name for the role. This defaults to
119 Moose::Meta::Role::Method.
120
121 $metarole->get_method($name)
122
123 $metarole->has_method($name)
124
125 $metarole->add_method( $name, $body )
126
127 $metarole->get_method_list
128
129 $metarole->find_method_by_name($name)
130
131 These methods are all identical to the methods of the same name in
132 Class::MOP::Package
133
134 Attributes
135 As with methods, the methods for dealing with a role's attribute are
136 all identical in API and behavior to the same methods in
137 Class::MOP::Class.
138
139 However, attributes stored in this class are not stored as objects.
140 Rather, the attribute definition is stored as a hash reference. When a
141 role is composed into a class, this hash reference is passed directly
142 to the metaclass's "add_attribute" method.
143
144 This is quite likely to change in the future.
145
146 $metarole->get_attribute($attribute_name)
147
148 $metarole->has_attribute($attribute_name)
149
150 $metarole->get_attribute_list
151
152 $metarole->add_attribute($name, %options)
153
154 $metarole->remove_attribute($attribute_name)
155
156 Overload introspection and creation
157 The methods for dealing with a role's overloads are all identical in
158 API and behavior to the same methods in Class::MOP::Class.
159
160 $metarole->is_overloaded
161
162 $metarole->get_overloaded_operator($op)
163
164 $metarole->has_overloaded_operator($op)
165
166 $metarole->get_overload_list
167
168 $metarole->get_all_overloaded_operators
169
170 $metarole->add_overloaded_operator($op, $impl)
171
172 $metarole->remove_overloaded_operator($op)
173
174 Required methods
175 $metarole->get_required_method_list
176
177 Returns the list of methods required by the role.
178
179 $metarole->requires_method($name)
180
181 Returns true if the role requires the named method.
182
183 $metarole->add_required_methods(@names)
184
185 Adds the named methods to the role's list of required methods.
186
187 $metarole->remove_required_methods(@names)
188
189 Removes the named methods from the role's list of required methods.
190
191 $metarole->add_conflicting_method(%params)
192
193 Instantiate the parameters as a Moose::Meta::Role::Method::Conflicting
194 object, then add it to the required method list.
195
196 Method modifiers
197 These methods act like their counterparts in Class::MOP::Class and
198 Moose::Meta::Class.
199
200 However, method modifiers are simply stored internally, and are not
201 applied until the role itself is applied to a class or object.
202
203 $metarole->add_after_method_modifier($method_name, $method)
204
205 $metarole->add_around_method_modifier($method_name, $method)
206
207 $metarole->add_before_method_modifier($method_name, $method)
208
209 $metarole->add_override_method_modifier($method_name, $method)
210
211 These methods all add an appropriate modifier to the internal list of
212 modifiers.
213
214 $metarole->has_after_method_modifiers
215
216 $metarole->has_around_method_modifiers
217
218 $metarole->has_before_method_modifiers
219
220 $metarole->has_override_method_modifier
221
222 Return true if the role has any modifiers of the given type.
223
224 $metarole->get_after_method_modifiers($method_name)
225
226 $metarole->get_around_method_modifiers($method_name)
227
228 $metarole->get_before_method_modifiers($method_name)
229
230 Given a method name, returns a list of the appropriate modifiers for
231 that method.
232
233 $metarole->get_override_method_modifier($method_name)
234
235 Given a method name, returns the override method modifier for that
236 method, if it has one.
237
238 Introspection
239 Moose::Meta::Role->meta
240
241 This will return a Class::MOP::Class instance for this class.
242
244 See "BUGS" in Moose for details on reporting bugs.
245
247 · Stevan Little <stevan.little@iinteractive.com>
248
249 · Dave Rolsky <autarch@urth.org>
250
251 · Jesse Luehrs <doy@tozt.net>
252
253 · Shawn M Moore <code@sartak.org>
254
255 · יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
256
257 · Karen Etheridge <ether@cpan.org>
258
259 · Florian Ragwitz <rafl@debian.org>
260
261 · Hans Dieter Pearcey <hdp@weftsoar.net>
262
263 · Chris Prather <chris@prather.org>
264
265 · Matt S Trout <mst@shadowcat.co.uk>
266
268 This software is copyright (c) 2006 by Infinity Interactive, Inc.
269
270 This is free software; you can redistribute it and/or modify it under
271 the same terms as the Perl 5 programming language system itself.
272
273
274
275perl v5.28.0 2018-05-16 Moose::Meta::Role(3)