line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moose::Meta::Role::Composite; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2206'; |
3
|
|
|
|
|
|
|
|
4
|
377
|
|
|
377
|
|
3033
|
use strict; |
|
377
|
|
|
|
|
1092
|
|
|
377
|
|
|
|
|
13299
|
|
5
|
377
|
|
|
377
|
|
2392
|
use warnings; |
|
377
|
|
|
|
|
1106
|
|
|
377
|
|
|
|
|
10420
|
|
6
|
377
|
|
|
377
|
|
2146
|
use metaclass; |
|
377
|
|
|
|
|
999
|
|
|
377
|
|
|
|
|
2738
|
|
7
|
|
|
|
|
|
|
|
8
|
377
|
|
|
377
|
|
3210
|
use Scalar::Util 'blessed'; |
|
377
|
|
|
|
|
1103
|
|
|
377
|
|
|
|
|
21968
|
|
9
|
377
|
|
|
377
|
|
6380
|
use Moose::Util 'throw_exception'; |
|
377
|
|
|
|
|
1209
|
|
|
377
|
|
|
|
|
3369
|
|
10
|
377
|
|
|
377
|
|
107824
|
use parent 'Moose::Meta::Role'; |
|
377
|
|
|
|
|
1208
|
|
|
377
|
|
|
|
|
2788
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# NOTE: |
13
|
|
|
|
|
|
|
# we need to override the ->name |
14
|
|
|
|
|
|
|
# method from Class::MOP::Package |
15
|
|
|
|
|
|
|
# since we don't have an actual |
16
|
|
|
|
|
|
|
# package for this. |
17
|
|
|
|
|
|
|
# - SL |
18
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute('name' => ( |
19
|
|
|
|
|
|
|
reader => 'name', |
20
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
21
|
|
|
|
|
|
|
)); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# NOTE: |
24
|
|
|
|
|
|
|
# Again, since we don't have a real |
25
|
|
|
|
|
|
|
# package to store our methods in, |
26
|
|
|
|
|
|
|
# we use a HASH ref instead. |
27
|
|
|
|
|
|
|
# - SL |
28
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute('_methods' => ( |
29
|
|
|
|
|
|
|
reader => '_method_map', |
30
|
|
|
|
|
|
|
default => sub { {} }, |
31
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
32
|
|
|
|
|
|
|
)); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute('_overloads' => ( |
35
|
|
|
|
|
|
|
reader => '_overload_map', |
36
|
|
|
|
|
|
|
default => sub { {} }, |
37
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
38
|
|
|
|
|
|
|
)); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute('_overload_fallback' => ( |
41
|
|
|
|
|
|
|
accessor => '_overload_fallback', |
42
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
43
|
|
|
|
|
|
|
)); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute( |
46
|
|
|
|
|
|
|
'application_role_summation_class', |
47
|
|
|
|
|
|
|
reader => 'application_role_summation_class', |
48
|
|
|
|
|
|
|
default => 'Moose::Meta::Role::Application::RoleSummation', |
49
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub new { |
53
|
259
|
|
|
259
|
1
|
1502
|
my ($class, %params) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# the roles param is required ... |
56
|
259
|
|
|
|
|
618
|
foreach ( @{$params{roles}} ) { |
|
259
|
|
|
|
|
980
|
|
57
|
582
|
100
|
|
|
|
2180
|
unless ( $_->isa('Moose::Meta::Role') ) { |
58
|
1
|
|
|
|
|
8
|
throw_exception( RolesListMustBeInstancesOfMooseMetaRole => params => \%params, |
59
|
|
|
|
|
|
|
role => $_, |
60
|
|
|
|
|
|
|
class => $class |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my @composition_roles = map { |
66
|
581
|
|
|
|
|
1569
|
$_->composition_class_roles |
67
|
258
|
|
|
|
|
663
|
} @{ $params{roles} }; |
|
258
|
|
|
|
|
791
|
|
68
|
|
|
|
|
|
|
|
69
|
258
|
100
|
|
|
|
1037
|
if (@composition_roles) { |
70
|
3
|
|
|
|
|
14
|
my $meta = Moose::Meta::Class->create_anon_class( |
71
|
|
|
|
|
|
|
superclasses => [ $class ], |
72
|
|
|
|
|
|
|
roles => [ @composition_roles ], |
73
|
|
|
|
|
|
|
cache => 1, |
74
|
|
|
|
|
|
|
); |
75
|
3
|
|
|
|
|
25
|
$class = $meta->name; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# and the name is created from the |
79
|
|
|
|
|
|
|
# roles if one has not been provided |
80
|
258
|
|
33
|
|
|
1602
|
$params{name} ||= (join "|" => map { $_->name } @{$params{roles}}); |
|
581
|
|
|
|
|
3074
|
|
|
258
|
|
|
|
|
665
|
|
81
|
258
|
|
|
|
|
9787
|
$class->_new(\%params); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# There's no such thing as an anonymous composite role since composites are an |
85
|
|
|
|
|
|
|
# artifact of Moose's internals. However, a composite role that contains an |
86
|
|
|
|
|
|
|
# anon role may _look_ like an anon role since $self->name =~ /$anon_key/ can |
87
|
|
|
|
|
|
|
# return true if the first role in the composite is anonymous itself. |
88
|
63
|
|
|
63
|
1
|
1934
|
sub is_anon { 0 } |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# This is largely a copy of what's in Moose::Meta::Role (itself |
91
|
|
|
|
|
|
|
# largely a copy of Class::MOP::Class). However, we can't actually |
92
|
|
|
|
|
|
|
# call add_package_symbol, because there's no package into which to |
93
|
|
|
|
|
|
|
# add the symbol. |
94
|
|
|
|
|
|
|
sub add_method { |
95
|
1502
|
|
|
1502
|
1
|
3392
|
my ($self, $method_name, $method) = @_; |
96
|
|
|
|
|
|
|
|
97
|
1502
|
100
|
66
|
|
|
5556
|
unless ( defined $method_name && $method_name ) { |
98
|
1
|
|
|
|
|
15
|
throw_exception( MustDefineAMethodName => instance => $self ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
1501
|
|
|
|
|
2078
|
my $body; |
102
|
1501
|
50
|
|
|
|
4531
|
if (blessed($method)) { |
103
|
1501
|
|
|
|
|
3730
|
$body = $method->body; |
104
|
1501
|
50
|
|
|
|
42420
|
if ($method->package_name ne $self->name) { |
105
|
1501
|
50
|
|
|
|
41724
|
$method = $method->clone( |
106
|
|
|
|
|
|
|
package_name => $self->name, |
107
|
|
|
|
|
|
|
name => $method_name |
108
|
|
|
|
|
|
|
) if $method->can('clone'); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else { |
112
|
0
|
|
|
|
|
0
|
$body = $method; |
113
|
0
|
|
|
|
|
0
|
$method = $self->wrap_method_body( body => $body, name => $method_name ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
1501
|
|
|
|
|
48579
|
$self->_method_map->{$method_name} = $method; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub get_method_list { |
120
|
4
|
|
|
4
|
1
|
1755
|
my $self = shift; |
121
|
4
|
|
|
|
|
7
|
return keys %{ $self->_method_map }; |
|
4
|
|
|
|
|
156
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _get_local_methods { |
125
|
200
|
|
|
200
|
|
549
|
my $self = shift; |
126
|
200
|
|
|
|
|
418
|
return values %{ $self->_method_map }; |
|
200
|
|
|
|
|
7292
|
|
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub has_method { |
130
|
498
|
|
|
498
|
1
|
931
|
my ($self, $method_name) = @_; |
131
|
|
|
|
|
|
|
|
132
|
498
|
|
|
|
|
15164
|
return exists $self->_method_map->{$method_name}; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub get_method { |
136
|
0
|
|
|
0
|
1
|
0
|
my ($self, $method_name) = @_; |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
0
|
return $self->_method_map->{$method_name}; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub is_overloaded { |
142
|
200
|
|
|
200
|
1
|
1029
|
my ($self) = @_; |
143
|
200
|
|
|
|
|
389
|
return keys %{ $self->_overload_map }; |
|
200
|
|
|
|
|
7506
|
|
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub add_overloaded_operator { |
147
|
4
|
|
|
4
|
1
|
16
|
my ( $self, $op_name, $overload ) = @_; |
148
|
|
|
|
|
|
|
|
149
|
4
|
50
|
33
|
|
|
41
|
unless ( defined $op_name && $op_name ) { |
150
|
0
|
|
|
|
|
0
|
throw_exception( |
151
|
|
|
|
|
|
|
'MustDefineAnOverloadOperator', |
152
|
|
|
|
|
|
|
instance => $self, |
153
|
|
|
|
|
|
|
); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
4
|
|
|
|
|
200
|
$self->_overload_map->{$op_name} = $overload; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub get_overload_fallback_value { |
160
|
4
|
|
|
4
|
0
|
24
|
my ($self) = @_; |
161
|
4
|
|
|
|
|
138
|
return $self->_overload_fallback; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub set_overload_fallback_value { |
165
|
8
|
|
|
8
|
0
|
19
|
my $self = shift; |
166
|
8
|
|
|
|
|
297
|
$self->_overload_fallback(shift); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub get_all_overloaded_operators { |
170
|
4
|
|
|
4
|
1
|
32
|
my ( $self, $method_name ) = @_; |
171
|
4
|
|
|
|
|
8
|
return values %{ $self->_overload_map }; |
|
4
|
|
|
|
|
169
|
|
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub apply_params { |
175
|
231
|
|
|
231
|
1
|
801
|
my ($self, $role_params) = @_; |
176
|
231
|
|
|
|
|
9903
|
Moose::Util::_load_user_class($self->application_role_summation_class); |
177
|
|
|
|
|
|
|
|
178
|
231
|
|
|
|
|
22076
|
$self->application_role_summation_class->new( |
179
|
|
|
|
|
|
|
role_params => $role_params, |
180
|
|
|
|
|
|
|
)->apply($self); |
181
|
|
|
|
|
|
|
|
182
|
216
|
|
|
|
|
3245
|
return $self; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub reinitialize { |
186
|
4
|
|
|
4
|
1
|
89
|
my ( $class, $old_meta, @args ) = @_; |
187
|
|
|
|
|
|
|
|
188
|
4
|
100
|
66
|
|
|
39
|
throw_exception( CannotInitializeMooseMetaRoleComposite => old_meta => $old_meta, |
189
|
|
|
|
|
|
|
args => \@args, |
190
|
|
|
|
|
|
|
role_composite => $class |
191
|
|
|
|
|
|
|
) |
192
|
|
|
|
|
|
|
if !blessed $old_meta |
193
|
|
|
|
|
|
|
|| !$old_meta->isa('Moose::Meta::Role::Composite'); |
194
|
|
|
|
|
|
|
|
195
|
3
|
|
|
|
|
9
|
my %existing_classes = map { $_ => $old_meta->$_() } qw( |
|
3
|
|
|
|
|
111
|
|
196
|
|
|
|
|
|
|
application_role_summation_class |
197
|
|
|
|
|
|
|
); |
198
|
|
|
|
|
|
|
|
199
|
3
|
|
|
|
|
12
|
return $old_meta->meta->clone_object( $old_meta, %existing_classes, @args ); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
1; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# ABSTRACT: An object to represent the set of roles |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
__END__ |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=pod |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=encoding UTF-8 |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 NAME |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Moose::Meta::Role::Composite - An object to represent the set of roles |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 VERSION |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
version 2.2206 |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 DESCRIPTION |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
A composite is a role that consists of a set of two or more roles. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
The API of a composite role is almost identical to that of a regular |
225
|
|
|
|
|
|
|
role. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 INHERITANCE |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
C<Moose::Meta::Role::Composite> is a subclass of L<Moose::Meta::Role>. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 METHODS |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head2 Moose::Meta::Role::Composite->new(%options) |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
This returns a new composite role object. It accepts the same |
236
|
|
|
|
|
|
|
options as its parent class, with a few changes: |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=over 4 |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=item * roles |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
This option is an array reference containing a list of |
243
|
|
|
|
|
|
|
L<Moose::Meta::Role> object. This is a required option. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=item * name |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
If a name is not given, one is generated from the roles provided. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=item * apply_params(\%role_params) |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
Creates a new RoleSummation role application with C<%role_params> and applies |
252
|
|
|
|
|
|
|
the composite role to it. The RoleSummation role application class used is |
253
|
|
|
|
|
|
|
determined by the composite role's C<application_role_summation_class> |
254
|
|
|
|
|
|
|
attribute. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=item * reinitialize($metaclass) |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Like C<< Class::MOP::Package->reinitialize >>, but doesn't allow passing a |
259
|
|
|
|
|
|
|
string with the package name, as there is no real package for composite roles. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=back |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head1 BUGS |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
See L<Moose/BUGS> for details on reporting bugs. |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head1 AUTHORS |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=over 4 |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=item * |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Stevan Little <stevan@cpan.org> |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=item * |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=item * |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Jesse Luehrs <doy@cpan.org> |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=item * |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
Shawn M Moore <sartak@cpan.org> |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=item * |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=item * |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=item * |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=item * |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
Hans Dieter Pearcey <hdp@cpan.org> |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=item * |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
Chris Prather <chris@prather.org> |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=item * |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
Matt S Trout <mstrout@cpan.org> |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=back |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
This software is copyright (c) 2006 by Infinity Interactive, Inc. |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
318
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=cut |