| 1 | package Operator::Util; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use parent 'Exporter'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use List::MoreUtils qw( uniq ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||
| 9 | 5 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||
| 10 | 5 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||
| 11 | reduce reducewith | ||||||||||||||||||||||||||||||||||||
| 12 | zip zipwith | ||||||||||||||||||||||||||||||||||||
| 13 | cross crosswith | ||||||||||||||||||||||||||||||||||||
| 14 | hyper hyperwith | ||||||||||||||||||||||||||||||||||||
| 15 | applyop reverseop | ||||||||||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||||||||||
| 17 | 5 | our %EXPORT_TAGS = ( all => \@EXPORT_OK ); | |||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||
| 19 | 5 | *reducewith = \&reduce; | |||||||||||||||||||||||||||||||||||
| 20 | 5 | *hyperwith = \&hyper; | |||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||
| 22 | # sub: operator subroutines | ||||||||||||||||||||||||||||||||||||
| 23 | # res: responses in an arrayref for when zero or one argument is provided -- | ||||||||||||||||||||||||||||||||||||
| 24 | # the first element is the response for zero args and the second is for | ||||||||||||||||||||||||||||||||||||
| 25 | # one arg, defaulting to the arg itself | ||||||||||||||||||||||||||||||||||||
| 26 | # chain: set non-chaining Perl 5 operator to chaining-associative | ||||||||||||||||||||||||||||||||||||
| 27 | # right: set operator to right-associative | ||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||
| 29 | my %ops = ( | ||||||||||||||||||||||||||||||||||||
| 30 | # binary infix | ||||||||||||||||||||||||||||||||||||
| 31 | 20 | ▶ | 'infix:**' => { sub => sub { $_[0] ** $_[1] }, res => [1], right => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | 'infix:=~' => { sub => sub { $_[0] =~ $_[1] }, res => [1, 1] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | 'infix:!~' => { sub => sub { $_[0] !~ $_[1] }, res => [1, 1] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 34 | 28 | ▶ | 'infix:*' => { sub => sub { $_[0] * $_[1] }, res => [1] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 35 | 5 | ▶ | 'infix:/' => { sub => sub { $_[0] / $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | 'infix:%' => { sub => sub { $_[0] % $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | 'infix:x' => { sub => sub { $_[0] x $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 38 | 52 | ▶ | 'infix:+' => { sub => sub { $_[0] + $_[1] }, res => [0] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 39 | 20 | ▶ | 'infix:-' => { sub => sub { $_[0] - $_[1] }, res => [0] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 40 | 55 | ▶ | 'infix:.' => { sub => sub { $_[0] . $_[1] }, res => [''] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | 'infix:<<' => { sub => sub { $_[0] << $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | 'infix:>>' => { sub => sub { $_[0] >> $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 43 | 10 | ▶ | 'infix:<' => { sub => sub { $_[0] < $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 44 | 10 | ▶ | 'infix:>' => { sub => sub { $_[0] > $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | 'infix:<=' => { sub => sub { $_[0] <= $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | 'infix:>=' => { sub => sub { $_[0] >= $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 47 | 4 | ▶ | 'infix:lt' => { sub => sub { $_[0] lt $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | 'infix:gt' => { sub => sub { $_[0] gt $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | 'infix:le' => { sub => sub { $_[0] le $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | 'infix:ge' => { sub => sub { $_[0] ge $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 51 | 13 | ▶ | 'infix:==' => { sub => sub { $_[0] == $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 52 | 11 | ▶ | 'infix:!=' => { sub => sub { $_[0] != $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 53 | 8 | ▶ | 'infix:<=>' => { sub => sub { $_[0] <=> $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 54 | 5 | ▶ | 'infix:eq' => { sub => sub { $_[0] eq $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 55 | 4 | ▶ | 'infix:ne' => { sub => sub { $_[0] ne $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 56 | 4 | ▶ | 'infix:cmp' => { sub => sub { $_[0] cmp $_[1] }, res => [1, 1], chain => 1 }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | 'infix:&' => { sub => sub { $_[0] & $_[1] }, res => [-1] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | 'infix:|' => { sub => sub { $_[0] | $_[1] }, res => [0] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | 'infix:^' => { sub => sub { $_[0] ^ $_[1] }, res => [0] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 60 | 7 | ▶ | 'infix:&&' => { sub => sub { $_[0] && $_[1] }, res => [1] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 61 | 13 | ▶ | 'infix:||' => { sub => sub { $_[0] || $_[1] }, res => [0] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | 'infix:..' => { sub => sub { $_[0] .. $_[1] }, res => [1] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | 'infix:...' => { sub => sub { $_[0] ... $_[1] }, res => [1] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | 'infix:=' => { sub => sub { $_[0] = $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | 'infix:**=' => { sub => sub { $_[0] **= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 66 | 6 | ▶ | 'infix:*=' => { sub => sub { $_[0] *= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | 'infix:/=' => { sub => sub { $_[0] /= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | 'infix:%=' => { sub => sub { $_[0] %= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | 'infix:x=' => { sub => sub { $_[0] x= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 70 | 6 | ▶ | 'infix:+=' => { sub => sub { $_[0] += $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | 'infix:-=' => { sub => sub { $_[0] -= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 72 | 3 | ▶ | 'infix:.=' => { sub => sub { $_[0] .= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | 'infix:<<=' => { sub => sub { $_[0] <<= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | 'infix:>>=' => { sub => sub { $_[0] >>= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | 'infix:&=' => { sub => sub { $_[0] &= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | 'infix:|=' => { sub => sub { $_[0] |= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | 'infix:^=' => { sub => sub { $_[0] ^= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | 'infix:&&=' => { sub => sub { $_[0] &&= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Condition0%0/3
$_[0] &&= $_[1]
MC/DC0%0/2
$_[0] &&= $_[1]
$_[0]
$_[1]
Truth table0%0/3
A &&= B
A= $_[0]B= $_[1]
| |||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | 'infix:||=' => { sub => sub { $_[0] ||= $_[1] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Condition0%0/3
$_[0] ||= $_[1]
MC/DC0%0/2
$_[0] ||= $_[1]
$_[0]
$_[1]
Truth table0%0/3
A ||= B
A= $_[0]B= $_[1]
| |||||||||||||||||||||||||||||||||||||
| 80 | 21 | ▶ | 'infix:,' => { sub => sub { $_[0] , $_[1] }, res => [[]] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | 'infix:=>' => { sub => sub { $_[0] => $_[1] }, res => [[]] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 82 | 7 | ▶ | 'infix:and' => { sub => sub { $_[0] and $_[1] }, res => [1] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 83 | 9 | ▶ | 'infix:or' => { sub => sub { $_[0] or $_[1] }, res => [0] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 84 | 20 | ▶ | 'infix:xor' => { sub => sub { $_[0] xor $_[1] }, res => [0] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Condition100%4/4
$_[0] ^^ $_[1]
MC/DC100%2/2
$_[0] ^^ $_[1]
$_[0]
$_[1]
Truth table100%4/4
A ^^ B
A= $_[0]B= $_[1]
| |||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | 'infix:->' => { sub => sub { my $m = $_[1]; $_[0]->$m }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | 'infix:->=' => { sub => sub { my $m = $_[1]; $_[0] = $_[0]->$m }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||
| 88 | # unary prefix | ||||||||||||||||||||||||||||||||||||
| 89 | 7 | ▶ | 'prefix:++' => { sub => sub { ++$_[0] } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | 'prefix:--' => { sub => sub { --$_[0] } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | 'prefix:!' => { sub => sub { !$_[0] } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | 'prefix:~' => { sub => sub { ~$_[0] } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | 'prefix:\\' => { sub => sub { \$_[0] } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | 'prefix:+' => { sub => sub { +$_[0] } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 95 | 18 | ▶ | 'prefix:-' => { sub => sub { -$_[0] } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | 'prefix:$' => { sub => sub { ${$_[0]} } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | 'prefix:@' => { sub => sub { @{$_[0]} } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | 'prefix:%' => { sub => sub { %{$_[0]} } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | 'prefix:&' => { sub => sub { &{$_[0]} } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | 'prefix:*' => { sub => sub { *{$_[0]} } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||
| 102 | # unary postfix | ||||||||||||||||||||||||||||||||||||
| 103 | 11 | ▶ | 'postfix:++' => { sub => sub { $_[0]++ } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 104 | 4 | ▶ | 'postfix:--' => { sub => sub { $_[0]-- } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||
| 106 | # circumfix | ||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | 'circumfix:()' => { sub => sub { ($_[0]) } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | 'circumfix:[]' => { sub => sub { [$_[0]] } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | 'circumfix:{}' => { sub => sub { {$_[0]} } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | 'circumfix:${}' => { sub => sub { ${$_[0]} } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | 'circumfix:@{}' => { sub => sub { @{$_[0]} } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | 'circumfix:%{}' => { sub => sub { %{$_[0]} } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | 'circumfix:&{}' => { sub => sub { &{$_[0]} } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | 'circumfix:*{}' => { sub => sub { *{$_[0]} } }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||
| 116 | # postcircumfix | ||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | 'postcircumfix:[]' => { sub => sub { $_[0]->[$_[1]] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 118 | 5 | ▶ | 'postcircumfix:{}' => { sub => sub { $_[0]->{$_[1]} }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | 'postcircumfix:->[]' => { sub => sub { $_[0]->[$_[1]] }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | 'postcircumfix:->{}' => { sub => sub { $_[0]->{$_[1]} }, res => [undef] }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||
| 123 | # Perl 5.10 operators | ||||||||||||||||||||||||||||||||||||
| 124 | 5 | ▶ | if ($] >= 5.010) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 125 | 5 | $ops{'infix:~~'} = { sub => eval 'sub { $_[0] ~~ $_[1] }', res => [1, 1], chain => 1 }; | |||||||||||||||||||||||||||||||||||
| 126 | 5 | $ops{'infix://'} = { sub => eval 'sub { $_[0] // $_[1] }', res => [0] }; | |||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||
| 129 | 79 | ▶ | sub reduce { | ||||||||||||||||||||||||||||||||||
|
Subroutine
reduce: called CC=17 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 130 | 79 | my ($op, $list, %args) = @_; | |||||||||||||||||||||||||||||||||||
| 131 | 79 | my $type; | |||||||||||||||||||||||||||||||||||
| 132 | 79 | ($op, $type) = _get_op_info($op); | |||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||
| 134 | 79 | ▶ | return unless $op; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 135 | 79 | ▶ | return if $type ne 'infix'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||
| 137 | 79 | ▶ | my @list = ref $list eq 'ARRAY' ? @$list : | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 138 | defined $list ? $list : | ||||||||||||||||||||||||||||||||||||
| 139 | () ; | ||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||
| 141 | # return default for zero args | ||||||||||||||||||||||||||||||||||||
| 142 | 79 | ▶ | return $ops{$op}{res}[0] | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 143 | unless @list; | ||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||
| 145 | # return default for one arg if defined, otherwise return the arg itself | ||||||||||||||||||||||||||||||||||||
| 146 | 75 | ▶ | return exists $ops{$op}{res}[1] ? $ops{$op}{res}[1] : $list[0] | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 147 | if @list == 1; | ||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||
| 149 | 65 | ▶ | if ( $ops{$op}{right} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 150 | 3 | @list = reverse @list; | |||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||
| 153 | 65 | my $result = shift @list; | |||||||||||||||||||||||||||||||||||
| 154 | 65 | my $bool = 1; | |||||||||||||||||||||||||||||||||||
| 155 | 65 | ▶ | my @triangle = $ops{$op}{chain} ? $bool : $result; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||
| 157 | 163 | ▶ | my $apply = sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 158 | 163 | my ($a, $b) = @_; | |||||||||||||||||||||||||||||||||||
| 159 | 163 | ▶ | return applyop( $op, $ops{$op}{right} ? ($b, $a) : ($a, $b) ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 160 | 65 | }; | |||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||
| 162 | 65 | ▶ | while (@list) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 163 | 176 | my $next = shift @list; | |||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||
| 165 | 176 | ▶ | if ( $ops{$op}{chain} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 166 | 75 | ▶ | $bool = $bool && $apply->($result, $next); | ||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$bool && &$apply($result, $next)
MC/DC100%2/2
$bool && &$apply($result, $next)
$bool
&$apply($result, $next)
Truth table100%3/3
A && B
A= $boolB= &$apply($result, $next)
| |||||||||||||||||||||||||||||||||||||
| 167 | 75 | $result = $next; | |||||||||||||||||||||||||||||||||||
| 168 | 75 | ▶ | push @triangle, $bool if $args{triangle}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||
| 170 | else { | ||||||||||||||||||||||||||||||||||||
| 171 | 101 | $result = $apply->($result, $next); | |||||||||||||||||||||||||||||||||||
| 172 | 101 | ▶ | push @triangle, $result if $args{triangle}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||
| 176 | 65 | ▶ | return @triangle if $args{triangle}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 177 | 51 | ▶ | return $bool if $ops{$op}{chain}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 178 | 30 | return $result; | |||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||
| 181 | 1 | ▶ | sub zip { zipwith( ',', @_ ) } | ||||||||||||||||||||||||||||||||||
|
Subroutine
zip: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 182 | 2 | ▶ | sub cross { crosswith( ',', @_ ) } | ||||||||||||||||||||||||||||||||||
|
Subroutine
cross: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||
| 184 | 8 | ▶ | sub zipwith { | ||||||||||||||||||||||||||||||||||
|
Subroutine
zipwith: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 185 | 8 | my ($op, $lhs, $rhs) = @_; | |||||||||||||||||||||||||||||||||||
| 186 | 8 | my ($a, $b, @results); | |||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||
| 188 | 8 | ▶ | $lhs = [$lhs] if ref $lhs ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 189 | 8 | ▶ | $rhs = [$rhs] if ref $rhs ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||
| 191 | 8 | ▶ | while (@$lhs && @$rhs) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$lhs and @$rhs
MC/DC100%2/2
@$lhs and @$rhs
@$lhs
@$rhs
Truth table100%3/3
A and B
A= @$lhsB= @$rhs
| |||||||||||||||||||||||||||||||||||||
| 192 | 13 | $a = shift @$lhs; | |||||||||||||||||||||||||||||||||||
| 193 | 13 | $b = shift @$rhs; | |||||||||||||||||||||||||||||||||||
| 194 | 13 | push @results, applyop($op, $a, $b); | |||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||
| 197 | 8 | return @results; | |||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||
| 200 | 11 | ▶ | sub crosswith { | ||||||||||||||||||||||||||||||||||
|
Subroutine
crosswith: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 201 | 11 | my ($op, $lhs, $rhs) = @_; | |||||||||||||||||||||||||||||||||||
| 202 | 11 | my ($a, $b, @results); | |||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||
| 204 | 11 | ▶ | $lhs = [$lhs] if ref $lhs ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 205 | 11 | ▶ | $rhs = [$rhs] if ref $rhs ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||
| 207 | 11 | for my $a (@$lhs) { | |||||||||||||||||||||||||||||||||||
| 208 | 22 | for my $b (@$rhs) { | |||||||||||||||||||||||||||||||||||
| 209 | 43 | push @results, applyop($op, $a, $b); | |||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||
| 213 | 11 | return @results; | |||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||
| 216 | 71 | ▶ | sub hyper { | ||||||||||||||||||||||||||||||||||
|
Subroutine
hyper: called CC=39 SCAR=36.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 217 | 71 | my ($op, $lhs, $rhs, %args) = @_; | |||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||
| 219 | 71 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 220 | return map { | ||||||||||||||||||||||||||||||||||||
| 221 | 24 | ▶ | ref eq 'ARRAY' ? [ hyper($op, $_) ] : | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 222 | ref eq 'HASH' ? { hyper($op, $_) } : | ||||||||||||||||||||||||||||||||||||
| 223 | applyop($op, $_) | ||||||||||||||||||||||||||||||||||||
| 224 | } @$lhs if ref $lhs eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||
| 226 | return map { | ||||||||||||||||||||||||||||||||||||
| 227 | 6 | ▶ | $_ => ref eq 'ARRAY' ? [ hyper($op, $_) ] : | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 228 | ref eq 'HASH' ? { hyper($op, $_) } : | ||||||||||||||||||||||||||||||||||||
| 229 | 15 | ▶ | applyop($op, $lhs->{$_}) | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 230 | } keys %$lhs if ref $lhs eq 'HASH'; | ||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | return applyop($op, $$lhs) if ref $lhs eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 233 | 0 | return applyop($op, $lhs); | |||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||
| 236 | 47 | ▶ | my $dwim_left = $args{dwim_left} || $args{dwim}; | ||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$args{'dwim_left'} || $args{'dwim'}
MC/DC100%2/2
$args{'dwim_left'} || $args{'dwim'}
$args{'dwim_left'}
$args{'dwim'}
Truth table100%3/3
A || B
A= $args{'dwim_left'}B= $args{'dwim'}
| |||||||||||||||||||||||||||||||||||||
| 237 | 47 | ▶ | my $dwim_right = $args{dwim_right} || $args{dwim}; | ||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$args{'dwim_right'} || $args{'dwim'}
MC/DC100%2/2
$args{'dwim_right'} || $args{'dwim'}
$args{'dwim_right'}
$args{'dwim'}
Truth table100%3/3
A || B
A= $args{'dwim_right'}B= $args{'dwim'}
| |||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||
| 239 | 47 | ▶ | if (ref $lhs eq 'HASH' && ref $rhs eq 'HASH') { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
ref $lhs eq "HASH" and ref $rhs eq "HASH"
MC/DC100%2/2
ref $lhs eq "HASH" and ref $rhs eq "HASH"
ref $lhs eq "HASH"
ref $rhs eq "HASH"
Truth table100%3/3
A and B
A= ref $lhs eq "HASH"B= ref $rhs eq "HASH"
| |||||||||||||||||||||||||||||||||||||
| 240 | 10 | my %results; | |||||||||||||||||||||||||||||||||||
| 241 | 10 | my @keys = do { | |||||||||||||||||||||||||||||||||||
| 242 | 10 | ▶ | if ($dwim_left && $dwim_right) { # intersection | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$dwim_left and $dwim_right
MC/DC100%2/2
$dwim_left and $dwim_right
$dwim_left
$dwim_right
Truth table100%3/3
A and B
A= $dwim_leftB= $dwim_right
| |||||||||||||||||||||||||||||||||||||
| 243 | 3 | grep { exists $rhs->{$_} } keys %$lhs; | |||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||
| 245 | elsif ($dwim_left) { | ||||||||||||||||||||||||||||||||||||
| 246 | 2 | keys %$rhs; | |||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||
| 248 | elsif ($dwim_right) { | ||||||||||||||||||||||||||||||||||||
| 249 | 2 | keys %$lhs; | |||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||
| 251 | else { # union | ||||||||||||||||||||||||||||||||||||
| 252 | 3 | uniq keys %$lhs, keys %$rhs; | |||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||
| 254 | }; | ||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||
| 256 | 10 | for my $key (@keys) { | |||||||||||||||||||||||||||||||||||
| 257 | 26 | $results{$key} = do { | |||||||||||||||||||||||||||||||||||
| 258 | 26 | ▶ | if ( exists $lhs->{$key} && exists $rhs->{$key} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $lhs->{$key} and exists $rhs->{$key}
MC/DC100%2/2
exists $lhs->{$key} and exists $rhs->{$key}
exists $lhs->{$key}
exists $rhs->{$key}
Truth table100%3/3
A and B
A= exists $lhs->{$key}B= exists $rhs->{$key}
| |||||||||||||||||||||||||||||||||||||
| 259 | 22 | applyop( $op, $lhs->{$key}, $rhs->{$key} ); | |||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||
| 261 | else { | ||||||||||||||||||||||||||||||||||||
| 262 | exists $ops{$op}{res}[1] ? $ops{$op}{res}[1] : | ||||||||||||||||||||||||||||||||||||
| 263 | exists $lhs->{$key} ? $lhs->{$key} : | ||||||||||||||||||||||||||||||||||||
| 264 | 4 | ▶ | $rhs->{$key} ; | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||
| 266 | }; | ||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||
| 269 | 10 | return %results; | |||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||
| 271 | elsif (ref $lhs eq 'HASH') { | ||||||||||||||||||||||||||||||||||||
| 272 | 3 | ▶ | die "Sorry, structures on both sides of non-dwimmy hyper() are not of same shape:\n" | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 273 | . " left: HASH\n" | ||||||||||||||||||||||||||||||||||||
| 274 | . " right: " . ref($rhs) . "\n" | ||||||||||||||||||||||||||||||||||||
| 275 | unless $dwim_right; | ||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||
| 277 | 3 | return map { $_ => applyop( $op, $lhs->{$_}, $rhs ) } keys %$lhs; | |||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||
| 279 | elsif (ref $rhs eq 'HASH') { | ||||||||||||||||||||||||||||||||||||
| 280 | 2 | ▶ | die "Sorry, structures on both sides of non-dwimmy hyper() are not of same shape:\n" | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 281 | . " left: " . ref($rhs) . "\n" | ||||||||||||||||||||||||||||||||||||
| 282 | . " right: HASH\n" | ||||||||||||||||||||||||||||||||||||
| 283 | unless $dwim_left; | ||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||
| 285 | 2 | return map { $_ => applyop( $op, $lhs, $rhs->{$_} ) } keys %$rhs; | |||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||
| 288 | 32 | my $length; | |||||||||||||||||||||||||||||||||||
| 289 | 32 | ▶ | $lhs = [$lhs] if ref $lhs ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 290 | 32 | ▶ | $rhs = [$rhs] if ref $rhs ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||
| 292 | 32 | ▶ | if (!$dwim_left && !$dwim_right) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$dwim_left || $dwim_right
MC/DC100%2/2
$dwim_left || $dwim_right
$dwim_left
$dwim_right
Truth table100%3/3
A || B
A= $dwim_leftB= $dwim_right
| |||||||||||||||||||||||||||||||||||||
| 293 | 9 | ▶ | die "Sorry, arrayrefs passed to non-dwimmy hyper() are not of same length:\n" | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 294 | . " left: " . @$lhs . " elements\n" | ||||||||||||||||||||||||||||||||||||
| 295 | . " right: " . @$rhs . " elements\n" | ||||||||||||||||||||||||||||||||||||
| 296 | if @$lhs != @$rhs; | ||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||
| 298 | 9 | $length = @$lhs; | |||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||
| 300 | elsif (!$dwim_left) { | ||||||||||||||||||||||||||||||||||||
| 301 | 14 | $length = @$lhs; | |||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||
| 303 | elsif (!$dwim_right) { | ||||||||||||||||||||||||||||||||||||
| 304 | 7 | $length = @$rhs; | |||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||
| 306 | else { | ||||||||||||||||||||||||||||||||||||
| 307 | 2 | ▶ | $length = @$lhs > @$rhs ? @$lhs : @$rhs; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||
| 310 | 32 | my @results; | |||||||||||||||||||||||||||||||||||
| 311 | 32 | my $lhs_index = 0; | |||||||||||||||||||||||||||||||||||
| 312 | 32 | my $rhs_index = 0; | |||||||||||||||||||||||||||||||||||
| 313 | 32 | for (1 .. $length) { | |||||||||||||||||||||||||||||||||||
| 314 | 111 | ▶ | $lhs_index = 0 if $dwim_left && $lhs_index > $#{$lhs}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$dwim_left and $lhs_index > $#{$lhs;}
MC/DC100%2/2
$dwim_left and $lhs_index > $#{$lhs;}
$dwim_left
$lhs_index > $#{$lhs;}
Truth table100%3/3
A and B
A= $dwim_leftB= $lhs_index > $#{$lhs;}
| |||||||||||||||||||||||||||||||||||||
| 315 | 111 | ▶ | $rhs_index = 0 if $dwim_right && $rhs_index > $#{$rhs}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$dwim_right and $rhs_index > $#{$rhs;}
MC/DC100%2/2
$dwim_right and $rhs_index > $#{$rhs;}
$dwim_right
$rhs_index > $#{$rhs;}
Truth table100%3/3
A and B
A= $dwim_rightB= $rhs_index > $#{$rhs;}
| |||||||||||||||||||||||||||||||||||||
| 316 | 111 | push @results, applyop($op, $lhs->[$lhs_index], $rhs->[$rhs_index]); | |||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||
| 318 | continue { | ||||||||||||||||||||||||||||||||||||
| 319 | 111 | $lhs_index++; | |||||||||||||||||||||||||||||||||||
| 320 | 111 | $rhs_index++; | |||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||
| 323 | 32 | return @results; | |||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||
| 326 | 414 | ▶ | sub applyop { | ||||||||||||||||||||||||||||||||||
|
Subroutine
applyop: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 327 | 414 | my ($op) = @_; | |||||||||||||||||||||||||||||||||||
| 328 | 414 | my $type; | |||||||||||||||||||||||||||||||||||
| 329 | 414 | ($op, $type) = _get_op_info($op); | |||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||
| 331 | 414 | ▶ | return unless $op; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 332 | 408 | ▶ | return $ops{$op}{sub}->( @_[1, 2] ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$type eq "infix" or $type eq "postcircumfix"
MC/DC100%2/2
$type eq "infix" or $type eq "postcircumfix"
$type eq "infix"
$type eq "postcircumfix"
Truth table100%3/3
A or B
A= $type eq "infix"B= $type eq "postcircumfix"
| |||||||||||||||||||||||||||||||||||||
| 333 | if $type eq 'infix' | ||||||||||||||||||||||||||||||||||||
| 334 | || $type eq 'postcircumfix'; | ||||||||||||||||||||||||||||||||||||
| 335 | 43 | return $ops{$op}{sub}->( $_[1] ); | |||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | sub reverseop { | ||||||||||||||||||||||||||||||||||
|
Subroutine
reverseop: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 339 | 0 | my ($op) = @_; | |||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | return applyop( $op, $_[1] ) if $op =~ m{^ (?: pre | post ) fix : }x; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 342 | 0 | return applyop( $op, @_[1, 2] ); | |||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||
| 345 | 493 | ▶ | sub _get_op_info { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_op_info: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||
| 346 | 493 | my ($op) = @_; | |||||||||||||||||||||||||||||||||||
| 347 | 493 | my ($type) = $op =~ m{^ (\w+) : }x; | |||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||
| 349 | 493 | ▶ | if (!$type) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 350 | 282 | $type = "infix"; | |||||||||||||||||||||||||||||||||||
| 351 | 282 | $op = "infix:$op"; | |||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||
| 354 | 493 | ▶ | return unless exists $ops{$op}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 355 | 487 | return $op, $type; | |||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||
| 358 | 5 | 1; | |||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||
| 360 | __END__ | ||||||||||||||||||||||||||||||||||||