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