1Moose::Meta::Role(3)  User Contributed Perl Documentation Moose::Meta::Role(3)
2
3
4

NAME

6       Moose::Meta::Role - The Moose Role metaclass
7

DESCRIPTION

9       This class is a subclass of Class::MOP::Module that provides additional
10       Moose-specific functionality.
11
12       It's API looks a lot like Moose::Meta::Class, but internally it
13       implements many things differently. This may change in the future.
14

INHERITANCE

16       "Moose::Meta::Role" is a subclass of Class::MOP::Module.
17

METHODS

19   Construction
20       Moose::Meta::Role->initialize($role_name)
21           This method creates a new role object with the provided name.
22
23       Moose::Meta::Role->combine( [ $role => { ... } ], [ $role ], ... )
24           This method accepts a list of array references. Each array
25           reference should contain a role name or Moose::Meta::Role object as
26           its first element. The second element is an optional hash
27           reference. The hash reference can contain "-excludes" and "-alias"
28           keys to control how methods are composed from the role.
29
30           The return value is a new Moose::Meta::Role::Composite that
31           represents the combined roles.
32
33       $metarole->composition_class_roles
34           When combining multiple roles using "combine", this method is used
35           to obtain a list of role names to be applied to the
36           Moose::Meta::Role::Composite instance returned by "combine". The
37           default implementation returns an empty list. Extensions that need
38           to hook into role combination may wrap this method to return
39           additional role names.
40
41       Moose::Meta::Role->create($name, %options)
42           This method is identical to the Moose::Meta::Class "create" method.
43
44       Moose::Meta::Role->create_anon_role
45           This method is identical to the Moose::Meta::Class
46           "create_anon_class" method.
47
48       $metarole->is_anon_role
49           Returns true if the role is an anonymous role.
50
51       $metarole->consumers
52           Returns a list of names of classes and roles which consume this
53           role.
54
55   Role application
56       $metarole->apply( $thing, @options )
57           This method applies a role to the given $thing. That can be another
58           Moose::Meta::Role, object, a Moose::Meta::Class object, or a (non-
59           meta) object instance.
60
61           The options are passed directly to the constructor for the
62           appropriate Moose::Meta::Role::Application subclass.
63
64           Note that this will apply the role even if the $thing in question
65           already "does" this role.  "does_role" in Moose::Util is a
66           convenient wrapper for finding out if role application is
67           necessary.
68
69   Roles and other roles
70       $metarole->get_roles
71           This returns an array reference of roles which this role does. This
72           list may include duplicates.
73
74       $metarole->calculate_all_roles
75           This returns a unique list of all roles that this role does, and
76           all the roles that its roles do.
77
78       $metarole->does_role($role)
79           Given a role name or Moose::Meta::Role object, returns true if this
80           role does the given role.
81
82       $metarole->add_role($role)
83           Given a Moose::Meta::Role object, this adds the role to the list of
84           roles that the role does.
85
86       $metarole->get_excluded_roles_list
87           Returns a list of role names which this role excludes.
88
89       $metarole->excludes_role($role_name)
90           Given a role name, returns true if this role excludes the named
91           role.
92
93       $metarole->add_excluded_roles(@role_names)
94           Given one or more role names, adds those roles to the list of
95           excluded roles.
96
97   Methods
98       The methods for dealing with a role's methods are all identical in API
99       and behavior to the same methods in Class::MOP::Class.
100
101       $metarole->method_metaclass
102           Returns the method metaclass name for the role. This defaults to
103           Moose::Meta::Role::Method.
104
105       $metarole->get_method($name)
106       $metarole->has_method($name)
107       $metarole->add_method( $name, $body )
108       $metarole->get_method_list
109       $metarole->find_method_by_name($name)
110           These methods are all identical to the methods of the same name in
111           Class::MOP::Package
112
113   Attributes
114       As with methods, the methods for dealing with a role's attribute are
115       all identical in API and behavior to the same methods in
116       Class::MOP::Class.
117
118       However, attributes stored in this class are not stored as objects.
119       Rather, the attribute definition is stored as a hash reference. When a
120       role is composed into a class, this hash reference is passed directly
121       to the metaclass's "add_attribute" method.
122
123       This is quite likely to change in the future.
124
125       $metarole->get_attribute($attribute_name)
126       $metarole->has_attribute($attribute_name)
127       $metarole->get_attribute_list
128       $metarole->add_attribute($name, %options)
129       $metarole->remove_attribute($attribute_name)
130
131   Required methods
132       $metarole->get_required_method_list
133           Returns the list of methods required by the role.
134
135       $metarole->requires_method($name)
136           Returns true if the role requires the named method.
137
138       $metarole->add_required_methods(@names)
139           Adds the named methods to the role's list of required methods.
140
141       $metarole->remove_required_methods(@names)
142           Removes the named methods from the role's list of required methods.
143
144       $metarole->add_conflicting_method(%params)
145           Instantiate the parameters as a
146           Moose::Meta::Role::Method::Conflicting object, then add it to the
147           required method list.
148
149   Method modifiers
150       These methods act like their counterparts in Class::MOP::Class and
151       Moose::Meta::Class.
152
153       However, method modifiers are simply stored internally, and are not
154       applied until the role itself is applied to a class.
155
156       $metarole->add_after_method_modifier($method_name, $method)
157       $metarole->add_around_method_modifier($method_name, $method)
158       $metarole->add_before_method_modifier($method_name, $method)
159       $metarole->add_override_method_modifier($method_name, $method)
160           These methods all add an appropriate modifier to the internal list
161           of modifiers.
162
163       $metarole->has_after_method_modifiers
164       $metarole->has_around_method_modifiers
165       $metarole->has_before_method_modifiers
166       $metarole->has_override_method_modifier
167           Return true if the role has any modifiers of the given type.
168
169       $metarole->get_after_method_modifiers($method_name)
170       $metarole->get_around_method_modifiers($method_name)
171       $metarole->get_before_method_modifiers($method_name)
172           Given a method name, returns a list of the appropriate modifiers
173           for that method.
174
175       $metarole->get_override_method_modifier($method_name)
176           Given a method name, returns the override method modifier for that
177           method, if it has one.
178
179   Introspection
180       Moose::Meta::Role->meta
181           This will return a Class::MOP::Class instance for this class.
182

BUGS

184       See "BUGS" in Moose for details on reporting bugs.
185

AUTHOR

187       Stevan Little <stevan@iinteractive.com>
188
190       Copyright 2006-2010 by Infinity Interactive, Inc.
191
192       <http://www.iinteractive.com>
193
194       This library is free software; you can redistribute it and/or modify it
195       under the same terms as Perl itself.
196
197
198
199perl v5.12.2                      2010-08-28              Moose::Meta::Role(3)
Impressum