| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Moose::Meta::Role::Application::ToClass; |
|
2
|
|
|
|
|
|
|
our $VERSION = '2.2203'; |
|
3
|
|
|
|
|
|
|
|
|
4
|
388
|
|
|
388
|
|
2698
|
use strict; |
|
|
388
|
|
|
|
|
917
|
|
|
|
388
|
|
|
|
|
11146
|
|
|
5
|
388
|
|
|
388
|
|
1969
|
use warnings; |
|
|
388
|
|
|
|
|
812
|
|
|
|
388
|
|
|
|
|
8781
|
|
|
6
|
388
|
|
|
388
|
|
1834
|
use metaclass; |
|
|
388
|
|
|
|
|
800
|
|
|
|
388
|
|
|
|
|
2054
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
388
|
|
|
388
|
|
2843
|
use List::Util 'first'; |
|
|
388
|
|
|
|
|
970
|
|
|
|
388
|
|
|
|
|
24696
|
|
|
9
|
388
|
|
|
388
|
|
2605
|
use Moose::Util 'throw_exception'; |
|
|
388
|
|
|
|
|
1008
|
|
|
|
388
|
|
|
|
|
2735
|
|
|
10
|
388
|
|
|
388
|
|
90087
|
use Scalar::Util 'weaken'; |
|
|
388
|
|
|
|
|
943
|
|
|
|
388
|
|
|
|
|
18041
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
388
|
|
|
388
|
|
2519
|
use parent 'Moose::Meta::Role::Application'; |
|
|
388
|
|
|
|
|
930
|
|
|
|
388
|
|
|
|
|
2209
|
|
|
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
|
1126
|
|
|
1126
|
1
|
3274
|
my ($self, $role, $class) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# We need weak_ref in CMOP :( |
|
28
|
1126
|
|
|
|
|
4984
|
weaken($self->{role} = $role); |
|
29
|
1126
|
|
|
|
|
3966
|
weaken($self->{class} = $class); |
|
30
|
|
|
|
|
|
|
|
|
31
|
1126
|
|
|
|
|
5440
|
$self->SUPER::apply($role, $class); |
|
32
|
|
|
|
|
|
|
|
|
33
|
1091
|
|
|
|
|
5198
|
$class->add_role($role); |
|
34
|
1091
|
|
|
|
|
4581
|
$class->add_role_application($self); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub check_role_exclusions { |
|
38
|
1126
|
|
|
1126
|
1
|
2904
|
my ($self, $role, $class) = @_; |
|
39
|
1126
|
100
|
|
|
|
10542
|
if ($class->excludes_role($role->name)) { |
|
40
|
3
|
|
|
|
|
23
|
throw_exception( ConflictDetectedInCheckRoleExclusionsInToClass => class_name => $class->name, |
|
41
|
|
|
|
|
|
|
role_name => $role->name, |
|
42
|
|
|
|
|
|
|
); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
1123
|
|
|
|
|
5115
|
foreach my $excluded_role_name ($role->get_excluded_roles_list) { |
|
45
|
5
|
100
|
|
|
|
22
|
if ($class->does_role($excluded_role_name)) { |
|
46
|
1
|
|
|
|
|
7
|
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
|
1122
|
|
|
1122
|
1
|
2979
|
my ($self, $role, $class) = @_; |
|
56
|
|
|
|
|
|
|
|
|
57
|
1122
|
|
|
|
|
2732
|
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
|
1122
|
|
|
|
|
4166
|
foreach my $required_method ($role->get_required_method_list) { |
|
67
|
169
|
|
|
|
|
4699
|
my $required_method_name = $required_method->name; |
|
68
|
|
|
|
|
|
|
|
|
69
|
168
|
100
|
|
|
|
743
|
if (!$class->find_method_by_name($required_method_name)) { |
|
70
|
|
|
|
|
|
|
|
|
71
|
41
|
100
|
|
|
|
191
|
next if $self->is_aliased_method($required_method_name); |
|
72
|
|
|
|
|
|
|
|
|
73
|
40
|
|
|
|
|
122
|
push @missing, $required_method; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
1121
|
100
|
|
|
|
4438
|
return unless @missing; |
|
78
|
|
|
|
|
|
|
|
|
79
|
29
|
|
|
|
|
101
|
my $error = ''; |
|
80
|
|
|
|
|
|
|
|
|
81
|
28
|
|
|
|
|
97
|
@missing = sort { $a->name cmp $b->name } @missing; |
|
|
16
|
|
|
|
|
380
|
|
|
82
|
28
|
|
|
|
|
73
|
my @conflicts = grep { $_->isa('Moose::Meta::Role::Method::Conflicting') } @missing; |
|
|
40
|
|
|
|
|
284
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
28
|
100
|
|
|
|
138
|
if (@conflicts) { |
|
|
|
50
|
|
|
|
|
|
|
85
|
10
|
|
|
|
|
34
|
my $conflict = $conflicts[0]; |
|
86
|
10
|
|
|
|
|
52
|
my $roles = $conflict->roles_as_english_list; |
|
87
|
|
|
|
|
|
|
|
|
88
|
10
|
|
|
|
|
31
|
my @same_role_conflicts = grep { $_->roles_as_english_list eq $roles } @conflicts; |
|
|
14
|
|
|
|
|
42
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
10
|
|
|
|
|
80
|
throw_exception( MethodNameConflictInRoles => conflict => \@same_role_conflicts, |
|
91
|
|
|
|
|
|
|
class_name => $class->name |
|
92
|
|
|
|
|
|
|
); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
elsif (@missing) { |
|
95
|
18
|
100
|
|
26
|
|
131
|
if (my $meth = first { $class->name->can($_) } @missing) { |
|
|
26
|
|
|
|
|
212
|
|
|
96
|
2
|
|
|
|
|
17
|
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
|
|
|
|
|
200
|
throw_exception( RequiredMethodsNotImplementedByClass => class_name => $class->name, |
|
104
|
|
|
|
|
|
|
role_name => $role->name, |
|
105
|
|
|
|
|
|
|
missing_methods => \@missing, |
|
106
|
|
|
|
|
|
|
); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
1093
|
1
|
|
sub check_required_attributes { |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub apply_attributes { |
|
116
|
1094
|
|
|
1094
|
1
|
3370
|
my ($self, $role, $class) = @_; |
|
117
|
|
|
|
|
|
|
|
|
118
|
1094
|
|
|
|
|
5218
|
foreach my $attribute_name ($role->get_attribute_list) { |
|
119
|
|
|
|
|
|
|
# it if it has one already |
|
120
|
657
|
100
|
66
|
|
|
2861
|
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
|
655
|
|
|
|
|
3363
|
$class->add_attribute( |
|
127
|
|
|
|
|
|
|
$role->get_attribute($attribute_name)->attribute_for_class |
|
128
|
|
|
|
|
|
|
); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub apply_methods { |
|
134
|
1094
|
|
|
1094
|
1
|
2870
|
my ( $self, $role, $class ) = @_; |
|
135
|
|
|
|
|
|
|
|
|
136
|
1094
|
|
|
|
|
5163
|
foreach my $method ( $role->_get_local_methods ) { |
|
137
|
8700
|
|
|
|
|
26594
|
my $method_name = $method->name; |
|
138
|
|
|
|
|
|
|
|
|
139
|
8700
|
100
|
|
|
|
33039
|
next if $method->isa('Class::MOP::Method::Meta'); |
|
140
|
|
|
|
|
|
|
|
|
141
|
7731
|
100
|
|
|
|
17385
|
unless ( $self->is_method_excluded($method_name) ) { |
|
142
|
|
|
|
|
|
|
|
|
143
|
7723
|
|
|
|
|
20709
|
my $class_method = $class->get_method($method_name); |
|
144
|
|
|
|
|
|
|
|
|
145
|
7723
|
100
|
66
|
|
|
16533
|
next if $class_method && $class_method->body != $method->body; |
|
146
|
|
|
|
|
|
|
|
|
147
|
7710
|
|
|
|
|
17493
|
$class->add_method( |
|
148
|
|
|
|
|
|
|
$method_name, |
|
149
|
|
|
|
|
|
|
$method, |
|
150
|
|
|
|
|
|
|
); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
7718
|
100
|
|
|
|
21664
|
next unless $self->is_method_aliased($method_name); |
|
154
|
|
|
|
|
|
|
|
|
155
|
13
|
|
|
|
|
372
|
my $aliased_method_name = $self->get_method_aliases->{$method_name}; |
|
156
|
|
|
|
|
|
|
|
|
157
|
13
|
|
|
|
|
52
|
my $class_method = $class->get_method($aliased_method_name); |
|
158
|
|
|
|
|
|
|
|
|
159
|
13
|
100
|
66
|
|
|
100
|
if ( $class_method && $class_method->body != $method->body ) { |
|
160
|
2
|
|
|
|
|
21
|
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
|
11
|
|
|
|
|
42
|
$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
|
1092
|
|
|
|
|
5984
|
$class->reset_package_cache_flag; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub apply_override_method_modifiers { |
|
180
|
1092
|
|
|
1092
|
1
|
2761
|
my ($self, $role, $class) = @_; |
|
181
|
1092
|
|
|
|
|
4247
|
foreach my $method_name ($role->get_method_modifier_list('override')) { |
|
182
|
|
|
|
|
|
|
# it if it has one already then ... |
|
183
|
997
|
100
|
|
|
|
3015
|
if ($class->has_method($method_name)) { |
|
184
|
3
|
|
|
|
|
7
|
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
|
|
|
|
|
3101
|
my $method = $role->get_override_method_modifier($method_name); |
|
192
|
994
|
|
|
|
|
4264
|
my ($package) = Class::MOP::get_code_info($method); |
|
193
|
|
|
|
|
|
|
# if it is a class, we just add it |
|
194
|
994
|
|
|
|
|
3352
|
$class->add_override_method_modifier($method_name, $method, $package); |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub apply_method_modifiers { |
|
200
|
3273
|
|
|
3273
|
1
|
7443
|
my ($self, $modifier_type, $role, $class) = @_; |
|
201
|
3273
|
|
|
|
|
7022
|
my $add = "add_${modifier_type}_method_modifier"; |
|
202
|
3273
|
|
|
|
|
5856
|
my $get = "get_${modifier_type}_method_modifiers"; |
|
203
|
3273
|
|
|
|
|
7664
|
foreach my $method_name ($role->get_method_modifier_list($modifier_type)) { |
|
204
|
|
|
|
|
|
|
$class->$add( |
|
205
|
|
|
|
|
|
|
$method_name, |
|
206
|
|
|
|
|
|
|
$_ |
|
207
|
1093
|
|
|
|
|
4466
|
) 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.2203 |
|
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 |