MoreUtils/PP.pm

filter: Statementstmt 95.3% 447 / 469 Branchbran 89.1% 198 / 222 Conditioncond 72.5% 37 / 51 MC/DCmcdc 56.6% 17 / 30 Subroutinesub 96.1% 75 / 78 Podpod 0.0% 0 / 62 totaltotal 84.8% 774 / 912 CC 159 SCAR 16.8
CC
159
Cov
92%
minmaxstr
19.8
minmax
14.2
mode
11.4
CRAP 5.4
↑ Summary MoreUtils.pm »
1 package List::MoreUtils::PP;
2  
3 122 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 122 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 122 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 122 our $VERSION = '0.430';
8  
9 =pod
10  
11 =head1 NAME
12  
13 List::MoreUtils::PP - Provide List::MoreUtils pure Perl implementation
14  
15 =head1 SYNOPSIS
16  
17 BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; }
18 use List::MoreUtils qw(:all);
19  
20 =cut
21  
22 ## no critic (Subroutines::ProhibitSubroutinePrototypes, Subroutines::RequireArgUnpacking)
23 ## no critic (Subroutines::ProhibitManyArgs)
24  
25 sub any (&@)
26 13 ▶{
Subroutine any: called CC=3 SCAR=11.0
Pod undocumented
27 13 my $f = shift;
28 13 foreach (@_)
29 {
30 40005 ▶ return 1 if $f->();
Branch: 1 branch
BranchTrueFalseTotal
if &$f() 8 39994 40002
31 }
32 2 return 0;
33 }
34  
35 sub all (&@)
36 9 ▶{
Subroutine all: called CC=3 SCAR=11.0
Pod undocumented
37 9 my $f = shift;
38 9 foreach (@_)
39 {
40 25005 ▶ return 0 unless $f->();
Branch: 1 branch
BranchTrueFalseTotal
unless &$f() 5 24999 25004
41 }
42 3 return 1;
43 }
44  
45 sub none (&@)
46 9 ▶{
Subroutine none: called CC=3 SCAR=11.0
Pod undocumented
47 9 my $f = shift;
48 9 foreach (@_)
49 {
50 40002 ▶ return 0 if $f->();
Branch: 1 branch
BranchTrueFalseTotal
if &$f() 5 39996 40001
51 }
52 3 return 1;
53 }
54  
55 sub notall (&@)
56 9 ▶{
Subroutine notall: called CC=3 SCAR=11.0
Pod undocumented
57 9 my $f = shift;
58 9 foreach (@_)
59 {
60 20006 ▶ return 1 unless $f->();
Branch: 1 branch
BranchTrueFalseTotal
unless &$f() 6 19999 20005
61 }
62 2 return 0;
63 }
64  
65 sub one (&@)
66 12 ▶{
Subroutine one: called CC=4 SCAR=13.9
Pod undocumented
67 12 my $f = shift;
68 12 my $found = 0;
69 12 foreach (@_)
70 {
71 2063 ▶ $f->() and $found++ and return 0;
Branch: 1 branch
BranchTrueFalseTotal
&$f() and $found++ and return 0 6 2056 2062
Condition100%3/3
&$f() and $found++
!ll&&!rl&&r
204796
MC/DC100%2/2
&$f() and $found++
&$f() $found++
Truth table100%3/3
A and B
A= &$f()B= $found++
ABresult
0X0
100
111
72 }
73 5 return $found;
74 }
75  
76 sub any_u (&@)
77 13 ▶{
Subroutine any_u: called CC=4 SCAR=13.9
Pod undocumented
78 13 my $f = shift;
79 13 ▶ return if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 12 13
80 12 ▶ $f->() and return 1 foreach (@_);
Branch: 1 branch
BranchTrueFalseTotal
&$f() and return 1 8 39994 40002
81 1 return 0;
82 }
83  
84 sub all_u (&@)
85 9 ▶{
Subroutine all_u: called CC=4 SCAR=13.9
Pod undocumented
86 9 my $f = shift;
87 9 ▶ return if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 8 9
88 8 ▶ $f->() or return 0 foreach (@_);
Branch: 1 branch
BranchTrueFalseTotal
&$f() or return 0 24999 5 25004
89 2 return 1;
90 }
91  
92 sub none_u (&@)
93 9 ▶{
Subroutine none_u: called CC=4 SCAR=13.9
Pod undocumented
94 9 my $f = shift;
95 9 ▶ return if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 8 9
96 8 ▶ $f->() and return 0 foreach (@_);
Branch: 1 branch
BranchTrueFalseTotal
&$f() and return 0 5 39996 40001
97 2 return 1;
98 }
99  
100 sub notall_u (&@)
101 9 ▶{
Subroutine notall_u: called CC=4 SCAR=13.9
Pod undocumented
102 9 my $f = shift;
103 9 ▶ return if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 8 9
104 8 ▶ $f->() or return 1 foreach (@_);
Branch: 1 branch
BranchTrueFalseTotal
&$f() or return 1 19999 6 20005
105 1 return 0;
106 }
107  
108 sub one_u (&@)
109 12 ▶{
Subroutine one_u: called CC=5 SCAR=16.1
Pod undocumented
110 12 my $f = shift;
111 12 ▶ return if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 11 12
112 11 my $found = 0;
113 11 foreach (@_)
114 {
115 2063 ▶ $f->() and $found++ and return 0;
Branch: 1 branch
BranchTrueFalseTotal
&$f() and $found++ and return 0 6 2056 2062
Condition100%3/3
&$f() and $found++
!ll&&!rl&&r
204796
MC/DC100%2/2
&$f() and $found++
&$f() $found++
Truth table100%3/3
A and B
A= &$f()B= $found++
ABresult
0X0
100
111
116 }
117 4 return $found;
118 }
119  
120 sub reduce_u(&@)
121 8 ▶{
Subroutine reduce_u: called CC=2 SCAR=6.9
Pod undocumented
122 8 my $code = shift;
123  
124 # Localise $a, $b
125 my ($caller_a, $caller_b) = do
126 8 {
127 8 my $pkg = caller();
128 ## no critic (TestingAndDebugging::ProhibitNoStrict, ValuesAndExpressions::ProhibitCommaSeparatedStatements)
129 122 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
130 8 \*{$pkg . '::a'}, \*{$pkg . '::b'};
131 };
132  
133 ## no critic (Variables::RequireInitializationForLocalVars)
134 8 local (*$caller_a, *$caller_b);
135 8 *$caller_a = \();
136 8 for (0 .. $#_)
137 {
138 224 *$caller_b = \$_[$_];
139 224 *$caller_a = \($code->());
140 }
141  
142 5 return ${*$caller_a};
143 }
144  
145 sub reduce_0(&@)
146 9 ▶{
Subroutine reduce_0: called CC=2 SCAR=6.9
Pod undocumented
147 9 my $code = shift;
148  
149 # Localise $a, $b
150 my ($caller_a, $caller_b) = do
151 9 {
152 9 my $pkg = caller();
153 ## no critic (TestingAndDebugging::ProhibitNoStrict, ValuesAndExpressions::ProhibitCommaSeparatedStatements)
154 122 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
155 9 \*{$pkg . '::a'}, \*{$pkg . '::b'};
156 };
157  
158 ## no critic (Variables::RequireInitializationForLocalVars)
159 9 local (*$caller_a, *$caller_b);
160 9 *$caller_a = \0;
161 9 for (0 .. $#_)
162 {
163 231 *$caller_b = \$_[$_];
164 231 *$caller_a = \($code->());
165 }
166  
167 6 return ${*$caller_a};
168 }
169  
170 sub reduce_1(&@)
171 1 ▶{
Subroutine reduce_1: called CC=2 SCAR=6.9
Pod undocumented
172 1 my $code = shift;
173  
174 # Localise $a, $b
175 my ($caller_a, $caller_b) = do
176 1 {
177 1 my $pkg = caller();
178 ## no critic (TestingAndDebugging::ProhibitNoStrict, ValuesAndExpressions::ProhibitCommaSeparatedStatements)
179 122 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
180 1 \*{$pkg . '::a'}, \*{$pkg . '::b'};
181 };
182  
183 ## no critic (Variables::RequireInitializationForLocalVars)
184 1 local (*$caller_a, *$caller_b);
185 1 *$caller_a = \1;
186 1 for (0 .. $#_)
187 {
188 750 *$caller_b = \$_[$_];
189 750 *$caller_a = \($code->());
190 }
191  
192 1 return ${*$caller_a};
193 }
194  
195 sub true (&@)
196 10 ▶{
Subroutine true: called CC=3 SCAR=11.0
Pod undocumented
197 10 my $f = shift;
198 10 my $count = 0;
199 10 ▶ $f->() and ++$count foreach (@_);
Branch: 1 branch
BranchTrueFalseTotal
&$f() and ++$count 10005 59995 70000
200 9 return $count;
201 }
202  
203 sub false (&@)
204 10 ▶{
Subroutine false: called CC=3 SCAR=11.0
Pod undocumented
205 10 my $f = shift;
206 10 my $count = 0;
207 10 ▶ $f->() or ++$count foreach (@_);
Branch: 1 branch
BranchTrueFalseTotal
&$f() or ++$count 20003 49997 70000
208 9 return $count;
209 }
210  
211 sub firstidx (&@)
212 31 ▶{
Subroutine firstidx: called CC=3 SCAR=11.0
Pod undocumented
213 31 my $f = shift;
214 31 foreach my $i (0 .. $#_)
215 {
216 50060 local *_ = \$_[$i];
217 50060 ▶ return $i if $f->();
Branch: 1 branch
BranchTrueFalseTotal
if &$f() 20 50034 50054
218 }
219 5 return -1;
220 }
221  
222 sub firstval (&@)
223 8 ▶{
Subroutine firstval: called CC=3 SCAR=11.0
Pod undocumented
224 8 my $test = shift;
225 8 foreach (@_)
226 {
227 21 ▶ return $_ if $test->();
Branch: 1 branch
BranchTrueFalseTotal
if &$test() 4 16 20
228 }
229 ## no critic (Subroutines::ProhibitExplicitReturnUndef)
230 3 return undef;
231 }
232  
233 sub firstres (&@)
234 7 ▶{
Subroutine firstres: called CC=3 SCAR=11.0
Pod undocumented
235 7 my $test = shift;
236 7 foreach (@_)
237 {
238 21 my $testval = $test->();
239 20 ▶ $testval and return $testval;
Branch: 1 branch
BranchTrueFalseTotal
$testval and return $testval 4 16 20
240 }
241 ## no critic (Subroutines::ProhibitExplicitReturnUndef)
242 2 return undef;
243 }
244  
245 sub onlyidx (&@)
246 17 ▶{
Subroutine onlyidx: called CC=5 SCAR=16.1
Pod undocumented
247 17 my $f = shift;
248 17 my $found;
249 17 foreach my $i (0 .. $#_)
250 {
251 3521 local *_ = \$_[$i];
252 3521 ▶ $f->() or next;
Branch: 1 branch
BranchTrueFalseTotal
&$f() or next 22 3498 3520
253 22 ▶ defined $found and return -1;
Branch: 1 branch
BranchTrueFalseTotal
defined $found and return -1 8 14 22
254 14 $found = $i;
255 }
256 8 ▶ return defined $found ? $found : -1;
Branch: 1 branch
BranchTrueFalseTotal
defined $found ? : 6 2 8
257 }
258  
259 sub onlyval (&@)
260 17 ▶{
Subroutine onlyval: called CC=4 SCAR=13.9
Pod undocumented
261 17 my $test = shift;
262 17 my $result = undef;
263 17 my $found = 0;
264 17 foreach (@_)
265 {
266 3521 ▶ $test->() or next;
Branch: 1 branch
BranchTrueFalseTotal
&$test() or next 22 3498 3520
267 22 $result = $_;
268 ## no critic (Subroutines::ProhibitExplicitReturnUndef)
269 22 ▶ $found++ and return undef;
Branch: 1 branch
BranchTrueFalseTotal
$found++ and return undef 8 14 22
270 }
271 8 return $result;
272 }
273  
274 sub onlyres (&@)
275 15 ▶{
Subroutine onlyres: called CC=5 SCAR=16.1
Pod undocumented
276 15 my $test = shift;
277 15 my $result = undef;
278 15 my $found = 0;
279 15 foreach (@_)
280 {
281 2921 ▶ my $rv = $test->() or next;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = &$test() or next 20 2900 2920
282 20 $result = $rv;
283 ## no critic (Subroutines::ProhibitExplicitReturnUndef)
284 20 ▶ $found++ and return undef;
Branch: 1 branch
BranchTrueFalseTotal
$found++ and return undef 8 12 20
285 }
286 6 ▶ return $found ? $result : undef;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 4 2 6
287 }
288  
289 sub lastidx (&@)
290 13 ▶{
Subroutine lastidx: called CC=3 SCAR=11.0
Pod undocumented
291 13 my $f = shift;
292 13 foreach my $i (reverse 0 .. $#_)
293 {
294 20009 local *_ = \$_[$i];
295 20009 ▶ return $i if $f->();
Branch: 1 branch
BranchTrueFalseTotal
if &$f() 8 20000 20008
296 }
297 4 return -1;
298 }
299  
300 sub lastval (&@)
301 8 ▶{
Subroutine lastval: called CC=3 SCAR=11.0
Pod undocumented
302 8 my $test = shift;
303 8 my $ix;
304 8 ▶ for ($ix = $#_; $ix >= 0; $ix--)
Branch: 1 branch
BranchTrueFalseTotal
if ($ix >= 0) 13 3 16
305 {
306 13 local *_ = \$_[$ix];
307 13 my $testval = $test->();
308  
309 # Simulate $_ as alias
310 12 $_[$ix] = $_;
311 12 ▶ return $_ if $testval;
Branch: 1 branch
BranchTrueFalseTotal
if $testval 4 8 12
312 }
313 ## no critic (Subroutines::ProhibitExplicitReturnUndef)
314 3 return undef;
315 }
316  
317 sub lastres (&@)
318 7 ▶{
Subroutine lastres: called CC=3 SCAR=11.0
Pod undocumented
319 7 my $test = shift;
320 7 my $ix;
321 7 ▶ for ($ix = $#_; $ix >= 0; $ix--)
Branch: 1 branch
BranchTrueFalseTotal
if ($ix >= 0) 13 2 15
322 {
323 13 local *_ = \$_[$ix];
324 13 my $testval = $test->();
325  
326 # Simulate $_ as alias
327 12 $_[$ix] = $_;
328 12 ▶ return $testval if $testval;
Branch: 1 branch
BranchTrueFalseTotal
if $testval 4 8 12
329 }
330 ## no critic (Subroutines::ProhibitExplicitReturnUndef)
331 2 return undef;
332 }
333  
334 sub insert_after (&$\@)
335 11 ▶{
Subroutine insert_after: called CC=3 SCAR=11.1
Pod undocumented
336 11 my ($f, $val, $list) = @_;
337 11 my $c = &firstidx($f, @$list);
338 6 ▶ @$list = (@{$list}[0 .. $c], $val, @{$list}[$c + 1 .. $#$list],) and return 1 if $c != -1;
Branch: 1 branch
BranchTrueFalseTotal
if $c != -1 5 1 6
Condition60%3/5
$c != -1 && ((@$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*])) && (return 1))
!ll&&!rl&&r
150
@$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*]) and return 1
!ll
05
MC/DC0%0/2
$c != -1 && ((@$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*])) && (return 1))
$c != -1 @$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*])
Truth table33%1/3
A && B
A= $c != -1B= @$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*])
ABresult
0X0
100
111
339 1 return 0;
340 }
341  
342 sub insert_after_string ($$\@)
343 10 ▶{
Subroutine insert_after_string: called CC=3 SCAR=11.9
Pod undocumented
344 10 my ($string, $val, $list) = @_;
345 10 ▶ my $c = firstidx { defined $_ and $string eq $_ } @$list;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $string eq $_ 27 1 28
346 7 ▶ @$list = (@{$list}[0 .. $c], $val, @{$list}[$c + 1 .. $#$list],) and return 1 if $c != -1;
Branch: 1 branch
BranchTrueFalseTotal
if $c != -1 7 0 7
Condition40%2/5
$c != -1 && ((@$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*])) && (return 1))
!ll&&!rl&&r
070
@$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*]) and return 1
!ll
07
MC/DC0%0/2
$c != -1 && ((@$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*])) && (return 1))
$c != -1 @$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*])
Truth table0%0/3
A && B
A= $c != -1B= @$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*])
ABresult
0X0
100
111
347 0 return 0;
348 }
349  
350 sub apply (&@)
351 11 ▶{
Subroutine apply: called CC=3 SCAR=11.0
Pod undocumented
352 11 my $action = shift;
353 11 &$action foreach my @values = @_;
354 8 ▶ return wantarray ? @values : $values[-1];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 6 2 8
355 }
356  
357 sub after (&@)
358 7 ▶{
Subroutine after: called CC=2 SCAR=6.9
Pod undocumented
359 7 my $test = shift;
360 7 my $started;
361 my $lag;
362 ## no critic (BuiltinFunctions::RequireBlockGrep)
363 return grep $started ||= do
364 7 ▶ {
Condition100%3/3
$started ||= do { my $x = $lag; $lag = &$test(); $x }
l!l&&r!l&&!r
4415
MC/DC100%2/2
$started ||= do { my $x = $lag; $lag = &$test(); $x }
$started do { my $x = $lag; $lag = &$test(); $x }
Truth table100%3/3
A ||= B
A= $startedB= do { my $x = $lag; $lag = &$test(); $x }
ABresult
1X1
011
000
365 19 my $x = $lag;
366 19 $lag = $test->();
367 18 $x;
368 }, @_;
369 }
370  
371 sub after_incl (&@)
372 6 ▶{
Subroutine after_incl: called CC=2 SCAR=6.9
Pod undocumented
373 6 my $test = shift;
374 6 my $started;
375 6 ▶ return grep { $started ||= $test->() } @_;
Condition100%3/3
$started ||= &$test()
l!l&&r!l&&!r
849
MC/DC100%2/2
$started ||= &$test()
$started &$test()
Truth table100%3/3
A ||= B
A= $startedB= &$test()
ABresult
1X1
011
000
376 }
377  
378 sub before (&@)
379 6 ▶{
Subroutine before: called CC=2 SCAR=6.9
Pod undocumented
380 6 my $test = shift;
381 6 my $more = 1;
382 6 ▶ return grep { $more &&= !$test->() } @_;
Condition100%3/3
$more &&= !&$test()
!ll&&!rl&&r
5610
MC/DC100%2/2
$more &&= !&$test()
$more !&$test()
Truth table100%3/3
A &&= not(B)
A= $moreB= !&$test()
ABresult
0X0
100
111
383 }
384  
385 sub before_incl (&@)
386 6 ▶{
Subroutine before_incl: called CC=2 SCAR=6.9
Pod undocumented
387 6 my $test = shift;
388 6 my $more = 1;
389 6 my $lag = 1;
390 ## no critic (BuiltinFunctions::RequireBlockGrep)
391 return grep $more &&= do
392 6 ▶ {
Condition100%3/3
$more &&= do { my $x = $lag; $lag = !&$test(); $x }
!ll&&!rl&&r
3414
MC/DC100%2/2
$more &&= do { my $x = $lag; $lag = !&$test(); $x }
$more do { my $x = $lag; $lag = !&$test(); $x }
Truth table100%3/3
A &&= B
A= $moreB= do { my $x = $lag; $lag = !&$test(); $x }
ABresult
0X0
100
111
393 18 my $x = $lag;
394 18 $lag = !$test->();
395 17 $x;
396 }, @_;
397 }
398  
399 sub indexes (&@)
400 24 ▶{
Subroutine indexes: called CC=1 SCAR=0.0
Pod undocumented
401 24 my $test = shift;
402 return grep {
403 24 local *_ = \$_[$_];
404 144 $test->()
405 } 0 .. $#_;
406 }
407  
408 sub pairwise (&\@\@)
409 12 ▶{
Subroutine pairwise: called CC=4 SCAR=13.9
Pod undocumented
410 12 my $op = shift;
411  
412 # Symbols for caller's input arrays
413 122 ▶ use vars qw{ @A @B };
Subroutine BEGIN: called CC=1 SCAR=0.0
414 12 local (*A, *B) = @_;
415  
416 # Localise $a, $b
417 my ($caller_a, $caller_b) = do
418 12 {
419 12 my $pkg = caller();
420 ## no critic (TestingAndDebugging::ProhibitNoStrict, ValuesAndExpressions::ProhibitCommaSeparatedStatements)
421 122 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
422 12 \*{$pkg . '::a'}, \*{$pkg . '::b'};
423 };
424  
425 # Loop iteration limit
426 12 ▶ my $limit = $#A > $#B ? $#A : $#B;
Branch: 1 branch
BranchTrueFalseTotal
$#List::MoreUtils::PP::A > $#List::MoreUtils::PP::B ? : 0 12 12
427  
428 ## no critic (Variables::RequireInitializationForLocalVars)
429 # This map expression is also the return value
430 12 local (*$caller_a, *$caller_b);
431 ## no critic (BuiltinFunctions::ProhibitComplexMappings)
432 return map {
433 # Assign to $a, $b as refs to caller's array elements
434 12 ▶ (*$caller_a, *$caller_b) = \($#A < $_ ? undef : $A[$_], $#B < $_ ? undef : $B[$_]);
Branch: 2 branches
BranchTrueFalseTotal
$#List::MoreUtils::PP::A < $_ ? : 526 119 645
$#List::MoreUtils::PP::B < $_ ? : 0 645 645
435  
436 # Perform the transformation
437 645 $op->();
438 } 0 .. $limit;
439 }
440  
441 sub each_array (\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@)
442 10 ▶{
Subroutine each_array: called CC=1 SCAR=0.0
Pod undocumented
443 10 return each_arrayref(@_);
444 }
445  
446 sub each_arrayref
447 18 ▶{
Subroutine each_arrayref: called CC=4 SCAR=14.1
Pod undocumented
448 18 my @list = @_; # The list of references to the arrays
449 18 my $index = 0; # Which one the caller will get next
450 18 my $max = 0; # Number of elements in longest array
451  
452 # Get the length of the longest input array
453 18 foreach (@list)
454 {
455 26 ▶ unless (ref $_ eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ eq "ARRAY") 2 24 26
456 {
457 2 require Carp;
458 2 Carp::croak("each_arrayref: argument is not an array reference\n");
459 }
460 24 ▶ $max = @$_ if @$_ > $max;
Branch: 1 branch
BranchTrueFalseTotal
if @$_ > $max 16 8 24
461 }
462  
463 # Return the iterator as a closure wrt the above variables.
464 108 ▶ return sub {
Subroutine __ANON__: called CC=6 SCAR=19.2
465 108 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 10 98 108
466 {
467 10 my $method = shift;
468 10 ▶ unless ($method eq 'index')
Branch: 1 branch
BranchTrueFalseTotal
unless ($method eq "index") 0 10 10
469 {
470 0 require Carp;
471 0 Carp::croak("each_array: unknown argument '$method' passed to iterator.");
472 }
473  
474 ## no critic (Subroutines::ProhibitExplicitReturnUndef)
475 10 ▶ return undef if $index == 0 || $index > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $index == 0 or $index > $max 0 10 10
Condition33%1/3
$index == 0 or $index > $max
l!l&&r!l&&!r
0010
MC/DC0%0/2
$index == 0 or $index > $max
$index == 0 $index > $max
Truth table33%1/3
A or B
A= $index == 0B= $index > $max
ABresult
1X1
011
000
476 # Return current (last fetched) index
477 10 return $index - 1;
478 }
479  
480 # No more elements to return
481 98 ▶ return if $index >= $max;
Branch: 1 branch
BranchTrueFalseTotal
if $index >= $max 16 82 98
482 82 my $i = $index++;
483  
484 # Return ith elements
485 ## no critic (BuiltinFunctions::RequireBlockMap)
486 82 return map $_->[$i], @list;
487 }
488 16 }
489  
490 sub natatime ($@)
491 4 ▶{
Subroutine natatime: called CC=1 SCAR=0.0
Pod undocumented
492 4 my $n = shift;
493 4 my @list = @_;
494 1009 ▶ return sub { return splice @list, 0, $n; }
Subroutine __ANON__: called CC=1 SCAR=0.0
495 4 }
496  
497 # "leaks" when lexically hidden in arrayify
498 122 my $flatten;
499 165 ▶$flatten = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
500 165 ▶ return map { (ref $_ and ("ARRAY" eq ref $_ or overload::Method($_, '@{}'))) ? ($flatten->(@{$_})) : ($_) } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ && ('ARRAY' eq ref $_ || overload::Method($_, '@{}')) ? : 46 190 236
Condition83%5/6
ref $_ and "ARRAY" eq ref $_ || overload::Method($_, "\@{}")
!ll&&!rl&&r
182846
"ARRAY" eq ref $_ or overload::Method($_, "\@{}")
l!l&&r!l&&!r
4608
MC/DC66%2/3
ref $_ and "ARRAY" eq ref $_ || overload::Method($_, "\@{}")
ref $_ "ARRAY" eq ref $_ overload::Method($_, "\@{}")
Truth table75%3/4
A and B or C
A= ref $_B= "ARRAY" eq ref $_C= overload::Method($_, "\@{}")
ABCresult
0XX0
1000
11X1
1011
501 122 };
502  
503 sub arrayify
504 15 ▶{
Subroutine arrayify: called CC=1 SCAR=0.0
Pod undocumented
505 15 return map { $flatten->($_) } @_;
506 }
507  
508 sub mesh (\@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@)
509 26 ▶{
Subroutine mesh: called CC=3 SCAR=11.0
Pod undocumented
510 26 my $max = -1;
511 26 ▶ $max < $#$_ && ($max = $#$_) foreach @_;
Branch: 1 branch
BranchTrueFalseTotal
$max < $_->$#* and $max = $_->$#* 29 23 52
512 ## no critic (BuiltinFunctions::ProhibitComplexMappings)
513 return map {
514 25 my $ix = $_;
515 ## no critic (BuiltinFunctions::RequireBlockMap)
516 1834 map $_->[$ix], @_;
517 } 0 .. $max;
518 }
519  
520 sub zip6 (\@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@)
521 6 ▶{
Subroutine zip6: called CC=3 SCAR=11.0
Pod undocumented
522 6 my $max = -1;
523 6 ▶ $max < $#$_ && ($max = $#$_) foreach @_;
Branch: 1 branch
BranchTrueFalseTotal
$max < $_->$#* and $max = $_->$#* 7 4 11
524 ## no critic (BuiltinFunctions::ProhibitComplexMappings)
525 return map {
526 5 my $ix = $_;
527 ## no critic (BuiltinFunctions::RequireBlockMap)
528 27 [map $_->[$ix], @_];
529 } 0 .. $max;
530 }
531  
532 sub listcmp (\@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@)
533 10 ▶{
Subroutine listcmp: called CC=5 SCAR=16.1
Pod undocumented
534 10 my %ret;
535 10 ▶ for (my $i = 0; $i < scalar @_; ++$i)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 21 4 25
536 {
537 21 my %seen;
538 my $k;
539 21 ▶ foreach my $w (grep { defined $_ and not $seen{$k = $_}++ } @{$_[$i]})
Condition100%3/3
defined $_ && !$seen{$k = $_}++
!ll&&!rl&&r
212111
MC/DC100%2/2
defined $_ && !$seen{$k = $_}++
defined $_ !$seen{$k = $_}++
Truth table100%3/3
A && not(B)
A= defined $_B= !$seen{$k = $_}++
ABresult
0X0
100
111
540 {
541 102 ▶ $ret{$w} ||= [];
Condition100%2/2
$ret{$w} ||= []
l!l
3072
MC/DC100%1/1
$ret{$w} ||= []
$ret{$w}
Truth table100%2/2
A
A= $ret{$w}
Aresult
11
00
542 102 push @{$ret{$w}}, $i;
543 }
544 }
545 4 return %ret;
546 }
547  
548 sub uniq (@)
549 20 ▶{
Subroutine uniq: called CC=2 SCAR=6.9
Pod undocumented
550 20 my %seen = ();
551 20 my $k;
552 my $seen_undef;
553 20 ▶ return grep { defined $_ ? not $seen{$k = $_}++ : not $seen_undef++ } @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 4712 1 4713
554 }
555  
556 sub singleton (@)
557 19 ▶{
Subroutine singleton: called CC=3 SCAR=11.0
Pod undocumented
558 19 my %seen = ();
559 19 my $k;
560 my $seen_undef;
561 25535 ▶ return grep { 1 == (defined $_ ? $seen{$k = $_} : $seen_undef) }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 25532 3 25535
562 19 ▶ grep { defined $_ ? not $seen{$k = $_}++ : not $seen_undef++ } @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 42300 5 42305
563 }
564  
565 sub duplicates (@)
566 19 ▶{
Subroutine duplicates: called CC=3 SCAR=11.0
Pod undocumented
567 19 my %seen = ();
568 19 my $k;
569 my $seen_undef;
570 24659 ▶ return grep { 1 < (defined $_ ? $seen{$k = $_} : $seen_undef) }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 24656 3 24659
571 19 ▶ grep { defined $_ ? not $seen{$k = $_}++ : not $seen_undef++ } @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 41438 8 41446
572 }
573  
574 sub frequency (@)
575 17 ▶{
Subroutine frequency: called CC=6 SCAR=17.9
Pod undocumented
576 17 my %seen = ();
577 17 my $k;
578 my $seen_undef;
579 25525 ▶ my %h = map { defined $_ ? ($_ => $seen{$k = $_}) : () }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 25524 1 25525
580 17 ▶ grep { defined $_ ? not $seen{$k = $_}++ : not $seen_undef++ } @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 42302 6 42308
581 13 ▶ wantarray or return (scalar keys %h) + ($seen_undef ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
wantarray or return scalar(keys %h) + ($seen_undef ? 1 : 0) 7 6 13
$seen_undef ? : 0 6 6
582 7 undef $k;
583 7 ▶ return (%h, $seen_undef ? (\$k => $seen_undef) : ());
Branch: 1 branch
BranchTrueFalseTotal
$seen_undef ? : 1 6 7
584 }
585  
586 sub occurrences (@)
587 12 ▶{
Subroutine occurrences: called CC=5 SCAR=16.1
Pod undocumented
588 12 my %seen = ();
589 12 my $k;
590 my $seen_undef;
591 12 my @ret;
592 12 ▶ foreach my $l (map { $_ } grep { defined $_ ? not $seen{$k = $_}++ : not $seen_undef++ } @_)
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 414 5 419
593 {
594 119 ▶ my $n = defined $l ? $seen{$l} : $seen_undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $l ? : 118 1 119
595 119 ▶ defined $ret[$n] or $ret[$n] = [];
Branch: 1 branch
BranchTrueFalseTotal
defined $ret[$n] or $ret[$n] = [] 82 37 119
596 119 push @{$ret[$n]}, $l;
597 }
598 8 return @ret;
599 }
600  
601 sub mode (@)
602 32 ▶{
Subroutine mode: called CC=9 SCAR=24.3
Pod undocumented
603 32 my %seen = ();
604 32 my ($max, $k, $seen_undef) = (1);
605  
606 32 ▶ foreach (@_) { defined $_ ? ($max < ++$seen{$k = $_} and ++$max) : ($max < ++$seen_undef and ++$max) }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1180 0 1180
Condition33%2/6
$max < ++$seen{$k = $_} and ++$max
!ll&&!rl&&r
10021660
$max < ++$seen_undef and ++$max
!ll&&!rl&&r
000
MC/DC0%0/2
$max < ++$seen{$k = $_} and ++$max
$max < ++$seen{$k = $_} ++$max
MC/DC0%0/2
$max < ++$seen_undef and ++$max
$max < ++$seen_undef ++$max
Truth table66%2/3
A and B
A= $max < ++$seen{$k = $_}B= ++$max
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $max < ++$seen_undefB= ++$max
ABresult
0X0
100
111
607 20 ▶ wantarray or return $max;
Branch: 1 branch
BranchTrueFalseTotal
wantarray or return $max 10 10 20
608  
609 10 my @ret = ($max);
610 10 foreach my $l (grep { $seen{$_} == $max } keys %seen)
611 {
612 18 push @ret, $l;
613 }
614 10 ▶ $seen_undef and $seen_undef == $max and push @ret, undef;
Branch: 1 branch
BranchTrueFalseTotal
$seen_undef and $seen_undef == $max and push @ret, undef 0 10 10
Condition33%1/3
$seen_undef and $seen_undef == $max
!ll&&!rl&&r
1000
MC/DC0%0/2
$seen_undef and $seen_undef == $max
$seen_undef $seen_undef == $max
Truth table33%1/3
A and B
A= $seen_undefB= $seen_undef == $max
ABresult
0X0
100
111
615 10 return @ret;
616 }
617  
618 sub samples ($@)
619 4 ▶{
Subroutine samples: called CC=3 SCAR=12.7
Pod undocumented
620 4 my $n = shift;
621 4 ▶ if ($n > @_)
Branch: 1 branch
BranchTrueFalseTotal
if ($n > @_) 1 3 4
622 {
623 1 require Carp;
624 1 Carp::croak(sprintf("Cannot get %d samples from %d elements", $n, scalar @_));
625 }
626  
627 3 ▶ for (my $i = @_; @_ - $i > $n;)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ - $i > $n) 0 3 3
628 {
629 0 my $idx = @_ - $i;
630 0 my $swp = $idx + int(rand(--$i));
631 0 my $xchg = $_[$swp];
632 0 $_[$swp] = $_[$idx];
633 0 $_[$idx] = $xchg;
634 }
635  
636 3 return splice @_, 0, $n;
637 }
638  
639 sub minmax (@)
640 31 ▶{
Subroutine minmax: called CC=14 SCAR=26.5
Pod undocumented
641 31 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 31 31
642 31 my $min = my $max = $_[0];
643  
644 31 ▶ for (my $i = 1; $i < @_; $i += 2)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_) 10047 31 10078
645 {
646 10047 ▶ if ($_[$i - 1] <= $_[$i])
Branch: 1 branch
BranchTrueFalseTotal
if ($_[$i - 1] <= $_[$i]) { } 28 10019 10047
647 {
648 28 ▶ $min = $_[$i - 1] if $min > $_[$i - 1];
Branch: 1 branch
BranchTrueFalseTotal
if $min > $_[$i - 1] 1 27 28
649 28 ▶ $max = $_[$i] if $max < $_[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $max < $_[$i] 8 20 28
650 }
651 else
652 {
653 10019 ▶ $min = $_[$i] if $min > $_[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $min > $_[$i] 10016 3 10019
654 10019 ▶ $max = $_[$i - 1] if $max < $_[$i - 1];
Branch: 1 branch
BranchTrueFalseTotal
if $max < $_[$i - 1] 6 10013 10019
655 }
656 }
657  
658 31 ▶ if (@_ & 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ & 1) 25 6 31
659 {
660 25 my $i = $#_;
661 25 ▶ if ($_[$i - 1] <= $_[$i])
Branch: 1 branch
BranchTrueFalseTotal
if ($_[$i - 1] <= $_[$i]) { } 22 3 25
662 {
663 22 ▶ $min = $_[$i - 1] if $min > $_[$i - 1];
Branch: 1 branch
BranchTrueFalseTotal
if $min > $_[$i - 1] 0 22 22
664 22 ▶ $max = $_[$i] if $max < $_[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $max < $_[$i] 1 21 22
665 }
666 else
667 {
668 3 ▶ $min = $_[$i] if $min > $_[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $min > $_[$i] 3 0 3
669 3 ▶ $max = $_[$i - 1] if $max < $_[$i - 1];
Branch: 1 branch
BranchTrueFalseTotal
if $max < $_[$i - 1] 0 3 3
670 }
671 }
672  
673 31 return ($min, $max);
674 }
675  
676 sub minmaxstr (@)
677 25 ▶{
Subroutine minmaxstr: called CC=14 SCAR=29.9
Pod undocumented
678 25 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 25 25
679 25 my $min = my $max = $_[0];
680  
681 25 ▶ for (my $i = 1; $i < @_; $i += 2)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_) 1352 25 1377
682 {
683 1352 ▶ if ($_[$i - 1] le $_[$i])
Branch: 1 branch
BranchTrueFalseTotal
if ($_[$i - 1] le $_[$i]) { } 0 1352 1352
684 {
685 0 ▶ $min = $_[$i - 1] if $min gt $_[$i - 1];
Branch: 1 branch
BranchTrueFalseTotal
if $min gt $_[$i - 1] 0 0 0
686 0 ▶ $max = $_[$i] if $max lt $_[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $max lt $_[$i] 0 0 0
687 }
688 else
689 {
690 1352 ▶ $min = $_[$i] if $min gt $_[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $min gt $_[$i] 1352 0 1352
691 1352 ▶ $max = $_[$i - 1] if $max lt $_[$i - 1];
Branch: 1 branch
BranchTrueFalseTotal
if $max lt $_[$i - 1] 0 1352 1352
692 }
693 }
694  
695 25 ▶ if (@_ & 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ & 1) 24 1 25
696 {
697 24 my $i = $#_;
698 24 ▶ if ($_[$i - 1] le $_[$i])
Branch: 1 branch
BranchTrueFalseTotal
if ($_[$i - 1] le $_[$i]) { } 22 2 24
699 {
700 22 ▶ $min = $_[$i - 1] if $min gt $_[$i - 1];
Branch: 1 branch
BranchTrueFalseTotal
if $min gt $_[$i - 1] 0 22 22
701 22 ▶ $max = $_[$i] if $max lt $_[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $max lt $_[$i] 1 21 22
702 }
703 else
704 {
705 2 ▶ $min = $_[$i] if $min gt $_[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $min gt $_[$i] 2 0 2
706 2 ▶ $max = $_[$i - 1] if $max lt $_[$i - 1];
Branch: 1 branch
BranchTrueFalseTotal
if $max lt $_[$i - 1] 0 2 2
707 }
708 }
709  
710 25 return ($min, $max);
711 }
712  
713 sub part (&@)
714 13 ▶{
Subroutine part: called CC=2 SCAR=6.9
Pod undocumented
715 13 my ($code, @list) = @_;
716 13 my @parts;
717 13 push @{$parts[$code->($_)]}, $_ foreach @list;
718 12 return @parts;
719 }
720  
721 sub bsearch(&@)
722 2029 ▶{
Subroutine bsearch: called CC=6 SCAR=17.9
Pod undocumented
723 2029 my $code = shift;
724  
725 2029 my $rc;
726 2029 my $i = 0;
727 2029 my $j = @_;
728 ## no critic (ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions)
729 do
730 2029 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
$i > $j or do { do { my $k = int(($i + $j) / 2); $k >= @_ and return; local *_ = \$_[$k]; $rc = &$code(); $rc == 0 and return wantarray ? $_ : 1; if ($rc < 0) { $i = $k + 1; } else { $j = $k - 1; } } } 11 16207 16218
731 18236 my $k = int(($i + $j) / 2);
732  
733 18236 ▶ $k >= @_ and return;
Branch: 1 branch
BranchTrueFalseTotal
$k >= @_ and return 11 18225 18236
734  
735 18225 local *_ = \$_[$k];
736 18225 $rc = $code->();
737  
738 18222 ▶ $rc == 0
Branch: 2 branches
BranchTrueFalseTotal
$rc == 0 and return wantarray ? $_ : 1 2004 16218 18222
wantarray ? : 1000 1004 2004
739 and return wantarray ? $_ : 1;
740  
741 16218 ▶ if ($rc < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($rc < 0) { } 8206 8012 16218
742 {
743 8206 $i = $k + 1;
744 }
745 else
746 {
747 8012 $j = $k - 1;
748 }
749 } until $i > $j;
750  
751 11 return;
752 }
753  
754 sub bsearchidx(&@)
755 1029 ▶{
Subroutine bsearchidx: called CC=5 SCAR=16.1
Pod undocumented
756 1029 my $code = shift;
757  
758 1029 my $rc;
759 1029 my $i = 0;
760 1029 my $j = @_;
761 ## no critic (ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions)
762 do
763 1029 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
$i > $j or do { do { my $k = int(($i + $j) / 2); $k >= @_ and return -1; local *_ = \$_[$k]; $rc = &$code(); $rc == 0 and return $k; if ($rc < 0) { $i = $k + 1; } else { $j = $k - 1; } } } 11 8221 8232
764 9250 my $k = int(($i + $j) / 2);
765  
766 9250 ▶ $k >= @_ and return -1;
Branch: 1 branch
BranchTrueFalseTotal
$k >= @_ and return -1 11 9239 9250
767  
768 9239 local *_ = \$_[$k];
769 9239 $rc = $code->();
770  
771 9236 ▶ $rc == 0 and return $k;
Branch: 1 branch
BranchTrueFalseTotal
$rc == 0 and return $k 1004 8232 9236
772  
773 8232 ▶ if ($rc < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($rc < 0) { } 4161 4071 8232
774 {
775 4161 $i = $k + 1;
776 }
777 else
778 {
779 4071 $j = $k - 1;
780 }
781 } until $i > $j;
782  
783 11 return -1;
784 }
785  
786 sub lower_bound(&@)
787 2475 ▶{
Subroutine lower_bound: called CC=3 SCAR=11.0
Pod undocumented
788 2475 my $code = shift;
789 2475 my $count = @_;
790 2475 my $first = 0;
791 2475 ▶ while ($count > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 0) 17851 2464 20315
792 {
793 17851 my $step = $count >> 1;
794 17851 my $it = $first + $step;
795 17851 local *_ = \$_[$it];
796 17851 ▶ if ($code->() < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (&$code() < 0) { } 8834 9006 17840
797 {
798 8834 $first = ++$it;
799 8834 $count -= $step + 1;
800 }
801 else
802 {
803 9006 $count = $step;
804 }
805 }
806  
807 2464 return $first;
808 }
809  
810 sub upper_bound(&@)
811 243 ▶{
Subroutine upper_bound: called CC=3 SCAR=11.0
Pod undocumented
812 243 my $code = shift;
813 243 my $count = @_;
814 243 my $first = 0;
815 243 ▶ while ($count > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 0) 1606 242 1848
816 {
817 1606 my $step = $count >> 1;
818 1606 my $it = $first + $step;
819 1606 local *_ = \$_[$it];
820 1606 ▶ if ($code->() <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (&$code() <= 0) { } 771 834 1605
821 {
822 771 $first = ++$it;
823 771 $count -= $step + 1;
824 }
825 else
826 {
827 834 $count = $step;
828 }
829 }
830  
831 242 return $first;
832 }
833  
834 sub equal_range(&@)
835 12 ▶{
Subroutine equal_range: called CC=1 SCAR=0.0
Pod undocumented
836 12 my $lb = &lower_bound(@_);
837 9 my $ub = &upper_bound(@_);
838 9 return ($lb, $ub);
839 }
840  
841 sub binsert (&$\@)
842 1811 ▶{
Subroutine binsert: called CC=1 SCAR=0.0
Pod undocumented
843 1811 my $lb = &lower_bound($_[0], @{$_[2]});
844 1809 splice @{$_[2]}, $lb, 0, $_[1];
845 1809 return $lb;
846 }
847  
848 sub bremove (&\@)
849 420 ▶{
Subroutine bremove: called CC=1 SCAR=0.0
Pod undocumented
850 420 my $lb = &lower_bound($_[0], @{$_[1]});
851 413 return splice @{$_[1]}, $lb, 1;
852 }
853  
854 sub qsort(&\@)
855 0 ▶{
Subroutine qsort: not called CC=1 SCAR=6.9
Pod undocumented
856 0 require Carp;
857 0 Carp::croak("It's insane to use a pure-perl qsort");
858 }
859  
860 sub slide(&@)
861 2 ▶{
Subroutine slide: called CC=1 SCAR=0.0
Pod undocumented
862 2 my $op = shift;
863 2 my @l = @_;
864  
865 ## no critic (TestingAndDebugging::ProhibitNoStrict, ValuesAndExpressions::ProhibitCommaSeparatedStatements)
866 # Localise $a, $b
867 my ($caller_a, $caller_b) = do
868 2 {
869 2 my $pkg = caller();
870 122 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
871 2 \*{$pkg . '::a'}, \*{$pkg . '::b'};
872 };
873  
874 ## no critic (Variables::RequireInitializationForLocalVars)
875 # This map expression is also the return value
876 2 local (*$caller_a, *$caller_b);
877 ## no critic (BuiltinFunctions::ProhibitComplexMappings)
878 return map {
879 # Assign to $a, $b as refs to caller's array elements
880 2 (*$caller_a, *$caller_b) = \($l[$_], $l[$_ + 1]);
881  
882 # Perform the transformation
883 4 $op->();
884 } 0 .. ($#l - 1);
885 }
886  
887 sub slideatatime ($$@)
888 10 ▶{
Subroutine slideatatime: called CC=2 SCAR=6.9
Pod undocumented
889 10 my ($m, $w, @list) = @_;
890 10 my $n = $w - $m - 1;
891 return $n >= 0
892 37 ▶ ? sub { my @r = splice @list, 0, $m; $#list < $n and $n = $#list; @r and push @r, (@list ? @list[0 .. $n] : ()); return @r; }
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 3 branches
BranchTrueFalseTotal
$#list < $n and $n = $#list 7 30 37
@r and push @r, @list ? @list[0 .. $n] : () 35 2 37
@list ? : 33 2 35
893 10 ▶ : sub { return splice @list, 0, $m; };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$n >= 0 ? : 6 4 10
894 }
895  
896 sub sort_by(&@)
897 0 ▶{
Subroutine sort_by: not called CC=1 SCAR=6.9
Pod undocumented
898 0 my ($code, @list) = @_;
899 0 return map { $_->[0] }
900 0 sort { $a->[1] cmp $b->[1] }
901 0 map { [$_, scalar($code->())] } @list;
902 }
903  
904 sub nsort_by(&@)
905 0 ▶{
Subroutine nsort_by: not called CC=1 SCAR=6.9
Pod undocumented
906 0 my ($code, @list) = @_;
907 0 return map { $_->[0] }
908 0 sort { $a->[1] <=> $b->[1] }
909 0 map { [$_, scalar($code->())] } @list;
910 }
911  
912 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
913 1 ▶sub _XScompiled { return 0 }
Subroutine _XScompiled: called CC=1 SCAR=0.0
914  
915 =head1 SEE ALSO
916  
917 L<List::Util>
918  
919 =head1 AUTHOR
920  
921 Jens Rehsack E<lt>rehsack AT cpan.orgE<gt>
922  
923 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
924  
925 Tassilo von Parseval E<lt>tassilo.von.parseval@rwth-aachen.deE<gt>
926  
927 =head1 COPYRIGHT AND LICENSE
928  
929 Some parts copyright 2011 Aaron Crane.
930  
931 Copyright 2004 - 2010 by Tassilo von Parseval
932  
933 Copyright 2013 - 2017 by Jens Rehsack
934  
935 All code added with 0.417 or later is licensed under the Apache License,
936 Version 2.0 (the "License"); you may not use this file except in compliance
937 with the License. You may obtain a copy of the License at
938  
939 http://www.apache.org/licenses/LICENSE-2.0
940  
941 Unless required by applicable law or agreed to in writing, software
942 distributed under the License is distributed on an "AS IS" BASIS,
943 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
944 See the License for the specific language governing permissions and
945 limitations under the License.
946  
947 All code until 0.416 is licensed under the same terms as Perl itself,
948 either Perl version 5.8.4 or, at your option, any later version of
949 Perl 5 you may have available.
950  
951 =cut
952  
953 122 1;
↑ Summary MoreUtils.pm »