Beginning of dzilization
[gitmo/Moose.git] / lib / Moose / Meta / Role / Application.pm
CommitLineData
fb1e11d5 1package Moose::Meta::Role::Application;
2
3use strict;
4use warnings;
5use metaclass;
6
fb1e11d5 7our $AUTHORITY = 'cpan:STEVAN';
8
c4538447 9__PACKAGE__->meta->add_attribute('method_exclusions' => (
c8b8d92f 10 init_arg => '-excludes',
c4538447 11 reader => 'get_method_exclusions',
12 default => sub { [] }
13));
14
3e19778d 15__PACKAGE__->meta->add_attribute('method_aliases' => (
c8b8d92f 16 init_arg => '-alias',
3e19778d 17 reader => 'get_method_aliases',
18 default => sub { {} }
19));
20
d03bd989 21sub new {
c4538447 22 my ($class, %params) = @_;
1b8d1399 23 $class->_new(\%params);
c4538447 24}
25
26sub is_method_excluded {
27 my ($self, $method_name) = @_;
28 foreach (@{$self->get_method_exclusions}) {
29 return 1 if $_ eq $method_name;
30 }
31 return 0;
32}
fb1e11d5 33
3e19778d 34sub is_method_aliased {
35 my ($self, $method_name) = @_;
36 exists $self->get_method_aliases->{$method_name} ? 1 : 0
37}
38
39sub is_aliased_method {
40 my ($self, $method_name) = @_;
41 my %aliased_names = reverse %{$self->get_method_aliases};
42 exists $aliased_names{$method_name} ? 1 : 0;
43}
44
fb1e11d5 45sub apply {
1c9db35c 46 my $self = shift;
fb1e11d5 47
1c9db35c 48 $self->check_role_exclusions(@_);
49 $self->check_required_methods(@_);
709c321c 50 $self->check_required_attributes(@_);
d03bd989 51
1c9db35c 52 $self->apply_attributes(@_);
d03bd989 53 $self->apply_methods(@_);
54
1c9db35c 55 $self->apply_override_method_modifiers(@_);
d03bd989 56
1c9db35c 57 $self->apply_before_method_modifiers(@_);
58 $self->apply_around_method_modifiers(@_);
59 $self->apply_after_method_modifiers(@_);
fb1e11d5 60}
61
547dda77 62sub check_role_exclusions { Carp::croak "Abstract Method" }
63sub check_required_methods { Carp::croak "Abstract Method" }
64sub check_required_attributes { Carp::croak "Abstract Method" }
65
66sub apply_attributes { Carp::croak "Abstract Method" }
67sub apply_methods { Carp::croak "Abstract Method" }
68sub apply_override_method_modifiers { Carp::croak "Abstract Method" }
69sub apply_method_modifiers { Carp::croak "Abstract Method" }
bca01282 70
71sub apply_before_method_modifiers { (shift)->apply_method_modifiers('before' => @_) }
72sub apply_around_method_modifiers { (shift)->apply_method_modifiers('around' => @_) }
73sub apply_after_method_modifiers { (shift)->apply_method_modifiers('after' => @_) }
fb1e11d5 74
751;
76
ad46f524 77# ABSTRACT: A base class for role application
78
fb1e11d5 79__END__
80
81=pod
82
fb1e11d5 83=head1 DESCRIPTION
84
85This is the abstract base class for role applications.
86
a5583b3a 87The API for this class and its subclasses still needs some
88consideration, and is intentionally not yet documented.
89
fb1e11d5 90=head2 METHODS
91
92=over 4
93
94=item B<new>
95
96=item B<meta>
97
c4538447 98=item B<get_method_exclusions>
99
100=item B<is_method_excluded>
101
3e19778d 102=item B<get_method_aliases>
103
104=item B<is_aliased_method>
105
106=item B<is_method_aliased>
107
fb1e11d5 108=item B<apply>
109
709c321c 110=item B<check_role_exclusions>
111
fb1e11d5 112=item B<check_required_methods>
113
709c321c 114=item B<check_required_attributes>
fb1e11d5 115
116=item B<apply_attributes>
117
118=item B<apply_methods>
119
120=item B<apply_method_modifiers>
121
122=item B<apply_before_method_modifiers>
123
124=item B<apply_after_method_modifiers>
125
126=item B<apply_around_method_modifiers>
127
128=item B<apply_override_method_modifiers>
129
130=back
131
132=head1 BUGS
133
d4048ef3 134See L<Moose/BUGS> for details on reporting bugs.
fb1e11d5 135
fb1e11d5 136=cut
137