| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Data::Util::PurePerl; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
die qq{Don't use Data::Util::PurePerl directly, use Data::Util instead.\n} # ' for poor editors |
|
4
|
|
|
|
|
|
|
if caller() ne 'Data::Util'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package |
|
7
|
|
|
|
|
|
|
Data::Util; |
|
8
|
|
|
|
|
|
|
|
|
9
|
22
|
|
|
22
|
|
76
|
use strict; |
|
|
22
|
|
|
|
|
24
|
|
|
|
22
|
|
|
|
|
535
|
|
|
10
|
22
|
|
|
22
|
|
70
|
use warnings; |
|
|
22
|
|
|
|
|
20
|
|
|
|
22
|
|
|
|
|
469
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#use warnings::unused; |
|
13
|
|
|
|
|
|
|
|
|
14
|
22
|
|
|
22
|
|
74
|
use Scalar::Util (); |
|
|
22
|
|
|
|
|
23
|
|
|
|
22
|
|
|
|
|
224
|
|
|
15
|
22
|
|
|
22
|
|
924
|
use overload (); |
|
|
22
|
|
|
|
|
741
|
|
|
|
22
|
|
|
|
|
16511
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _croak{ |
|
18
|
75
|
|
|
75
|
|
3943
|
require Data::Util::Error; |
|
19
|
75
|
|
|
|
|
181
|
goto &Data::Util::Error::croak; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
sub _fail{ |
|
22
|
64
|
|
|
64
|
|
226
|
my($name, $value) = @_; |
|
23
|
64
|
|
|
|
|
104
|
_croak(sprintf 'Validation failed: you must supply %s, not %s', $name, neat($value)); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _overloaded{ |
|
27
|
423
|
|
100
|
423
|
|
1766
|
return Scalar::Util::blessed($_[0]) |
|
28
|
|
|
|
|
|
|
&& overload::Method($_[0], $_[1]); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub is_scalar_ref{ |
|
32
|
92
|
|
100
|
92
|
1
|
4425
|
return ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF' || _overloaded($_[0], '${}'); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
sub is_array_ref{ |
|
35
|
164
|
|
100
|
164
|
1
|
2662
|
return ref($_[0]) eq 'ARRAY' || _overloaded($_[0], '@{}'); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
sub is_hash_ref{ |
|
38
|
194
|
|
100
|
194
|
1
|
2697
|
return ref($_[0]) eq 'HASH' || _overloaded($_[0], '%{}'); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
sub is_code_ref{ |
|
41
|
106
|
|
100
|
106
|
1
|
1062
|
return ref($_[0]) eq 'CODE' || _overloaded($_[0], '&{}'); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
sub is_glob_ref{ |
|
44
|
65
|
|
100
|
65
|
1
|
959
|
return ref($_[0]) eq 'GLOB' || _overloaded($_[0], '*{}'); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
sub is_regex_ref{ |
|
47
|
3
|
|
|
3
|
0
|
171
|
return ref($_[0]) eq 'Regexp'; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
sub is_rx{ |
|
50
|
2
|
|
|
2
|
1
|
7
|
return ref($_[0]) eq 'Regexp'; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub is_instance{ |
|
54
|
31
|
|
|
31
|
1
|
3156
|
my($obj, $class) = @_; |
|
55
|
31
|
100
|
|
|
|
64
|
_fail('a class name', $class) |
|
56
|
|
|
|
|
|
|
unless is_string($class); |
|
57
|
|
|
|
|
|
|
|
|
58
|
27
|
|
100
|
|
|
219
|
return Scalar::Util::blessed($obj) && $obj->isa($class); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
sub is_invocant{ |
|
61
|
13
|
|
|
13
|
1
|
296
|
my($x) = @_; |
|
62
|
13
|
100
|
|
|
|
25
|
if(ref $x){ |
|
63
|
3
|
|
|
|
|
14
|
return !!Scalar::Util::blessed($x); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
else{ |
|
66
|
10
|
|
|
|
|
11
|
return !!get_stash($x); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub scalar_ref{ |
|
72
|
10
|
100
|
100
|
10
|
1
|
863
|
return ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF' || _overloaded($_[0], '${}') |
|
73
|
|
|
|
|
|
|
? $_[0] : _fail('a SCALAR reference', $_[0]); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
sub array_ref{ |
|
77
|
94
|
100
|
100
|
94
|
1
|
1935
|
return ref($_[0]) eq 'ARRAY' || _overloaded($_[0], '@{}') |
|
78
|
|
|
|
|
|
|
? $_[0] : _fail('an ARRAY reference', $_[0]); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
sub hash_ref{ |
|
81
|
6
|
100
|
100
|
6
|
1
|
932
|
return ref($_[0]) eq 'HASH' || _overloaded($_[0], '%{}') |
|
82
|
|
|
|
|
|
|
? $_[0] : _fail('a HASH reference', $_[0]); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
sub code_ref{ |
|
85
|
279
|
100
|
100
|
279
|
1
|
1284
|
return ref($_[0]) eq 'CODE' || _overloaded($_[0], '&{}') |
|
86
|
|
|
|
|
|
|
? $_[0] : _fail('a CODE reference', $_[0]); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
sub glob_ref{ |
|
89
|
5
|
100
|
100
|
5
|
1
|
599
|
return ref($_[0]) eq 'GLOB' || _overloaded($_[0], '*{}') |
|
90
|
|
|
|
|
|
|
? $_[0] : _fail('a GLOB reference', $_[0]); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
sub regex_ref{ |
|
93
|
1
|
50
|
|
1
|
0
|
584
|
return ref($_[0]) eq 'Regexp' |
|
94
|
|
|
|
|
|
|
? $_[0] : _fail('a regular expression reference', $_[0]); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
sub rx{ |
|
97
|
2
|
100
|
|
2
|
1
|
35
|
return ref($_[0]) eq 'Regexp' |
|
98
|
|
|
|
|
|
|
? $_[0] : _fail('a regular expression reference', $_[0]); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub instance{ |
|
102
|
11
|
|
|
11
|
1
|
349
|
my($obj, $class) = @_; |
|
103
|
|
|
|
|
|
|
|
|
104
|
11
|
100
|
|
|
|
14
|
_fail('a class name', $class) |
|
105
|
|
|
|
|
|
|
unless is_string($class); |
|
106
|
|
|
|
|
|
|
|
|
107
|
7
|
100
|
100
|
|
|
48
|
return Scalar::Util::blessed($obj) && $obj->isa($class) |
|
108
|
|
|
|
|
|
|
? $obj : _fail("an instance of $class", $obj); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub invocant{ |
|
112
|
15
|
|
|
15
|
1
|
121
|
my($x) = @_; |
|
113
|
15
|
100
|
|
|
|
30
|
if(ref $x){ |
|
|
|
100
|
|
|
|
|
|
|
114
|
3
|
100
|
|
|
|
11
|
if(Scalar::Util::blessed($x)){ |
|
115
|
2
|
|
|
|
|
10
|
return $x; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
elsif(is_string($x)){ |
|
119
|
9
|
100
|
|
|
|
11
|
if(get_stash($x)){ |
|
120
|
7
|
|
|
|
|
8
|
$x =~ s/^:://; |
|
121
|
7
|
|
|
|
|
11
|
$x =~ s/(?:main::)+//; |
|
122
|
7
|
|
|
|
|
39
|
return $x; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
} |
|
125
|
6
|
|
|
|
|
10
|
_fail('an invocant', $x); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub is_value{ |
|
129
|
11
|
|
100
|
11
|
1
|
3271
|
return defined($_[0]) && !ref($_[0]) && ref(\$_[0]) ne 'GLOB'; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
sub is_string{ |
|
132
|
22
|
|
|
22
|
|
106
|
no warnings 'uninitialized'; |
|
|
22
|
|
|
|
|
27
|
|
|
|
22
|
|
|
|
|
4657
|
|
|
133
|
450
|
|
100
|
450
|
1
|
4395
|
return !ref($_[0]) && ref(\$_[0]) ne 'GLOB' && length($_[0]) > 0; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub is_number{ |
|
137
|
125
|
100
|
100
|
125
|
1
|
4968
|
return 0 if !defined($_[0]) || ref($_[0]); |
|
138
|
|
|
|
|
|
|
|
|
139
|
122
|
|
|
|
|
683
|
return $_[0] =~ m{ |
|
140
|
|
|
|
|
|
|
\A \s* |
|
141
|
|
|
|
|
|
|
[+-]? |
|
142
|
|
|
|
|
|
|
(?= \d | \.\d) |
|
143
|
|
|
|
|
|
|
\d* |
|
144
|
|
|
|
|
|
|
(\.\d*)? |
|
145
|
|
|
|
|
|
|
(?: [Ee] (?: [+-]? \d+) )? |
|
146
|
|
|
|
|
|
|
\s* \z |
|
147
|
|
|
|
|
|
|
}xms; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub is_integer{ |
|
151
|
54
|
100
|
100
|
54
|
1
|
4608
|
return 0 if !defined($_[0]) || ref($_[0]); |
|
152
|
|
|
|
|
|
|
|
|
153
|
50
|
|
|
|
|
221
|
return $_[0] =~ m{ |
|
154
|
|
|
|
|
|
|
\A \s* |
|
155
|
|
|
|
|
|
|
[+-]? |
|
156
|
|
|
|
|
|
|
\d+ |
|
157
|
|
|
|
|
|
|
\s* \z |
|
158
|
|
|
|
|
|
|
}xms; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub get_stash{ |
|
162
|
71
|
|
|
71
|
1
|
4638
|
my($invocant) = @_; |
|
163
|
|
|
|
|
|
|
|
|
164
|
71
|
100
|
|
|
|
210
|
if(Scalar::Util::blessed($invocant)){ |
|
|
|
100
|
|
|
|
|
|
|
165
|
22
|
|
|
22
|
|
101
|
no strict 'refs'; |
|
|
22
|
|
|
|
|
21
|
|
|
|
22
|
|
|
|
|
6854
|
|
|
166
|
1
|
|
|
|
|
1
|
return \%{ref($invocant) . '::'}; |
|
|
1
|
|
|
|
|
3
|
|
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
elsif(!is_string($invocant)){ |
|
169
|
7
|
|
|
|
|
19
|
return undef; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
63
|
|
|
|
|
89
|
$invocant =~ s/^:://; |
|
173
|
|
|
|
|
|
|
|
|
174
|
63
|
|
|
|
|
107
|
my $pack = *main::; |
|
175
|
63
|
|
|
|
|
131
|
foreach my $part(split /::/, $invocant){ |
|
176
|
75
|
100
|
|
|
|
246
|
return undef unless $pack = $pack->{$part . '::'}; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
52
|
|
|
|
|
46
|
return *{$pack}{HASH}; |
|
|
52
|
|
|
|
|
187
|
|
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub anon_scalar{ |
|
182
|
12
|
|
|
12
|
1
|
2356
|
my($s) = @_; |
|
183
|
12
|
|
|
|
|
33
|
return \$s; # not \$_[0] |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub neat{ |
|
187
|
170
|
|
|
170
|
1
|
1847
|
my($s) = @_; |
|
188
|
|
|
|
|
|
|
|
|
189
|
170
|
100
|
|
|
|
325
|
if(ref $s){ |
|
|
|
100
|
|
|
|
|
|
|
190
|
48
|
100
|
|
|
|
133
|
if(ref($s) eq 'CODE'){ |
|
|
|
100
|
|
|
|
|
|
|
191
|
3
|
|
|
|
|
7
|
return sprintf '\\&%s(0x%x)', scalar(get_code_info($s)), Scalar::Util::refaddr($s); |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
elsif(ref($s) eq 'Regexp'){ |
|
194
|
1
|
|
|
|
|
7
|
return qq{qr{$s}}; |
|
195
|
|
|
|
|
|
|
} |
|
196
|
44
|
|
|
|
|
104
|
return overload::StrVal($s); |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
elsif(defined $s){ |
|
199
|
98
|
100
|
|
|
|
114
|
return "$s" if is_number($s); |
|
200
|
57
|
100
|
|
|
|
98
|
return "$s" if is_glob_ref(\$s); |
|
201
|
|
|
|
|
|
|
|
|
202
|
50
|
|
|
|
|
177
|
require B; |
|
203
|
50
|
|
|
|
|
279
|
return B::perlstring($s); |
|
204
|
|
|
|
|
|
|
} |
|
205
|
|
|
|
|
|
|
else{ |
|
206
|
24
|
|
|
|
|
107
|
return 'undef'; |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub install_subroutine{ |
|
212
|
28
|
100
|
|
28
|
1
|
8067
|
_croak('Usage: install_subroutine(package, name => code, ...)') unless @_; |
|
213
|
|
|
|
|
|
|
|
|
214
|
27
|
|
|
|
|
28
|
my $into = shift; |
|
215
|
27
|
100
|
|
|
|
42
|
is_string($into) or _fail('a package name', $into); |
|
216
|
|
|
|
|
|
|
|
|
217
|
26
|
100
|
|
|
|
76
|
my $param = mkopt_hash(@_ == 1 ? shift : \@_, 'install_subroutine', 'CODE'); |
|
218
|
|
|
|
|
|
|
|
|
219
|
23
|
|
|
|
|
25
|
while(my($as, $code) = each %{$param}){ |
|
|
49
|
|
|
|
|
129
|
|
|
220
|
29
|
100
|
|
|
|
49
|
defined($code) or _fail('a CODE reference', $code); |
|
221
|
|
|
|
|
|
|
|
|
222
|
22
|
|
|
22
|
|
105
|
my $slot = do{ no strict 'refs'; \*{ $into . '::' . $as } }; |
|
|
22
|
|
|
|
|
21
|
|
|
|
22
|
|
|
|
|
1261
|
|
|
|
28
|
|
|
|
|
34
|
|
|
|
28
|
|
|
|
|
16
|
|
|
|
28
|
|
|
|
|
76
|
|
|
223
|
|
|
|
|
|
|
|
|
224
|
28
|
100
|
|
|
|
26
|
if(defined &{$slot}){ |
|
|
28
|
|
|
|
|
54
|
|
|
225
|
8
|
|
|
|
|
284
|
warnings::warnif(redefine => "Subroutine $as redefined"); |
|
226
|
|
|
|
|
|
|
} |
|
227
|
|
|
|
|
|
|
|
|
228
|
22
|
|
|
22
|
|
81
|
no warnings 'redefine'; |
|
|
22
|
|
|
|
|
31
|
|
|
|
22
|
|
|
|
|
5390
|
|
|
229
|
28
|
|
|
|
|
444
|
*{$slot} = \&{$code}; |
|
|
26
|
|
|
|
|
67
|
|
|
|
28
|
|
|
|
|
113
|
|
|
230
|
|
|
|
|
|
|
} |
|
231
|
20
|
|
|
|
|
94
|
return; |
|
232
|
|
|
|
|
|
|
} |
|
233
|
|
|
|
|
|
|
sub uninstall_subroutine { |
|
234
|
17
|
100
|
|
17
|
1
|
9477
|
_croak('Usage: uninstall_subroutine(package, name, ...)') unless @_; |
|
235
|
|
|
|
|
|
|
|
|
236
|
16
|
|
|
|
|
17
|
my $package = shift; |
|
237
|
|
|
|
|
|
|
|
|
238
|
16
|
100
|
|
|
|
22
|
is_string($package) or _fail('a package name', $package); |
|
239
|
15
|
100
|
|
|
|
25
|
my $stash = get_stash($package) or return 0; |
|
240
|
|
|
|
|
|
|
|
|
241
|
14
|
100
|
100
|
|
|
42
|
my $param = mkopt_hash(@_ == 1 && is_hash_ref($_[0]) ? shift : \@_, 'install_subroutine', 'CODE'); |
|
242
|
|
|
|
|
|
|
|
|
243
|
13
|
|
|
|
|
56
|
require B; |
|
244
|
|
|
|
|
|
|
|
|
245
|
13
|
|
|
|
|
11
|
while(my($name, $specified_code) = each %{$param}){ |
|
|
36
|
|
|
|
|
350
|
|
|
246
|
24
|
|
|
|
|
33
|
my $glob = $stash->{$name}; |
|
247
|
|
|
|
|
|
|
|
|
248
|
24
|
100
|
|
|
|
43
|
if(ref(\$glob) ne 'GLOB'){ |
|
249
|
9
|
100
|
|
|
|
15
|
if(ref $glob) { |
|
250
|
6
|
100
|
|
|
|
13
|
if(Scalar::Util::reftype $glob eq 'CODE'){ |
|
251
|
3
|
100
|
100
|
|
|
12
|
if(defined $specified_code && |
|
252
|
|
|
|
|
|
|
$specified_code != $glob) { |
|
253
|
1
|
|
|
|
|
2
|
next; |
|
254
|
|
|
|
|
|
|
} |
|
255
|
|
|
|
|
|
|
} |
|
256
|
|
|
|
|
|
|
else { |
|
257
|
3
|
|
|
|
|
55
|
warnings::warnif(misc => "Constant subroutine $name uninstalled"); |
|
258
|
|
|
|
|
|
|
} |
|
259
|
|
|
|
|
|
|
} |
|
260
|
7
|
|
|
|
|
150
|
delete $stash->{$name}; |
|
261
|
7
|
|
|
|
|
10
|
next; |
|
262
|
|
|
|
|
|
|
} |
|
263
|
|
|
|
|
|
|
|
|
264
|
15
|
|
|
|
|
24
|
my $code = *{$glob}{CODE}; |
|
|
15
|
|
|
|
|
28
|
|
|
265
|
15
|
100
|
|
|
|
26
|
if(not defined $code){ |
|
266
|
2
|
|
|
|
|
2
|
next; |
|
267
|
|
|
|
|
|
|
} |
|
268
|
|
|
|
|
|
|
|
|
269
|
13
|
100
|
100
|
|
|
33
|
if(defined $specified_code && $specified_code != $code){ |
|
270
|
1
|
|
|
|
|
2
|
next; |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
|
|
273
|
12
|
50
|
|
|
|
64
|
if(B::svref_2object($code)->CONST){ |
|
274
|
0
|
|
|
|
|
0
|
warnings::warnif(misc => "Constant subroutine $name uninstalled"); |
|
275
|
|
|
|
|
|
|
} |
|
276
|
|
|
|
|
|
|
|
|
277
|
12
|
|
|
|
|
21
|
delete $stash->{$name}; |
|
278
|
|
|
|
|
|
|
|
|
279
|
22
|
|
|
22
|
|
89
|
my $newglob = do{ no strict 'refs'; \*{$package . '::' . $name} }; # vivify |
|
|
22
|
|
|
|
|
31
|
|
|
|
22
|
|
|
|
|
4819
|
|
|
|
12
|
|
|
|
|
10
|
|
|
|
12
|
|
|
|
|
8
|
|
|
|
12
|
|
|
|
|
55
|
|
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
# copy all the slot except for CODE |
|
282
|
12
|
|
|
|
|
16
|
foreach my $slot( qw(SCALAR ARRAY HASH IO FORMAT) ){ |
|
283
|
60
|
100
|
|
|
|
34
|
*{$newglob} = *{$glob}{$slot} if defined *{$glob}{$slot}; |
|
|
15
|
|
|
|
|
27
|
|
|
|
15
|
|
|
|
|
24
|
|
|
|
60
|
|
|
|
|
132
|
|
|
284
|
|
|
|
|
|
|
} |
|
285
|
|
|
|
|
|
|
} |
|
286
|
|
|
|
|
|
|
|
|
287
|
12
|
|
|
|
|
236
|
return; |
|
288
|
|
|
|
|
|
|
} |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
sub get_code_info{ |
|
291
|
11
|
|
|
11
|
1
|
1650
|
my($code) = @_; |
|
292
|
|
|
|
|
|
|
|
|
293
|
11
|
100
|
|
|
|
19
|
is_code_ref($code) or _fail('a CODE reference', $code); |
|
294
|
|
|
|
|
|
|
|
|
295
|
10
|
|
|
|
|
42
|
require B; |
|
296
|
10
|
|
|
|
|
9
|
my $gv = B::svref_2object(\&{$code})->GV; |
|
|
10
|
|
|
|
|
58
|
|
|
297
|
10
|
50
|
|
|
|
42
|
return unless $gv->isa('B::GV'); |
|
298
|
10
|
100
|
|
|
|
119
|
return wantarray ? ($gv->STASH->NAME, $gv->NAME) : join('::', $gv->STASH->NAME, $gv->NAME); |
|
299
|
|
|
|
|
|
|
} |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
sub get_code_ref{ |
|
302
|
30
|
|
|
30
|
1
|
15803
|
my($package, $name, @flags) = @_; |
|
303
|
|
|
|
|
|
|
|
|
304
|
30
|
100
|
|
|
|
40
|
is_string($package) or _fail('a package name', $package); |
|
305
|
28
|
100
|
|
|
|
33
|
is_string($name) or _fail('a subroutine name', $name); |
|
306
|
|
|
|
|
|
|
|
|
307
|
27
|
100
|
|
|
|
57
|
if(@flags){ |
|
308
|
2
|
50
|
|
|
|
3
|
if(grep{ $_ eq '-create' } @flags){ |
|
|
2
|
|
|
|
|
6
|
|
|
309
|
22
|
|
|
22
|
|
93
|
no strict 'refs'; |
|
|
22
|
|
|
|
|
23
|
|
|
|
22
|
|
|
|
|
1728
|
|
|
310
|
2
|
|
|
|
|
2
|
return \&{$package . '::' . $name}; |
|
|
2
|
|
|
|
|
15
|
|
|
311
|
|
|
|
|
|
|
} |
|
312
|
|
|
|
|
|
|
else{ |
|
313
|
0
|
|
|
|
|
0
|
_fail('a flag', @flags); |
|
314
|
|
|
|
|
|
|
} |
|
315
|
|
|
|
|
|
|
} |
|
316
|
|
|
|
|
|
|
|
|
317
|
25
|
100
|
|
|
|
33
|
my $stash = get_stash($package) or return undef; |
|
318
|
|
|
|
|
|
|
|
|
319
|
21
|
100
|
|
|
|
55
|
if(defined(my $glob = $stash->{$name})){ |
|
320
|
16
|
100
|
|
|
|
32
|
if(ref(\$glob) eq 'GLOB'){ |
|
321
|
12
|
|
|
|
|
7
|
return *{$glob}{CODE}; |
|
|
12
|
|
|
|
|
73
|
|
|
322
|
|
|
|
|
|
|
} |
|
323
|
|
|
|
|
|
|
else{ # a stub or special constant |
|
324
|
22
|
|
|
22
|
|
74
|
no strict 'refs'; |
|
|
22
|
|
|
|
|
26
|
|
|
|
22
|
|
|
|
|
16601
|
|
|
325
|
4
|
|
|
|
|
3
|
return *{$package . '::' . $name}{CODE}; |
|
|
4
|
|
|
|
|
27
|
|
|
326
|
|
|
|
|
|
|
} |
|
327
|
|
|
|
|
|
|
} |
|
328
|
5
|
|
|
|
|
12
|
return undef; |
|
329
|
|
|
|
|
|
|
} |
|
330
|
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
sub curry{ |
|
332
|
42
|
|
|
42
|
1
|
16641
|
my $is_method = !is_code_ref($_[0]); |
|
333
|
|
|
|
|
|
|
|
|
334
|
42
|
|
|
|
|
1693
|
my $proc; |
|
335
|
42
|
100
|
|
|
|
60
|
$proc = shift if !$is_method; |
|
336
|
|
|
|
|
|
|
|
|
337
|
42
|
|
|
|
|
41
|
my $args = \@_; |
|
338
|
|
|
|
|
|
|
|
|
339
|
42
|
|
|
|
|
33
|
my @tmpl; |
|
340
|
|
|
|
|
|
|
|
|
341
|
42
|
|
|
|
|
27
|
my $i = 0; |
|
342
|
42
|
|
|
|
|
26
|
my $max_ph = -1; |
|
343
|
42
|
|
|
|
|
37
|
my $min_ph = 0; |
|
344
|
|
|
|
|
|
|
|
|
345
|
42
|
|
|
|
|
48
|
foreach my $arg(@_){ |
|
346
|
79
|
100
|
100
|
|
|
79
|
if(is_scalar_ref($arg) && is_integer($$arg)){ |
|
|
|
100
|
100
|
|
|
|
|
|
347
|
25
|
|
|
|
|
59
|
push @tmpl, sprintf '$_[%d]', $$arg; |
|
348
|
|
|
|
|
|
|
|
|
349
|
25
|
50
|
|
|
|
53
|
if($$arg >= 0){ |
|
350
|
25
|
100
|
|
|
|
37
|
$max_ph = $$arg if $$arg > $max_ph; |
|
351
|
|
|
|
|
|
|
} |
|
352
|
|
|
|
|
|
|
else{ |
|
353
|
0
|
0
|
|
|
|
0
|
$min_ph = $$arg if $$arg < $min_ph; |
|
354
|
|
|
|
|
|
|
} |
|
355
|
|
|
|
|
|
|
} |
|
356
|
|
|
|
|
|
|
elsif(defined($arg) && (\$arg) == \*_){ |
|
357
|
14
|
|
|
|
|
15
|
push @tmpl, '@_[$max_ph .. $#_ + $min_ph]'; |
|
358
|
|
|
|
|
|
|
} |
|
359
|
|
|
|
|
|
|
else{ |
|
360
|
40
|
|
|
|
|
530
|
push @tmpl, sprintf '$args->[%d]', $i; |
|
361
|
|
|
|
|
|
|
} |
|
362
|
79
|
|
|
|
|
96
|
$i++; |
|
363
|
|
|
|
|
|
|
} |
|
364
|
|
|
|
|
|
|
|
|
365
|
42
|
|
|
|
|
32
|
$max_ph++; |
|
366
|
|
|
|
|
|
|
|
|
367
|
42
|
|
|
|
|
87
|
my($pkg, $file, $line, $hints, $bitmask) = (caller 0 )[0, 1, 2, 8, 9]; |
|
368
|
42
|
|
|
|
|
707
|
my $body = sprintf <<'END_CXT', $pkg, $line, $file; |
|
369
|
|
|
|
|
|
|
BEGIN{ $^H = $hints; ${^WARNING_BITS} = $bitmask; } |
|
370
|
|
|
|
|
|
|
package %s; |
|
371
|
|
|
|
|
|
|
#line %s %s |
|
372
|
|
|
|
|
|
|
END_CXT |
|
373
|
|
|
|
|
|
|
|
|
374
|
42
|
100
|
|
|
|
51
|
if($is_method){ |
|
375
|
14
|
|
|
|
|
19
|
my $selfp = shift @tmpl; |
|
376
|
14
|
|
|
|
|
12
|
$proc = shift @tmpl; |
|
377
|
14
|
100
|
|
|
|
46
|
$body .= sprintf q{ sub { |
|
378
|
|
|
|
|
|
|
my $self = %s; |
|
379
|
|
|
|
|
|
|
my $method = %s; |
|
380
|
|
|
|
|
|
|
$self->$method(%s); |
|
381
|
|
|
|
|
|
|
} }, $selfp, defined($proc) ? $proc : 'undef', join(q{,}, @tmpl); |
|
382
|
|
|
|
|
|
|
} |
|
383
|
|
|
|
|
|
|
else{ |
|
384
|
28
|
|
|
|
|
57
|
$body .= sprintf q{ sub { $proc->(%s) } }, join q{,}, @tmpl; |
|
385
|
|
|
|
|
|
|
} |
|
386
|
42
|
50
|
|
4
|
|
2592
|
eval $body or die $@; |
|
|
5
|
|
|
3
|
|
11
|
|
|
|
5
|
|
|
2
|
|
933
|
|
|
|
4
|
|
|
2
|
|
8
|
|
|
|
4
|
|
|
2
|
|
364
|
|
|
|
3
|
|
|
2
|
|
6
|
|
|
|
3
|
|
|
2
|
|
241
|
|
|
|
2
|
|
|
2
|
|
4
|
|
|
|
2
|
|
|
2
|
|
144
|
|
|
|
2
|
|
|
2
|
|
5
|
|
|
|
2
|
|
|
2
|
|
135
|
|
|
|
2
|
|
|
2
|
|
4
|
|
|
|
2
|
|
|
2
|
|
146
|
|
|
|
2
|
|
|
2
|
|
4
|
|
|
|
2
|
|
|
2
|
|
139
|
|
|
|
2
|
|
|
2
|
|
5
|
|
|
|
2
|
|
|
2
|
|
135
|
|
|
|
2
|
|
|
2
|
|
5
|
|
|
|
2
|
|
|
2
|
|
152
|
|
|
|
2
|
|
|
2
|
|
4
|
|
|
|
2
|
|
|
2
|
|
152
|
|
|
|
2
|
|
|
2
|
|
4
|
|
|
|
2
|
|
|
2
|
|
148
|
|
|
|
2
|
|
|
2
|
|
4
|
|
|
|
2
|
|
|
2
|
|
158
|
|
|
|
2
|
|
|
2
|
|
5
|
|
|
|
2
|
|
|
2
|
|
144
|
|
|
|
2
|
|
|
2
|
|
4
|
|
|
|
2
|
|
|
2
|
|
146
|
|
|
|
2
|
|
|
2
|
|
6
|
|
|
|
2
|
|
|
2
|
|
168
|
|
|
|
2
|
|
|
2
|
|
5
|
|
|
|
2
|
|
|
2
|
|
180
|
|
|
|
2
|
|
|
2
|
|
5
|
|
|
|
2
|
|
|
2
|
|
177
|
|
|
|
2
|
|
|
2
|
|
4
|
|
|
|
2
|
|
|
2
|
|
179
|
|
|
|
2
|
|
|
2
|
|
5
|
|
|
|
2
|
|
|
2
|
|
182
|
|
|
|
2
|
|
|
1
|
|
4
|
|
|
|
2
|
|
|
1
|
|
207
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
140
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
133
|
|
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
142
|
|
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
162
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
124
|
|
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
138
|
|
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
198
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
130
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
122
|
|
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
209
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
139
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
134
|
|
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
160
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
136
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
150
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
137
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
144
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
150
|
|
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
136
|
|
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
139
|
|
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
49
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
45
|
|
|
387
|
|
|
|
|
|
|
} |
|
388
|
|
|
|
|
|
|
|
|
389
|
0
|
|
|
5
|
|
0
|
BEGIN{ |
|
390
|
22
|
|
|
22
|
|
69
|
our %modifiers; |
|
391
|
|
|
|
|
|
|
|
|
392
|
22
|
|
|
|
|
22
|
my $initializer; |
|
393
|
|
|
|
|
|
|
$initializer = sub{ |
|
394
|
4
|
|
|
|
|
1640
|
require Hash::Util::FieldHash::Compat; |
|
395
|
4
|
|
|
|
|
6249
|
Hash::Util::FieldHash::Compat::fieldhash(\%modifiers); |
|
396
|
4
|
|
|
|
|
65
|
undef $initializer; |
|
397
|
22
|
|
|
|
|
88
|
}; |
|
398
|
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
sub modify_subroutine{ |
|
400
|
51
|
|
|
51
|
1
|
16795
|
my $code = code_ref shift; |
|
401
|
|
|
|
|
|
|
|
|
402
|
50
|
100
|
|
|
|
110
|
if((@_ % 2) != 0){ |
|
403
|
1
|
|
|
|
|
3
|
_croak('Odd number of arguments for modify_subroutine()'); |
|
404
|
|
|
|
|
|
|
} |
|
405
|
49
|
|
|
|
|
79
|
my %args = @_; |
|
406
|
|
|
|
|
|
|
|
|
407
|
49
|
|
|
|
|
34
|
my(@before, @around, @after); |
|
408
|
|
|
|
|
|
|
|
|
409
|
49
|
100
|
|
|
|
85
|
@before = map{ code_ref $_ } @{array_ref delete $args{before}} if exists $args{before}; |
|
|
41
|
|
|
|
|
41
|
|
|
|
28
|
|
|
|
|
49
|
|
|
410
|
48
|
100
|
|
|
|
68
|
@around = map{ code_ref $_ } @{array_ref delete $args{around}} if exists $args{around}; |
|
|
41
|
|
|
|
|
40
|
|
|
|
28
|
|
|
|
|
35
|
|
|
411
|
47
|
100
|
|
|
|
67
|
@after = map{ code_ref $_ } @{array_ref delete $args{after}} if exists $args{after}; |
|
|
42
|
|
|
|
|
44
|
|
|
|
29
|
|
|
|
|
36
|
|
|
412
|
|
|
|
|
|
|
|
|
413
|
46
|
50
|
|
|
|
77
|
if(%args){ |
|
414
|
0
|
|
|
|
|
0
|
_fail('a modifier property', join ', ', keys %args); |
|
415
|
|
|
|
|
|
|
} |
|
416
|
|
|
|
|
|
|
|
|
417
|
46
|
|
|
|
|
107
|
my %props = ( |
|
418
|
|
|
|
|
|
|
before => \@before, |
|
419
|
|
|
|
|
|
|
around => \@around, |
|
420
|
|
|
|
|
|
|
after => \@after, |
|
421
|
|
|
|
|
|
|
current_ref => \$code, |
|
422
|
|
|
|
|
|
|
); |
|
423
|
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
#$code = curry($_, (my $tmp = $code), *_) for @around; |
|
425
|
46
|
|
|
|
|
63
|
for my $ar_code(reverse @around){ |
|
426
|
40
|
|
|
|
|
23
|
my $next = $code; |
|
427
|
40
|
|
|
42
|
|
105
|
$code = sub{ $ar_code->($next, @_) }; |
|
|
42
|
|
|
|
|
9950
|
|
|
428
|
|
|
|
|
|
|
} |
|
429
|
46
|
|
|
|
|
121
|
my($pkg, $file, $line, $hints, $bitmask) = (caller 0)[0, 1, 2, 8, 9]; |
|
430
|
|
|
|
|
|
|
|
|
431
|
46
|
|
|
|
|
661
|
my $context = sprintf <<'END_CXT', $pkg, $line, $file; |
|
432
|
|
|
|
|
|
|
BEGIN{ $^H = $hints; ${^WARNING_BITS} = $bitmask; } |
|
433
|
|
|
|
|
|
|
package %s; |
|
434
|
|
|
|
|
|
|
#line %s %s(modify_subroutine) |
|
435
|
|
|
|
|
|
|
END_CXT |
|
436
|
|
|
|
|
|
|
|
|
437
|
46
|
50
|
|
|
|
2762
|
my $modified = eval $context . q{sub{ |
|
438
|
|
|
|
|
|
|
$_->(@_) for @before; |
|
439
|
|
|
|
|
|
|
if(wantarray){ # list context |
|
440
|
|
|
|
|
|
|
my @ret = $code->(@_); |
|
441
|
|
|
|
|
|
|
$_->(@_) for @after; |
|
442
|
|
|
|
|
|
|
return @ret; |
|
443
|
|
|
|
|
|
|
} |
|
444
|
|
|
|
|
|
|
elsif(defined wantarray){ # scalar context |
|
445
|
|
|
|
|
|
|
my $ret = $code->(@_); |
|
446
|
|
|
|
|
|
|
$_->(@_) for @after; |
|
447
|
|
|
|
|
|
|
return $ret; |
|
448
|
|
|
|
|
|
|
} |
|
449
|
|
|
|
|
|
|
else{ # void context |
|
450
|
|
|
|
|
|
|
$code->(@_); |
|
451
|
|
|
|
|
|
|
$_->(@_) for @after; |
|
452
|
|
|
|
|
|
|
return; |
|
453
|
|
|
|
|
|
|
} |
|
454
|
|
|
|
|
|
|
}} or die $@; |
|
455
|
|
|
|
|
|
|
|
|
456
|
46
|
100
|
|
|
|
478
|
$initializer->() if $initializer; |
|
457
|
|
|
|
|
|
|
|
|
458
|
46
|
|
|
|
|
244
|
$modifiers{$modified} = \%props; |
|
459
|
46
|
|
|
|
|
211
|
return $modified; |
|
460
|
|
|
|
|
|
|
} |
|
461
|
|
|
|
|
|
|
|
|
462
|
22
|
|
|
|
|
57
|
my %valid_modifiers = map{ $_ => undef } qw(before around after); |
|
|
66
|
|
|
|
|
9062
|
|
|
463
|
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
sub subroutine_modifier{ |
|
465
|
55
|
|
|
55
|
1
|
4299
|
my $modified = code_ref shift; |
|
466
|
|
|
|
|
|
|
|
|
467
|
55
|
|
|
|
|
63
|
my $props_ref = $modifiers{$modified}; |
|
468
|
|
|
|
|
|
|
|
|
469
|
55
|
100
|
|
|
|
79
|
unless(@_){ # subroutine_modifier($subr) - only checking |
|
470
|
6
|
|
|
|
|
20
|
return defined $props_ref; |
|
471
|
|
|
|
|
|
|
} |
|
472
|
49
|
100
|
|
|
|
62
|
unless($props_ref){ # otherwise, it should be modified subroutines |
|
473
|
2
|
|
|
|
|
4
|
_fail('a modified subroutine', $modified); |
|
474
|
|
|
|
|
|
|
} |
|
475
|
|
|
|
|
|
|
|
|
476
|
47
|
|
|
|
|
62
|
my($name, @subs) = @_; |
|
477
|
47
|
100
|
66
|
|
|
49
|
(is_string($name) && exists $valid_modifiers{$name}) or _fail('a modifier property', $name); |
|
478
|
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
|
|
480
|
44
|
|
|
|
|
42
|
my $property = $props_ref->{$name}; |
|
481
|
44
|
100
|
|
|
|
63
|
if(@subs){ |
|
482
|
32
|
100
|
|
|
|
38
|
if($name eq 'after'){ |
|
483
|
9
|
|
|
|
|
5
|
push @{$property}, map{ code_ref $_ } @subs; |
|
|
9
|
|
|
|
|
10
|
|
|
|
12
|
|
|
|
|
13
|
|
|
484
|
|
|
|
|
|
|
} |
|
485
|
|
|
|
|
|
|
else{ |
|
486
|
23
|
|
|
|
|
14
|
unshift @{$property}, reverse map{ code_ref $_ } @subs; |
|
|
23
|
|
|
|
|
31
|
|
|
|
29
|
|
|
|
|
27
|
|
|
487
|
|
|
|
|
|
|
} |
|
488
|
|
|
|
|
|
|
|
|
489
|
31
|
100
|
|
|
|
51
|
if($name eq 'around'){ |
|
490
|
11
|
|
|
|
|
8
|
my $current_ref = $props_ref->{current_ref}; |
|
491
|
11
|
|
|
|
|
12
|
for my $ar(reverse @subs){ |
|
492
|
14
|
|
|
|
|
11
|
my $base = $$current_ref; |
|
493
|
14
|
|
|
12
|
|
36
|
$$current_ref = sub{ $ar->($base, @_) }; |
|
|
12
|
|
|
|
|
625
|
|
|
494
|
|
|
|
|
|
|
} |
|
495
|
|
|
|
|
|
|
} |
|
496
|
|
|
|
|
|
|
} |
|
497
|
43
|
100
|
|
|
|
73
|
return @{$property} if defined wantarray; |
|
|
12
|
|
|
|
|
47
|
|
|
498
|
|
|
|
|
|
|
|
|
499
|
31
|
|
|
|
|
47
|
return; |
|
500
|
|
|
|
|
|
|
} |
|
501
|
|
|
|
|
|
|
} |
|
502
|
|
|
|
|
|
|
# |
|
503
|
|
|
|
|
|
|
# mkopt() and mkopt_hash() are originated from Data::OptList |
|
504
|
|
|
|
|
|
|
# |
|
505
|
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
my %test_for = ( |
|
507
|
|
|
|
|
|
|
CODE => \&is_code_ref, |
|
508
|
|
|
|
|
|
|
HASH => \&is_hash_ref, |
|
509
|
|
|
|
|
|
|
ARRAY => \&is_array_ref, |
|
510
|
|
|
|
|
|
|
SCALAR => \&is_scalar_ref, |
|
511
|
|
|
|
|
|
|
GLOB => \&is_glob_ref, |
|
512
|
|
|
|
|
|
|
); |
|
513
|
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
sub __is_a { |
|
516
|
74
|
|
|
74
|
|
75
|
my ($got, $expected) = @_; |
|
517
|
|
|
|
|
|
|
|
|
518
|
74
|
100
|
|
|
|
109
|
return scalar grep{ __is_a($got, $_) } @{$expected} if ref $expected; |
|
|
15
|
|
|
|
|
50
|
|
|
|
7
|
|
|
|
|
34
|
|
|
519
|
|
|
|
|
|
|
|
|
520
|
67
|
|
|
|
|
66
|
my $t = $test_for{$expected}; |
|
521
|
67
|
100
|
|
|
|
109
|
return defined($t) ? $t->($got) : is_instance($got, $expected); |
|
522
|
|
|
|
|
|
|
} |
|
523
|
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
sub mkopt{ |
|
525
|
88
|
|
|
88
|
1
|
8541
|
my($opt_list, $moniker, $require_unique, $must_be) = @_; |
|
526
|
|
|
|
|
|
|
|
|
527
|
88
|
100
|
|
|
|
149
|
return [] unless defined $opt_list; |
|
528
|
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
$opt_list = [ |
|
530
|
87
|
100
|
|
|
|
119
|
map { $_ => (ref $opt_list->{$_} ? $opt_list->{$_} : ()) } keys %$opt_list |
|
|
9
|
100
|
|
|
|
29
|
|
|
531
|
|
|
|
|
|
|
] if is_hash_ref($opt_list); |
|
532
|
|
|
|
|
|
|
|
|
533
|
86
|
100
|
|
|
|
142
|
is_array_ref($opt_list) or _fail('an ARRAY or HASH reference', $opt_list); |
|
534
|
|
|
|
|
|
|
|
|
535
|
83
|
|
|
|
|
89
|
my @return; |
|
536
|
|
|
|
|
|
|
my %seen; |
|
537
|
|
|
|
|
|
|
|
|
538
|
83
|
|
|
|
|
82
|
my $vh = is_hash_ref($must_be); |
|
539
|
83
|
|
|
|
|
163
|
my $validator = $must_be; |
|
540
|
|
|
|
|
|
|
|
|
541
|
83
|
100
|
100
|
|
|
227
|
if(defined($validator) && (!$vh && !is_array_ref($validator) && !is_string($validator))){ |
|
|
|
|
100
|
|
|
|
|
|
542
|
1
|
|
|
|
|
3
|
_fail('a type name, or ARRAY or HASH reference', $validator); |
|
543
|
|
|
|
|
|
|
} |
|
544
|
|
|
|
|
|
|
|
|
545
|
82
|
|
|
|
|
230
|
for(my $i = 0; $i < @$opt_list; $i++) { |
|
546
|
116
|
|
|
|
|
115
|
my $name = $opt_list->[$i]; |
|
547
|
116
|
|
|
|
|
70
|
my $value; |
|
548
|
|
|
|
|
|
|
|
|
549
|
116
|
100
|
|
|
|
116
|
is_string($name) or _fail("a name in $moniker opt list", $name); |
|
550
|
|
|
|
|
|
|
|
|
551
|
113
|
100
|
100
|
|
|
350
|
if($require_unique && $seen{$name}++) { |
|
552
|
2
|
|
|
|
|
7
|
_croak("Validation failed: Multiple definitions provided for $name in $moniker opt list") |
|
553
|
|
|
|
|
|
|
} |
|
554
|
|
|
|
|
|
|
|
|
555
|
111
|
100
|
|
|
|
281
|
if ($i == $#$opt_list) { $value = undef; } |
|
|
28
|
100
|
|
|
|
29
|
|
|
|
|
100
|
|
|
|
|
|
|
556
|
2
|
|
|
|
|
2
|
elsif(not defined $opt_list->[$i+1]) { $value = undef; $i++ } |
|
|
2
|
|
|
|
|
2
|
|
|
557
|
63
|
|
|
|
|
63
|
elsif(ref $opt_list->[$i+1]) { $value = $opt_list->[++$i] } |
|
558
|
18
|
|
|
|
|
18
|
else { $value = undef; } |
|
559
|
|
|
|
|
|
|
|
|
560
|
111
|
100
|
100
|
|
|
359
|
if (defined $value and defined( $vh ? ($validator = $must_be->{$name}) : $validator )){ |
|
|
|
100
|
|
|
|
|
|
|
561
|
59
|
100
|
|
|
|
81
|
unless(__is_a($value, $validator)) { |
|
562
|
6
|
|
|
|
|
18
|
_croak("Validation failed: ".ref($value)."-ref values are not valid for $name in $moniker opt list"); |
|
563
|
|
|
|
|
|
|
} |
|
564
|
|
|
|
|
|
|
} |
|
565
|
|
|
|
|
|
|
|
|
566
|
105
|
|
|
|
|
1824
|
push @return, [ $name => $value ]; |
|
567
|
|
|
|
|
|
|
} |
|
568
|
|
|
|
|
|
|
|
|
569
|
71
|
|
|
|
|
186
|
return \@return; |
|
570
|
|
|
|
|
|
|
} |
|
571
|
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
sub mkopt_hash { |
|
573
|
57
|
|
|
57
|
1
|
1611
|
my($opt_list, $moniker, $must_be) = @_; |
|
574
|
57
|
100
|
|
|
|
101
|
return {} unless $opt_list; |
|
575
|
|
|
|
|
|
|
|
|
576
|
56
|
|
|
|
|
46
|
my %hash = map { $_->[0] => $_->[1] } @{ mkopt($opt_list, $moniker, 1, $must_be) }; |
|
|
75
|
|
|
|
|
171
|
|
|
|
56
|
|
|
|
|
77
|
|
|
577
|
50
|
|
|
|
|
128
|
return \%hash; |
|
578
|
|
|
|
|
|
|
} |
|
579
|
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
1; |
|
581
|
|
|
|
|
|
|
__END__ |