line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mouse::Meta::Module; |
2
|
284
|
|
|
416
|
|
964
|
use Mouse::Util qw/:meta/; # enables strict and warnings |
|
284
|
|
|
|
|
291
|
|
|
284
|
|
|
|
|
1703
|
|
3
|
|
|
|
|
|
|
|
4
|
284
|
|
|
400
|
|
1030
|
use Carp (); |
|
284
|
|
|
|
|
294
|
|
|
284
|
|
|
|
|
3493
|
|
5
|
284
|
|
|
357
|
|
761
|
use Scalar::Util (); |
|
284
|
|
|
|
|
255
|
|
|
284
|
|
|
|
|
250500
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my %METAS; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
if(Mouse::Util::MOUSE_XS){ |
10
|
|
|
|
|
|
|
# register meta storage for performance |
11
|
|
|
|
|
|
|
Mouse::Util::__register_metaclass_storage(\%METAS, 0); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# ensure thread safety |
14
|
0
|
|
|
0
|
|
0
|
*CLONE = sub { Mouse::Util::__register_metaclass_storage(\%METAS, 1) }; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub initialize { |
18
|
2892
|
|
|
2892
|
0
|
17628
|
my($class, $package_name, @args) = @_; |
19
|
|
|
|
|
|
|
|
20
|
2892
|
50
|
33
|
|
|
19191
|
($package_name && !ref($package_name)) |
21
|
|
|
|
|
|
|
|| $class->throw_error("You must pass a package name and it cannot be blessed"); |
22
|
|
|
|
|
|
|
|
23
|
2892
|
|
66
|
|
|
29523
|
return $METAS{$package_name} |
24
|
|
|
|
|
|
|
||= $class->_construct_meta(package => $package_name, @args); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub reinitialize { |
28
|
31
|
|
|
31
|
0
|
43
|
my($class, $package_name, @args) = @_; |
29
|
|
|
|
|
|
|
|
30
|
31
|
100
|
|
|
|
98
|
$package_name = $package_name->name if ref $package_name; |
31
|
|
|
|
|
|
|
|
32
|
31
|
50
|
33
|
|
|
131
|
($package_name && !ref($package_name)) |
33
|
|
|
|
|
|
|
|| $class->throw_error("You must pass a package name and it cannot be blessed"); |
34
|
|
|
|
|
|
|
|
35
|
31
|
50
|
|
|
|
57
|
if(exists $METAS{$package_name}) { |
36
|
31
|
|
|
|
|
29
|
unshift @args, %{ $METAS{$package_name} }; |
|
31
|
|
|
|
|
138
|
|
37
|
|
|
|
|
|
|
} |
38
|
31
|
|
|
|
|
45
|
delete $METAS{$package_name}; |
39
|
31
|
|
|
|
|
99
|
return $class->initialize($package_name, @args); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _class_of{ |
43
|
225
|
|
|
225
|
|
2210
|
my($class_or_instance) = @_; |
44
|
225
|
100
|
|
|
|
1198
|
return undef unless defined $class_or_instance; |
45
|
223
|
|
66
|
|
|
2310
|
return $METAS{ ref($class_or_instance) || $class_or_instance }; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Means of accessing all the metaclasses that have |
49
|
|
|
|
|
|
|
# been initialized thus far. |
50
|
|
|
|
|
|
|
# The public versions are aliased into Mouse::Util::*. |
51
|
|
|
|
|
|
|
#sub _get_all_metaclasses { %METAS } |
52
|
0
|
|
|
0
|
|
0
|
sub _get_all_metaclass_instances { values %METAS } |
53
|
0
|
|
|
0
|
|
0
|
sub _get_all_metaclass_names { keys %METAS } |
54
|
3196
|
|
|
3196
|
|
33954
|
sub _get_metaclass_by_name { $METAS{$_[0]} } |
55
|
|
|
|
|
|
|
#sub _store_metaclass_by_name { $METAS{$_[0]} = $_[1] } |
56
|
|
|
|
|
|
|
#sub _weaken_metaclass { weaken($METAS{$_[0]}) } |
57
|
|
|
|
|
|
|
#sub _does_metaclass_exist { defined $METAS{$_[0]} } |
58
|
|
|
|
|
|
|
#sub _remove_metaclass_by_name { delete $METAS{$_[0]} } |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub name; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub namespace; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# add_attribute is an abstract method |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get_attribute_map { # DEPRECATED |
67
|
0
|
|
|
0
|
0
|
0
|
Carp::cluck('get_attribute_map() has been deprecated. Use get_attribute_list() and get_attribute() instead'); |
68
|
0
|
|
|
|
|
0
|
return $_[0]->{attributes}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
143
|
|
|
143
|
0
|
4583
|
sub has_attribute { exists $_[0]->{attributes}->{$_[1]} } |
72
|
217
|
|
|
217
|
0
|
1511
|
sub get_attribute { $_[0]->{attributes}->{$_[1]} } |
73
|
1
|
|
|
1
|
0
|
27
|
sub remove_attribute { delete $_[0]->{attributes}->{$_[1]} } |
74
|
|
|
|
|
|
|
|
75
|
356
|
|
|
356
|
0
|
4812
|
sub get_attribute_list{ keys %{$_[0]->{attributes}} } |
|
356
|
|
|
|
|
12215
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# XXX: not completely compatible with Moose |
78
|
|
|
|
|
|
|
my %foreign = map{ $_ => undef } qw( |
79
|
|
|
|
|
|
|
Mouse Mouse::Role Mouse::Util Mouse::Util::TypeConstraints |
80
|
|
|
|
|
|
|
Carp Scalar::Util List::Util |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
sub _get_method_body { |
83
|
5475
|
|
|
5475
|
|
48234
|
my($self, $method_name) = @_; |
84
|
5475
|
|
|
|
|
51967
|
my $code = Mouse::Util::get_code_ref($self->{package}, $method_name); |
85
|
5475
|
100
|
100
|
|
|
204092
|
return $code && !exists $foreign{ Mouse::Util::get_code_package($code) } |
86
|
|
|
|
|
|
|
? $code |
87
|
|
|
|
|
|
|
: undef; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub add_method; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub has_method { |
93
|
5805
|
|
|
5805
|
0
|
62050
|
my($self, $method_name) = @_; |
94
|
5805
|
100
|
|
|
|
55351
|
defined($method_name) |
95
|
|
|
|
|
|
|
or $self->throw_error('You must define a method name'); |
96
|
|
|
|
|
|
|
|
97
|
5804
|
|
100
|
|
|
67876
|
return defined( $self->{methods}{$method_name} ) |
98
|
|
|
|
|
|
|
|| defined( $self->_get_method_body($method_name) ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub get_method_body { |
102
|
404
|
|
|
404
|
0
|
1734
|
my($self, $method_name) = @_; |
103
|
404
|
50
|
|
|
|
1992
|
defined($method_name) |
104
|
|
|
|
|
|
|
or $self->throw_error('You must define a method name'); |
105
|
|
|
|
|
|
|
|
106
|
404
|
|
100
|
|
|
3943
|
return $self->{methods}{$method_name} |
107
|
|
|
|
|
|
|
||= $self->_get_method_body($method_name); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub get_method { |
111
|
101
|
|
|
101
|
0
|
3168
|
my($self, $method_name) = @_; |
112
|
|
|
|
|
|
|
|
113
|
101
|
100
|
|
|
|
160
|
if(my $code = $self->get_method_body($method_name)){ |
114
|
64
|
|
|
|
|
224
|
return Mouse::Util::load_class($self->method_metaclass)->wrap( |
115
|
|
|
|
|
|
|
body => $code, |
116
|
|
|
|
|
|
|
name => $method_name, |
117
|
|
|
|
|
|
|
package => $self->name, |
118
|
|
|
|
|
|
|
associated_metaclass => $self, |
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
37
|
|
|
|
|
137
|
return undef; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub get_method_list { |
126
|
327
|
|
|
327
|
0
|
3141
|
my($self) = @_; |
127
|
|
|
|
|
|
|
|
128
|
327
|
|
|
|
|
3120
|
return grep { $self->has_method($_) } keys %{ $self->namespace }; |
|
5366
|
|
|
|
|
52510
|
|
|
327
|
|
|
|
|
7648
|
|
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub _collect_methods { # Mouse specific, used for method modifiers |
132
|
67
|
|
|
67
|
|
107
|
my($meta, @args) = @_; |
133
|
|
|
|
|
|
|
|
134
|
67
|
|
|
|
|
76
|
my @methods; |
135
|
67
|
|
|
|
|
107
|
foreach my $arg(@args){ |
136
|
69
|
100
|
|
|
|
160
|
if(my $type = ref $arg){ |
137
|
6
|
50
|
|
|
|
11
|
if($type eq 'Regexp'){ |
|
|
0
|
|
|
|
|
|
138
|
6
|
|
|
|
|
50
|
push @methods, grep { $_ =~ $arg } $meta->get_all_method_names; |
|
27
|
|
|
|
|
64
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
elsif($type eq 'ARRAY'){ |
141
|
0
|
|
|
|
|
0
|
push @methods, @{$arg}; |
|
0
|
|
|
|
|
0
|
|
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
else{ |
144
|
0
|
|
|
|
|
0
|
my $subname = ( caller(1) )[3]; |
145
|
0
|
|
|
|
|
0
|
$meta->throw_error( |
146
|
|
|
|
|
|
|
sprintf( |
147
|
|
|
|
|
|
|
'Methods passed to %s must be provided as a list,' |
148
|
|
|
|
|
|
|
. ' ArrayRef or regular expression, not %s', |
149
|
|
|
|
|
|
|
$subname, |
150
|
|
|
|
|
|
|
$type, |
151
|
|
|
|
|
|
|
) |
152
|
|
|
|
|
|
|
); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
else{ |
156
|
63
|
|
|
|
|
103
|
push @methods, $arg; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
64
|
|
|
|
|
153
|
return @methods; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
my $ANON_SERIAL = 0; # anonymous class/role id |
163
|
|
|
|
|
|
|
my %IMMORTALS; # immortal anonymous classes |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub create { |
166
|
184
|
|
|
184
|
0
|
10624
|
my($self, $package_name, %options) = @_; |
167
|
|
|
|
|
|
|
|
168
|
184
|
|
66
|
|
|
6455
|
my $class = ref($self) || $self; |
169
|
184
|
50
|
|
|
|
6482
|
$self->throw_error('You must pass a package name') if @_ < 2; |
170
|
|
|
|
|
|
|
|
171
|
184
|
|
|
|
|
6246
|
my $superclasses; |
172
|
184
|
100
|
|
|
|
6204
|
if(exists $options{superclasses}){ |
173
|
91
|
50
|
|
|
|
1918
|
if(Mouse::Util::is_a_metarole($self)){ |
174
|
0
|
|
|
|
|
0
|
delete $options{superclasses}; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
else{ |
177
|
91
|
|
|
|
|
1808
|
$superclasses = delete $options{superclasses}; |
178
|
91
|
100
|
|
|
|
5129
|
(ref $superclasses eq 'ARRAY') |
179
|
|
|
|
|
|
|
|| $self->throw_error("You must pass an ARRAY ref of superclasses"); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
183
|
|
|
|
|
6261
|
my $attributes = delete $options{attributes}; |
184
|
183
|
100
|
|
|
|
6148
|
if(defined $attributes){ |
185
|
8
|
100
|
100
|
|
|
1356
|
(ref $attributes eq 'ARRAY' || ref $attributes eq 'HASH') |
186
|
|
|
|
|
|
|
|| $self->throw_error("You must pass an ARRAY ref of attributes"); |
187
|
|
|
|
|
|
|
} |
188
|
182
|
|
|
|
|
5993
|
my $methods = delete $options{methods}; |
189
|
182
|
100
|
|
|
|
6029
|
if(defined $methods){ |
190
|
8
|
100
|
|
|
|
24
|
(ref $methods eq 'HASH') |
191
|
|
|
|
|
|
|
|| $self->throw_error("You must pass a HASH ref of methods"); |
192
|
|
|
|
|
|
|
} |
193
|
181
|
|
|
|
|
5874
|
my $roles = delete $options{roles}; |
194
|
181
|
100
|
|
|
|
6034
|
if(defined $roles){ |
195
|
90
|
100
|
|
|
|
4379
|
(ref $roles eq 'ARRAY') |
196
|
|
|
|
|
|
|
|| $self->throw_error("You must pass an ARRAY ref of roles"); |
197
|
|
|
|
|
|
|
} |
198
|
180
|
|
|
|
|
5680
|
my $mortal; |
199
|
|
|
|
|
|
|
my $cache_key; |
200
|
|
|
|
|
|
|
|
201
|
180
|
100
|
|
|
|
5930
|
if(!defined $package_name){ # anonymous |
202
|
171
|
|
|
|
|
5767
|
$mortal = !$options{cache}; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# anonymous but immortal |
205
|
171
|
100
|
|
|
|
5935
|
if(!$mortal){ |
206
|
|
|
|
|
|
|
# something like Super::Class|Super::Class::2=Role|Role::1 |
207
|
|
|
|
|
|
|
$cache_key = join '=' => ( |
208
|
51
|
100
|
|
|
|
153
|
join('|', @{$superclasses || []}), |
209
|
51
|
100
|
|
|
|
50
|
join('|', sort @{$roles || []}), |
|
51
|
|
|
|
|
184
|
|
210
|
|
|
|
|
|
|
); |
211
|
51
|
100
|
|
|
|
150
|
return $IMMORTALS{$cache_key} if exists $IMMORTALS{$cache_key}; |
212
|
|
|
|
|
|
|
} |
213
|
162
|
|
|
|
|
5849
|
$options{anon_serial_id} = ++$ANON_SERIAL; |
214
|
162
|
|
|
|
|
11389
|
$package_name = $class . '::__ANON__::' . $ANON_SERIAL; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# instantiate a module |
219
|
|
|
|
|
|
|
{ |
220
|
284
|
|
|
339
|
|
1407
|
no strict 'refs'; |
|
284
|
|
|
|
|
319
|
|
|
284
|
|
|
|
|
98979
|
|
|
171
|
|
|
|
|
5698
|
|
221
|
171
|
50
|
|
|
|
5829
|
${ $package_name . '::VERSION' } = delete $options{version} if exists $options{version}; |
|
0
|
|
|
|
|
0
|
|
222
|
171
|
50
|
|
|
|
11375
|
${ $package_name . '::AUTHORITY' } = delete $options{authority} if exists $options{authority}; |
|
0
|
|
|
|
|
0
|
|
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
171
|
|
|
|
|
6151
|
my $meta = $self->initialize( $package_name, %options); |
226
|
|
|
|
|
|
|
|
227
|
171
|
100
|
|
|
|
6330
|
Scalar::Util::weaken($METAS{$package_name}) |
228
|
|
|
|
|
|
|
if $mortal; |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
$meta->add_method(meta => sub { |
231
|
96
|
|
66
|
96
|
|
4483
|
$self->initialize(ref($_[0]) || $_[0]); |
|
|
|
|
95
|
|
|
|
232
|
171
|
|
|
|
|
7584
|
}); |
233
|
|
|
|
|
|
|
|
234
|
171
|
100
|
|
|
|
6160
|
$meta->superclasses(@{$superclasses}) |
|
80
|
|
|
|
|
3020
|
|
235
|
|
|
|
|
|
|
if defined $superclasses; |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# NOTE: |
238
|
|
|
|
|
|
|
# process attributes first, so that they can |
239
|
|
|
|
|
|
|
# install accessors, but locally defined methods |
240
|
|
|
|
|
|
|
# can then overwrite them. It is maybe a little odd, but |
241
|
|
|
|
|
|
|
# I think this should be the order of things. |
242
|
170
|
100
|
|
|
|
6067
|
if (defined $attributes) { |
243
|
7
|
100
|
|
|
|
698
|
if(ref($attributes) eq 'ARRAY'){ |
244
|
|
|
|
|
|
|
# array of Mouse::Meta::Attribute |
245
|
5
|
|
|
|
|
663
|
foreach my $attr (@{$attributes}) { |
|
5
|
|
|
|
|
1322
|
|
246
|
5
|
|
|
|
|
684
|
$meta->add_attribute($attr); |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
else{ |
250
|
|
|
|
|
|
|
# hash map of name and attribute spec pairs |
251
|
2
|
|
|
|
|
4
|
while(my($name, $attr) = each %{$attributes}){ |
|
4
|
|
|
|
|
26
|
|
252
|
2
|
|
|
|
|
9
|
$meta->add_attribute($name => $attr); |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
} |
256
|
170
|
100
|
|
|
|
6078
|
if (defined $methods) { |
257
|
7
|
|
|
|
|
11
|
while(my($method_name, $method_body) = each %{$methods}){ |
|
18
|
|
|
|
|
57
|
|
258
|
11
|
|
|
|
|
61
|
$meta->add_method($method_name, $method_body); |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
} |
261
|
170
|
100
|
100
|
|
|
6386
|
if (defined $roles and !$options{in_application_to_instance}){ |
262
|
56
|
|
|
|
|
1411
|
Mouse::Util::apply_all_roles($package_name, @{$roles}); |
|
56
|
|
|
|
|
2893
|
|
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
169
|
100
|
|
|
|
5939
|
if($cache_key){ |
266
|
42
|
|
|
|
|
85
|
$IMMORTALS{$cache_key} = $meta; |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
169
|
|
|
|
|
9818
|
return $meta; |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
sub DESTROY{ |
273
|
109
|
|
|
109
|
|
33375
|
my($self) = @_; |
274
|
|
|
|
|
|
|
|
275
|
109
|
50
|
|
|
|
5741
|
return if Mouse::Util::in_global_destruction(); |
276
|
|
|
|
|
|
|
|
277
|
109
|
|
|
|
|
5780
|
my $serial_id = $self->{anon_serial_id}; |
278
|
109
|
100
|
|
|
|
5959
|
return if !$serial_id; |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
# XXX: cleaning stash with threads causes panic/SEGV on legacy perls. |
281
|
80
|
50
|
|
|
|
5731
|
if(exists $INC{'threads.pm'}) { |
282
|
|
|
|
|
|
|
# (caller)[2] indicates the caller's line number, |
283
|
|
|
|
|
|
|
# which is zero when the current thread is joining (destroying). |
284
|
0
|
0
|
|
|
|
0
|
return if( (caller)[2] == 0); |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
# clean up mortal anonymous class stuff |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
# @ISA is a magical variable, so we must clear it manually. |
290
|
80
|
100
|
|
|
|
5846
|
@{$self->{superclasses}} = () if exists $self->{superclasses}; |
|
51
|
|
|
|
|
7721
|
|
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
# Then, clear the symbol table hash |
293
|
80
|
|
|
|
|
5854
|
%{$self->namespace} = (); |
|
80
|
|
|
|
|
12617
|
|
294
|
|
|
|
|
|
|
|
295
|
80
|
|
|
|
|
5994
|
my $name = $self->name; |
296
|
80
|
|
|
|
|
5860
|
delete $METAS{$name}; |
297
|
|
|
|
|
|
|
|
298
|
80
|
|
|
|
|
7849
|
$name =~ s/ $serial_id \z//xms; |
299
|
284
|
|
|
339
|
|
1187
|
no strict 'refs'; |
|
284
|
|
|
|
|
332
|
|
|
284
|
|
|
|
|
17289
|
|
300
|
80
|
|
|
|
|
5973
|
delete ${$name}{ $serial_id . '::' }; |
|
80
|
|
|
|
|
12196
|
|
301
|
80
|
|
|
|
|
31124
|
return; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
1; |
306
|
|
|
|
|
|
|
__END__ |