Commit | Line | Data |
e185c027 |
1 | |
2 | package Moose::Meta::Role; |
3 | |
4 | use strict; |
5 | use warnings; |
6 | use metaclass; |
7 | |
21f1e231 |
8 | use Scalar::Util 'blessed'; |
bdabd620 |
9 | |
e606ae5f |
10 | our $VERSION = '0.57'; |
11 | $VERSION = eval $VERSION; |
d44714be |
12 | our $AUTHORITY = 'cpan:STEVAN'; |
e185c027 |
13 | |
8ee73eeb |
14 | use Moose::Meta::Class; |
39b3bc94 |
15 | use Moose::Meta::Role::Method; |
d67145ed |
16 | use Moose::Meta::Role::Method::Required; |
8ee73eeb |
17 | |
68efb014 |
18 | use base 'Class::MOP::Module'; |
80572233 |
19 | |
fb1e11d5 |
20 | ## ------------------------------------------------------------------ |
21 | ## NOTE: |
22 | ## I normally don't do this, but I am doing |
23 | ## a whole bunch of meta-programmin in this |
24 | ## module, so it just makes sense. For a clearer |
25 | ## picture of what is going on in the next |
26 | ## several lines of code, look at the really |
27 | ## big comment at the end of this file (right |
28 | ## before the POD). |
29 | ## - SL |
30 | ## ------------------------------------------------------------------ |
80572233 |
31 | |
21716c07 |
32 | my $META = __PACKAGE__->meta; |
33 | |
34 | ## ------------------------------------------------------------------ |
35 | ## attributes ... |
e185c027 |
36 | |
21716c07 |
37 | # NOTE: |
38 | # since roles are lazy, we hold all the attributes |
fb1e11d5 |
39 | # of the individual role in 'statis' until which |
40 | # time when it is applied to a class. This means |
41 | # keeping a lot of things in hash maps, so we are |
21716c07 |
42 | # using a little of that meta-programmin' magic |
fb1e11d5 |
43 | # here an saving lots of extra typin. And since |
44 | # many of these attributes above require similar |
45 | # functionality to support them, so we again use |
46 | # the wonders of meta-programmin' to deliver a |
21716c07 |
47 | # very compact solution to this normally verbose |
48 | # problem. |
49 | # - SL |
50 | |
51 | foreach my $action ( |
fb1e11d5 |
52 | { |
53 | name => 'excluded_roles_map', |
54 | attr_reader => 'get_excluded_roles_map' , |
21716c07 |
55 | methods => { |
fb1e11d5 |
56 | add => 'add_excluded_roles', |
57 | get_list => 'get_excluded_roles_list', |
58 | existence => 'excludes_role', |
21716c07 |
59 | } |
60 | }, |
fb1e11d5 |
61 | { |
62 | name => 'required_methods', |
21716c07 |
63 | attr_reader => 'get_required_methods_map', |
64 | methods => { |
fb1e11d5 |
65 | add => 'add_required_methods', |
21716c07 |
66 | remove => 'remove_required_methods', |
67 | get_list => 'get_required_method_list', |
68 | existence => 'requires_method', |
69 | } |
709c321c |
70 | }, |
21716c07 |
71 | { |
fb1e11d5 |
72 | name => 'attribute_map', |
21716c07 |
73 | attr_reader => 'get_attribute_map', |
74 | methods => { |
75 | get => 'get_attribute', |
76 | get_list => 'get_attribute_list', |
77 | existence => 'has_attribute', |
78 | remove => 'remove_attribute', |
79 | } |
80 | } |
81 | ) { |
fb1e11d5 |
82 | |
21716c07 |
83 | my $attr_reader = $action->{attr_reader}; |
84 | my $methods = $action->{methods}; |
fb1e11d5 |
85 | |
86 | # create the attribute |
87 | $META->add_attribute($action->{name} => ( |
88 | reader => $attr_reader, |
89 | default => sub { {} } |
90 | )); |
91 | |
92 | # create some helper methods |
21716c07 |
93 | $META->add_method($methods->{add} => sub { |
94 | my ($self, @values) = @_; |
fb1e11d5 |
95 | $self->$attr_reader->{$_} = undef foreach @values; |
21716c07 |
96 | }) if exists $methods->{add}; |
fb1e11d5 |
97 | |
21716c07 |
98 | $META->add_method($methods->{get_list} => sub { |
99 | my ($self) = @_; |
fb1e11d5 |
100 | keys %{$self->$attr_reader}; |
101 | }) if exists $methods->{get_list}; |
102 | |
21716c07 |
103 | $META->add_method($methods->{get} => sub { |
104 | my ($self, $name) = @_; |
fb1e11d5 |
105 | $self->$attr_reader->{$name} |
106 | }) if exists $methods->{get}; |
107 | |
21716c07 |
108 | $META->add_method($methods->{existence} => sub { |
109 | my ($self, $name) = @_; |
fb1e11d5 |
110 | exists $self->$attr_reader->{$name} ? 1 : 0; |
111 | }) if exists $methods->{existence}; |
112 | |
21716c07 |
113 | $META->add_method($methods->{remove} => sub { |
114 | my ($self, @values) = @_; |
115 | delete $self->$attr_reader->{$_} foreach @values; |
fb1e11d5 |
116 | }) if exists $methods->{remove}; |
21716c07 |
117 | } |
d79e62fd |
118 | |
21716c07 |
119 | ## some things don't always fit, so they go here ... |
80572233 |
120 | |
21716c07 |
121 | sub add_attribute { |
122 | my $self = shift; |
123 | my $name = shift; |
124 | my $attr_desc; |
125 | if (scalar @_ == 1 && ref($_[0]) eq 'HASH') { |
126 | $attr_desc = $_[0]; |
127 | } |
128 | else { |
129 | $attr_desc = { @_ }; |
130 | } |
131 | $self->get_attribute_map->{$name} = $attr_desc; |
132 | } |
e185c027 |
133 | |
bca01282 |
134 | # DEPRECATED |
135 | # sub _clean_up_required_methods { |
136 | # my $self = shift; |
137 | # foreach my $method ($self->get_required_method_list) { |
138 | # $self->remove_required_methods($method) |
139 | # if $self->has_method($method); |
140 | # } |
141 | # } |
1331430a |
142 | |
21716c07 |
143 | ## ------------------------------------------------------------------ |
144 | ## method modifiers |
145 | |
21716c07 |
146 | # NOTE: |
fb1e11d5 |
147 | # the before/around/after method modifiers are |
21716c07 |
148 | # stored by name, but there can be many methods |
149 | # then associated with that name. So again we have |
150 | # lots of similar functionality, so we can do some |
151 | # meta-programmin' and save some time. |
152 | # - SL |
153 | |
154 | foreach my $modifier_type (qw[ before around after ]) { |
fb1e11d5 |
155 | |
156 | my $attr_reader = "get_${modifier_type}_method_modifiers_map"; |
21716c07 |
157 | |
fb1e11d5 |
158 | # create the attribute ... |
159 | $META->add_attribute("${modifier_type}_method_modifiers" => ( |
160 | reader => $attr_reader, |
161 | default => sub { {} } |
162 | )); |
163 | |
164 | # and some helper methods ... |
21716c07 |
165 | $META->add_method("get_${modifier_type}_method_modifiers" => sub { |
166 | my ($self, $method_name) = @_; |
fb1e11d5 |
167 | #return () unless exists $self->$attr_reader->{$method_name}; |
21716c07 |
168 | @{$self->$attr_reader->{$method_name}}; |
169 | }); |
fb1e11d5 |
170 | |
21716c07 |
171 | $META->add_method("has_${modifier_type}_method_modifiers" => sub { |
172 | my ($self, $method_name) = @_; |
173 | # NOTE: |
fb1e11d5 |
174 | # for now we assume that if it exists,.. |
21716c07 |
175 | # it has at least one modifier in it |
176 | (exists $self->$attr_reader->{$method_name}) ? 1 : 0; |
fb1e11d5 |
177 | }); |
178 | |
21716c07 |
179 | $META->add_method("add_${modifier_type}_method_modifier" => sub { |
180 | my ($self, $method_name, $method) = @_; |
fb1e11d5 |
181 | |
182 | $self->$attr_reader->{$method_name} = [] |
21716c07 |
183 | unless exists $self->$attr_reader->{$method_name}; |
fb1e11d5 |
184 | |
21716c07 |
185 | my $modifiers = $self->$attr_reader->{$method_name}; |
fb1e11d5 |
186 | |
21716c07 |
187 | # NOTE: |
fb1e11d5 |
188 | # check to see that we aren't adding the |
189 | # same code twice. We err in favor of the |
21716c07 |
190 | # first on here, this may not be as expected |
191 | foreach my $modifier (@{$modifiers}) { |
192 | return if $modifier == $method; |
193 | } |
fb1e11d5 |
194 | |
21716c07 |
195 | push @{$modifiers} => $method; |
196 | }); |
fb1e11d5 |
197 | |
21716c07 |
198 | } |
1331430a |
199 | |
21716c07 |
200 | ## ------------------------------------------------------------------ |
201 | ## override method mofidiers |
0558683c |
202 | |
fb1e11d5 |
203 | $META->add_attribute('override_method_modifiers' => ( |
204 | reader => 'get_override_method_modifiers_map', |
205 | default => sub { {} } |
206 | )); |
207 | |
21716c07 |
208 | # NOTE: |
fb1e11d5 |
209 | # these are a little different because there |
21716c07 |
210 | # can only be one per name, whereas the other |
211 | # method modifiers can have multiples. |
212 | # - SL |
0558683c |
213 | |
21716c07 |
214 | sub add_override_method_modifier { |
215 | my ($self, $method_name, $method) = @_; |
216 | (!$self->has_method($method_name)) |
c245d69b |
217 | || Moose->throw_error("Cannot add an override of method '$method_name' " . |
4c0b3599 |
218 | "because there is a local version of '$method_name'"); |
fb1e11d5 |
219 | $self->get_override_method_modifiers_map->{$method_name} = $method; |
21716c07 |
220 | } |
0558683c |
221 | |
21716c07 |
222 | sub has_override_method_modifier { |
223 | my ($self, $method_name) = @_; |
224 | # NOTE: |
fb1e11d5 |
225 | # for now we assume that if it exists,.. |
21716c07 |
226 | # it has at least one modifier in it |
fb1e11d5 |
227 | (exists $self->get_override_method_modifiers_map->{$method_name}) ? 1 : 0; |
21716c07 |
228 | } |
0558683c |
229 | |
21716c07 |
230 | sub get_override_method_modifier { |
231 | my ($self, $method_name) = @_; |
fb1e11d5 |
232 | $self->get_override_method_modifiers_map->{$method_name}; |
21716c07 |
233 | } |
0558683c |
234 | |
21716c07 |
235 | ## general list accessor ... |
80572233 |
236 | |
21716c07 |
237 | sub get_method_modifier_list { |
238 | my ($self, $modifier_type) = @_; |
fb1e11d5 |
239 | my $accessor = "get_${modifier_type}_method_modifiers_map"; |
21716c07 |
240 | keys %{$self->$accessor}; |
241 | } |
e185c027 |
242 | |
e606ae5f |
243 | sub reset_package_cache_flag { (shift)->{'_package_cache_flag'} = undef } |
244 | sub update_package_cache_flag { |
245 | my $self = shift; |
246 | $self->{'_package_cache_flag'} = Class::MOP::check_package_cache_flag($self->name); |
247 | } |
248 | |
249 | |
250 | |
21716c07 |
251 | ## ------------------------------------------------------------------ |
80572233 |
252 | ## subroles |
253 | |
21716c07 |
254 | __PACKAGE__->meta->add_attribute('roles' => ( |
255 | reader => 'get_roles', |
256 | default => sub { [] } |
257 | )); |
258 | |
80572233 |
259 | sub add_role { |
260 | my ($self, $role) = @_; |
261 | (blessed($role) && $role->isa('Moose::Meta::Role')) |
c245d69b |
262 | || Moose->throw_error("Roles must be instances of Moose::Meta::Role"); |
80572233 |
263 | push @{$self->get_roles} => $role; |
e606ae5f |
264 | $self->reset_package_cache_flag; |
80572233 |
265 | } |
266 | |
b8aeb4dc |
267 | sub calculate_all_roles { |
268 | my $self = shift; |
269 | my %seen; |
fb1e11d5 |
270 | grep { |
271 | !$seen{$_->name}++ |
272 | } ($self, map { |
273 | $_->calculate_all_roles |
274 | } @{ $self->get_roles }); |
b8aeb4dc |
275 | } |
276 | |
80572233 |
277 | sub does_role { |
278 | my ($self, $role_name) = @_; |
279 | (defined $role_name) |
c245d69b |
280 | || Moose->throw_error("You must supply a role name to look for"); |
bdabd620 |
281 | # if we are it,.. then return true |
282 | return 1 if $role_name eq $self->name; |
283 | # otherwise.. check our children |
80572233 |
284 | foreach my $role (@{$self->get_roles}) { |
bdabd620 |
285 | return 1 if $role->does_role($role_name); |
80572233 |
286 | } |
287 | return 0; |
288 | } |
289 | |
21716c07 |
290 | ## ------------------------------------------------------------------ |
fb1e11d5 |
291 | ## methods |
1331430a |
292 | |
21716c07 |
293 | sub method_metaclass { 'Moose::Meta::Role::Method' } |
80572233 |
294 | |
fb1e11d5 |
295 | sub get_method_map { |
093b12c2 |
296 | my $self = shift; |
e606ae5f |
297 | |
298 | my $current = Class::MOP::check_package_cache_flag($self->name); |
299 | |
300 | if (defined $self->{'_package_cache_flag'} && $self->{'_package_cache_flag'} == $current) { |
301 | return $self->{'methods'} ||= {}; |
302 | } |
303 | |
304 | $self->{_package_cache_flag} = $current; |
305 | |
306 | my $map = $self->{'methods'} ||= {}; |
fb1e11d5 |
307 | |
308 | my $role_name = $self->name; |
309 | my $method_metaclass = $self->method_metaclass; |
310 | |
0addec44 |
311 | my %all_code = $self->get_all_package_symbols('CODE'); |
fb1e11d5 |
312 | |
0addec44 |
313 | foreach my $symbol (keys %all_code) { |
314 | my $code = $all_code{$symbol}; |
fb1e11d5 |
315 | |
e606ae5f |
316 | next if exists $map->{$symbol} && |
317 | defined $map->{$symbol} && |
318 | $map->{$symbol}->body == $code; |
319 | |
fb1e11d5 |
320 | my ($pkg, $name) = Class::MOP::get_code_info($code); |
321 | |
322 | if ($pkg->can('meta') |
323 | # NOTE: |
324 | # we don't know what ->meta we are calling |
325 | # here, so we need to be careful cause it |
326 | # just might blow up at us, or just complain |
327 | # loudly (in the case of Curses.pm) so we |
328 | # just be a little overly cautious here. |
329 | # - SL |
e606ae5f |
330 | && eval { no warnings; blessed($pkg->meta) } # FIXME calls meta |
fb1e11d5 |
331 | && $pkg->meta->isa('Moose::Meta::Role')) { |
332 | my $role = $pkg->meta->name; |
333 | next unless $self->does_role($role); |
334 | } |
335 | else { |
2887c827 |
336 | # NOTE: |
337 | # in 5.10 constant.pm the constants show up |
338 | # as being in the right package, but in pre-5.10 |
339 | # they show up as constant::__ANON__ so we |
340 | # make an exception here to be sure that things |
341 | # work as expected in both. |
342 | # - SL |
343 | unless ($pkg eq 'constant' && $name eq '__ANON__') { |
344 | next if ($pkg || '') ne $role_name || |
345 | (($name || '') ne '__ANON__' && ($pkg || '') ne $role_name); |
346 | } |
fb1e11d5 |
347 | } |
c4538447 |
348 | |
1b2aea39 |
349 | $map->{$symbol} = $method_metaclass->wrap( |
350 | $code, |
351 | package_name => $role_name, |
352 | name => $name |
353 | ); |
fb1e11d5 |
354 | } |
355 | |
356 | return $map; |
093b12c2 |
357 | } |
358 | |
fb1e11d5 |
359 | sub get_method { |
360 | my ($self, $name) = @_; |
c4538447 |
361 | $self->get_method_map->{$name}; |
fb1e11d5 |
362 | } |
40e89659 |
363 | |
fb1e11d5 |
364 | sub has_method { |
365 | my ($self, $name) = @_; |
366 | exists $self->get_method_map->{$name} ? 1 : 0 |
e185c027 |
367 | } |
368 | |
e606ae5f |
369 | # FIXME this is copypasated from Class::MOP::Class |
370 | # refactor to inherit from some common base |
371 | sub wrap_method_body { |
372 | my ( $self, %args ) = @_; |
373 | |
374 | my $body = delete $args{body}; # delete is for compat |
375 | |
376 | ('CODE' eq ref($body)) |
c245d69b |
377 | || Moose->throw_error("Your code block must be a CODE reference"); |
e606ae5f |
378 | |
379 | $self->method_metaclass->wrap( $body => ( |
380 | package_name => $self->name, |
381 | %args, |
382 | )); |
383 | } |
384 | |
385 | sub add_method { |
386 | my ($self, $method_name, $method) = @_; |
387 | (defined $method_name && $method_name) |
c245d69b |
388 | || Moose->throw_error("You must define a method name"); |
e606ae5f |
389 | |
390 | my $body; |
391 | if (blessed($method)) { |
392 | $body = $method->body; |
393 | if ($method->package_name ne $self->name && |
394 | $method->name ne $method_name) { |
395 | warn "Hello there, got something for you." |
396 | . " Method says " . $method->package_name . " " . $method->name |
397 | . " Class says " . $self->name . " " . $method_name; |
398 | $method = $method->clone( |
399 | package_name => $self->name, |
400 | name => $method_name |
401 | ) if $method->can('clone'); |
402 | } |
403 | } |
404 | else { |
405 | $body = $method; |
406 | $method = $self->wrap_method_body( body => $body, name => $method_name ); |
407 | } |
408 | |
409 | $method->attach_to_class($self); |
410 | |
411 | $self->get_method_map->{$method_name} = $method; |
412 | |
413 | my $full_method_name = ($self->name . '::' . $method_name); |
414 | $self->add_package_symbol( |
415 | { sigil => '&', type => 'CODE', name => $method_name }, |
416 | Class::MOP::subname($full_method_name => $body) |
417 | ); |
418 | |
419 | $self->update_package_cache_flag; # still valid, since we just added the method to the map, and if it was invalid before that then get_method_map updated it |
420 | } |
421 | |
1db8ecc7 |
422 | sub find_method_by_name { (shift)->get_method(@_) } |
093b12c2 |
423 | |
fb1e11d5 |
424 | sub get_method_list { |
425 | my $self = shift; |
426 | grep { !/^meta$/ } keys %{$self->get_method_map}; |
427 | } |
428 | |
429 | sub alias_method { |
430 | my ($self, $method_name, $method) = @_; |
431 | (defined $method_name && $method_name) |
c245d69b |
432 | || Moose->throw_error("You must define a method name"); |
fb1e11d5 |
433 | |
434 | my $body = (blessed($method) ? $method->body : $method); |
21f1e231 |
435 | ('CODE' eq ref($body)) |
c245d69b |
436 | || Moose->throw_error("Your code block must be a CODE reference"); |
fb1e11d5 |
437 | |
8371f6e1 |
438 | $self->add_package_symbol( |
439 | { sigil => '&', type => 'CODE', name => $method_name }, |
440 | $body |
441 | ); |
fb1e11d5 |
442 | } |
443 | |
21716c07 |
444 | ## ------------------------------------------------------------------ |
fb1e11d5 |
445 | ## role construction |
21716c07 |
446 | ## ------------------------------------------------------------------ |
e185c027 |
447 | |
21716c07 |
448 | sub apply { |
bca01282 |
449 | my ($self, $other, @args) = @_; |
450 | |
451 | (blessed($other)) |
c245d69b |
452 | || Moose->throw_error("You must pass in an blessed instance"); |
bca01282 |
453 | |
1c9db35c |
454 | if ($other->isa('Moose::Meta::Role')) { |
455 | require Moose::Meta::Role::Application::ToRole; |
709c321c |
456 | return Moose::Meta::Role::Application::ToRole->new(@args)->apply($self, $other); |
1c9db35c |
457 | } |
458 | elsif ($other->isa('Moose::Meta::Class')) { |
459 | require Moose::Meta::Role::Application::ToClass; |
709c321c |
460 | return Moose::Meta::Role::Application::ToClass->new(@args)->apply($self, $other); |
1c9db35c |
461 | } |
462 | else { |
463 | require Moose::Meta::Role::Application::ToInstance; |
709c321c |
464 | return Moose::Meta::Role::Application::ToInstance->new(@args)->apply($self, $other); |
1c9db35c |
465 | } |
0558683c |
466 | } |
467 | |
21716c07 |
468 | sub combine { |
a4e516f6 |
469 | my ($class, @role_specs) = @_; |
21716c07 |
470 | |
fb1e11d5 |
471 | require Moose::Meta::Role::Application::RoleSummation; |
a4e516f6 |
472 | require Moose::Meta::Role::Composite; |
473 | |
28412c0b |
474 | my (@roles, %role_params); |
475 | while (@role_specs) { |
476 | my ($role, $params) = @{ splice @role_specs, 0, 1 }; |
477 | push @roles => $role->meta; |
478 | next unless defined $params; |
479 | $role_params{$role} = $params; |
480 | } |
21716c07 |
481 | |
fb1e11d5 |
482 | my $c = Moose::Meta::Role::Composite->new(roles => \@roles); |
a4e516f6 |
483 | Moose::Meta::Role::Application::RoleSummation->new( |
28412c0b |
484 | role_params => \%role_params |
a4e516f6 |
485 | )->apply($c); |
28412c0b |
486 | |
fb1e11d5 |
487 | return $c; |
0558683c |
488 | } |
489 | |
fb1e11d5 |
490 | ##################################################################### |
491 | ## NOTE: |
492 | ## This is Moose::Meta::Role as defined by Moose (plus the use of |
493 | ## MooseX::AttributeHelpers module). It is here as a reference to |
494 | ## make it easier to see what is happening above with all the meta |
495 | ## programming. - SL |
496 | ##################################################################### |
497 | # |
498 | # has 'roles' => ( |
499 | # metaclass => 'Collection::Array', |
500 | # reader => 'get_roles', |
501 | # isa => 'ArrayRef[Moose::Meta::Roles]', |
502 | # default => sub { [] }, |
503 | # provides => { |
504 | # 'push' => 'add_role', |
505 | # } |
506 | # ); |
507 | # |
508 | # has 'excluded_roles_map' => ( |
509 | # metaclass => 'Collection::Hash', |
510 | # reader => 'get_excluded_roles_map', |
511 | # isa => 'HashRef[Str]', |
512 | # provides => { |
513 | # # Not exactly set, cause it sets multiple |
514 | # 'set' => 'add_excluded_roles', |
515 | # 'keys' => 'get_excluded_roles_list', |
516 | # 'exists' => 'excludes_role', |
517 | # } |
518 | # ); |
519 | # |
520 | # has 'attribute_map' => ( |
521 | # metaclass => 'Collection::Hash', |
522 | # reader => 'get_attribute_map', |
523 | # isa => 'HashRef[Str]', |
524 | # provides => { |
525 | # # 'set' => 'add_attribute' # has some special crap in it |
526 | # 'get' => 'get_attribute', |
527 | # 'keys' => 'get_attribute_list', |
528 | # 'exists' => 'has_attribute', |
529 | # # Not exactly delete, cause it sets multiple |
530 | # 'delete' => 'remove_attribute', |
531 | # } |
532 | # ); |
533 | # |
534 | # has 'required_methods' => ( |
535 | # metaclass => 'Collection::Hash', |
536 | # reader => 'get_required_methods_map', |
537 | # isa => 'HashRef[Str]', |
538 | # provides => { |
539 | # # not exactly set, or delete since it works for multiple |
540 | # 'set' => 'add_required_methods', |
541 | # 'delete' => 'remove_required_methods', |
542 | # 'keys' => 'get_required_method_list', |
543 | # 'exists' => 'requires_method', |
544 | # } |
545 | # ); |
546 | # |
547 | # # the before, around and after modifiers are |
548 | # # HASH keyed by method-name, with ARRAY of |
549 | # # CODE refs to apply in that order |
550 | # |
551 | # has 'before_method_modifiers' => ( |
552 | # metaclass => 'Collection::Hash', |
553 | # reader => 'get_before_method_modifiers_map', |
554 | # isa => 'HashRef[ArrayRef[CodeRef]]', |
555 | # provides => { |
556 | # 'keys' => 'get_before_method_modifiers', |
557 | # 'exists' => 'has_before_method_modifiers', |
558 | # # This actually makes sure there is an |
559 | # # ARRAY at the given key, and pushed onto |
560 | # # it. It also checks for duplicates as well |
561 | # # 'add' => 'add_before_method_modifier' |
562 | # } |
563 | # ); |
564 | # |
565 | # has 'after_method_modifiers' => ( |
566 | # metaclass => 'Collection::Hash', |
567 | # reader =>'get_after_method_modifiers_map', |
568 | # isa => 'HashRef[ArrayRef[CodeRef]]', |
569 | # provides => { |
570 | # 'keys' => 'get_after_method_modifiers', |
571 | # 'exists' => 'has_after_method_modifiers', |
572 | # # This actually makes sure there is an |
573 | # # ARRAY at the given key, and pushed onto |
574 | # # it. It also checks for duplicates as well |
575 | # # 'add' => 'add_after_method_modifier' |
576 | # } |
577 | # ); |
578 | # |
579 | # has 'around_method_modifiers' => ( |
580 | # metaclass => 'Collection::Hash', |
581 | # reader =>'get_around_method_modifiers_map', |
582 | # isa => 'HashRef[ArrayRef[CodeRef]]', |
583 | # provides => { |
584 | # 'keys' => 'get_around_method_modifiers', |
585 | # 'exists' => 'has_around_method_modifiers', |
586 | # # This actually makes sure there is an |
587 | # # ARRAY at the given key, and pushed onto |
588 | # # it. It also checks for duplicates as well |
589 | # # 'add' => 'add_around_method_modifier' |
590 | # } |
591 | # ); |
592 | # |
593 | # # override is similar to the other modifiers |
594 | # # except that it is not an ARRAY of code refs |
595 | # # but instead just a single name->code mapping |
596 | # |
597 | # has 'override_method_modifiers' => ( |
598 | # metaclass => 'Collection::Hash', |
599 | # reader =>'get_override_method_modifiers_map', |
600 | # isa => 'HashRef[CodeRef]', |
601 | # provides => { |
602 | # 'keys' => 'get_override_method_modifier', |
603 | # 'exists' => 'has_override_method_modifier', |
604 | # 'add' => 'add_override_method_modifier', # checks for local method .. |
605 | # } |
606 | # ); |
607 | # |
608 | ##################################################################### |
609 | |
610 | |
e185c027 |
611 | 1; |
612 | |
613 | __END__ |
614 | |
615 | =pod |
616 | |
617 | =head1 NAME |
618 | |
619 | Moose::Meta::Role - The Moose Role metaclass |
620 | |
621 | =head1 DESCRIPTION |
622 | |
fb1e11d5 |
623 | Please see L<Moose::Role> for more information about roles. |
d44714be |
624 | For the most part, this has no user-serviceable parts inside |
fb1e11d5 |
625 | this module. It's API is still subject to some change (although |
02a0fb52 |
626 | probably not that much really). |
79592a54 |
627 | |
e185c027 |
628 | =head1 METHODS |
629 | |
630 | =over 4 |
631 | |
632 | =item B<meta> |
633 | |
634 | =item B<new> |
635 | |
78cd1d3b |
636 | =item B<apply> |
637 | |
e606ae5f |
638 | =item B<apply_to_metaclass_instance> |
639 | |
db1ab48d |
640 | =item B<combine> |
641 | |
e185c027 |
642 | =back |
643 | |
644 | =over 4 |
645 | |
646 | =item B<name> |
647 | |
648 | =item B<version> |
649 | |
650 | =item B<role_meta> |
651 | |
652 | =back |
653 | |
654 | =over 4 |
655 | |
80572233 |
656 | =item B<get_roles> |
657 | |
658 | =item B<add_role> |
659 | |
660 | =item B<does_role> |
661 | |
662 | =back |
663 | |
664 | =over 4 |
665 | |
d79e62fd |
666 | =item B<add_excluded_roles> |
667 | |
668 | =item B<excludes_role> |
669 | |
670 | =item B<get_excluded_roles_list> |
671 | |
672 | =item B<get_excluded_roles_map> |
673 | |
2b14ac61 |
674 | =item B<calculate_all_roles> |
675 | |
d79e62fd |
676 | =back |
677 | |
678 | =over 4 |
679 | |
68efb014 |
680 | =item B<method_metaclass> |
681 | |
be4427d0 |
682 | =item B<find_method_by_name> |
683 | |
e185c027 |
684 | =item B<get_method> |
685 | |
686 | =item B<has_method> |
687 | |
e606ae5f |
688 | =item B<add_method> |
689 | |
690 | =item B<wrap_method_body> |
691 | |
bdabd620 |
692 | =item B<alias_method> |
693 | |
e185c027 |
694 | =item B<get_method_list> |
695 | |
093b12c2 |
696 | =item B<get_method_map> |
697 | |
638853cb |
698 | =item B<update_package_cache_flag> |
699 | |
53dd42d8 |
700 | =item B<reset_package_cache_flag> |
701 | |
e185c027 |
702 | =back |
703 | |
704 | =over 4 |
705 | |
706 | =item B<add_attribute> |
707 | |
708 | =item B<has_attribute> |
709 | |
710 | =item B<get_attribute> |
711 | |
712 | =item B<get_attribute_list> |
713 | |
714 | =item B<get_attribute_map> |
715 | |
716 | =item B<remove_attribute> |
717 | |
718 | =back |
719 | |
720 | =over 4 |
721 | |
1331430a |
722 | =item B<add_required_methods> |
723 | |
38f1204c |
724 | =item B<remove_required_methods> |
725 | |
1331430a |
726 | =item B<get_required_method_list> |
727 | |
728 | =item B<get_required_methods_map> |
729 | |
730 | =item B<requires_method> |
731 | |
732 | =back |
733 | |
0558683c |
734 | =over 4 |
735 | |
736 | =item B<add_after_method_modifier> |
737 | |
738 | =item B<add_around_method_modifier> |
739 | |
740 | =item B<add_before_method_modifier> |
741 | |
742 | =item B<add_override_method_modifier> |
743 | |
744 | =over 4 |
745 | |
746 | =back |
747 | |
748 | =item B<has_after_method_modifiers> |
749 | |
750 | =item B<has_around_method_modifiers> |
751 | |
752 | =item B<has_before_method_modifiers> |
753 | |
754 | =item B<has_override_method_modifier> |
755 | |
756 | =over 4 |
757 | |
758 | =back |
759 | |
760 | =item B<get_after_method_modifiers> |
761 | |
762 | =item B<get_around_method_modifiers> |
763 | |
764 | =item B<get_before_method_modifiers> |
765 | |
766 | =item B<get_method_modifier_list> |
767 | |
768 | =over 4 |
769 | |
770 | =back |
771 | |
772 | =item B<get_override_method_modifier> |
773 | |
774 | =item B<get_after_method_modifiers_map> |
775 | |
776 | =item B<get_around_method_modifiers_map> |
777 | |
778 | =item B<get_before_method_modifiers_map> |
779 | |
780 | =item B<get_override_method_modifiers_map> |
781 | |
782 | =back |
783 | |
e185c027 |
784 | =head1 BUGS |
785 | |
fb1e11d5 |
786 | All complex software has bugs lurking in it, and this module is no |
e185c027 |
787 | exception. If you find a bug please either email me, or add the bug |
788 | to cpan-RT. |
789 | |
790 | =head1 AUTHOR |
791 | |
792 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
793 | |
794 | =head1 COPYRIGHT AND LICENSE |
795 | |
778db3ac |
796 | Copyright 2006-2008 by Infinity Interactive, Inc. |
e185c027 |
797 | |
798 | L<http://www.iinteractive.com> |
799 | |
800 | This library is free software; you can redistribute it and/or modify |
fb1e11d5 |
801 | it under the same terms as Perl itself. |
e185c027 |
802 | |
b8aeb4dc |
803 | =cut |