d9d4c2f1dc9d3f84efadaf55c96189fd454b55fa
[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     Class::MOP::_definition_context(),
12 ));
13
14 __PACKAGE__->meta->add_attribute('method_aliases' => (
15     init_arg => '-alias',
16     reader   => 'get_method_aliases',
17     default  => sub { {} },
18     Class::MOP::_definition_context(),
19 ));
20
21 sub new {
22     my ($class, %params) = @_;
23     $class->_new(\%params);
24 }
25
26 sub 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 }
33
34 sub is_method_aliased {
35     my ($self, $method_name) = @_;
36     exists $self->get_method_aliases->{$method_name} ? 1 : 0
37 }
38
39 sub 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
45 sub apply {
46     my $self = shift;
47
48     $self->check_role_exclusions(@_);
49     $self->check_required_methods(@_);
50     $self->check_required_attributes(@_);
51
52     $self->apply_attributes(@_);
53     $self->apply_methods(@_);
54
55     $self->apply_override_method_modifiers(@_);
56
57     $self->apply_before_method_modifiers(@_);
58     $self->apply_around_method_modifiers(@_);
59     $self->apply_after_method_modifiers(@_);
60 }
61
62 sub check_role_exclusions           { Carp::croak "Abstract Method" }
63 sub check_required_methods          { Carp::croak "Abstract Method" }
64 sub check_required_attributes       { Carp::croak "Abstract Method" }
65
66 sub apply_attributes                { Carp::croak "Abstract Method" }
67 sub apply_methods                   { Carp::croak "Abstract Method" }
68 sub apply_override_method_modifiers { Carp::croak "Abstract Method" }
69 sub apply_method_modifiers          { Carp::croak "Abstract Method" }
70
71 sub apply_before_method_modifiers   { (shift)->apply_method_modifiers('before' => @_) }
72 sub apply_around_method_modifiers   { (shift)->apply_method_modifiers('around' => @_) }
73 sub apply_after_method_modifiers    { (shift)->apply_method_modifiers('after'  => @_) }
74
75 1;
76
77 # ABSTRACT: A base class for role application
78
79 __END__
80
81 =pod
82
83 =head1 DESCRIPTION
84
85 This is the abstract base class for role applications.
86
87 The API for this class and its subclasses still needs some
88 consideration, and is intentionally not yet documented.
89
90 =head2 METHODS
91
92 =over 4
93
94 =item B<new>
95
96 =item B<meta>
97
98 =item B<get_method_exclusions>
99
100 =item B<is_method_excluded>
101
102 =item B<get_method_aliases>
103
104 =item B<is_aliased_method>
105
106 =item B<is_method_aliased>
107
108 =item B<apply>
109
110 =item B<check_role_exclusions>
111
112 =item B<check_required_methods>
113
114 =item B<check_required_attributes>
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
134 See L<Moose/BUGS> for details on reporting bugs.
135
136 =cut
137