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