1 package Moose::Meta::Role::Application;
8 $VERSION = eval $VERSION;
9 our $AUTHORITY = 'cpan:STEVAN';
11 __PACKAGE__->meta->add_attribute('method_exclusions' => (
12 init_arg => 'excludes',
13 reader => 'get_method_exclusions',
17 __PACKAGE__->meta->add_attribute('method_aliases' => (
19 reader => 'get_method_aliases',
24 my ($class, %params) = @_;
26 if (exists $params{excludes}) {
27 # I wish we had coercion here :)
28 $params{excludes} = (ref $params{excludes} eq 'ARRAY'
30 : [ $params{excludes} ]);
33 $class->_new(\%params);
36 sub is_method_excluded {
37 my ($self, $method_name) = @_;
38 foreach (@{$self->get_method_exclusions}) {
39 return 1 if $_ eq $method_name;
44 sub is_method_aliased {
45 my ($self, $method_name) = @_;
46 exists $self->get_method_aliases->{$method_name} ? 1 : 0
49 sub is_aliased_method {
50 my ($self, $method_name) = @_;
51 my %aliased_names = reverse %{$self->get_method_aliases};
52 exists $aliased_names{$method_name} ? 1 : 0;
58 $self->check_role_exclusions(@_);
59 $self->check_required_methods(@_);
60 $self->check_required_attributes(@_);
62 $self->apply_attributes(@_);
63 $self->apply_methods(@_);
65 $self->apply_override_method_modifiers(@_);
67 $self->apply_before_method_modifiers(@_);
68 $self->apply_around_method_modifiers(@_);
69 $self->apply_after_method_modifiers(@_);
72 sub check_role_exclusions { Carp::croak "Abstract Method" }
73 sub check_required_methods { Carp::croak "Abstract Method" }
74 sub check_required_attributes { Carp::croak "Abstract Method" }
76 sub apply_attributes { Carp::croak "Abstract Method" }
77 sub apply_methods { Carp::croak "Abstract Method" }
78 sub apply_override_method_modifiers { Carp::croak "Abstract Method" }
79 sub apply_method_modifiers { Carp::croak "Abstract Method" }
81 sub apply_before_method_modifiers { (shift)->apply_method_modifiers('before' => @_) }
82 sub apply_around_method_modifiers { (shift)->apply_method_modifiers('around' => @_) }
83 sub apply_after_method_modifiers { (shift)->apply_method_modifiers('after' => @_) }
93 Moose::Meta::Role::Application - A base class for role application
97 This is the abstract base class for role applications. Role
98 application is the logic of composing a role into something. That
99 something could be a class, another role, or an object instance.
105 =item B<< Moose::Meta::Role::Application->new(%options) >>
107 This method returns a new role application. It accepts several
114 This is an optional array reference of methods to be excluded when
119 This is an optional hash reference of methods to be renamed when
120 applying the role. The keys are the original method names, and the
121 values are the new method names.
125 Note that the constructor does not actually take any roles as
128 =item B<< $application->get_method_exclusions >>
130 Returns an array reference containing the names of the excluded
133 =item B<< $application->is_method_excluded($method_name) >>
135 Given a method name, returns true if the method is excluded.
137 =item B<< $application->get_method_aliases >>
139 Returns the hash reference of method aliases passed to the
142 =item B<< $application->is_aliased_method($method_name) >>
144 This takes the name of the original method, and returns true if it is
147 =item B<< $application->is_method_aliased($method_name) >>
149 Returns true if the method name given is being used as the I<new> name
152 =item B<< $application->apply($role, $thing) >>
154 This method implements the logic of role application by calling the
155 various check and apply methods below. Any arguments passed to this
156 method are simply passed on to the other methods, without any
159 The first argument is always a L<Moose::Meta::Role> object, and the
160 second is the thing to which the role is being applied.
162 In some cases, the second
164 =item B<< $application->check_role_exclusions(...) >>
166 A virtual method. Subclasses are expected to throw an error if
168 =item B<check_required_methods>
170 =item B<check_required_attributes>
172 =item B<apply_attributes>
174 =item B<apply_methods>
176 =item B<apply_method_modifiers>
178 =item B<apply_before_method_modifiers>
180 =item B<apply_after_method_modifiers>
182 =item B<apply_around_method_modifiers>
184 =item B<apply_override_method_modifiers>
192 All complex software has bugs lurking in it, and this module is no
193 exception. If you find a bug please either email me, or add the bug
198 Stevan Little E<lt>stevan@iinteractive.comE<gt>
200 =head1 COPYRIGHT AND LICENSE
202 Copyright 2006-2009 by Infinity Interactive, Inc.
204 L<http://www.iinteractive.com>
206 This library is free software; you can redistribute it and/or modify
207 it under the same terms as Perl itself.