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 | |
d03bd989 |
21 | sub new { |
c4538447 |
22 | my ($class, %params) = @_; |
1b8d1399 |
23 | $class->_new(\%params); |
c4538447 |
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 | } |
fb1e11d5 |
33 | |
3e19778d |
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 | |
fb1e11d5 |
45 | sub 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 |
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" } |
bca01282 |
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' => @_) } |
fb1e11d5 |
74 | |
75 | 1; |
76 | |
ad46f524 |
77 | # ABSTRACT: A base class for role application |
78 | |
fb1e11d5 |
79 | __END__ |
80 | |
81 | =pod |
82 | |
fb1e11d5 |
83 | =head1 DESCRIPTION |
84 | |
85 | This is the abstract base class for role applications. |
86 | |
a5583b3a |
87 | The API for this class and its subclasses still needs some |
88 | consideration, 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 |
134 | See L<Moose/BUGS> for details on reporting bugs. |
fb1e11d5 |
135 | |
fb1e11d5 |
136 | =cut |
137 | |