SomeUtils/PP.pm

filter: Statementstmt 95.7% 270 / 282 Branchbran 96.4% 135 / 140 Conditioncond 80.6% 25 / 31 MC/DCmcdc 66.6% 12 / 18 Subroutinesub 96.1% 50 / 52 Podpod 0.0% 0 / 43 totaltotal 86.9% 492 / 566 CC 104 SCAR 14.9
CC
104
Cov
95%
minmax
14.1
__ANON__
6.8
bsearch
6.0
CRAP 4.4
↑ Summary SomeUtils.pm »
1 package List::SomeUtils::PP;
2  
3 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use List::Util qw( max );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 our $VERSION = '0.59';
10  
11 ## no critic (BuiltinFunctions::ProhibitComplexMappings)
12 ## no critic (BuiltinFunctions::RequireBlockGrep)
13 ## no critic (BuiltinFunctions::RequireBlockMap)
14 ## no critic (ControlStructures::ProhibitCStyleForLoops)
15 ## no critic (Subroutines::ProhibitManyArgs)
16  
17 14 ▶sub any (&@) {
Subroutine any: called CC=3 SCAR=11.0
Pod undocumented
18 14 my $f = shift;
19 14 foreach (@_) {
20 40005 ▶ return 1 if $f->();
Branch: 1 branch
BranchTrueFalseTotal
if &$f() 8 39994 40002
21 }
22 3 return 0;
23 }
24  
25 10 ▶sub all (&@) {
Subroutine all: called CC=3 SCAR=11.0
Pod undocumented
26 10 my $f = shift;
27 10 foreach (@_) {
28 25005 ▶ return 0 unless $f->();
Branch: 1 branch
BranchTrueFalseTotal
unless &$f() 5 24999 25004
29 }
30 4 return 1;
31 }
32  
33 10 ▶sub none (&@) {
Subroutine none: called CC=3 SCAR=11.0
Pod undocumented
34 10 my $f = shift;
35 10 foreach (@_) {
36 40002 ▶ return 0 if $f->();
Branch: 1 branch
BranchTrueFalseTotal
if &$f() 5 39996 40001
37 }
38 4 return 1;
39 }
40  
41 10 ▶sub notall (&@) {
Subroutine notall: called CC=3 SCAR=11.0
Pod undocumented
42 10 my $f = shift;
43 10 foreach (@_) {
44 20006 ▶ return 1 unless $f->();
Branch: 1 branch
BranchTrueFalseTotal
unless &$f() 6 19999 20005
45 }
46 3 return 0;
47 }
48  
49 12 ▶sub one (&@) {
Subroutine one: called CC=4 SCAR=13.9
Pod undocumented
50 12 my $f = shift;
51 12 my $found = 0;
52 12 foreach (@_) {
53 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
54 }
55 5 $found;
56 }
57  
58 14 ▶sub any_u (&@) {
Subroutine any_u: called CC=4 SCAR=13.9
Pod undocumented
59 14 my $f = shift;
60 14 ▶ return undef if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 2 12 14
61 12 ▶ $f->() and return 1 foreach (@_);
Branch: 1 branch
BranchTrueFalseTotal
&$f() and return 1 8 39994 40002
62 1 return 0;
63 }
64  
65 10 ▶sub all_u (&@) {
Subroutine all_u: called CC=4 SCAR=13.9
Pod undocumented
66 10 my $f = shift;
67 10 ▶ return undef if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 2 8 10
68 8 ▶ $f->() or return 0 foreach (@_);
Branch: 1 branch
BranchTrueFalseTotal
&$f() or return 0 24999 5 25004
69 2 return 1;
70 }
71  
72 10 ▶sub none_u (&@) {
Subroutine none_u: called CC=4 SCAR=13.9
Pod undocumented
73 10 my $f = shift;
74 10 ▶ return undef if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 2 8 10
75 8 ▶ $f->() and return 0 foreach (@_);
Branch: 1 branch
BranchTrueFalseTotal
&$f() and return 0 5 39996 40001
76 2 return 1;
77 }
78  
79 10 ▶sub notall_u (&@) {
Subroutine notall_u: called CC=4 SCAR=13.9
Pod undocumented
80 10 my $f = shift;
81 10 ▶ return undef if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 2 8 10
82 8 ▶ $f->() or return 1 foreach (@_);
Branch: 1 branch
BranchTrueFalseTotal
&$f() or return 1 19999 6 20005
83 1 return 0;
84 }
85  
86 13 ▶sub one_u (&@) {
Subroutine one_u: called CC=5 SCAR=16.1
Pod undocumented
87 13 my $f = shift;
88 13 ▶ return undef if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 2 11 13
89 11 my $found = 0;
90 11 foreach (@_) {
91 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
92 }
93 4 $found;
94 }
95  
96 11 ▶sub true (&@) {
Subroutine true: called CC=3 SCAR=11.0
Pod undocumented
97 11 my $f = shift;
98 11 my $count = 0;
99 11 ▶ $f->() and ++$count foreach (@_);
Branch: 1 branch
BranchTrueFalseTotal
&$f() and ++$count 10005 59995 70000
100 10 return $count;
101 }
102  
103 11 ▶sub false (&@) {
Subroutine false: called CC=3 SCAR=11.0
Pod undocumented
104 11 my $f = shift;
105 11 my $count = 0;
106 11 ▶ $f->() or ++$count foreach (@_);
Branch: 1 branch
BranchTrueFalseTotal
&$f() or ++$count 20003 49997 70000
107 10 return $count;
108 }
109  
110 30 ▶sub firstidx (&@) {
Subroutine firstidx: called CC=3 SCAR=11.0
Pod undocumented
111 30 my $f = shift;
112 30 foreach my $i ( 0 .. $#_ ) {
113 50048 local *_ = \$_[$i];
114 50048 ▶ return $i if $f->();
Branch: 1 branch
BranchTrueFalseTotal
if &$f() 20 50026 50046
115 }
116 8 return -1;
117 }
118  
119 9 ▶sub firstval (&@) {
Subroutine firstval: called CC=3 SCAR=11.0
Pod undocumented
120 9 my $test = shift;
121 9 foreach (@_) {
122 21 ▶ return $_ if $test->();
Branch: 1 branch
BranchTrueFalseTotal
if &$test() 4 16 20
123 }
124 4 return undef;
125 }
126  
127 8 ▶sub firstres (&@) {
Subroutine firstres: called CC=3 SCAR=11.0
Pod undocumented
128 8 my $test = shift;
129 8 foreach (@_) {
130 21 my $testval = $test->();
131 20 ▶ $testval and return $testval;
Branch: 1 branch
BranchTrueFalseTotal
$testval and return $testval 4 16 20
132 }
133 3 return undef;
134 }
135  
136 18 ▶sub onlyidx (&@) {
Subroutine onlyidx: called CC=5 SCAR=16.1
Pod undocumented
137 18 my $f = shift;
138 18 my $found;
139 18 foreach my $i ( 0 .. $#_ ) {
140 3521 local *_ = \$_[$i];
141 3521 ▶ $f->() or next;
Branch: 1 branch
BranchTrueFalseTotal
&$f() or next 22 3498 3520
142 22 ▶ defined $found and return -1;
Branch: 1 branch
BranchTrueFalseTotal
defined $found and return -1 8 14 22
143 14 $found = $i;
144 }
145 9 ▶ return defined $found ? $found : -1;
Branch: 1 branch
BranchTrueFalseTotal
defined $found ? : 6 3 9
146 }
147  
148 18 ▶sub onlyval (&@) {
Subroutine onlyval: called CC=4 SCAR=13.9
Pod undocumented
149 18 my $test = shift;
150 18 my $result = undef;
151 18 my $found = 0;
152 18 foreach (@_) {
153 3521 ▶ $test->() or next;
Branch: 1 branch
BranchTrueFalseTotal
&$test() or next 22 3498 3520
154 22 $result = $_;
155 22 ▶ $found++ and return undef;
Branch: 1 branch
BranchTrueFalseTotal
$found++ and return undef 8 14 22
156 }
157 9 return $result;
158 }
159  
160 16 ▶sub onlyres (&@) {
Subroutine onlyres: called CC=5 SCAR=16.1
Pod undocumented
161 16 my $test = shift;
162 16 my $result = undef;
163 16 my $found = 0;
164 16 foreach (@_) {
165 2921 ▶ my $rv = $test->() or next;
Branch: 1 branch
BranchTrueFalseTotal
my $rv = &$test() or next 20 2900 2920
166 20 $result = $rv;
167 20 ▶ $found++ and return undef;
Branch: 1 branch
BranchTrueFalseTotal
$found++ and return undef 8 12 20
168 }
169 7 ▶ return $found ? $result : undef;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 4 3 7
170 }
171  
172 14 ▶sub lastidx (&@) {
Subroutine lastidx: called CC=3 SCAR=11.0
Pod undocumented
173 14 my $f = shift;
174 14 foreach my $i ( reverse 0 .. $#_ ) {
175 20009 local *_ = \$_[$i];
176 20009 ▶ return $i if $f->();
Branch: 1 branch
BranchTrueFalseTotal
if &$f() 8 20000 20008
177 }
178 5 return -1;
179 }
180  
181 9 ▶sub lastval (&@) {
Subroutine lastval: called CC=3 SCAR=11.0
Pod undocumented
182 9 my $test = shift;
183 9 my $ix;
184 9 ▶ for ( $ix = $#_; $ix >= 0; $ix-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ix >= 0) 13 4 17
185 13 local *_ = \$_[$ix];
186 13 my $testval = $test->();
187  
188 # Simulate $_ as alias
189 12 $_[$ix] = $_;
190 12 ▶ return $_ if $testval;
Branch: 1 branch
BranchTrueFalseTotal
if $testval 4 8 12
191 }
192 4 return undef;
193 }
194  
195 8 ▶sub lastres (&@) {
Subroutine lastres: called CC=3 SCAR=11.0
Pod undocumented
196 8 my $test = shift;
197 8 my $ix;
198 8 ▶ for ( $ix = $#_; $ix >= 0; $ix-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ix >= 0) 13 3 16
199 13 local *_ = \$_[$ix];
200 13 my $testval = $test->();
201  
202 # Simulate $_ as alias
203 12 $_[$ix] = $_;
204 12 ▶ return $testval if $testval;
Branch: 1 branch
BranchTrueFalseTotal
if $testval 4 8 12
205 }
206 3 return undef;
207 }
208  
209 10 ▶sub insert_after (&$\@) {
Subroutine insert_after: called CC=3 SCAR=11.1
Pod undocumented
210 10 my ( $f, $val, $list ) = @_;
211 10 my $c = &firstidx( $f, @$list );
212 7 ▶ @$list = ( @{$list}[ 0 .. $c ], $val, @{$list}[ $c + 1 .. $#$list ], )
Branch: 1 branch
BranchTrueFalseTotal
if $c != -1 5 2 7
Condition60%3/5
$c != -1 && ((@$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*])) && (return 1))
!ll&&!rl&&r
250
@$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
213 and return 1
214 if $c != -1;
215 2 return 0;
216 }
217  
218 9 ▶sub insert_after_string ($$\@) {
Subroutine insert_after_string: called CC=3 SCAR=11.0
Pod undocumented
219 9 my ( $string, $val, $list ) = @_;
220 9 ▶ my $c = firstidx { defined $_ and $string eq $_ } @$list;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $string eq $_ 21 1 22
221 8 ▶ @$list = ( @{$list}[ 0 .. $c ], $val, @{$list}[ $c + 1 .. $#$list ], )
Branch: 1 branch
BranchTrueFalseTotal
if $c != -1 7 1 8
Condition60%3/5
$c != -1 && ((@$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*])) && (return 1))
!ll&&!rl&&r
170
@$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 table33%1/3
A && B
A= $c != -1B= @$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*])
ABresult
0X0
100
111
222 and return 1
223 if $c != -1;
224 1 return 0;
225 }
226  
227 10 ▶sub apply (&@) {
Subroutine apply: called CC=3 SCAR=11.0
Pod undocumented
228 10 my $action = shift;
229 10 &$action foreach my @values = @_;
230 9 ▶ wantarray ? @values : $values[-1];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 6 3 9
231 }
232  
233 8 ▶sub after (&@) {
Subroutine after: called CC=2 SCAR=6.9
Pod undocumented
234 8 my $test = shift;
235 8 my $started;
236 my $lag;
237 8 ▶ grep $started ||= do {
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
238 19 my $x = $lag;
239 19 $lag = $test->();
240 18 $x;
241 }, @_;
242 }
243  
244 7 ▶sub after_incl (&@) {
Subroutine after_incl: called CC=2 SCAR=6.9
Pod undocumented
245 7 my $test = shift;
246 7 my $started;
247 7 ▶ 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
248 }
249  
250 7 ▶sub before (&@) {
Subroutine before: called CC=2 SCAR=6.9
Pod undocumented
251 7 my $test = shift;
252 7 my $more = 1;
253 7 ▶ 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
254 }
255  
256 7 ▶sub before_incl (&@) {
Subroutine before_incl: called CC=2 SCAR=6.9
Pod undocumented
257 7 my $test = shift;
258 7 my $more = 1;
259 7 my $lag = 1;
260 7 ▶ grep $more &&= do {
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
261 18 my $x = $lag;
262 18 $lag = !$test->();
263 17 $x;
264 }, @_;
265 }
266  
267 21 ▶sub indexes (&@) {
Subroutine indexes: called CC=1 SCAR=0.0
Pod undocumented
268 21 my $test = shift;
269 grep {
270 21 local *_ = \$_[$_];
271 102 $test->()
272 } 0 .. $#_;
273 }
274  
275 12 ▶sub pairwise (&\@\@) {
Subroutine pairwise: called CC=2 SCAR=6.9
Pod undocumented
276 12 my $op = shift;
277  
278 # Symbols for caller's input arrays
279 4 ▶ use vars qw{ @A @B };
Subroutine BEGIN: called CC=1 SCAR=0.0
280 12 local ( *A, *B ) = @_;
281  
282 # Localise $a, $b
283 12 my ( $caller_a, $caller_b ) = do {
284 12 my $pkg = caller();
285 ## no critic (TestingAndDebugging::ProhibitNoStrict)
286 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
287 ## no critic (ValuesAndExpressions::ProhibitCommaSeparatedStatements)
288 12 \*{ $pkg . '::a' }, \*{ $pkg . '::b' };
289 };
290  
291 # Loop iteration limit
292 12 ▶ my $limit = $#A > $#B ? $#A : $#B;
Branch: 1 branch
BranchTrueFalseTotal
$#List::SomeUtils::PP::A > $#List::SomeUtils::PP::B ? : 1 11 12
293  
294 ## no critic (Variables::RequireInitializationForLocalVars)
295 # This map expression is also the return value
296 12 local ( *$caller_a, *$caller_b );
297 map {
298 # Assign to $a, $b as refs to caller's array elements
299 12 ( *$caller_a, *$caller_b ) = \( $A[$_], $B[$_] );
300  
301 # Perform the transformation
302 585 $op->();
303 } 0 .. $limit;
304 }
305  
306 11 ▶sub each_array (\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@) {
Subroutine each_array: called CC=1 SCAR=0.0
Pod undocumented
307 11 return each_arrayref(@_);
308 }
309  
310 19 ▶sub each_arrayref {
Subroutine each_arrayref: called CC=4 SCAR=14.1
Pod undocumented
311 19 my @list = @_; # The list of references to the arrays
312 19 my $index = 0; # Which one the caller will get next
313 19 my $max = 0; # Number of elements in longest array
314  
315 # Get the length of the longest input array
316 19 foreach (@list) {
317 28 ▶ unless ( ref $_ eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ eq "ARRAY") 2 26 28
318 2 require Carp;
319 2 Carp::croak(
320 "each_arrayref: argument is not an array reference\n");
321 }
322 26 ▶ $max = @$_ if @$_ > $max;
Branch: 1 branch
BranchTrueFalseTotal
if @$_ > $max 16 10 26
323 }
324  
325 # Return the iterator as a closure wrt the above variables.
326 109 ▶ return sub {
Subroutine __ANON__: called CC=6 SCAR=19.2
327 109 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 10 99 109
328 10 my $method = shift;
329 10 ▶ unless ( $method eq 'index' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($method eq "index") 0 10 10
330 0 require Carp;
331 0 Carp::croak(
332 "each_array: unknown argument '$method' passed to iterator."
333 );
334 }
335  
336 # Return current (last fetched) index
337 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
338 10 return $index - 1;
339 }
340  
341 # No more elements to return
342 99 ▶ return if $index >= $max;
Branch: 1 branch
BranchTrueFalseTotal
if $index >= $max 17 82 99
343 82 my $i = $index++;
344  
345 # Return ith elements
346 82 return map $_->[$i], @list;
347 }
348 17 }
349  
350 5 ▶sub natatime ($@) {
Subroutine natatime: called CC=1 SCAR=0.0
Pod undocumented
351 5 my $n = shift;
352 5 my @list = @_;
353 1010 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
354 1010 return splice @list, 0, $n;
355 }
356 5 }
357  
358 14 ▶sub mesh (\@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@) {
Subroutine mesh: called CC=3 SCAR=11.0
Pod undocumented
359 14 my $max = -1;
360 14 ▶ $max < $#$_ && ( $max = $#$_ ) foreach @_;
Branch: 1 branch
BranchTrueFalseTotal
$max < $_->$#* and $max = $_->$#* 14 12 26
361 map {
362 12 my $ix = $_;
363 50 map $_->[$ix], @_;
364 } 0 .. $max;
365 }
366  
367 20 ▶sub uniq (@) {
Subroutine uniq: called CC=2 SCAR=6.9
Pod undocumented
368 20 my %seen = ();
369 20 my $k;
370 my $seen_undef;
371 20 ▶ grep { defined $_ ? not $seen{ $k = $_ }++ : not $seen_undef++ } @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 4682 1 4683
372 }
373  
374 20 ▶sub singleton (@) {
Subroutine singleton: called CC=3 SCAR=11.0
Pod undocumented
375 20 my %seen = ();
376 20 my $k;
377 my $seen_undef;
378 25535 ▶ grep { 1 == ( defined $_ ? $seen{ $k = $_ } : $seen_undef ) }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 25532 3 25535
379 20 ▶ grep { defined $_ ? not $seen{ $k = $_ }++ : not $seen_undef++ } @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 42300 5 42305
380 }
381  
382 32 ▶sub minmax (@) {
Subroutine minmax: called CC=14 SCAR=26.4
Pod undocumented
383 32 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 31 32
384 31 my $min = my $max = $_[0];
385  
386 31 ▶ for ( my $i = 1; $i < @_; $i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_) 10047 31 10078
387 10047 ▶ if ( $_[ $i - 1 ] <= $_[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[$i - 1] <= $_[$i]) { } 28 10019 10047
388 28 ▶ $min = $_[ $i - 1 ] if $min > $_[ $i - 1 ];
Branch: 1 branch
BranchTrueFalseTotal
if $min > $_[$i - 1] 1 27 28
389 28 ▶ $max = $_[$i] if $max < $_[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $max < $_[$i] 8 20 28
390 }
391 else {
392 10019 ▶ $min = $_[$i] if $min > $_[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $min > $_[$i] 10016 3 10019
393 10019 ▶ $max = $_[ $i - 1 ] if $max < $_[ $i - 1 ];
Branch: 1 branch
BranchTrueFalseTotal
if $max < $_[$i - 1] 6 10013 10019
394 }
395 }
396  
397 31 ▶ if ( @_ & 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ & 1) 25 6 31
398 25 my $i = $#_;
399 25 ▶ if ( $_[ $i - 1 ] <= $_[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[$i - 1] <= $_[$i]) { } 22 3 25
400 22 ▶ $min = $_[ $i - 1 ] if $min > $_[ $i - 1 ];
Branch: 1 branch
BranchTrueFalseTotal
if $min > $_[$i - 1] 0 22 22
401 22 ▶ $max = $_[$i] if $max < $_[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $max < $_[$i] 1 21 22
402 }
403 else {
404 3 ▶ $min = $_[$i] if $min > $_[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $min > $_[$i] 3 0 3
405 3 ▶ $max = $_[ $i - 1 ] if $max < $_[ $i - 1 ];
Branch: 1 branch
BranchTrueFalseTotal
if $max < $_[$i - 1] 0 3 3
406 }
407 }
408  
409 31 return ( $min, $max );
410 }
411  
412 12 ▶sub part (&@) {
Subroutine part: called CC=2 SCAR=6.9
Pod undocumented
413 12 my ( $code, @list ) = @_;
414 12 my @parts;
415 12 push @{ $parts[ $code->($_) ] }, $_ foreach @list;
416 11 return @parts;
417 }
418  
419 2030 ▶sub bsearch(&@) {
Subroutine bsearch: called CC=6 SCAR=17.9
Pod undocumented
420 2030 my $code = shift;
421  
422 2030 my $rc;
423 2030 my $i = 0;
424 2030 my $j = @_;
425 2030 ▶ do {
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 16206 16217
426 18236 my $k = int( ( $i + $j ) / 2 );
427  
428 18236 ▶ $k >= @_ and return;
Branch: 1 branch
BranchTrueFalseTotal
$k >= @_ and return 12 18224 18236
429  
430 18224 local *_ = \$_[$k];
431 18224 $rc = $code->();
432  
433 18221 ▶ $rc == 0
Branch: 2 branches
BranchTrueFalseTotal
$rc == 0 and return wantarray ? $_ : 1 2004 16217 18221
wantarray ? : 1000 1004 2004
434 and return wantarray ? $_ : 1;
435  
436 16217 ▶ if ( $rc < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc < 0) { } 8211 8006 16217
437 8211 $i = $k + 1;
438 }
439 else {
440 8006 $j = $k - 1;
441 }
442 } until $i > $j;
443  
444 11 return;
445 }
446  
447 1030 ▶sub bsearchidx(&@) {
Subroutine bsearchidx: called CC=5 SCAR=16.1
Pod undocumented
448 1030 my $code = shift;
449  
450 1030 my $rc;
451 1030 my $i = 0;
452 1030 my $j = @_;
453 1030 ▶ do {
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
454 9251 my $k = int( ( $i + $j ) / 2 );
455  
456 9251 ▶ $k >= @_ and return -1;
Branch: 1 branch
BranchTrueFalseTotal
$k >= @_ and return -1 12 9239 9251
457  
458 9239 local *_ = \$_[$k];
459 9239 $rc = $code->();
460  
461 9236 ▶ $rc == 0 and return $k;
Branch: 1 branch
BranchTrueFalseTotal
$rc == 0 and return $k 1004 8232 9236
462  
463 8232 ▶ if ( $rc < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc < 0) { } 4164 4068 8232
464 4164 $i = $k + 1;
465 }
466 else {
467 4068 $j = $k - 1;
468 }
469 } until $i > $j;
470  
471 11 return -1;
472 }
473  
474 0 ▶sub sort_by(&@) {
Subroutine sort_by: not called CC=1 SCAR=6.9
Pod undocumented
475 0 my ( $code, @list ) = @_;
476 0 return map { $_->[0] }
477 0 sort { $a->[1] cmp $b->[1] }
478 0 map { [ $_, scalar( $code->() ) ] } @list;
479 }
480  
481 0 ▶sub nsort_by(&@) {
Subroutine nsort_by: not called CC=1 SCAR=6.9
Pod undocumented
482 0 my ( $code, @list ) = @_;
483 0 return map { $_->[0] }
484 0 sort { $a->[1] <=> $b->[1] }
485 0 map { [ $_, scalar( $code->() ) ] } @list;
486 }
487  
488 21 ▶sub mode (@) {
Subroutine mode: called CC=2 SCAR=6.9
Pod undocumented
489 21 my %v;
490 21 $v{$_}++ for @_;
491 21 my $max = max( values %v );
492 21 return grep { $v{$_} == $max } keys %v;
493 }
494  
495 4 1;
496  
497 # ABSTRACT: Pure Perl implementation for List::SomeUtils
498  
499 __END__
↑ Summary SomeUtils.pm »