| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
&$f() and $found++
MC/DC100%2/2
&$f() and $found++
&$f()
$found++
Truth table100%3/3
A and B
A= &$f()B= $found++
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 61 | 12 | ▶ | $f->() and return 1 foreach (@_); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 68 | 8 | ▶ | $f->() or return 0 foreach (@_); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 75 | 8 | ▶ | $f->() and return 0 foreach (@_); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 82 | 8 | ▶ | $f->() or return 1 foreach (@_); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 89 | 11 | my $found = 0; | |||||||||||||||||||||||||||||||
| 90 | 11 | foreach (@_) { | |||||||||||||||||||||||||||||||
| 91 | 2063 | ▶ | $f->() and $found++ and return 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&$f() and $found++
MC/DC100%2/2
&$f() and $found++
&$f()
$found++
Truth table100%3/3
A and B
A= &$f()B= $found++
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 142 | 22 | ▶ | defined $found and return -1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 143 | 14 | $found = $i; | |||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | 9 | ▶ | return defined $found ? $found : -1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 154 | 22 | $result = $_; | |||||||||||||||||||||||||||||||
| 155 | 22 | ▶ | $found++ and return undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 166 | 20 | $result = $rv; | |||||||||||||||||||||||||||||||
| 167 | 20 | ▶ | $found++ and return undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | 7 | ▶ | return $found ? $result : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition60%3/5
$c != -1 && ((@$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*])) && (return 1))
@$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*]) and return 1
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->$#*])
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 221 | 8 | ▶ | @$list = ( @{$list}[ 0 .. $c ], $val, @{$list}[ $c + 1 .. $#$list ], ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
$c != -1 && ((@$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*])) && (return 1))
@$list = (@{$list;}[0 .. $c], $val, @{$list;}[$c + 1 .. $list->$#*]) and return 1
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->$#*])
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
}
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
}
| |||||||||||||||||||||||||||||||||
| 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()
MC/DC100%2/2
$started ||= &$test()
$started
&$test()
Truth table100%3/3
A ||= B
A= $startedB= &$test()
| |||||||||||||||||||||||||||||||||
| 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()
MC/DC100%2/2
$more &&= !&$test()
$more
!&$test()
Truth table100%3/3
A &&= not(B)
A= $moreB= !&$test()
| |||||||||||||||||||||||||||||||||
| 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
}
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
}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 328 | 10 | my $method = shift; | |||||||||||||||||||||||||||||||
| 329 | 10 | ▶ | unless ( $method eq 'index' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$index == 0 or $index > $max
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
| |||||||||||||||||||||||||||||||||
| 338 | 10 | return $index - 1; | |||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||
| 341 | # No more elements to return | ||||||||||||||||||||||||||||||||
| 342 | 99 | ▶ | return if $index >= $max; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 379 | 20 | ▶ | grep { defined $_ ? not $seen{ $k = $_ }++ : not $seen_undef++ } @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||
| 382 | 32 | ▶ | sub minmax (@) { | ||||||||||||||||||||||||||||||
|
Subroutine
minmax: called CC=14 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 383 | 32 | ▶ | return unless @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 384 | 31 | my $min = my $max = $_[0]; | |||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||
| 386 | 31 | ▶ | for ( my $i = 1; $i < @_; $i += 2 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 387 | 10047 | ▶ | if ( $_[ $i - 1 ] <= $_[$i] ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 388 | 28 | ▶ | $min = $_[ $i - 1 ] if $min > $_[ $i - 1 ]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 389 | 28 | ▶ | $max = $_[$i] if $max < $_[$i]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||
| 391 | else { | ||||||||||||||||||||||||||||||||
| 392 | 10019 | ▶ | $min = $_[$i] if $min > $_[$i]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 393 | 10019 | ▶ | $max = $_[ $i - 1 ] if $max < $_[ $i - 1 ]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||
| 397 | 31 | ▶ | if ( @_ & 1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 398 | 25 | my $i = $#_; | |||||||||||||||||||||||||||||||
| 399 | 25 | ▶ | if ( $_[ $i - 1 ] <= $_[$i] ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 400 | 22 | ▶ | $min = $_[ $i - 1 ] if $min > $_[ $i - 1 ]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 401 | 22 | ▶ | $max = $_[$i] if $max < $_[$i]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||
| 403 | else { | ||||||||||||||||||||||||||||||||
| 404 | 3 | ▶ | $min = $_[$i] if $min > $_[$i]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 405 | 3 | ▶ | $max = $_[ $i - 1 ] if $max < $_[ $i - 1 ]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 426 | 18236 | my $k = int( ( $i + $j ) / 2 ); | |||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | 18236 | ▶ | $k >= @_ and return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||
| 430 | 18224 | local *_ = \$_[$k]; | |||||||||||||||||||||||||||||||
| 431 | 18224 | $rc = $code->(); | |||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||
| 433 | 18221 | ▶ | $rc == 0 | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 434 | and return wantarray ? $_ : 1; | ||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||
| 436 | 16217 | ▶ | if ( $rc < 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 454 | 9251 | my $k = int( ( $i + $j ) / 2 ); | |||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||
| 456 | 9251 | ▶ | $k >= @_ and return -1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||
| 458 | 9239 | local *_ = \$_[$k]; | |||||||||||||||||||||||||||||||
| 459 | 9239 | $rc = $code->(); | |||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||
| 461 | 9236 | ▶ | $rc == 0 and return $k; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||
| 463 | 8232 | ▶ | if ( $rc < 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||