Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Moose / Meta / Role.pm
CommitLineData
3fea05b9 1
2package Moose::Meta::Role;
3
4use strict;
5use warnings;
6use metaclass;
7
8use Scalar::Util 'blessed';
9use Carp 'confess';
10use Devel::GlobalDestruction 'in_global_destruction';
11
12our $VERSION = '0.93';
13$VERSION = eval $VERSION;
14our $AUTHORITY = 'cpan:STEVAN';
15
16use Moose::Meta::Class;
17use Moose::Meta::Role::Method;
18use Moose::Meta::Role::Method::Required;
19use Moose::Meta::Role::Method::Conflicting;
20
21use base 'Class::MOP::Module';
22
23## ------------------------------------------------------------------
24## NOTE:
25## I normally don't do this, but I am doing
26## a whole bunch of meta-programmin in this
27## module, so it just makes sense. For a clearer
28## picture of what is going on in the next
29## several lines of code, look at the really
30## big comment at the end of this file (right
31## before the POD).
32## - SL
33## ------------------------------------------------------------------
34
35my $META = __PACKAGE__->meta;
36
37## ------------------------------------------------------------------
38## attributes ...
39
40# NOTE:
41# since roles are lazy, we hold all the attributes
42# of the individual role in 'statis' until which
43# time when it is applied to a class. This means
44# keeping a lot of things in hash maps, so we are
45# using a little of that meta-programmin' magic
46# here an saving lots of extra typin. And since
47# many of these attributes above require similar
48# functionality to support them, so we again use
49# the wonders of meta-programmin' to deliver a
50# very compact solution to this normally verbose
51# problem.
52# - SL
53
54foreach my $action (
55 {
56 name => 'excluded_roles_map',
57 attr_reader => 'get_excluded_roles_map' ,
58 methods => {
59 add => 'add_excluded_roles',
60 get_keys => 'get_excluded_roles_list',
61 existence => 'excludes_role',
62 }
63 },
64 {
65 name => 'required_methods',
66 attr_reader => 'get_required_methods_map',
67 methods => {
68 remove => 'remove_required_methods',
69 get_values => 'get_required_method_list',
70 existence => 'requires_method',
71 }
72 },
73 {
74 name => '_attribute_map',
75 attr_reader => '_attribute_map',
76 methods => {
77 get => 'get_attribute',
78 get_keys => 'get_attribute_list',
79 existence => 'has_attribute',
80 remove => 'remove_attribute',
81 }
82 }
83) {
84
85 my $attr_reader = $action->{attr_reader};
86 my $methods = $action->{methods};
87
88 # create the attribute
89 $META->add_attribute($action->{name} => (
90 reader => $attr_reader,
91 default => sub { {} }
92 ));
93
94 # create some helper methods
95 $META->add_method($methods->{add} => sub {
96 my ($self, @values) = @_;
97 $self->$attr_reader->{$_} = undef foreach @values;
98 }) if exists $methods->{add};
99
100 $META->add_method($methods->{get_keys} => sub {
101 my ($self) = @_;
102 keys %{$self->$attr_reader};
103 }) if exists $methods->{get_keys};
104
105 $META->add_method($methods->{get_values} => sub {
106 my ($self) = @_;
107 values %{$self->$attr_reader};
108 }) if exists $methods->{get_values};
109
110 $META->add_method($methods->{get} => sub {
111 my ($self, $name) = @_;
112 $self->$attr_reader->{$name}
113 }) if exists $methods->{get};
114
115 $META->add_method($methods->{existence} => sub {
116 my ($self, $name) = @_;
117 exists $self->$attr_reader->{$name} ? 1 : 0;
118 }) if exists $methods->{existence};
119
120 $META->add_method($methods->{remove} => sub {
121 my ($self, @values) = @_;
122 delete $self->$attr_reader->{$_} foreach @values;
123 }) if exists $methods->{remove};
124}
125
126$META->add_attribute(
127 'method_metaclass',
128 reader => 'method_metaclass',
129 default => 'Moose::Meta::Role::Method',
130);
131
132$META->add_attribute(
133 'required_method_metaclass',
134 reader => 'required_method_metaclass',
135 default => 'Moose::Meta::Role::Method::Required',
136);
137
138$META->add_attribute(
139 'conflicting_method_metaclass',
140 reader => 'conflicting_method_metaclass',
141 default => 'Moose::Meta::Role::Method::Conflicting',
142);
143
144$META->add_attribute(
145 'application_to_class_class',
146 reader => 'application_to_class_class',
147 default => 'Moose::Meta::Role::Application::ToClass',
148);
149
150$META->add_attribute(
151 'application_to_role_class',
152 reader => 'application_to_role_class',
153 default => 'Moose::Meta::Role::Application::ToRole',
154);
155
156$META->add_attribute(
157 'application_to_instance_class',
158 reader => 'application_to_instance_class',
159 default => 'Moose::Meta::Role::Application::ToInstance',
160);
161
162$META->add_attribute(
163 'composition_class_roles',
164 reader => 'composition_class_roles',
165 predicate => 'has_composition_class_roles',
166);
167
168## some things don't always fit, so they go here ...
169
170sub add_attribute {
171 my $self = shift;
172 my $name = shift;
173 unless ( defined $name ) {
174 require Moose;
175 Moose->throw_error("You must provide a name for the attribute");
176 }
177 my $attr_desc;
178 if (scalar @_ == 1 && ref($_[0]) eq 'HASH') {
179 $attr_desc = $_[0];
180 }
181 else {
182 $attr_desc = { @_ };
183 }
184 $self->_attribute_map->{$name} = $attr_desc;
185}
186
187sub add_required_methods {
188 my $self = shift;
189
190 for (@_) {
191 my $method = $_;
192 if (!blessed($method)) {
193 $method = $self->required_method_metaclass->new(
194 name => $method,
195 );
196 }
197 $self->get_required_methods_map->{$method->name} = $method;
198 }
199}
200
201sub add_conflicting_method {
202 my $self = shift;
203
204 my $method;
205 if (@_ == 1 && blessed($_[0])) {
206 $method = shift;
207 }
208 else {
209 $method = $self->conflicting_method_metaclass->new(@_);
210 }
211
212 $self->add_required_methods($method);
213}
214
215## ------------------------------------------------------------------
216## method modifiers
217
218# NOTE:
219# the before/around/after method modifiers are
220# stored by name, but there can be many methods
221# then associated with that name. So again we have
222# lots of similar functionality, so we can do some
223# meta-programmin' and save some time.
224# - SL
225
226foreach my $modifier_type (qw[ before around after ]) {
227
228 my $attr_reader = "get_${modifier_type}_method_modifiers_map";
229
230 # create the attribute ...
231 $META->add_attribute("${modifier_type}_method_modifiers" => (
232 reader => $attr_reader,
233 default => sub { {} }
234 ));
235
236 # and some helper methods ...
237 $META->add_method("get_${modifier_type}_method_modifiers" => sub {
238 my ($self, $method_name) = @_;
239 #return () unless exists $self->$attr_reader->{$method_name};
240 my $mm = $self->$attr_reader->{$method_name};
241 $mm ? @$mm : ();
242 });
243
244 $META->add_method("has_${modifier_type}_method_modifiers" => sub {
245 my ($self, $method_name) = @_;
246 # NOTE:
247 # for now we assume that if it exists,..
248 # it has at least one modifier in it
249 (exists $self->$attr_reader->{$method_name}) ? 1 : 0;
250 });
251
252 $META->add_method("add_${modifier_type}_method_modifier" => sub {
253 my ($self, $method_name, $method) = @_;
254
255 $self->$attr_reader->{$method_name} = []
256 unless exists $self->$attr_reader->{$method_name};
257
258 my $modifiers = $self->$attr_reader->{$method_name};
259
260 # NOTE:
261 # check to see that we aren't adding the
262 # same code twice. We err in favor of the
263 # first on here, this may not be as expected
264 foreach my $modifier (@{$modifiers}) {
265 return if $modifier == $method;
266 }
267
268 push @{$modifiers} => $method;
269 });
270
271}
272
273## ------------------------------------------------------------------
274## override method mofidiers
275
276$META->add_attribute('override_method_modifiers' => (
277 reader => 'get_override_method_modifiers_map',
278 default => sub { {} }
279));
280
281# NOTE:
282# these are a little different because there
283# can only be one per name, whereas the other
284# method modifiers can have multiples.
285# - SL
286
287sub add_override_method_modifier {
288 my ($self, $method_name, $method) = @_;
289 (!$self->has_method($method_name))
290 || Moose->throw_error("Cannot add an override of method '$method_name' " .
291 "because there is a local version of '$method_name'");
292 $self->get_override_method_modifiers_map->{$method_name} = $method;
293}
294
295sub has_override_method_modifier {
296 my ($self, $method_name) = @_;
297 # NOTE:
298 # for now we assume that if it exists,..
299 # it has at least one modifier in it
300 (exists $self->get_override_method_modifiers_map->{$method_name}) ? 1 : 0;
301}
302
303sub get_override_method_modifier {
304 my ($self, $method_name) = @_;
305 $self->get_override_method_modifiers_map->{$method_name};
306}
307
308## general list accessor ...
309
310sub get_method_modifier_list {
311 my ($self, $modifier_type) = @_;
312 my $accessor = "get_${modifier_type}_method_modifiers_map";
313 keys %{$self->$accessor};
314}
315
316sub reset_package_cache_flag { (shift)->{'_package_cache_flag'} = undef }
317sub update_package_cache_flag {
318 my $self = shift;
319 $self->{'_package_cache_flag'} = Class::MOP::check_package_cache_flag($self->name);
320}
321
322
323
324## ------------------------------------------------------------------
325## subroles
326
327$META->add_attribute('roles' => (
328 reader => 'get_roles',
329 default => sub { [] }
330));
331
332sub add_role {
333 my ($self, $role) = @_;
334 (blessed($role) && $role->isa('Moose::Meta::Role'))
335 || Moose->throw_error("Roles must be instances of Moose::Meta::Role");
336 push @{$self->get_roles} => $role;
337 $self->reset_package_cache_flag;
338}
339
340sub calculate_all_roles {
341 my $self = shift;
342 my %seen;
343 grep {
344 !$seen{$_->name}++
345 } ($self, map {
346 $_->calculate_all_roles
347 } @{ $self->get_roles });
348}
349
350sub does_role {
351 my ($self, $role_name) = @_;
352 (defined $role_name)
353 || Moose->throw_error("You must supply a role name to look for");
354 # if we are it,.. then return true
355 return 1 if $role_name eq $self->name;
356 # otherwise.. check our children
357 foreach my $role (@{$self->get_roles}) {
358 return 1 if $role->does_role($role_name);
359 }
360 return 0;
361}
362
363sub find_method_by_name { (shift)->get_method(@_) }
364
365sub alias_method {
366 Carp::cluck("The alias_method method is deprecated. Use add_method instead.\n");
367
368 my $self = shift;
369
370 $self->add_method(@_);
371}
372
373## ------------------------------------------------------------------
374## role construction
375## ------------------------------------------------------------------
376
377sub apply {
378 my ($self, $other, @args) = @_;
379
380 (blessed($other))
381 || Moose->throw_error("You must pass in an blessed instance");
382
383 my $application_class;
384 if ($other->isa('Moose::Meta::Role')) {
385 $application_class = $self->application_to_role_class;
386 }
387 elsif ($other->isa('Moose::Meta::Class')) {
388 $application_class = $self->application_to_class_class;
389 }
390 else {
391 $application_class = $self->application_to_instance_class;
392 }
393
394 Class::MOP::load_class($application_class);
395 return $application_class->new(@args)->apply($self, $other);
396}
397
398sub combine {
399 my ($class, @role_specs) = @_;
400
401 require Moose::Meta::Role::Composite;
402
403 my (@roles, %role_params);
404 while (@role_specs) {
405 my ($role_name, $params) = @{ splice @role_specs, 0, 1 };
406 my $requested_role = Class::MOP::class_of($role_name);
407
408 my $actual_role = $requested_role->_role_for_combination($params);
409 push @roles => $actual_role;
410
411 next unless defined $params;
412 $role_params{$actual_role->name} = $params;
413 }
414
415 my $c = Moose::Meta::Role::Composite->new(roles => \@roles);
416 return $c->apply_params(\%role_params);
417}
418
419sub _role_for_combination {
420 my ($self, $params) = @_;
421 return $self;
422}
423
424sub create {
425 my ( $role, $package_name, %options ) = @_;
426
427 $options{package} = $package_name;
428
429 (ref $options{attributes} eq 'HASH')
430 || confess "You must pass a HASH ref of attributes"
431 if exists $options{attributes};
432
433 (ref $options{methods} eq 'HASH')
434 || confess "You must pass a HASH ref of methods"
435 if exists $options{methods};
436
437 my (%initialize_options) = %options;
438 delete @initialize_options{qw(
439 package
440 attributes
441 methods
442 version
443 authority
444 )};
445
446 my $meta = $role->initialize( $package_name => %initialize_options );
447
448 $meta->_instantiate_module( $options{version}, $options{authority} );
449
450 # FIXME totally lame
451 $meta->add_method('meta' => sub {
452 $role->initialize(ref($_[0]) || $_[0]);
453 });
454
455 if (exists $options{attributes}) {
456 foreach my $attribute_name (keys %{$options{attributes}}) {
457 my $attr = $options{attributes}->{$attribute_name};
458 $meta->add_attribute($attribute_name => $attr);
459 }
460 }
461
462 if (exists $options{methods}) {
463 foreach my $method_name (keys %{$options{methods}}) {
464 $meta->add_method($method_name, $options{methods}->{$method_name});
465 }
466 }
467
468 Class::MOP::weaken_metaclass($meta->name)
469 if $meta->is_anon_role;
470
471 return $meta;
472}
473
474# anonymous roles. most of it is copied straight out of Class::MOP::Class.
475# an intrepid hacker might find great riches if he unifies this code with that
476# code in Class::MOP::Module or Class::MOP::Package
477{
478 # NOTE:
479 # this should be sufficient, if you have a
480 # use case where it is not, write a test and
481 # I will change it.
482 my $ANON_ROLE_SERIAL = 0;
483
484 # NOTE:
485 # we need a sufficiently annoying prefix
486 # this should suffice for now, this is
487 # used in a couple of places below, so
488 # need to put it up here for now.
489 my $ANON_ROLE_PREFIX = 'Moose::Meta::Role::__ANON__::SERIAL::';
490
491 sub is_anon_role {
492 my $self = shift;
493 no warnings 'uninitialized';
494 $self->name =~ /^$ANON_ROLE_PREFIX/;
495 }
496
497 sub create_anon_role {
498 my ($role, %options) = @_;
499 my $package_name = $ANON_ROLE_PREFIX . ++$ANON_ROLE_SERIAL;
500 return $role->create($package_name, %options);
501 }
502
503 # NOTE:
504 # this will only get called for
505 # anon-roles, all other calls
506 # are assumed to occur during
507 # global destruction and so don't
508 # really need to be handled explicitly
509 sub DESTROY {
510 my $self = shift;
511
512 return if in_global_destruction(); # it'll happen soon anyway and this just makes things more complicated
513
514 no warnings 'uninitialized';
515 return unless $self->name =~ /^$ANON_ROLE_PREFIX/;
516
517 # XXX: is this necessary for us? I don't understand what it's doing
518 # -sartak
519
520 # Moose does a weird thing where it replaces the metaclass for
521 # class when fixing metaclass incompatibility. In that case,
522 # we don't want to clean out the namespace now. We can detect
523 # that because Moose will explicitly update the singleton
524 # cache in Class::MOP.
525 #my $current_meta = Class::MOP::get_metaclass_by_name($self->name);
526 #return if $current_meta ne $self;
527
528 my ($serial_id) = ($self->name =~ /^$ANON_ROLE_PREFIX(\d+)/);
529 no strict 'refs';
530 foreach my $key (keys %{$ANON_ROLE_PREFIX . $serial_id}) {
531 delete ${$ANON_ROLE_PREFIX . $serial_id}{$key};
532 }
533 delete ${'main::' . $ANON_ROLE_PREFIX}{$serial_id . '::'};
534 }
535}
536
537#####################################################################
538## NOTE:
539## This is Moose::Meta::Role as defined by Moose (plus the use of
540## MooseX::AttributeHelpers module). It is here as a reference to
541## make it easier to see what is happening above with all the meta
542## programming. - SL
543#####################################################################
544#
545# has 'roles' => (
546# metaclass => 'Array',
547# reader => 'get_roles',
548# isa => 'ArrayRef[Moose::Meta::Role]',
549# default => sub { [] },
550# provides => {
551# 'push' => 'add_role',
552# }
553# );
554#
555# has 'excluded_roles_map' => (
556# metaclass => 'Hash',
557# reader => 'get_excluded_roles_map',
558# isa => 'HashRef[Str]',
559# provides => {
560# # Not exactly set, cause it sets multiple
561# 'set' => 'add_excluded_roles',
562# 'keys' => 'get_excluded_roles_list',
563# 'exists' => 'excludes_role',
564# }
565# );
566#
567# has 'attribute_map' => (
568# metaclass => 'Hash',
569# reader => '_attribute_map',
570# isa => 'HashRef[Str]',
571# provides => {
572# # 'set' => 'add_attribute' # has some special crap in it
573# 'get' => 'get_attribute',
574# 'keys' => 'get_attribute_list',
575# 'exists' => 'has_attribute',
576# # Not exactly delete, cause it sets multiple
577# 'delete' => 'remove_attribute',
578# }
579# );
580#
581# has 'required_methods' => (
582# metaclass => 'Hash',
583# reader => 'get_required_methods_map',
584# isa => 'HashRef[Moose::Meta::Role::Method::Required]',
585# provides => {
586# # not exactly set, or delete since it works for multiple
587# 'set' => 'add_required_methods',
588# 'delete' => 'remove_required_methods',
589# 'keys' => 'get_required_method_list',
590# 'exists' => 'requires_method',
591# }
592# );
593#
594# # the before, around and after modifiers are
595# # HASH keyed by method-name, with ARRAY of
596# # CODE refs to apply in that order
597#
598# has 'before_method_modifiers' => (
599# metaclass => 'Hash',
600# reader => 'get_before_method_modifiers_map',
601# isa => 'HashRef[ArrayRef[CodeRef]]',
602# provides => {
603# 'keys' => 'get_before_method_modifiers',
604# 'exists' => 'has_before_method_modifiers',
605# # This actually makes sure there is an
606# # ARRAY at the given key, and pushed onto
607# # it. It also checks for duplicates as well
608# # 'add' => 'add_before_method_modifier'
609# }
610# );
611#
612# has 'after_method_modifiers' => (
613# metaclass => 'Hash',
614# reader =>'get_after_method_modifiers_map',
615# isa => 'HashRef[ArrayRef[CodeRef]]',
616# provides => {
617# 'keys' => 'get_after_method_modifiers',
618# 'exists' => 'has_after_method_modifiers',
619# # This actually makes sure there is an
620# # ARRAY at the given key, and pushed onto
621# # it. It also checks for duplicates as well
622# # 'add' => 'add_after_method_modifier'
623# }
624# );
625#
626# has 'around_method_modifiers' => (
627# metaclass => 'Hash',
628# reader =>'get_around_method_modifiers_map',
629# isa => 'HashRef[ArrayRef[CodeRef]]',
630# provides => {
631# 'keys' => 'get_around_method_modifiers',
632# 'exists' => 'has_around_method_modifiers',
633# # This actually makes sure there is an
634# # ARRAY at the given key, and pushed onto
635# # it. It also checks for duplicates as well
636# # 'add' => 'add_around_method_modifier'
637# }
638# );
639#
640# # override is similar to the other modifiers
641# # except that it is not an ARRAY of code refs
642# # but instead just a single name->code mapping
643#
644# has 'override_method_modifiers' => (
645# metaclass => 'Hash',
646# reader =>'get_override_method_modifiers_map',
647# isa => 'HashRef[CodeRef]',
648# provides => {
649# 'keys' => 'get_override_method_modifier',
650# 'exists' => 'has_override_method_modifier',
651# 'add' => 'add_override_method_modifier', # checks for local method ..
652# }
653# );
654#
655#####################################################################
656
657
6581;
659
660__END__
661
662=pod
663
664=head1 NAME
665
666Moose::Meta::Role - The Moose Role metaclass
667
668=head1 DESCRIPTION
669
670This class is a subclass of L<Class::MOP::Module> that provides
671additional Moose-specific functionality.
672
673It's API looks a lot like L<Moose::Meta::Class>, but internally it
674implements many things differently. This may change in the future.
675
676=head1 INHERITANCE
677
678C<Moose::Meta::Role> is a subclass of L<Class::MOP::Module>.
679
680=head1 METHODS
681
682=head2 Construction
683
684=over 4
685
686=item B<< Moose::Meta::Role->initialize($role_name) >>
687
688This method creates a new role object with the provided name.
689
690=item B<< Moose::Meta::Role->combine( [ $role => { ... } ], [ $role ], ... ) >>
691
692This method accepts a list of array references. Each array reference
693should contain a role name as its first element. The second element is
694an optional hash reference. The hash reference can contain C<-excludes>
695and C<-alias> keys to control how methods are composed from the role.
696
697The return value is a new L<Moose::Meta::Role::Composite> that
698represents the combined roles.
699
700=item B<< Moose::Meta::Role->create($name, %options) >>
701
702This method is identical to the L<Moose::Meta::Class> C<create>
703method.
704
705=item B<< Moose::Meta::Role->create_anon_role >>
706
707This method is identical to the L<Moose::Meta::Class>
708C<create_anon_class> method.
709
710=item B<< $metarole->is_anon_role >>
711
712Returns true if the role is an anonymous role.
713
714=back
715
716=head2 Role application
717
718=over 4
719
720=item B<< $metarole->apply( $thing, @options ) >>
721
722This method applies a role to the given C<$thing>. That can be another
723L<Moose::Meta::Role>, object, a L<Moose::Meta::Class> object, or a
724(non-meta) object instance.
725
726The options are passed directly to the constructor for the appropriate
727L<Moose::Meta::Role::Application> subclass.
728
729Note that this will apply the role even if the C<$thing> in question already
730C<does> this role. L<Moose::Util/does_role> is a convenient wrapper for
731finding out if role application is necessary.
732
733=back
734
735=head2 Roles and other roles
736
737=over 4
738
739=item B<< $metarole->get_roles >>
740
741This returns an array reference of roles which this role does. This
742list may include duplicates.
743
744=item B<< $metarole->calculate_all_roles >>
745
746This returns a I<unique> list of all roles that this role does, and
747all the roles that its roles do.
748
749=item B<< $metarole->does_role($role_name) >>
750
751Given a role I<name>, returns true if this role does the given
752role.
753
754=item B<< $metarole->add_role($role) >>
755
756Given a L<Moose::Meta::Role> object, this adds the role to the list of
757roles that the role does.
758
759=item B<< $metarole->get_excluded_roles_list >>
760
761Returns a list of role names which this role excludes.
762
763=item B<< $metarole->excludes_role($role_name) >>
764
765Given a role I<name>, returns true if this role excludes the named
766role.
767
768=item B<< $metarole->add_excluded_roles(@role_names) >>
769
770Given one or more role names, adds those roles to the list of excluded
771roles.
772
773=back
774
775=head2 Methods
776
777The methods for dealing with a role's methods are all identical in API
778and behavior to the same methods in L<Class::MOP::Class>.
779
780=over 4
781
782=item B<< $metarole->method_metaclass >>
783
784Returns the method metaclass name for the role. This defaults to
785L<Moose::Meta::Role::Method>.
786
787=item B<< $metarole->get_method($name) >>
788
789=item B<< $metarole->has_method($name) >>
790
791=item B<< $metarole->add_method( $name, $body ) >>
792
793=item B<< $metarole->get_method_list >>
794
795=item B<< $metarole->find_method_by_name($name) >>
796
797These methods are all identical to the methods of the same name in
798L<Class::MOP::Package>
799
800=back
801
802=head2 Attributes
803
804As with methods, the methods for dealing with a role's attribute are
805all identical in API and behavior to the same methods in
806L<Class::MOP::Class>.
807
808However, attributes stored in this class are I<not> stored as
809objects. Rather, the attribute definition is stored as a hash
810reference. When a role is composed into a class, this hash reference
811is passed directly to the metaclass's C<add_attribute> method.
812
813This is quite likely to change in the future.
814
815=over 4
816
817=item B<< $metarole->get_attribute($attribute_name) >>
818
819=item B<< $metarole->has_attribute($attribute_name) >>
820
821=item B<< $metarole->get_attribute_list >>
822
823=item B<< $metarole->add_attribute($name, %options) >>
824
825=item B<< $metarole->remove_attribute($attribute_name) >>
826
827=back
828
829=head2 Required methods
830
831=over 4
832
833=item B<< $metarole->get_required_method_list >>
834
835Returns the list of methods required by the role.
836
837=item B<< $metarole->requires_method($name) >>
838
839Returns true if the role requires the named method.
840
841=item B<< $metarole->add_required_methods(@names) >>
842
843Adds the named methods to the role's list of required methods.
844
845=item B<< $metarole->remove_required_methods(@names) >>
846
847Removes the named methods from the role's list of required methods.
848
849=item B<< $metarole->add_conflicting_method(%params) >>
850
851Instantiate the parameters as a L<Moose::Meta::Role::Method::Conflicting>
852object, then add it to the required method list.
853
854=back
855
856=head2 Method modifiers
857
858These methods act like their counterparts in L<Class::Mop::Class> and
859L<Moose::Meta::Class>.
860
861However, method modifiers are simply stored internally, and are not
862applied until the role itself is applied to a class.
863
864=over 4
865
866=item B<< $metarole->add_after_method_modifier($method_name, $method) >>
867
868=item B<< $metarole->add_around_method_modifier($method_name, $method) >>
869
870=item B<< $metarole->add_before_method_modifier($method_name, $method) >>
871
872=item B<< $metarole->add_override_method_modifier($method_name, $method) >>
873
874These methods all add an appropriate modifier to the internal list of
875modifiers.
876
877=item B<< $metarole->has_after_method_modifiers >>
878
879=item B<< $metarole->has_around_method_modifiers >>
880
881=item B<< $metarole->has_before_method_modifiers >>
882
883=item B<< $metarole->has_override_method_modifier >>
884
885Return true if the role has any modifiers of the given type.
886
887=item B<< $metarole->get_after_method_modifiers($method_name) >>
888
889=item B<< $metarole->get_around_method_modifiers($method_name) >>
890
891=item B<< $metarole->get_before_method_modifiers($method_name) >>
892
893Given a method name, returns a list of the appropriate modifiers for
894that method.
895
896=item B<< $metarole->get_override_method_modifier($method_name) >>
897
898Given a method name, returns the override method modifier for that
899method, if it has one.
900
901=back
902
903=head2 Introspection
904
905=over 4
906
907=item B<< Moose::Meta::Role->meta >>
908
909This will return a L<Class::MOP::Class> instance for this class.
910
911=back
912
913=head1 BUGS
914
915All complex software has bugs lurking in it, and this module is no
916exception. If you find a bug please either email me, or add the bug
917to cpan-RT.
918
919=head1 AUTHOR
920
921Stevan Little E<lt>stevan@iinteractive.comE<gt>
922
923=head1 COPYRIGHT AND LICENSE
924
925Copyright 2006-2009 by Infinity Interactive, Inc.
926
927L<http://www.iinteractive.com>
928
929This library is free software; you can redistribute it and/or modify
930it under the same terms as Perl itself.
931
932=cut