blib/lib/Operator/Util.pm

filter: Statementstmt 71.6% 167 / 233 Branchbran 87.2% 103 / 118 Conditioncond 86.0% 37 / 43 MC/DCmcdc 85.7% 24 / 28 Subroutinesub 48.4% 47 / 97 Podpod 100% 8 / 8 totaltotal 73.2% 386 / 527 CC 77 SCAR 25.0
CC
77
Cov
78%
hyper
40.1
reduce
17.0
__ANON__
6.0
CRAP 12.2
↑ Summary
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
BranchTrueFalseTotal
$_[0] and $_[1] 2 5 7
61 13 ▶ 'infix:||' => { sub => sub { $_[0] || $_[1] }, res => [0] },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] or $_[1] 6 7 13
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]
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] &&= $_[1]
$_[0] $_[1]
Truth table0%0/3
A &&= B
A= $_[0]B= $_[1]
ABresult
0X0
100
111
79 0 ▶ 'infix:||=' => { sub => sub { $_[0] ||= $_[1] }, res => [undef] },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/3
$_[0] ||= $_[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] ||= $_[1]
$_[0] $_[1]
Truth table0%0/3
A ||= B
A= $_[0]B= $_[1]
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$_[0] and $_[1] 2 5 7
83 9 ▶ 'infix:or' => { sub => sub { $_[0] or $_[1] }, res => [0] },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] or $_[1] 4 5 9
84 20 ▶ 'infix:xor' => { sub => sub { $_[0] xor $_[1] }, res => [0] },
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%4/4
$_[0] ^^ $_[1]
l&&rl&&!r!l&&r!l&&!r
5555
MC/DC100%2/2
$_[0] ^^ $_[1]
$_[0] $_[1]
Truth table100%4/4
A ^^ B
A= $_[0]B= $_[1]
ABresult
110
101
011
000
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
BranchTrueFalseTotal
if ($] >= "5.01") 5 0 5
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
BranchTrueFalseTotal
unless $op 0 79 79
135 79 ▶ return if $type ne 'infix';
Branch: 1 branch
BranchTrueFalseTotal
if $type ne "infix" 0 79 79
136  
137 79 ▶ my @list = ref $list eq 'ARRAY' ? @$list :
Branch: 2 branches
BranchTrueFalseTotal
ref $list eq 'ARRAY' ? : 65 14 79
defined $list ? : 10 4 14
138 defined $list ? $list :
139 () ;
140  
141 # return default for zero args
142 79 ▶ return $ops{$op}{res}[0]
Branch: 1 branch
BranchTrueFalseTotal
unless @list 4 75 79
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
BranchTrueFalseTotal
if @list == 1 10 65 75
exists $ops{$op}{'res'}[1] ? : 3 7 10
147 if @list == 1;
148  
149 65 ▶ if ( $ops{$op}{right} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ops{$op}{"right"}) 3 62 65
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
BranchTrueFalseTotal
$ops{$op}{'chain'} ? : 29 36 65
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
BranchTrueFalseTotal
$ops{$op}{'right'} ? : 6 157 163
160 65 };
161  
162 65 ▶ while (@list) {
Branch: 1 branch
BranchTrueFalseTotal
if (@list) 176 65 241
163 176 my $next = shift @list;
164  
165 176 ▶ if ( $ops{$op}{chain} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ops{$op}{'chain'}) { } 75 101 176
166 75 ▶ $bool = $bool && $apply->($result, $next);
Condition100%3/3
$bool && &$apply($result, $next)
!ll&&!rl&&r
131448
MC/DC100%2/2
$bool && &$apply($result, $next)
$bool &$apply($result, $next)
Truth table100%3/3
A && B
A= $boolB= &$apply($result, $next)
ABresult
0X0
100
111
167 75 $result = $next;
168 75 ▶ push @triangle, $bool if $args{triangle};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"triangle"} 20 55 75
169 }
170 else {
171 101 $result = $apply->($result, $next);
172 101 ▶ push @triangle, $result if $args{triangle};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"triangle"} 18 83 101
173 }
174 }
175  
176 65 ▶ return @triangle if $args{triangle};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"triangle"} 14 51 65
177 51 ▶ return $bool if $ops{$op}{chain};
Branch: 1 branch
BranchTrueFalseTotal
if $ops{$op}{"chain"} 21 30 51
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
BranchTrueFalseTotal
if ref $lhs ne "ARRAY" 2 6 8
189 8 ▶ $rhs = [$rhs] if ref $rhs ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $rhs ne "ARRAY" 2 6 8
190  
191 8 ▶ while (@$lhs && @$rhs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$lhs and @$rhs) 13 8 21
Condition100%3/3
@$lhs and @$rhs
!ll&&!rl&&r
6213
MC/DC100%2/2
@$lhs and @$rhs
@$lhs @$rhs
Truth table100%3/3
A and B
A= @$lhsB= @$rhs
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ref $lhs ne "ARRAY" 2 9 11
205 11 ▶ $rhs = [$rhs] if ref $rhs ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $rhs ne "ARRAY" 2 9 11
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
BranchTrueFalseTotal
if (@_ == 2) 24 47 71
220 return map {
221 24 ▶ ref eq 'ARRAY' ? [ hyper($op, $_) ] :
Branch: 3 branches
BranchTrueFalseTotal
if ref $lhs eq "ARRAY" 18 6 24
ref $_ eq 'ARRAY' ? : 8 37 45
ref $_ eq 'HASH' ? : 3 34 37
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
BranchTrueFalseTotal
if ref $lhs eq "HASH" 6 0 6
228 ref eq 'HASH' ? { hyper($op, $_) } :
229 15 ▶ applyop($op, $lhs->{$_})
Branch: 2 branches
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 15 15
ref $_ eq 'HASH' ? : 0 15 15
230 } keys %$lhs if ref $lhs eq 'HASH';
231  
232 0 ▶ return applyop($op, $$lhs) if ref $lhs eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $lhs eq "SCALAR" 0 0 0
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'}
l!l&&r!l&&!r
10730
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'}
ABresult
1X1
011
000
237 47 ▶ my $dwim_right = $args{dwim_right} || $args{dwim};
Condition100%3/3
$args{'dwim_right'} || $args{'dwim'}
l!l&&r!l&&!r
18722
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'}
ABresult
1X1
011
000
238  
239 47 ▶ if (ref $lhs eq 'HASH' && ref $rhs eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $lhs eq 'HASH' and ref $rhs eq 'HASH') { } 10 37 47
elsif (ref $lhs eq 'HASH') { } 3 34 37
elsif (ref $rhs eq 'HASH') { } 2 32 34
Condition100%3/3
ref $lhs eq "HASH" and ref $rhs eq "HASH"
!ll&&!rl&&r
34310
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"
ABresult
0X0
100
111
240 10 my %results;
241 10 my @keys = do {
242 10 ▶ if ($dwim_left && $dwim_right) { # intersection
Branch: 3 branches
BranchTrueFalseTotal
if ($dwim_left and $dwim_right) { } 3 7 10
elsif ($dwim_left) { } 2 5 7
elsif ($dwim_right) { } 2 3 5
Condition100%3/3
$dwim_left and $dwim_right
!ll&&!rl&&r
523
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (exists $lhs->{$key} and exists $rhs->{$key}) { } 22 4 26
Condition100%3/3
exists $lhs->{$key} and exists $rhs->{$key}
!ll&&!rl&&r
2222
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}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
exists $ops{$op}{'res'}[1] ? : 0 4 4
exists $lhs->{$key} ? : 2 2 4
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
BranchTrueFalseTotal
unless $dwim_right 0 3 3
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
BranchTrueFalseTotal
unless $dwim_left 0 2 2
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
BranchTrueFalseTotal
if ref $lhs ne "ARRAY" 2 30 32
290 32 ▶ $rhs = [$rhs] if ref $rhs ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $rhs ne "ARRAY" 6 26 32
291  
292 32 ▶ if (!$dwim_left && !$dwim_right) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $dwim_left || $dwim_right) { } 9 23 32
elsif (not $dwim_left) { } 14 9 23
elsif (not $dwim_right) { } 7 2 9
Condition100%3/3
$dwim_left || $dwim_right
l!l&&r!l&&!r
9149
MC/DC100%2/2
$dwim_left || $dwim_right
$dwim_left $dwim_right
Truth table100%3/3
A || B
A= $dwim_leftB= $dwim_right
ABresult
1X1
011
000
293 9 ▶ die "Sorry, arrayrefs passed to non-dwimmy hyper() are not of same length:\n"
Branch: 1 branch
BranchTrueFalseTotal
if @$lhs != @$rhs 0 9 9
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
BranchTrueFalseTotal
@$lhs > @$rhs ? : 0 2 2
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
BranchTrueFalseTotal
if $dwim_left and $lhs_index > $#{$lhs;} 12 99 111
Condition100%3/3
$dwim_left and $lhs_index > $#{$lhs;}
!ll&&!rl&&r
792012
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;}
ABresult
0X0
100
111
315 111 ▶ $rhs_index = 0 if $dwim_right && $rhs_index > $#{$rhs};
Branch: 1 branch
BranchTrueFalseTotal
if $dwim_right and $rhs_index > $#{$rhs;} 20 91 111
Condition100%3/3
$dwim_right and $rhs_index > $#{$rhs;}
!ll&&!rl&&r
563520
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;}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $op 6 408 414
332 408 ▶ return $ops{$op}{sub}->( @_[1, 2] )
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "infix" or $type eq "postcircumfix" 365 43 408
Condition100%3/3
$type eq "infix" or $type eq "postcircumfix"
l!l&&r!l&&!r
360543
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"
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if $op =~ /^ (?: pre | post ) fix : /x 0 0 0
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
BranchTrueFalseTotal
unless ($type) 282 211 493
350 282 $type = "infix";
351 282 $op = "infix:$op";
352 }
353  
354 493 ▶ return unless exists $ops{$op};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ops{$op} 6 487 493
355 487 return $op, $type;
356 }
357  
358 5 1;
359  
360 __END__
↑ Summary