| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Moose::Meta::Role::Application::ToClass; |
|
2
|
|
|
|
|
|
|
our $VERSION = '2.2206'; |
|
3
|
|
|
|
|
|
|
|
|
4
|
377
|
|
|
377
|
|
3147
|
use strict; |
|
|
377
|
|
|
|
|
1115
|
|
|
|
377
|
|
|
|
|
12375
|
|
|
5
|
377
|
|
|
377
|
|
2361
|
use warnings; |
|
|
377
|
|
|
|
|
1119
|
|
|
|
377
|
|
|
|
|
9672
|
|
|
6
|
377
|
|
|
377
|
|
2160
|
use metaclass; |
|
|
377
|
|
|
|
|
1072
|
|
|
|
377
|
|
|
|
|
2536
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
377
|
|
|
377
|
|
3212
|
use List::Util 'first'; |
|
|
377
|
|
|
|
|
1268
|
|
|
|
377
|
|
|
|
|
27734
|
|
|
9
|
377
|
|
|
377
|
|
3092
|
use Moose::Util 'throw_exception'; |
|
|
377
|
|
|
|
|
1297
|
|
|
|
377
|
|
|
|
|
3473
|
|
|
10
|
377
|
|
|
377
|
|
100135
|
use Scalar::Util 'weaken'; |
|
|
377
|
|
|
|
|
1269
|
|
|
|
377
|
|
|
|
|
20463
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
377
|
|
|
377
|
|
2867
|
use parent 'Moose::Meta::Role::Application'; |
|
|
377
|
|
|
|
|
1171
|
|
|
|
377
|
|
|
|
|
2727
|
|
|
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
|
3686
|
my ($self, $role, $class) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# We need weak_ref in CMOP :( |
|
28
|
1117
|
|
|
|
|
5853
|
weaken($self->{role} = $role); |
|
29
|
1117
|
|
|
|
|
4642
|
weaken($self->{class} = $class); |
|
30
|
|
|
|
|
|
|
|
|
31
|
1117
|
|
|
|
|
6217
|
$self->SUPER::apply($role, $class); |
|
32
|
|
|
|
|
|
|
|
|
33
|
1082
|
|
|
|
|
6355
|
$class->add_role($role); |
|
34
|
1082
|
|
|
|
|
6162
|
$class->add_role_application($self); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub check_role_exclusions { |
|
38
|
1117
|
|
|
1117
|
1
|
3218
|
my ($self, $role, $class) = @_; |
|
39
|
1117
|
100
|
|
|
|
11439
|
if ($class->excludes_role($role->name)) { |
|
40
|
3
|
|
|
|
|
22
|
throw_exception( ConflictDetectedInCheckRoleExclusionsInToClass => class_name => $class->name, |
|
41
|
|
|
|
|
|
|
role_name => $role->name, |
|
42
|
|
|
|
|
|
|
); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
1114
|
|
|
|
|
6060
|
foreach my $excluded_role_name ($role->get_excluded_roles_list) { |
|
45
|
5
|
100
|
|
|
|
23
|
if ($class->does_role($excluded_role_name)) { |
|
46
|
1
|
|
|
|
|
8
|
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
|
3354
|
my ($self, $role, $class) = @_; |
|
56
|
|
|
|
|
|
|
|
|
57
|
1113
|
|
|
|
|
2845
|
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
|
|
|
|
|
4493
|
foreach my $required_method ($role->get_required_method_list) { |
|
67
|
169
|
|
|
|
|
5378
|
my $required_method_name = $required_method->name; |
|
68
|
|
|
|
|
|
|
|
|
69
|
168
|
100
|
|
|
|
824
|
if (!$class->find_method_by_name($required_method_name)) { |
|
70
|
|
|
|
|
|
|
|
|
71
|
41
|
100
|
|
|
|
202
|
next if $self->is_aliased_method($required_method_name); |
|
72
|
|
|
|
|
|
|
|
|
73
|
40
|
|
|
|
|
149
|
push @missing, $required_method; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
1112
|
100
|
|
|
|
5090
|
return unless @missing; |
|
78
|
|
|
|
|
|
|
|
|
79
|
29
|
|
|
|
|
131
|
my $error = ''; |
|
80
|
|
|
|
|
|
|
|
|
81
|
28
|
|
|
|
|
111
|
@missing = sort { $a->name cmp $b->name } @missing; |
|
|
16
|
|
|
|
|
479
|
|
|
82
|
28
|
|
|
|
|
93
|
my @conflicts = grep { $_->isa('Moose::Meta::Role::Method::Conflicting') } @missing; |
|
|
40
|
|
|
|
|
359
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
28
|
100
|
|
|
|
129
|
if (@conflicts) { |
|
|
|
50
|
|
|
|
|
|
|
85
|
10
|
|
|
|
|
26
|
my $conflict = $conflicts[0]; |
|
86
|
10
|
|
|
|
|
57
|
my $roles = $conflict->roles_as_english_list; |
|
87
|
|
|
|
|
|
|
|
|
88
|
10
|
|
|
|
|
53
|
my @same_role_conflicts = grep { $_->roles_as_english_list eq $roles } @conflicts; |
|
|
14
|
|
|
|
|
48
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
10
|
|
|
|
|
77
|
throw_exception( MethodNameConflictInRoles => conflict => \@same_role_conflicts, |
|
91
|
|
|
|
|
|
|
class_name => $class->name |
|
92
|
|
|
|
|
|
|
); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
elsif (@missing) { |
|
95
|
18
|
100
|
|
26
|
|
179
|
if (my $meth = first { $class->name->can($_) } @missing) { |
|
|
26
|
|
|
|
|
264
|
|
|
96
|
2
|
|
|
|
|
22
|
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
|
|
|
|
|
248
|
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
|
3893
|
my ($self, $role, $class) = @_; |
|
117
|
|
|
|
|
|
|
|
|
118
|
1085
|
|
|
|
|
5838
|
foreach my $attribute_name ($role->get_attribute_list) { |
|
119
|
|
|
|
|
|
|
# it if it has one already |
|
120
|
656
|
100
|
66
|
|
|
3277
|
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
|
|
|
|
|
4298
|
$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
|
3483
|
my ( $self, $role, $class ) = @_; |
|
135
|
|
|
|
|
|
|
|
|
136
|
1085
|
|
|
|
|
5713
|
foreach my $method ( $role->_get_local_methods ) { |
|
137
|
8683
|
|
|
|
|
29990
|
my $method_name = $method->name; |
|
138
|
|
|
|
|
|
|
|
|
139
|
8683
|
100
|
|
|
|
35130
|
next if $method->isa('Class::MOP::Method::Meta'); |
|
140
|
|
|
|
|
|
|
|
|
141
|
7723
|
100
|
|
|
|
19242
|
unless ( $self->is_method_excluded($method_name) ) { |
|
142
|
|
|
|
|
|
|
|
|
143
|
7717
|
|
|
|
|
22129
|
my $class_method = $class->get_method($method_name); |
|
144
|
|
|
|
|
|
|
|
|
145
|
7717
|
100
|
66
|
|
|
18601
|
next if $class_method && $class_method->body != $method->body; |
|
146
|
|
|
|
|
|
|
|
|
147
|
7705
|
|
|
|
|
18883
|
$class->add_method( |
|
148
|
|
|
|
|
|
|
$method_name, |
|
149
|
|
|
|
|
|
|
$method, |
|
150
|
|
|
|
|
|
|
); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
7711
|
100
|
|
|
|
24767
|
next unless $self->is_method_aliased($method_name); |
|
154
|
|
|
|
|
|
|
|
|
155
|
12
|
|
|
|
|
435
|
my $aliased_method_name = $self->get_method_aliases->{$method_name}; |
|
156
|
|
|
|
|
|
|
|
|
157
|
12
|
|
|
|
|
55
|
my $class_method = $class->get_method($aliased_method_name); |
|
158
|
|
|
|
|
|
|
|
|
159
|
12
|
100
|
66
|
|
|
117
|
if ( $class_method && $class_method->body != $method->body ) { |
|
160
|
2
|
|
|
|
|
23
|
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
|
|
|
|
|
47
|
$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
|
|
|
|
|
6872
|
$class->reset_package_cache_flag; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub apply_override_method_modifiers { |
|
180
|
1083
|
|
|
1083
|
1
|
3301
|
my ($self, $role, $class) = @_; |
|
181
|
1083
|
|
|
|
|
4607
|
foreach my $method_name ($role->get_method_modifier_list('override')) { |
|
182
|
|
|
|
|
|
|
# it if it has one already then ... |
|
183
|
997
|
100
|
|
|
|
3245
|
if ($class->has_method($method_name)) { |
|
184
|
3
|
|
|
|
|
14
|
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
|
|
|
|
|
3416
|
my $method = $role->get_override_method_modifier($method_name); |
|
192
|
994
|
|
|
|
|
4630
|
my ($package) = Class::MOP::get_code_info($method); |
|
193
|
|
|
|
|
|
|
# if it is a class, we just add it |
|
194
|
994
|
|
|
|
|
3875
|
$class->add_override_method_modifier($method_name, $method, $package); |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub apply_method_modifiers { |
|
200
|
3246
|
|
|
3246
|
1
|
8441
|
my ($self, $modifier_type, $role, $class) = @_; |
|
201
|
3246
|
|
|
|
|
7923
|
my $add = "add_${modifier_type}_method_modifier"; |
|
202
|
3246
|
|
|
|
|
6609
|
my $get = "get_${modifier_type}_method_modifiers"; |
|
203
|
3246
|
|
|
|
|
8627
|
foreach my $method_name ($role->get_method_modifier_list($modifier_type)) { |
|
204
|
|
|
|
|
|
|
$class->$add( |
|
205
|
|
|
|
|
|
|
$method_name, |
|
206
|
|
|
|
|
|
|
$_ |
|
207
|
1086
|
|
|
|
|
4863
|
) 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.2206 |
|
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 |