Commit | Line | Data |
fb1e11d5 |
1 | package Moose::Meta::Role::Application; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use metaclass; |
6 | |
75d2da34 |
7 | our $VERSION = '0.77'; |
75b95414 |
8 | $VERSION = eval $VERSION; |
fb1e11d5 |
9 | our $AUTHORITY = 'cpan:STEVAN'; |
10 | |
c4538447 |
11 | __PACKAGE__->meta->add_attribute('method_exclusions' => ( |
12 | init_arg => 'excludes', |
13 | reader => 'get_method_exclusions', |
14 | default => sub { [] } |
15 | )); |
16 | |
3e19778d |
17 | __PACKAGE__->meta->add_attribute('method_aliases' => ( |
18 | init_arg => 'alias', |
19 | reader => 'get_method_aliases', |
20 | default => sub { {} } |
21 | )); |
22 | |
d03bd989 |
23 | sub new { |
c4538447 |
24 | my ($class, %params) = @_; |
d03bd989 |
25 | |
c4538447 |
26 | if (exists $params{excludes}) { |
27 | # I wish we had coercion here :) |
d03bd989 |
28 | $params{excludes} = (ref $params{excludes} eq 'ARRAY' |
29 | ? $params{excludes} |
c4538447 |
30 | : [ $params{excludes} ]); |
31 | } |
d03bd989 |
32 | |
1b8d1399 |
33 | $class->_new(\%params); |
c4538447 |
34 | } |
35 | |
36 | sub is_method_excluded { |
37 | my ($self, $method_name) = @_; |
38 | foreach (@{$self->get_method_exclusions}) { |
39 | return 1 if $_ eq $method_name; |
40 | } |
41 | return 0; |
42 | } |
fb1e11d5 |
43 | |
3e19778d |
44 | sub is_method_aliased { |
45 | my ($self, $method_name) = @_; |
46 | exists $self->get_method_aliases->{$method_name} ? 1 : 0 |
47 | } |
48 | |
49 | sub is_aliased_method { |
50 | my ($self, $method_name) = @_; |
51 | my %aliased_names = reverse %{$self->get_method_aliases}; |
52 | exists $aliased_names{$method_name} ? 1 : 0; |
53 | } |
54 | |
fb1e11d5 |
55 | sub apply { |
1c9db35c |
56 | my $self = shift; |
fb1e11d5 |
57 | |
1c9db35c |
58 | $self->check_role_exclusions(@_); |
59 | $self->check_required_methods(@_); |
709c321c |
60 | $self->check_required_attributes(@_); |
d03bd989 |
61 | |
1c9db35c |
62 | $self->apply_attributes(@_); |
d03bd989 |
63 | $self->apply_methods(@_); |
64 | |
1c9db35c |
65 | $self->apply_override_method_modifiers(@_); |
d03bd989 |
66 | |
1c9db35c |
67 | $self->apply_before_method_modifiers(@_); |
68 | $self->apply_around_method_modifiers(@_); |
69 | $self->apply_after_method_modifiers(@_); |
fb1e11d5 |
70 | } |
71 | |
547dda77 |
72 | sub check_role_exclusions { Carp::croak "Abstract Method" } |
73 | sub check_required_methods { Carp::croak "Abstract Method" } |
74 | sub check_required_attributes { Carp::croak "Abstract Method" } |
75 | |
76 | sub apply_attributes { Carp::croak "Abstract Method" } |
77 | sub apply_methods { Carp::croak "Abstract Method" } |
78 | sub apply_override_method_modifiers { Carp::croak "Abstract Method" } |
79 | sub apply_method_modifiers { Carp::croak "Abstract Method" } |
bca01282 |
80 | |
81 | sub apply_before_method_modifiers { (shift)->apply_method_modifiers('before' => @_) } |
82 | sub apply_around_method_modifiers { (shift)->apply_method_modifiers('around' => @_) } |
83 | sub apply_after_method_modifiers { (shift)->apply_method_modifiers('after' => @_) } |
fb1e11d5 |
84 | |
85 | 1; |
86 | |
87 | __END__ |
88 | |
89 | =pod |
90 | |
91 | =head1 NAME |
92 | |
ab76842e |
93 | Moose::Meta::Role::Application - A base class for role application |
fb1e11d5 |
94 | |
95 | =head1 DESCRIPTION |
96 | |
97 | This is the abstract base class for role applications. |
98 | |
a5583b3a |
99 | The API for this class and its subclasses still needs some |
100 | consideration, and is intentionally not yet documented. |
101 | |
fb1e11d5 |
102 | =head2 METHODS |
103 | |
104 | =over 4 |
105 | |
106 | =item B<new> |
107 | |
108 | =item B<meta> |
109 | |
c4538447 |
110 | =item B<get_method_exclusions> |
111 | |
112 | =item B<is_method_excluded> |
113 | |
3e19778d |
114 | =item B<get_method_aliases> |
115 | |
116 | =item B<is_aliased_method> |
117 | |
118 | =item B<is_method_aliased> |
119 | |
fb1e11d5 |
120 | =item B<apply> |
121 | |
709c321c |
122 | =item B<check_role_exclusions> |
123 | |
fb1e11d5 |
124 | =item B<check_required_methods> |
125 | |
709c321c |
126 | =item B<check_required_attributes> |
fb1e11d5 |
127 | |
128 | =item B<apply_attributes> |
129 | |
130 | =item B<apply_methods> |
131 | |
132 | =item B<apply_method_modifiers> |
133 | |
134 | =item B<apply_before_method_modifiers> |
135 | |
136 | =item B<apply_after_method_modifiers> |
137 | |
138 | =item B<apply_around_method_modifiers> |
139 | |
140 | =item B<apply_override_method_modifiers> |
141 | |
142 | =back |
143 | |
144 | =head1 BUGS |
145 | |
146 | All complex software has bugs lurking in it, and this module is no |
147 | exception. If you find a bug please either email me, or add the bug |
148 | to cpan-RT. |
149 | |
150 | =head1 AUTHOR |
151 | |
152 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
153 | |
154 | =head1 COPYRIGHT AND LICENSE |
155 | |
2840a3b2 |
156 | Copyright 2006-2009 by Infinity Interactive, Inc. |
fb1e11d5 |
157 | |
158 | L<http://www.iinteractive.com> |
159 | |
160 | This library is free software; you can redistribute it and/or modify |
161 | it under the same terms as Perl itself. |
162 | |
163 | =cut |
164 | |