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',
23 __PACKAGE__->meta->add_attribute('fire_alias_excludes_warning' => (
24 init_arg => 'fire_alias_excludes_warning',
25 reader => 'fire_alias_excludes_warning',
30 my ($class, %params) = @_;
32 if ( exists $params{excludes} || exists $params{alias} ) {
33 $params{fire_alias_excludes_warning} = 1;
36 if ( exists $params{excludes} && !exists $params{'-excludes'} ) {
37 $params{'-excludes'} = delete $params{excludes};
39 if ( exists $params{alias} && !exists $params{'-alias'} ) {
40 $params{'-alias'} = delete $params{alias};
43 if ( exists $params{'-excludes'} ) {
45 # I wish we had coercion here :)
46 $params{'-excludes'} = (
47 ref $params{'-excludes'} eq 'ARRAY'
48 ? $params{'-excludes'}
49 : [ $params{'-excludes'} ]
53 $class->_new(\%params);
56 sub is_method_excluded {
57 my ($self, $method_name) = @_;
58 foreach (@{$self->get_method_exclusions}) {
59 return 1 if $_ eq $method_name;
64 sub is_method_aliased {
65 my ($self, $method_name) = @_;
66 exists $self->get_method_aliases->{$method_name} ? 1 : 0
69 sub is_aliased_method {
70 my ($self, $method_name) = @_;
71 my %aliased_names = reverse %{$self->get_method_aliases};
72 exists $aliased_names{$method_name} ? 1 : 0;
78 if ($self->fire_alias_excludes_warning) {
79 Moose::Deprecated::deprecated(
80 feature => 'alias or excludes',
82 "The alias and excludes options for role application have been renamed -alias and -excludes (applying ${\$_[0]->name} to ${\$_[1]->name} - do you need to upgrade ${\$_[1]->name}?)"
86 $self->check_role_exclusions(@_);
87 $self->check_required_methods(@_);
88 $self->check_required_attributes(@_);
90 $self->apply_attributes(@_);
91 $self->apply_methods(@_);
93 $self->apply_override_method_modifiers(@_);
95 $self->apply_before_method_modifiers(@_);
96 $self->apply_around_method_modifiers(@_);
97 $self->apply_after_method_modifiers(@_);
100 sub check_role_exclusions { Carp::croak "Abstract Method" }
101 sub check_required_methods { Carp::croak "Abstract Method" }
102 sub check_required_attributes { Carp::croak "Abstract Method" }
104 sub apply_attributes { Carp::croak "Abstract Method" }
105 sub apply_methods { Carp::croak "Abstract Method" }
106 sub apply_override_method_modifiers { Carp::croak "Abstract Method" }
107 sub apply_method_modifiers { Carp::croak "Abstract Method" }
109 sub apply_before_method_modifiers { (shift)->apply_method_modifiers('before' => @_) }
110 sub apply_around_method_modifiers { (shift)->apply_method_modifiers('around' => @_) }
111 sub apply_after_method_modifiers { (shift)->apply_method_modifiers('after' => @_) }
121 Moose::Meta::Role::Application - A base class for role application
125 This is the abstract base class for role applications.
127 The API for this class and its subclasses still needs some
128 consideration, and is intentionally not yet documented.
138 =item B<get_method_exclusions>
140 =item B<is_method_excluded>
142 =item B<get_method_aliases>
144 =item B<is_aliased_method>
146 =item B<is_method_aliased>
150 =item B<check_role_exclusions>
152 =item B<check_required_methods>
154 =item B<check_required_attributes>
156 =item B<apply_attributes>
158 =item B<apply_methods>
160 =item B<apply_method_modifiers>
162 =item B<apply_before_method_modifiers>
164 =item B<apply_after_method_modifiers>
166 =item B<apply_around_method_modifiers>
168 =item B<apply_override_method_modifiers>
174 See L<Moose/BUGS> for details on reporting bugs.
178 Stevan Little E<lt>stevan@iinteractive.comE<gt>
180 =head1 COPYRIGHT AND LICENSE
182 Copyright 2006-2010 by Infinity Interactive, Inc.
184 L<http://www.iinteractive.com>
186 This library is free software; you can redistribute it and/or modify
187 it under the same terms as Perl itself.