bump version to 1.12
[gitmo/Moose.git] / lib / Moose / Meta / Role / Application.pm
CommitLineData
fb1e11d5 1package Moose::Meta::Role::Application;
2
3use strict;
4use warnings;
5use metaclass;
6
55d05fb1 7our $VERSION = '1.12';
75b95414 8$VERSION = eval $VERSION;
fb1e11d5 9our $AUTHORITY = 'cpan:STEVAN';
10
c4538447 11__PACKAGE__->meta->add_attribute('method_exclusions' => (
c8b8d92f 12 init_arg => '-excludes',
c4538447 13 reader => 'get_method_exclusions',
14 default => sub { [] }
15));
16
3e19778d 17__PACKAGE__->meta->add_attribute('method_aliases' => (
c8b8d92f 18 init_arg => '-alias',
3e19778d 19 reader => 'get_method_aliases',
20 default => sub { {} }
21));
22
d03bd989 23sub new {
c4538447 24 my ($class, %params) = @_;
d03bd989 25
82f8ace6 26 if ( exists $params{excludes} || exists $params{alias} ) {
a1224bfc 27 # Moose::Deprecated::deprecated(
28 # feature => 'alias or excludes',
29 # message =>
30 # "The alias and excludes options for role application have been renamed -alias and -excludes"
31 # );
82f8ace6 32 }
33
3a4fc1c0 34 if ( exists $params{excludes} && !exists $params{'-excludes'} ) {
c8b8d92f 35 $params{'-excludes'} = delete $params{excludes};
36 }
3a4fc1c0 37 if ( exists $params{alias} && !exists $params{'-alias'} ) {
c8b8d92f 38 $params{'-alias'} = delete $params{alias};
39 }
40
3a4fc1c0 41 if ( exists $params{'-excludes'} ) {
42
c4538447 43 # I wish we had coercion here :)
3a4fc1c0 44 $params{'-excludes'} = (
45 ref $params{'-excludes'} eq 'ARRAY'
46 ? $params{'-excludes'}
47 : [ $params{'-excludes'} ]
48 );
c4538447 49 }
d03bd989 50
1b8d1399 51 $class->_new(\%params);
c4538447 52}
53
54sub is_method_excluded {
55 my ($self, $method_name) = @_;
56 foreach (@{$self->get_method_exclusions}) {
57 return 1 if $_ eq $method_name;
58 }
59 return 0;
60}
fb1e11d5 61
3e19778d 62sub is_method_aliased {
63 my ($self, $method_name) = @_;
64 exists $self->get_method_aliases->{$method_name} ? 1 : 0
65}
66
67sub is_aliased_method {
68 my ($self, $method_name) = @_;
69 my %aliased_names = reverse %{$self->get_method_aliases};
70 exists $aliased_names{$method_name} ? 1 : 0;
71}
72
fb1e11d5 73sub apply {
1c9db35c 74 my $self = shift;
fb1e11d5 75
1c9db35c 76 $self->check_role_exclusions(@_);
77 $self->check_required_methods(@_);
709c321c 78 $self->check_required_attributes(@_);
d03bd989 79
1c9db35c 80 $self->apply_attributes(@_);
d03bd989 81 $self->apply_methods(@_);
82
1c9db35c 83 $self->apply_override_method_modifiers(@_);
d03bd989 84
1c9db35c 85 $self->apply_before_method_modifiers(@_);
86 $self->apply_around_method_modifiers(@_);
87 $self->apply_after_method_modifiers(@_);
fb1e11d5 88}
89
547dda77 90sub check_role_exclusions { Carp::croak "Abstract Method" }
91sub check_required_methods { Carp::croak "Abstract Method" }
92sub check_required_attributes { Carp::croak "Abstract Method" }
93
94sub apply_attributes { Carp::croak "Abstract Method" }
95sub apply_methods { Carp::croak "Abstract Method" }
96sub apply_override_method_modifiers { Carp::croak "Abstract Method" }
97sub apply_method_modifiers { Carp::croak "Abstract Method" }
bca01282 98
99sub apply_before_method_modifiers { (shift)->apply_method_modifiers('before' => @_) }
100sub apply_around_method_modifiers { (shift)->apply_method_modifiers('around' => @_) }
101sub apply_after_method_modifiers { (shift)->apply_method_modifiers('after' => @_) }
fb1e11d5 102
1031;
104
105__END__
106
107=pod
108
109=head1 NAME
110
ab76842e 111Moose::Meta::Role::Application - A base class for role application
fb1e11d5 112
113=head1 DESCRIPTION
114
115This is the abstract base class for role applications.
116
a5583b3a 117The API for this class and its subclasses still needs some
118consideration, and is intentionally not yet documented.
119
fb1e11d5 120=head2 METHODS
121
122=over 4
123
124=item B<new>
125
126=item B<meta>
127
c4538447 128=item B<get_method_exclusions>
129
130=item B<is_method_excluded>
131
3e19778d 132=item B<get_method_aliases>
133
134=item B<is_aliased_method>
135
136=item B<is_method_aliased>
137
fb1e11d5 138=item B<apply>
139
709c321c 140=item B<check_role_exclusions>
141
fb1e11d5 142=item B<check_required_methods>
143
709c321c 144=item B<check_required_attributes>
fb1e11d5 145
146=item B<apply_attributes>
147
148=item B<apply_methods>
149
150=item B<apply_method_modifiers>
151
152=item B<apply_before_method_modifiers>
153
154=item B<apply_after_method_modifiers>
155
156=item B<apply_around_method_modifiers>
157
158=item B<apply_override_method_modifiers>
159
160=back
161
162=head1 BUGS
163
d4048ef3 164See L<Moose/BUGS> for details on reporting bugs.
fb1e11d5 165
166=head1 AUTHOR
167
168Stevan Little E<lt>stevan@iinteractive.comE<gt>
169
170=head1 COPYRIGHT AND LICENSE
171
7e0492d3 172Copyright 2006-2010 by Infinity Interactive, Inc.
fb1e11d5 173
174L<http://www.iinteractive.com>
175
176This library is free software; you can redistribute it and/or modify
177it under the same terms as Perl itself.
178
179=cut
180