line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moose::Meta::Role::Application::ToClass; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2205'; |
3
|
|
|
|
|
|
|
|
4
|
377
|
|
|
377
|
|
3139
|
use strict; |
|
377
|
|
|
|
|
1181
|
|
|
377
|
|
|
|
|
12227
|
|
5
|
377
|
|
|
377
|
|
2371
|
use warnings; |
|
377
|
|
|
|
|
1111
|
|
|
377
|
|
|
|
|
9579
|
|
6
|
377
|
|
|
377
|
|
2276
|
use metaclass; |
|
377
|
|
|
|
|
1105
|
|
|
377
|
|
|
|
|
2491
|
|
7
|
|
|
|
|
|
|
|
8
|
377
|
|
|
377
|
|
3171
|
use List::Util 'first'; |
|
377
|
|
|
|
|
1218
|
|
|
377
|
|
|
|
|
27943
|
|
9
|
377
|
|
|
377
|
|
3132
|
use Moose::Util 'throw_exception'; |
|
377
|
|
|
|
|
1325
|
|
|
377
|
|
|
|
|
3249
|
|
10
|
377
|
|
|
377
|
|
100991
|
use Scalar::Util 'weaken'; |
|
377
|
|
|
|
|
1312
|
|
|
377
|
|
|
|
|
20337
|
|
11
|
|
|
|
|
|
|
|
12
|
377
|
|
|
377
|
|
2831
|
use parent 'Moose::Meta::Role::Application'; |
|
377
|
|
|
|
|
1252
|
|
|
377
|
|
|
|
|
2659
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute('role' => ( |
15
|
|
|
|
|
|
|
reader => 'role', |
16
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
17
|
|
|
|
|
|
|
)); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute('class' => ( |
20
|
|
|
|
|
|
|
accessor => 'class', |
21
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
22
|
|
|
|
|
|
|
)); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub apply { |
25
|
1117
|
|
|
1117
|
1
|
3781
|
my ($self, $role, $class) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# We need weak_ref in CMOP :( |
28
|
1117
|
|
|
|
|
5874
|
weaken($self->{role} = $role); |
29
|
1117
|
|
|
|
|
4668
|
weaken($self->{class} = $class); |
30
|
|
|
|
|
|
|
|
31
|
1117
|
|
|
|
|
6275
|
$self->SUPER::apply($role, $class); |
32
|
|
|
|
|
|
|
|
33
|
1082
|
|
|
|
|
6197
|
$class->add_role($role); |
34
|
1082
|
|
|
|
|
6095
|
$class->add_role_application($self); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub check_role_exclusions { |
38
|
1117
|
|
|
1117
|
1
|
3336
|
my ($self, $role, $class) = @_; |
39
|
1117
|
100
|
|
|
|
11519
|
if ($class->excludes_role($role->name)) { |
40
|
3
|
|
|
|
|
32
|
throw_exception( ConflictDetectedInCheckRoleExclusionsInToClass => class_name => $class->name, |
41
|
|
|
|
|
|
|
role_name => $role->name, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
} |
44
|
1114
|
|
|
|
|
5892
|
foreach my $excluded_role_name ($role->get_excluded_roles_list) { |
45
|
5
|
100
|
|
|
|
33
|
if ($class->does_role($excluded_role_name)) { |
46
|
1
|
|
|
|
|
11
|
throw_exception( ClassDoesTheExcludedRole => role_name => $role->name, |
47
|
|
|
|
|
|
|
excluded_role_name => $excluded_role_name, |
48
|
|
|
|
|
|
|
class_name => $class->name, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub check_required_methods { |
55
|
1113
|
|
|
1113
|
1
|
3467
|
my ($self, $role, $class) = @_; |
56
|
|
|
|
|
|
|
|
57
|
1113
|
|
|
|
|
2891
|
my @missing; |
58
|
|
|
|
|
|
|
my @is_attr; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# NOTE: |
61
|
|
|
|
|
|
|
# we might need to move this down below the |
62
|
|
|
|
|
|
|
# the attributes so that we can require any |
63
|
|
|
|
|
|
|
# attribute accessors. However I am thinking |
64
|
|
|
|
|
|
|
# that maybe those are somehow exempt from |
65
|
|
|
|
|
|
|
# the require methods stuff. |
66
|
1113
|
|
|
|
|
4545
|
foreach my $required_method ($role->get_required_method_list) { |
67
|
169
|
|
|
|
|
5501
|
my $required_method_name = $required_method->name; |
68
|
|
|
|
|
|
|
|
69
|
168
|
100
|
|
|
|
853
|
if (!$class->find_method_by_name($required_method_name)) { |
70
|
|
|
|
|
|
|
|
71
|
41
|
100
|
|
|
|
241
|
next if $self->is_aliased_method($required_method_name); |
72
|
|
|
|
|
|
|
|
73
|
40
|
|
|
|
|
138
|
push @missing, $required_method; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
1112
|
100
|
|
|
|
5240
|
return unless @missing; |
78
|
|
|
|
|
|
|
|
79
|
29
|
|
|
|
|
133
|
my $error = ''; |
80
|
|
|
|
|
|
|
|
81
|
28
|
|
|
|
|
122
|
@missing = sort { $a->name cmp $b->name } @missing; |
|
14
|
|
|
|
|
459
|
|
82
|
28
|
|
|
|
|
107
|
my @conflicts = grep { $_->isa('Moose::Meta::Role::Method::Conflicting') } @missing; |
|
40
|
|
|
|
|
339
|
|
83
|
|
|
|
|
|
|
|
84
|
28
|
100
|
|
|
|
151
|
if (@conflicts) { |
|
|
50
|
|
|
|
|
|
85
|
10
|
|
|
|
|
52
|
my $conflict = $conflicts[0]; |
86
|
10
|
|
|
|
|
60
|
my $roles = $conflict->roles_as_english_list; |
87
|
|
|
|
|
|
|
|
88
|
10
|
|
|
|
|
42
|
my @same_role_conflicts = grep { $_->roles_as_english_list eq $roles } @conflicts; |
|
14
|
|
|
|
|
45
|
|
89
|
|
|
|
|
|
|
|
90
|
10
|
|
|
|
|
83
|
throw_exception( MethodNameConflictInRoles => conflict => \@same_role_conflicts, |
91
|
|
|
|
|
|
|
class_name => $class->name |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif (@missing) { |
95
|
18
|
100
|
|
26
|
|
152
|
if (my $meth = first { $class->name->can($_) } @missing) { |
|
26
|
|
|
|
|
281
|
|
96
|
2
|
|
|
|
|
21
|
throw_exception( RequiredMethodsImportedByClass => class_name => $class->name, |
97
|
|
|
|
|
|
|
role_name => $role->name, |
98
|
|
|
|
|
|
|
missing_methods => \@missing, |
99
|
|
|
|
|
|
|
imported_method => $meth |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else { |
103
|
16
|
|
|
|
|
216
|
throw_exception( RequiredMethodsNotImplementedByClass => class_name => $class->name, |
104
|
|
|
|
|
|
|
role_name => $role->name, |
105
|
|
|
|
|
|
|
missing_methods => \@missing, |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
1084
|
1
|
|
sub check_required_attributes { |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub apply_attributes { |
116
|
1085
|
|
|
1085
|
1
|
4016
|
my ($self, $role, $class) = @_; |
117
|
|
|
|
|
|
|
|
118
|
1085
|
|
|
|
|
5902
|
foreach my $attribute_name ($role->get_attribute_list) { |
119
|
|
|
|
|
|
|
# it if it has one already |
120
|
656
|
100
|
66
|
|
|
3430
|
if ($class->has_attribute($attribute_name) && |
121
|
|
|
|
|
|
|
# make sure we haven't seen this one already too |
122
|
|
|
|
|
|
|
$class->get_attribute($attribute_name) != $role->get_attribute($attribute_name)) { |
123
|
2
|
|
|
|
|
7
|
next; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
else { |
126
|
654
|
|
|
|
|
4431
|
$class->add_attribute( |
127
|
|
|
|
|
|
|
$role->get_attribute($attribute_name)->attribute_for_class |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub apply_methods { |
134
|
1085
|
|
|
1085
|
1
|
3544
|
my ( $self, $role, $class ) = @_; |
135
|
|
|
|
|
|
|
|
136
|
1085
|
|
|
|
|
5778
|
foreach my $method ( $role->_get_local_methods ) { |
137
|
8681
|
|
|
|
|
30586
|
my $method_name = $method->name; |
138
|
|
|
|
|
|
|
|
139
|
8681
|
100
|
|
|
|
35842
|
next if $method->isa('Class::MOP::Method::Meta'); |
140
|
|
|
|
|
|
|
|
141
|
7723
|
100
|
|
|
|
19418
|
unless ( $self->is_method_excluded($method_name) ) { |
142
|
|
|
|
|
|
|
|
143
|
7717
|
|
|
|
|
22518
|
my $class_method = $class->get_method($method_name); |
144
|
|
|
|
|
|
|
|
145
|
7717
|
100
|
66
|
|
|
18834
|
next if $class_method && $class_method->body != $method->body; |
146
|
|
|
|
|
|
|
|
147
|
7705
|
|
|
|
|
19063
|
$class->add_method( |
148
|
|
|
|
|
|
|
$method_name, |
149
|
|
|
|
|
|
|
$method, |
150
|
|
|
|
|
|
|
); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
7711
|
100
|
|
|
|
24423
|
next unless $self->is_method_aliased($method_name); |
154
|
|
|
|
|
|
|
|
155
|
12
|
|
|
|
|
439
|
my $aliased_method_name = $self->get_method_aliases->{$method_name}; |
156
|
|
|
|
|
|
|
|
157
|
12
|
|
|
|
|
54
|
my $class_method = $class->get_method($aliased_method_name); |
158
|
|
|
|
|
|
|
|
159
|
12
|
100
|
66
|
|
|
148
|
if ( $class_method && $class_method->body != $method->body ) { |
160
|
2
|
|
|
|
|
25
|
throw_exception( CannotCreateMethodAliasLocalMethodIsPresentInClass => aliased_method_name => $aliased_method_name, |
161
|
|
|
|
|
|
|
method => $method, |
162
|
|
|
|
|
|
|
role_name => $role->name, |
163
|
|
|
|
|
|
|
class_name => $class->name, |
164
|
|
|
|
|
|
|
); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
$class->add_method( |
168
|
10
|
|
|
|
|
53
|
$aliased_method_name, |
169
|
|
|
|
|
|
|
$method, |
170
|
|
|
|
|
|
|
); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# we must reset the cache here since |
174
|
|
|
|
|
|
|
# we are just aliasing methods, otherwise |
175
|
|
|
|
|
|
|
# the modifiers go wonky. |
176
|
1083
|
|
|
|
|
7059
|
$class->reset_package_cache_flag; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub apply_override_method_modifiers { |
180
|
1083
|
|
|
1083
|
1
|
3327
|
my ($self, $role, $class) = @_; |
181
|
1083
|
|
|
|
|
4641
|
foreach my $method_name ($role->get_method_modifier_list('override')) { |
182
|
|
|
|
|
|
|
# it if it has one already then ... |
183
|
997
|
100
|
|
|
|
3407
|
if ($class->has_method($method_name)) { |
184
|
3
|
|
|
|
|
8
|
next; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
else { |
187
|
|
|
|
|
|
|
# if this is not a role, then we need to |
188
|
|
|
|
|
|
|
# find the original package of the method |
189
|
|
|
|
|
|
|
# so that we can tell the class were to |
190
|
|
|
|
|
|
|
# find the right super() method |
191
|
994
|
|
|
|
|
3711
|
my $method = $role->get_override_method_modifier($method_name); |
192
|
994
|
|
|
|
|
4561
|
my ($package) = Class::MOP::get_code_info($method); |
193
|
|
|
|
|
|
|
# if it is a class, we just add it |
194
|
994
|
|
|
|
|
3934
|
$class->add_override_method_modifier($method_name, $method, $package); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub apply_method_modifiers { |
200
|
3246
|
|
|
3246
|
1
|
8349
|
my ($self, $modifier_type, $role, $class) = @_; |
201
|
3246
|
|
|
|
|
7999
|
my $add = "add_${modifier_type}_method_modifier"; |
202
|
3246
|
|
|
|
|
6739
|
my $get = "get_${modifier_type}_method_modifiers"; |
203
|
3246
|
|
|
|
|
8857
|
foreach my $method_name ($role->get_method_modifier_list($modifier_type)) { |
204
|
|
|
|
|
|
|
$class->$add( |
205
|
|
|
|
|
|
|
$method_name, |
206
|
|
|
|
|
|
|
$_ |
207
|
1086
|
|
|
|
|
4765
|
) foreach $role->$get($method_name); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
1; |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
# ABSTRACT: Compose a role into a class |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
__END__ |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=pod |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=encoding UTF-8 |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 NAME |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Moose::Meta::Role::Application::ToClass - Compose a role into a class |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 VERSION |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
version 2.2205 |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 DESCRIPTION |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 METHODS |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=over 4 |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item B<new> |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item B<meta> |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=item B<apply> |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item B<check_role_exclusions> |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=item B<check_required_methods> |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=item B<check_required_attributes> |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=item B<apply_attributes> |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=item B<apply_methods> |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=item B<apply_method_modifiers> |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=item B<apply_override_method_modifiers> |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=back |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 BUGS |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
See L<Moose/BUGS> for details on reporting bugs. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 AUTHORS |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=over 4 |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=item * |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Stevan Little <stevan@cpan.org> |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=item * |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=item * |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Jesse Luehrs <doy@cpan.org> |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=item * |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
Shawn M Moore <sartak@cpan.org> |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item * |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item * |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item * |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=item * |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
Hans Dieter Pearcey <hdp@cpan.org> |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=item * |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
Chris Prather <chris@prather.org> |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=item * |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
Matt S Trout <mstrout@cpan.org> |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=back |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
This software is copyright (c) 2006 by Infinity Interactive, Inc. |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
312
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=cut |