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