blib/lib/Switch.pm

filter: Statementstmt 72.4% 216 / 298 Branchbran 67.5% 123 / 182 Conditioncond 67.9% 91 / 134 MC/DCmcdc 31.8% 21 / 66 Subroutinesub 42.6% 35 / 82 Podpod 0.0% 0 / 13 totaltotal 62.7% 486 / 775 CC 140 SCAR 36.6
CC
140
Cov
70%
filter_blocks
115.3
__ANON__
72.0
switch
14.3
CRAP 39.0
↑ Summary
1 package Switch;
2  
3 3 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use if $] >= 5.011, 'deprecate';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 $VERSION = '2.17';
11
12  
13 # LOAD FILTERING MODULE...
14 3 ▶use Filter::Util::Call;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 sub __();
17  
18 # CATCH ATTEMPTS TO CALL case OUTSIDE THE SCOPE OF ANY switch
19  
20 2 ▶$::_S_W_I_T_C_H = sub { croak "case/when statement not in switch/given block" };
Subroutine __ANON__: called CC=1 SCAR=0.0
21  
22 3 my $offset;
23 my $fallthrough;
24 3 my ($Perl5, $Perl6) = (0,0);
25  
26 sub import
27 3 ▶{
Subroutine import: called CC=8 SCAR=20.9
28 3 $fallthrough = grep /\bfallthrough\b/, @_;
29 3 $offset = (caller)[2]+1;
30 3 ▶ filter_add({}) unless @_>1 && $_[1] eq 'noimport';
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 and $_[1] eq "noimport" 3 0 3
Condition66%2/3
@_ > 1 and $_[1] eq "noimport"
!ll&&!rl&&r
120
MC/DC0%0/2
@_ > 1 and $_[1] eq "noimport"
@_ > 1 $_[1] eq "noimport"
Truth table66%2/3
A and B
A= @_ > 1B= $_[1] eq "noimport"
ABresult
0X0
100
111
31 3 my $pkg = caller;
32 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 3 for ( qw( on_defined on_exists ) )
34 {
35 6 *{"${pkg}::$_"} = \&$_;
36 }
37 3 ▶ *{"${pkg}::__"} = \&__ if grep /__/, @_;
Branch: 1 branch
BranchTrueFalseTotal
if grep /__/, @_ 2 1 3
38 3 ▶ $Perl6 = 1 if grep(/Perl\s*6/i, @_);
Branch: 1 branch
BranchTrueFalseTotal
if grep /Perl\s*6/i, @_ 1 2 3
39 3 ▶ $Perl5 = 1 if grep(/Perl\s*5/i, @_) || !grep(/Perl\s*6/i, @_);
Branch: 1 branch
BranchTrueFalseTotal
if grep /Perl\s*5/i, @_ or not grep(/Perl\s*6/i, @_) 2 1 3
Condition66%2/3
grep /Perl\s*5/i, @_ or not grep(/Perl\s*6/i, @_)
l!l&&r!l&&!r
021
MC/DC50%1/2
grep /Perl\s*5/i, @_ or not grep(/Perl\s*6/i, @_)
grep /Perl\s*5/i, @_ not grep(/Perl\s*6/i, @_)
Truth table66%2/3
A or not(B)
A= grep /Perl\s*5/i, @_B= not grep(/Perl\s*6/i, @_)
ABresult
1X1
011
000
40 3 1;
41 }
42  
43 sub unimport
44 0 ▶{
Subroutine unimport: not called CC=1 SCAR=6.9
45 0 filter_del()
46 }
47  
48 sub filter
49 5 ▶{
Subroutine filter: called CC=3 SCAR=11.0
Pod undocumented
50 5 my($self) = @_ ;
51 5 local $Switch::file = (caller)[1];
52  
53 5 my $status = 1;
54 5 $status = filter_read(1_000_000);
55 5 ▶ return $status if $status<0;
Branch: 1 branch
BranchTrueFalseTotal
if $status < 0 0 5 5
56 5 $_ = filter_blocks($_,$offset);
57 5 ▶ $_ = "# line $offset\n" . $_ if $offset; undef $offset;
Branch: 1 branch
BranchTrueFalseTotal
if $offset 3 2 5
58 5 return $status;
59 }
60  
61 3 ▶use Text::Balanced ':ALL';
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 sub line
64 461 ▶{
Subroutine line: called CC=2 SCAR=7.2
Pod undocumented
65 461 my ($pretext,$offset) = @_;
66 461 ▶ ($pretext=~tr/\n/\n/)+($offset||0);
Condition50%1/2
$offset || 0
l!l
4610
MC/DC0%0/1
$offset || 0
$offset
Truth table50%1/2
A
A= $offset
Aresult
11
00
67 }
68  
69 sub is_block
70 34 ▶{
Subroutine is_block: called CC=1 SCAR=0.0
Pod undocumented
71 34 ▶ local $SIG{__WARN__}=sub{die$@};
Subroutine __ANON__: called CC=1 SCAR=0.0
72 34 local $^W=1;
73 34 my $ishash = defined eval 'my $hr='.$_[0];
74 34 undef $@;
75 34 return !$ishash;
76 }
77  
78 3 my $pod_or_DATA = qr/ ^=[A-Za-z] .*? ^=cut (?![A-Za-z]) .*? $
79 | ^__(DATA|END)__\n.*
80 /smx;
81  
82 3 my $casecounter = 1;
83 sub filter_blocks
84 466 ▶{
Subroutine filter_blocks: called CC=62 SCAR=47.5
Pod undocumented
85 466 my ($source, $line) = @_;
86 466 ▶ return $source unless $Perl5 && $source =~ /case|switch/
Branch: 1 branch
BranchTrueFalseTotal
unless $Perl5 and $source =~ /case|switch/ or $Perl6 and $source =~ /when|given|default/ 440 26 466
Condition100%9/9
$Perl5 and $source =~ /case|switch/ or $Perl6 and $source =~ /when|given|default/
l!l&&r!l&&!r
1511440
$Perl5 and $source =~ /case|switch/
!ll&&!rl&&r
22622515
$Perl6 and $source =~ /when|given|default/
!ll&&!rl&&r
22521511
MC/DC75%3/4
$Perl5 and $source =~ /case|switch/ or $Perl6 and $source =~ /when|given|default/
$Perl5 $source =~ /case|switch/ $Perl6 $source =~ /when|given|default/
Truth table57%4/7
A and B or C and D
A= $Perl5B= $source =~ /case|switch/C= $Perl6D= $source =~ /when|given|default/
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
87 || $Perl6 && $source =~ /when|given|default/;
88 26 pos $source = 0;
89 26 my $text = "";
90 26 ▶ component: while (pos $source < length $source)
Branch: 1 branch
BranchTrueFalseTotal
if (pos $source < length $source) 2553 26 2579
91 {
92 2553 ▶ if ($source =~ m/(\G\s*use\s+Switch\b)/gc)
Branch: 1 branch
BranchTrueFalseTotal
if ($source =~ /(\G\s*use\s+Switch\b)/cg) 0 2553 2553
93 {
94 0 $text .= q{use Switch 'noimport'};
95 0 next component;
96 }
97 2553 my @pos = Text::Balanced::_match_quotelike(\$source,qr/\s*/,1,0);
98 2553 ▶ if (defined $pos[0])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos[0]) 58 2495 2553
99 {
100 58 my $pre = substr($source,$pos[0],$pos[1]); # matched prefix
101 58 my $iEol;
102 58 ▶ if( substr($source,$pos[4],$pos[5]) eq '/' && # 1st delimiter
Branch: 1 branch
BranchTrueFalseTotal
if (substr($source, $pos[4], $pos[5]) eq '/' and substr($source, $pos[2], $pos[3]) eq '' and index(substr($source, $pos[16], $pos[17]), 'x') == -1 and ($iEol = index($source, "\n", $pos[4])) > 0 and $iEol < $pos[8]) { } 0 58 58
Condition66%8/12
substr($source, $pos[4], $pos[5]) eq "/" and substr($source, $pos[2], $pos[3]) eq "" and index(substr($source, $pos[16], $pos[17]), "x") == -1 and ($iEol = index($source, "\n", $pos[4])) > 0 and $iEol < $pos[8]
!ll&&!rl&&r
5260
substr($source, $pos[4], $pos[5]) eq "/" and substr($source, $pos[2], $pos[3]) eq "" and index(substr($source, $pos[16], $pos[17]), "x") == -1 and ($iEol = index($source, "\n", $pos[4])) > 0
!ll&&!rl&&r
5206
substr($source, $pos[4], $pos[5]) eq "/" and substr($source, $pos[2], $pos[3]) eq "" and index(substr($source, $pos[16], $pos[17]), "x") == -1
!ll&&!rl&&r
5206
substr($source, $pos[4], $pos[5]) eq "/" and substr($source, $pos[2], $pos[3]) eq ""
!ll&&!rl&&r
5206
MC/DC0%0/5
substr($source, $pos[4], $pos[5]) eq "/" and substr($source, $pos[2], $pos[3]) eq "" and index(substr($source, $pos[16], $pos[17]), "x") == -1 and ($iEol = index($source, "\n", $pos[4])) > 0 and $iEol < $pos[8]
substr($source, $pos[4], $pos[5]) eq "/" substr($source, $pos[2], $pos[3]) eq "" index(substr($source, $pos[16], $pos[17]), "x") == -1 ($iEol = index($source, "\n", $pos[4])) > 0 $iEol < $pos[8]
Truth table33%2/6
A and B and C and D and E
A= substr($source, $pos[4], $pos[5]) eq "/"B= substr($source, $pos[2], $pos[3]) eq ""C= index(substr($source, $pos[16], $pos[17]), "x") == -1D= ($iEol = index($source, "\n", $pos[4])) > 0E= $iEol < $pos[8]
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
103 substr($source,$pos[2],$pos[3]) eq '' && # no op like 'm'
104 index( substr($source,$pos[16],$pos[17]), 'x' ) == -1 && # no //x
105 ($iEol = index( $source, "\n", $pos[4] )) > 0 &&
106 $iEol < $pos[8] ){ # embedded newlines
107 # If this is a pattern, it isn't compatible with Switch. Backup past 1st '/'.
108 0 pos( $source ) = $pos[6];
109 0 $text .= $pre . substr($source,$pos[2],$pos[6]-$pos[2]);
110 } else {
111 58 $text .= $pre . substr($source,$pos[2],$pos[18]-$pos[2]);
112 }
113 58 next component;
114 }
115 2495 ▶ if ($source =~ m/(\G\s*$pod_or_DATA)/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source =~ /(\G\s*$pod_or_DATA)/cg) 2 2493 2495
116 2 $text .= $1;
117 2 next component;
118 }
119 2493 @pos = Text::Balanced::_match_variable(\$source,qr/\s*/);
120 2493 ▶ if (defined $pos[0])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos[0]) 162 2331 2493
121 {
122 162 ▶ $text .= " " if $pos[0] < $pos[2];
Branch: 1 branch
BranchTrueFalseTotal
if $pos[0] < $pos[2] 44 118 162
123 162 $text .= substr($source,$pos[0],$pos[4]-$pos[0]);
124 162 next component;
125 }
126  
127 2331 ▶ if ($Perl5 && $source =~ m/\G(\n*)(\s*)(switch)\b(?=\s*[(])/gc
Branch: 2 branches
BranchTrueFalseTotal
if ($Perl5 and $source =~ /\G(\n*)(\s*)(switch)\b(?=\s*[(])/cg or $Perl6 and $source =~ /\G(\n*)(\s*)(given)\b(?=\s*[(])/cg or $Perl6 and $source =~ /\G(\n*)(\s*)(given)\b(.*)(?=\{)/cg) { } 20 2311 2331
elsif ($Perl5 and $source =~ /\G(\s*)(case\b)(?!\s*=>)/cg or $Perl6 and $source =~ /\G(\s*)(when\b)(?!\s*=>)/cg or $Perl6 and $source =~ /\G(\s*)(default\b)(?=\s*\{)/cg) { } 212 3160 3372
Condition100%15/15
$Perl5 and $source =~ /\G(\n*)(\s*)(switch)\b(?=\s*[(])/cg or $Perl6 and $source =~ /\G(\n*)(\s*)(given)\b(?=\s*[(])/cg or $Perl6 and $source =~ /\G(\n*)(\s*)(given)\b(.*)(?=\{)/cg
l!l&&r!l&&!r
1912311
$Perl5 and $source =~ /\G(\n*)(\s*)(switch)\b(?=\s*[(])/cg or $Perl6 and $source =~ /\G(\n*)(\s*)(given)\b(?=\s*[(])/cg
l!l&&r!l&&!r
1182312
$Perl5 and $source =~ /\G(\n*)(\s*)(switch)\b(?=\s*[(])/cg
!ll&&!rl&&r
1151116911
$Perl6 and $source =~ /\G(\n*)(\s*)(given)\b(?=\s*[(])/cg
!ll&&!rl&&r
116911438
$Perl6 and $source =~ /\G(\n*)(\s*)(given)\b(.*)(?=\{)/cg
!ll&&!rl&&r
116911421
MC/DC66%4/6
$Perl5 and $source =~ /\G(\n*)(\s*)(switch)\b(?=\s*[(])/cg or $Perl6 and $source =~ /\G(\n*)(\s*)(given)\b(?=\s*[(])/cg or $Perl6 and $source =~ /\G(\n*)(\s*)(given)\b(.*)(?=\{)/cg
$Perl5 $source =~ /\G(\n*)(\s*)(switch)\b(?=\s*[(])/cg $Perl6 $source =~ /\G(\n*)(\s*)(given)\b(?=\s*[(])/cg $Perl6 $source =~ /\G(\n*)(\s*)(given)\b(.*)(?=\{)/cg
Truth table33%5/15
A and B or C and D or E and F
A= $Perl5B= $source =~ /\G(\n*)(\s*)(switch)\b(?=\s*[(])/cgC= $Perl6D= $source =~ /\G(\n*)(\s*)(given)\b(?=\s*[(])/cgE= $Perl6F= $source =~ /\G(\n*)(\s*)(given)\b(.*)(?=\{)/cg
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
128 || $Perl6 && $source =~ m/\G(\n*)(\s*)(given)\b(?=\s*[(])/gc
129 || $Perl6 && $source =~ m/\G(\n*)(\s*)(given)\b(.*)(?=\{)/gc)
130 {
131 20 my $keyword = $3;
132 20 my $arg = $4;
133 20 $text .= $1.$2.'S_W_I_T_C_H: while (1) ';
134 20 ▶ unless ($arg) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg) 19 1 20
135 @pos = Text::Balanced::_match_codeblock(\$source,qr/\s*/,qr/\(/,qr/\)/,qr/[[{(<]/,qr/[]})>]/,undef)
136 19 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
@pos = Text::Balanced::_match_codeblock(\$source, qr/\s*/, qr/\(/, qr/\)/, qr/[[{(<]/, qr/[]})>]/, undef) or do { die "Bad $keyword statement (problem in the parentheses?) near $Switch::file line ", line(substr($source, 0, pos $source), $line), "\n" } 19 0 19
137 0 die "Bad $keyword statement (problem in the parentheses?) near $Switch::file line ", line(substr($source,0,pos $source),$line), "\n";
138 };
139 19 $arg = filter_blocks(substr($source,$pos[0],$pos[4]-$pos[0]),line(substr($source,0,$pos[0]),$line));
140 }
141 20 ▶ $arg =~ s {^\s*[(]\s*%} { ( \\\%} ||
Branch: 1 branch
BranchTrueFalseTotal
$arg =~ s/^\s*[(]\s*%/ ( \\%/ or $arg =~ s/^\s*[(]\s*m\b/ ( qr/ or $arg =~ s[^\s*[(]\s*/][ ( qr/] or $arg =~ s/^\s*[(]\s*qw/ ( \\qw/ 0 20 20
Condition33%2/6
$arg =~ s/^\s*[(]\s*%/ ( \\%/ or $arg =~ s/^\s*[(]\s*m\b/ ( qr/ or $arg =~ s[^\s*[(]\s*/][ ( qr/]
l!l&&r!l&&!r
0020
$arg =~ s/^\s*[(]\s*%/ ( \\%/ or $arg =~ s/^\s*[(]\s*m\b/ ( qr/
l!l&&r!l&&!r
0020
MC/DC0%0/3
$arg =~ s/^\s*[(]\s*%/ ( \\%/ or $arg =~ s/^\s*[(]\s*m\b/ ( qr/ or $arg =~ s[^\s*[(]\s*/][ ( qr/]
$arg =~ s/^\s*[(]\s*%/ ( \\%/ $arg =~ s/^\s*[(]\s*m\b/ ( qr/ $arg =~ s[^\s*[(]\s*/][ ( qr/]
Truth table25%1/4
A or B or C
A= $arg =~ s/^\s*[(]\s*%/ ( \\%/B= $arg =~ s/^\s*[(]\s*m\b/ ( qr/C= $arg =~ s[^\s*[(]\s*/][ ( qr/]
ABCresult
1XX1
01X1
0011
0000
142 $arg =~ s {^\s*[(]\s*m\b} { ( qr} ||
143 $arg =~ s {^\s*[(]\s*/} { ( qr/} ||
144 $arg =~ s {^\s*[(]\s*qw} { ( \\qw};
145 @pos = Text::Balanced::_match_codeblock(\$source,qr/\s*/,qr/\{/,qr/\}/,qr/\{/,qr/\}/,undef)
146 20 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
@pos = Text::Balanced::_match_codeblock(\$source, qr/\s*/, qr/\{/, qr/\}/, qr/\{/, qr/\}/, undef) or do { die "Bad $keyword statement (problem in the code block?) near $Switch::file line ", line(substr($source, 0, pos $source), $line), "\n" } 20 0 20
147 0 die "Bad $keyword statement (problem in the code block?) near $Switch::file line ", line(substr($source,0, pos $source), $line), "\n";
148 };
149 20 my $code = filter_blocks(substr($source,$pos[0],$pos[4]-$pos[0]),line(substr($source,0,$pos[0]),$line));
150 20 $code =~ s/{/{ local \$::_S_W_I_T_C_H; Switch::switch($arg);/;
151 20 $text .= $code . 'continue {last}';
152 20 next component;
153 }
154 ▶ elsif ($Perl5 && $source =~ m/\G(\s*)(case\b)(?!\s*=>)/gc
Condition86%13/15
$Perl5 and $source =~ /\G(\s*)(case\b)(?!\s*=>)/cg or $Perl6 and $source =~ /\G(\s*)(when\b)(?!\s*=>)/cg or $Perl6 and $source =~ /\G(\s*)(default\b)(?=\s*\{)/cg
l!l&&r!l&&!r
21202099
$Perl5 and $source =~ /\G(\s*)(case\b)(?!\s*=>)/cg or $Perl6 and $source =~ /\G(\s*)(when\b)(?!\s*=>)/cg
l!l&&r!l&&!r
1081042099
$Perl5 and $source =~ /\G(\s*)(case\b)(?!\s*=>)/cg
!ll&&!rl&&r
11421061108
$Perl6 and $source =~ /\G(\s*)(when\b)(?!\s*=>)/cg
!ll&&!rl&&r
10611038104
$Perl6 and $source =~ /\G(\s*)(default\b)(?=\s*\{)/cg
!ll&&!rl&&r
106110380
MC/DC50%3/6
$Perl5 and $source =~ /\G(\s*)(case\b)(?!\s*=>)/cg or $Perl6 and $source =~ /\G(\s*)(when\b)(?!\s*=>)/cg or $Perl6 and $source =~ /\G(\s*)(default\b)(?=\s*\{)/cg
$Perl5 $source =~ /\G(\s*)(case\b)(?!\s*=>)/cg $Perl6 $source =~ /\G(\s*)(when\b)(?!\s*=>)/cg $Perl6 $source =~ /\G(\s*)(default\b)(?=\s*\{)/cg
Truth table26%4/15
A and B or C and D or E and F
A= $Perl5B= $source =~ /\G(\s*)(case\b)(?!\s*=>)/cgC= $Perl6D= $source =~ /\G(\s*)(when\b)(?!\s*=>)/cgE= $Perl6F= $source =~ /\G(\s*)(default\b)(?=\s*\{)/cg
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
155 || $Perl6 && $source =~ m/\G(\s*)(when\b)(?!\s*=>)/gc
156 || $Perl6 && $source =~ m/\G(\s*)(default\b)(?=\s*\{)/gc)
157 {
158 212 my $keyword = $2;
159 212 ▶ $text .= $1 . ($keyword eq "default"
Branch: 1 branch
BranchTrueFalseTotal
$keyword eq 'default' ? : 0 212 212
160 ? "if (1)"
161 : "if (Switch::case");
162  
163 212 ▶ if ($keyword eq "default") {
Branch: 6 branches
BranchTrueFalseTotal
if ($keyword eq 'default') { } 0 212 212
elsif (@pos = Text::Balanced::_match_codeblock(\$source, qr/\s*/, qr/\{/, qr/\}/, qr/\{/, qr/\}/, undef)) { } 34 178 212
elsif (@pos = Text::Balanced::_match_codeblock(\$source, qr/\s*/, qr/[[(]/, qr/[])]/, qr/[[({]/, qr/[])}]/, undef)) { } 155 23 178
elsif ($Perl6 and do { @pos = Text::Balanced::_match_variable(\$source, qr/\s*/) }) { } 0 23 23
elsif (@pos = Text::Balanced::_match_quotelike(\$source, qr/\s*/, 1, 0)) { } 4 19 23
elsif ($Perl5 and $source =~ /\G\s*(([^\$\@{])[^\$\@{]*)(?=\s*{)/cg or $Perl6 and $source =~ /\G\s*([^;{]*)()/cg) { } 19 0 19
164 # Nothing to do
165 }
166 elsif (@pos = Text::Balanced::_match_codeblock(\$source,qr/\s*/,qr/\{/,qr/\}/,qr/\{/,qr/\}/,undef)) {
167 34 my $code = substr($source,$pos[0],$pos[4]-$pos[0]);
168 34 ▶ $text .= " " if $pos[0] < $pos[2];
Branch: 1 branch
BranchTrueFalseTotal
if $pos[0] < $pos[2] 34 0 34
169 34 ▶ $text .= "sub " if is_block $code;
Branch: 1 branch
BranchTrueFalseTotal
if is_block($code) 30 4 34
170 34 $text .= filter_blocks($code,line(substr($source,0,$pos[0]),$line)) . ")";
171 }
172 elsif (@pos = Text::Balanced::_match_codeblock(\$source,qr/\s*/,qr/[[(]/,qr/[])]/,qr/[[({]/,qr/[])}]/,undef)) {
173 155 my $code = filter_blocks(substr($source,$pos[0],$pos[4]-$pos[0]),line(substr($source,0,$pos[0]),$line));
174 155 ▶ $code =~ s {^\s*[(]\s*%} { ( \\\%} ||
Branch: 1 branch
BranchTrueFalseTotal
$code =~ s/^\s*[(]\s*%/ ( \\%/ or $code =~ s/^\s*[(]\s*m\b/ ( qr/ or $code =~ s[^\s*[(]\s*/][ ( qr/] or $code =~ s/^\s*[(]\s*qw/ ( \\qw/ 0 155 155
Condition33%2/6
$code =~ s/^\s*[(]\s*%/ ( \\%/ or $code =~ s/^\s*[(]\s*m\b/ ( qr/ or $code =~ s[^\s*[(]\s*/][ ( qr/]
l!l&&r!l&&!r
00155
$code =~ s/^\s*[(]\s*%/ ( \\%/ or $code =~ s/^\s*[(]\s*m\b/ ( qr/
l!l&&r!l&&!r
00155
MC/DC0%0/3
$code =~ s/^\s*[(]\s*%/ ( \\%/ or $code =~ s/^\s*[(]\s*m\b/ ( qr/ or $code =~ s[^\s*[(]\s*/][ ( qr/]
$code =~ s/^\s*[(]\s*%/ ( \\%/ $code =~ s/^\s*[(]\s*m\b/ ( qr/ $code =~ s[^\s*[(]\s*/][ ( qr/]
Truth table25%1/4
A or B or C
A= $code =~ s/^\s*[(]\s*%/ ( \\%/B= $code =~ s/^\s*[(]\s*m\b/ ( qr/C= $code =~ s[^\s*[(]\s*/][ ( qr/]
ABCresult
1XX1
01X1
0011
0000
175 $code =~ s {^\s*[(]\s*m\b} { ( qr} ||
176 $code =~ s {^\s*[(]\s*/} { ( qr/} ||
177 $code =~ s {^\s*[(]\s*qw} { ( \\qw};
178 155 ▶ $text .= " " if $pos[0] < $pos[2];
Branch: 1 branch
BranchTrueFalseTotal
if $pos[0] < $pos[2] 155 0 155
179 155 $text .= "$code)";
180 }
181 11 ▶ elsif ($Perl6 && do{@pos = Text::Balanced::_match_variable(\$source,qr/\s*/)}) {
Condition66%2/3
$Perl6 and do { @pos = Text::Balanced::_match_variable(\$source, qr/\s*/) }
!ll&&!rl&&r
12110
MC/DC0%0/2
$Perl6 and do { @pos = Text::Balanced::_match_variable(\$source, qr/\s*/) }
$Perl6 do { @pos = Text::Balanced::_match_variable(\$source, qr/\s*/) }
Truth table66%2/3
A and B
A= $Perl6B= do { @pos = Text::Balanced::_match_variable(\$source, qr/\s*/) }
ABresult
0X0
100
111
182 0 my $code = filter_blocks(substr($source,$pos[0],$pos[4]-$pos[0]),line(substr($source,0,$pos[0]),$line));
183 0 ▶ $code =~ s {^\s*%} { \%} ||
Branch: 1 branch
BranchTrueFalseTotal
$code =~ s/^\s*%/ %/ or $code =~ s/^\s*@/ \@/ 0 0 0
184 $code =~ s {^\s*@} { \@};
185 0 ▶ $text .= " " if $pos[0] < $pos[2];
Branch: 1 branch
BranchTrueFalseTotal
if $pos[0] < $pos[2] 0 0 0
186 0 $text .= "$code)";
187 }
188 elsif ( @pos = Text::Balanced::_match_quotelike(\$source,qr/\s*/,1,0)) {
189 4 my $code = substr($source,$pos[2],$pos[18]-$pos[2]);
190 4 $code = filter_blocks($code,line(substr($source,0,$pos[2]),$line));
191 4 ▶ $code =~ s {^\s*m} { qr} ||
Branch: 1 branch
BranchTrueFalseTotal
$code =~ s/^\s*m/ qr/ or $code =~ s[^\s*/][ qr/] or $code =~ s/^\s*qw/ \\qw/ 0 4 4
Condition33%1/3
$code =~ s/^\s*m/ qr/ or $code =~ s[^\s*/][ qr/]
l!l&&r!l&&!r
004
MC/DC0%0/2
$code =~ s/^\s*m/ qr/ or $code =~ s[^\s*/][ qr/]
$code =~ s/^\s*m/ qr/ $code =~ s[^\s*/][ qr/]
Truth table33%1/3
A or B
A= $code =~ s/^\s*m/ qr/B= $code =~ s[^\s*/][ qr/]
ABresult
1X1
011
000
192 $code =~ s {^\s*/} { qr/} ||
193 $code =~ s {^\s*qw} { \\qw};
194 4 ▶ $text .= " " if $pos[0] < $pos[2];
Branch: 1 branch
BranchTrueFalseTotal
if $pos[0] < $pos[2] 4 0 4
195 4 $text .= "$code)";
196 }
197 ▶ elsif ($Perl5 && $source =~ m/\G\s*(([^\$\@{])[^\$\@{]*)(?=\s*{)/gc
Condition55%5/9
$Perl5 and $source =~ /\G\s*(([^\$\@{])[^\$\@{]*)(?=\s*{)/cg or $Perl6 and $source =~ /\G\s*([^;{]*)()/cg
l!l&&r!l&&!r
9100
$Perl5 and $source =~ /\G\s*(([^\$\@{])[^\$\@{]*)(?=\s*{)/cg
!ll&&!rl&&r
1009
$Perl6 and $source =~ /\G\s*([^;{]*)()/cg
!ll&&!rl&&r
0010
MC/DC0%0/4
$Perl5 and $source =~ /\G\s*(([^\$\@{])[^\$\@{]*)(?=\s*{)/cg or $Perl6 and $source =~ /\G\s*([^;{]*)()/cg
$Perl5 $source =~ /\G\s*(([^\$\@{])[^\$\@{]*)(?=\s*{)/cg $Perl6 $source =~ /\G\s*([^;{]*)()/cg
Truth table28%2/7
A and B or C and D
A= $Perl5B= $source =~ /\G\s*(([^\$\@{])[^\$\@{]*)(?=\s*{)/cgC= $Perl6D= $source =~ /\G\s*([^;{]*)()/cg
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
198 || $Perl6 && $source =~ m/\G\s*([^;{]*)()/gc) {
199 19 my $code = filter_blocks($1,line(substr($source,0,pos $source),$line));
200 19 ▶ $text .= ' \\' if $2 eq '%';
Branch: 1 branch
BranchTrueFalseTotal
if $2 eq "%" 0 19 19
201 19 $text .= " $code)";
202 }
203 else {
204 0 die "Bad $keyword statement (invalid $keyword value?) near $Switch::file line ", line(substr($source,0,pos $source), $line), "\n";
205 }
206  
207 212 ▶ die "Missing opening brace or semi-colon after 'when' value near $Switch::file line ", line(substr($source,0,pos $source), $line), "\n"
Branch: 1 branch
BranchTrueFalseTotal
unless not $Perl6 or $source =~ /\G(\s*)(?=;|\{)/cg 0 212 212
Condition66%2/3
not $Perl6 or $source =~ /\G(\s*)(?=;|\{)/cg
l!l&&r!l&&!r
1081040
MC/DC0%0/2
not $Perl6 or $source =~ /\G(\s*)(?=;|\{)/cg
not $Perl6 $source =~ /\G(\s*)(?=;|\{)/cg
Truth table66%2/3
not(A) or B
A= not $Perl6B= $source =~ /\G(\s*)(?=;|\{)/cg
ABresult
1X1
011
000
208 unless !$Perl6 || $source =~ m/\G(\s*)(?=;|\{)/gc;
209  
210 212 do{@pos = Text::Balanced::_match_codeblock(\$source,qr/\s*/,qr/\{/,qr/\}/,qr/\{/,qr/\}/,undef)}
211 212 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
do { @pos = Text::Balanced::_match_codeblock(\$source, qr/\s*/, qr/\{/, qr/\}/, qr/\{/, qr/\}/, undef) } or do { if ($source =~ /\G\s*(?=([};]|\Z))/cg) { ++$casecounter; next component; } ; die "Bad $keyword statement (problem in the code block?) near $Switch::file line ", line(substr($source, 0, pos $source), $line), "\n" } 210 2 212
212 2 ▶ if ($source =~ m/\G\s*(?=([};]|\Z))/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source =~ /\G\s*(?=([};]|\Z))/cg) 2 0 2
213 2 $casecounter++;
214 2 next component;
215 }
216 0 die "Bad $keyword statement (problem in the code block?) near $Switch::file line ", line(substr($source,0,pos $source),$line), "\n";
217 };
218 210 my $code = filter_blocks(substr($source,$pos[0],$pos[4]-$pos[0]),line(substr($source,0,$pos[0]),$line));
219 210 ▶ $code =~ s/}(?=\s*\Z)/;last S_W_I_T_C_H }/
Branch: 1 branch
BranchTrueFalseTotal
unless $fallthrough 4 206 210
220 unless $fallthrough;
221 210 $text .= "{ while (1) $code continue { goto C_A_S_E_$casecounter } last S_W_I_T_C_H; C_A_S_E_$casecounter: }";
222 210 $casecounter++;
223 210 next component;
224 }
225  
226 2099 $source =~ m/\G(\s*(-[sm]\s+|\w+|#.*\n|\W))/gc;
227 2099 $text .= $1;
228 }
229 26 $text;
230 }
231  
232  
233  
234 sub in
235 135 ▶{
Subroutine in: called CC=12 SCAR=25.0
Pod undocumented
236 135 my ($x,$y) = @_;
237 135 my @numy;
238 135 for my $nextx ( @$x )
239 {
240 153 ▶ my $numx = ref($nextx) || defined $nextx && (~$nextx&$nextx) eq 0;
Condition66%4/6
ref $nextx || defined $nextx && (~$nextx & $nextx) eq 0
l!l&&r!l&&!r
09657
defined $nextx and (~$nextx & $nextx) eq 0
!ll&&!rl&&r
05796
MC/DC33%1/3
ref $nextx || defined $nextx && (~$nextx & $nextx) eq 0
ref $nextx defined $nextx (~$nextx & $nextx) eq 0
Truth table50%2/4
A || B and C
A= ref $nextxB= defined $nextxC= (~$nextx & $nextx) eq 0
ABCresult
1XX1
0111
00X0
0100
241 153 for my $j ( 0..$#$y )
242 {
243 958 my $nexty = $y->[$j];
244 958 ▶ push @numy, ref($nexty) || defined $nexty && (~$nexty&$nexty) eq 0
Branch: 1 branch
BranchTrueFalseTotal
if @numy <= $j 550 408 958
Condition66%4/6
ref $nexty || defined $nexty && (~$nexty & $nexty) eq 0
l!l&&r!l&&!r
046585
defined $nexty and (~$nexty & $nexty) eq 0
!ll&&!rl&&r
085465
MC/DC33%1/3
ref $nexty || defined $nexty && (~$nexty & $nexty) eq 0
ref $nexty defined $nexty (~$nexty & $nexty) eq 0
Truth table50%2/4
A || B and C
A= ref $nextyB= defined $nextyC= (~$nexty & $nexty) eq 0
ABCresult
1XX1
0111
00X0
0100
245 if @numy <= $j;
246 958 ▶ return 1 if $numx && $numy[$j] && $nextx==$nexty
Branch: 1 branch
BranchTrueFalseTotal
if $numx and $numy[$j] and $nextx == $nexty or $nextx eq $nexty 41 917 958
Condition100%9/9
$numx and $numy[$j] and $nextx == $nexty or $nextx eq $nexty
l!l&&r!l&&!r
2813917
$numx and $numy[$j] and $nextx == $nexty
!ll&&!rl&&r
48744328
$numx and $numy[$j]
!ll&&!rl&&r
43354471
MC/DC100%4/4
$numx and $numy[$j] and $nextx == $nexty or $nextx eq $nexty
$numx $numy[$j] $nextx == $nexty $nextx eq $nexty
Truth table85%6/7
A and B and C or D
A= $numxB= $numy[$j]C= $nextx == $nextyD= $nextx eq $nexty
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
247 || $nextx eq $nexty;
248
249 }
250 }
251 94 return "";
252 }
253  
254 sub on_exists
255 0 ▶{
Subroutine on_exists: not called CC=3 SCAR=24.8
Pod undocumented
256 0 ▶ my $ref = @_==1 && ref($_[0]) eq 'HASH' ? $_[0] : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] eq 'HASH' ? : 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
257 0 [ keys %$ref ]
258 }
259  
260 sub on_defined
261 0 ▶{
Subroutine on_defined: not called CC=3 SCAR=24.8
Pod undocumented
262 0 ▶ my $ref = @_==1 && ref($_[0]) eq 'HASH' ? $_[0] : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] eq 'HASH' ? : 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
263 0 [ grep { defined $ref->{$_} } keys %$ref ]
264 }
265  
266 sub switch(;$)
267 53 ▶{
Subroutine switch: called CC=11 SCAR=26.6
Pod undocumented
268 53 ▶ my ($s_val) = @_ ? $_[0] : $_;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 53 0 53
269 53 my $s_ref = ref $s_val;
270
271 53 ▶ if ($s_ref eq 'CODE')
Branch: 7 branches
BranchTrueFalseTotal
if ($s_ref eq 'CODE') { } 6 47 53
elsif ($s_ref eq '' and defined $s_val and (~$s_val & $s_val) eq 0) { } 18 29 47
elsif ($s_ref eq '') { } 8 21 29
elsif ($s_ref eq 'ARRAY') { } 16 5 21
elsif ($s_ref eq 'Regexp') { } 0 5 5
elsif ($s_ref eq 'HASH') { } 4 1 5
elsif ($s_ref eq 'Switch') { } 1 0 1
272 {
273 $::_S_W_I_T_C_H =
274 114 ▶ sub { my $c_val = $_[0];
Subroutine __ANON__: called CC=3 SCAR=11.0
275 114 ▶ return $s_val == $c_val if ref $c_val eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $c_val eq "CODE" 30 84 114
276 84 ▶ return $s_val->(@$c_val) if ref $c_val eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $c_val eq "ARRAY" 30 54 84
277 54 return $s_val->($c_val);
278 6 };
279 }
280 ▶ elsif ($s_ref eq "" && defined $s_val && (~$s_val&$s_val) eq 0) # NUMERIC SCALAR
Condition83%5/6
$s_ref eq "" and defined $s_val and (~$s_val & $s_val) eq 0
!ll&&!rl&&r
21818
$s_ref eq "" and defined $s_val
!ll&&!rl&&r
21026
MC/DC66%2/3
$s_ref eq "" and defined $s_val and (~$s_val & $s_val) eq 0
$s_ref eq "" defined $s_val (~$s_val & $s_val) eq 0
Truth table75%3/4
A and B and C
A= $s_ref eq ""B= defined $s_valC= (~$s_val & $s_val) eq 0
ABCresult
0XX0
10X0
1100
1111
281 {
282 $::_S_W_I_T_C_H =
283 170 ▶ sub { my $c_val = $_[0];
Subroutine __ANON__: called CC=10 SCAR=23.3
284 170 my $c_ref = ref $c_val;
285 170 ▶ return $s_val == $c_val if $c_ref eq ""
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "" and defined $c_val and (~$c_val & $c_val) eq 0 45 125 170
Condition83%5/6
$c_ref eq "" and defined $c_val and (~$c_val & $c_val) eq 0
!ll&&!rl&&r
1012445
$c_ref eq "" and defined $c_val
!ll&&!rl&&r
101069
MC/DC66%2/3
$c_ref eq "" and defined $c_val and (~$c_val & $c_val) eq 0
$c_ref eq "" defined $c_val (~$c_val & $c_val) eq 0
Truth table75%3/4
A and B and C
A= $c_ref eq ""B= defined $c_valC= (~$c_val & $c_val) eq 0
ABCresult
0XX0
10X0
1100
1111
286 && defined $c_val
287 && (~$c_val&$c_val) eq 0;
288 125 ▶ return $s_val eq $c_val if $c_ref eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "" 24 101 125
289 101 ▶ return in([$s_val],$c_val) if $c_ref eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "ARRAY" 44 57 101
290 57 ▶ return $c_val->($s_val) if $c_ref eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "CODE" 24 33 57
291 33 ▶ return $c_val->call($s_val) if $c_ref eq 'Switch';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "Switch" 9 24 33
292 24 ▶ return scalar $s_val=~/$c_val/
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "Regexp" 0 24 24
293 if $c_ref eq 'Regexp';
294 24 ▶ return scalar $c_val->{$s_val}
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "HASH" 24 0 24
295 if $c_ref eq 'HASH';
296 0 return;
297 18 };
298 }
299 elsif ($s_ref eq "") # STRING SCALAR
300 {
301 $::_S_W_I_T_C_H =
302 136 ▶ sub { my $c_val = $_[0];
Subroutine __ANON__: called CC=7 SCAR=19.9
303 136 my $c_ref = ref $c_val;
304 136 ▶ return $s_val eq $c_val if $c_ref eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "" 64 72 136
305 72 ▶ return in([$s_val],$c_val) if $c_ref eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "ARRAY" 24 48 72
306 48 ▶ return $c_val->($s_val) if $c_ref eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "CODE" 32 16 48
307 16 ▶ return $c_val->call($s_val) if $c_ref eq 'Switch';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "Switch" 0 16 16
308 16 ▶ return scalar $s_val=~/$c_val/
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "Regexp" 0 16 16
309 if $c_ref eq 'Regexp';
310 16 ▶ return scalar $c_val->{$s_val}
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "HASH" 16 0 16
311 if $c_ref eq 'HASH';
312 0 return;
313 8 };
314 }
315 elsif ($s_ref eq 'ARRAY')
316 {
317 $::_S_W_I_T_C_H =
318 113 ▶ sub { my $c_val = $_[0];
Subroutine __ANON__: called CC=7 SCAR=19.6
319 113 my $c_ref = ref $c_val;
320 113 ▶ return in($s_val,[$c_val]) if $c_ref eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "" 37 76 113
321 76 ▶ return in($s_val,$c_val) if $c_ref eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "ARRAY" 30 46 76
322 46 ▶ return $c_val->(@$s_val) if $c_ref eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "CODE" 24 22 46
323 22 ▶ return $c_val->call(@$s_val)
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "Switch" 0 22 22
324 if $c_ref eq 'Switch';
325 22 ▶ return scalar grep {$_=~/$c_val/} @$s_val
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "Regexp" 10 12 22
326 if $c_ref eq 'Regexp';
327 12 ▶ return scalar grep {$c_val->{$_}} @$s_val
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "HASH" 12 0 12
328 if $c_ref eq 'HASH';
329 0 return;
330 16 };
331 }
332 elsif ($s_ref eq 'Regexp')
333 {
334 $::_S_W_I_T_C_H =
335 0 ▶ sub { my $c_val = $_[0];
Subroutine __ANON__: not called CC=8 SCAR=42.8
336 0 my $c_ref = ref $c_val;
337 0 ▶ return $c_val=~/s_val/ if $c_ref eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "" 0 0 0
338 0 ▶ return scalar grep {$_=~/s_val/} @$c_val
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "ARRAY" 0 0 0
339 if $c_ref eq 'ARRAY';
340 0 ▶ return $c_val->($s_val) if $c_ref eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "CODE" 0 0 0
341 0 ▶ return $c_val->call($s_val) if $c_ref eq 'Switch';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "Switch" 0 0 0
342 0 ▶ return $s_val eq $c_val if $c_ref eq 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "Regexp" 0 0 0
343 0 ▶ return grep {$_=~/$s_val/ && $c_val->{$_}} keys %$c_val
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "HASH" 0 0 0
Condition0%0/3
$_ =~ /$s_val/ && $c_val->{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
$_ =~ /$s_val/ && $c_val->{$_}
$_ =~ /$s_val/ $c_val->{$_}
Truth table0%0/3
A && B
A= $_ =~ /$s_val/B= $c_val->{$_}
ABresult
0X0
100
111
344 if $c_ref eq 'HASH';
345 0 return;
346 0 };
347 }
348 elsif ($s_ref eq 'HASH')
349 {
350 $::_S_W_I_T_C_H =
351 68 ▶ sub { my $c_val = $_[0];
Subroutine __ANON__: called CC=8 SCAR=22.9
352 68 my $c_ref = ref $c_val;
353 68 ▶ return $s_val->{$c_val} if $c_ref eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "" 20 48 68
354 48 ▶ return scalar grep {$s_val->{$_}} @$c_val
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "ARRAY" 20 28 48
355 if $c_ref eq 'ARRAY';
356 28 ▶ return $c_val->($s_val) if $c_ref eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "CODE" 16 12 28
357 12 ▶ return $c_val->call($s_val) if $c_ref eq 'Switch';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "Switch" 0 12 12
358 0 ▶ return grep {$_=~/$c_val/ && $s_val->{"$_"}} keys %$s_val
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "Regexp" 0 12 12
Condition0%0/3
$_ =~ /$c_val/ && $$s_val{"$_"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_ =~ /$c_val/ && $$s_val{"$_"}
$_ =~ /$c_val/ $$s_val{"$_"}
Truth table0%0/3
A && B
A= $_ =~ /$c_val/B= $$s_val{"$_"}
ABresult
0X0
100
111
359 if $c_ref eq 'Regexp';
360 12 ▶ return $s_val==$c_val if $c_ref eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if $c_ref eq "HASH" 12 0 12
361 0 return;
362 4 };
363 }
364 elsif ($s_ref eq 'Switch')
365 {
366 $::_S_W_I_T_C_H =
367 3 ▶ sub { my $c_val = $_[0];
Subroutine __ANON__: called CC=3 SCAR=11.4
368 3 ▶ return $s_val == $c_val if ref $c_val eq 'Switch';
Branch: 1 branch
BranchTrueFalseTotal
if ref $c_val eq "Switch" 0 3 3
369 3 ▶ return $s_val->call(@$c_val)
Branch: 1 branch
BranchTrueFalseTotal
if ref $c_val eq "ARRAY" 0 3 3
370 if ref $c_val eq 'ARRAY';
371 3 return $s_val->call($c_val);
372 1 };
373 }
374 else
375 {
376 0 croak "Cannot switch on $s_ref";
377 }
378 53 return 1;
379 }
380  
381 606 ▶sub case($) { local $SIG{__WARN__} = \&carp;
Subroutine case: called CC=1 SCAR=0.0
Pod undocumented
382 606 $::_S_W_I_T_C_H->(@_); }
383  
384 # IMPLEMENT __
385  
386 12 ▶my $placeholder = bless { arity=>1, impl=>sub{$_[1+$_[0]]} };
Subroutine __ANON__: called CC=1 SCAR=0.0
387  
388 12 ▶sub __() { $placeholder }
Subroutine __: called CC=1 SCAR=0.0
389  
390 sub __arg($)
391 0 ▶{
Subroutine __arg: not called CC=1 SCAR=6.9
392 0 my $index = $_[0]+1;
393 0 ▶ bless { arity=>0, impl=>sub{$_[$index]} };
Subroutine __ANON__: not called CC=1 SCAR=6.9
394 }
395  
396 sub hosub(&@)
397 0 ▶{
Subroutine hosub: not called CC=1 SCAR=0.0
Pod undocumented
398 # WRITE THIS
399 }
400  
401 sub call
402 12 ▶{
Subroutine call: called CC=1 SCAR=0.0
Pod undocumented
403 12 my ($self,@args) = @_;
404 12 return $self->{impl}->(0,@args);
405 }
406  
407 sub meta_bop(&)
408 84 ▶{
Subroutine meta_bop: called CC=1 SCAR=0.1
Pod undocumented
409 84 my ($op) = @_;
410 sub
411 3 ▶ {
Subroutine __ANON__: called CC=4 SCAR=14.5
412 3 my ($left, $right, $reversed) = @_;
413 3 ▶ ($right,$left) = @_ if $reversed;
Branch: 1 branch
BranchTrueFalseTotal
if $reversed 0 3 3
414  
415 my $rop = ref $right eq 'Switch'
416 ? $right
417 3 ▶ : bless { arity=>0, impl=>sub{$right} };
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
ref $right eq 'Switch' ? : 0 3 3
418  
419 my $lop = ref $left eq 'Switch'
420 ? $left
421 0 ▶ : bless { arity=>0, impl=>sub{$left} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
ref $left eq 'Switch' ? : 3 0 3
422  
423 3 my $arity = $lop->{arity} + $rop->{arity};
424  
425 return bless {
426 arity => $arity,
427 3 ▶ impl => sub { my $start = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
428 return $op->($lop->{impl}->($start,@_),
429 3 $rop->{impl}->($start+$lop->{arity},@_));
430 }
431 3 };
432 84 };
433 }
434  
435 sub meta_uop(&)
436 27 ▶{
Subroutine meta_uop: called CC=1 SCAR=4.1
Pod undocumented
437 27 my ($op) = @_;
438 sub
439 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
440 0 my ($left) = @_;
441  
442 my $lop = ref $left eq 'Switch'
443 ? $left
444 0 ▶ : bless { arity=>0, impl=>sub{$left} };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $left eq 'Switch' ? : 0 0 0
445  
446 0 my $arity = $lop->{arity};
447  
448 return bless {
449 arity => $arity,
450 0 ▶ impl => sub { $op->($lop->{impl}->(@_)) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
451 0 };
452 27 };
453 }
454  
455  
456 use overload
457 0 ▶ "+" => meta_bop {$_[0] + $_[1]},
Subroutine BEGIN: called CC=1 SCAR=5.2
Subroutine __ANON__: not called CC=1 SCAR=6.9
458 0 ▶ "-" => meta_bop {$_[0] - $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
459 0 ▶ "*" => meta_bop {$_[0] * $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
460 0 ▶ "/" => meta_bop {$_[0] / $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
461 0 ▶ "%" => meta_bop {$_[0] % $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
462 0 ▶ "**" => meta_bop {$_[0] ** $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
463 0 ▶ "<<" => meta_bop {$_[0] << $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
464 0 ▶ ">>" => meta_bop {$_[0] >> $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
465 0 ▶ "x" => meta_bop {$_[0] x $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
466 0 ▶ "." => meta_bop {$_[0] . $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
467 0 ▶ "<" => meta_bop {$_[0] < $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
468 0 ▶ "<=" => meta_bop {$_[0] <= $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
469 3 ▶ ">" => meta_bop {$_[0] > $_[1]},
Subroutine __ANON__: called CC=1 SCAR=0.0
470 0 ▶ ">=" => meta_bop {$_[0] >= $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
471 0 ▶ "==" => meta_bop {$_[0] == $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
472 0 ▶ "!=" => meta_bop {$_[0] != $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
473 0 ▶ "<=>" => meta_bop {$_[0] <=> $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
474 0 ▶ "lt" => meta_bop {$_[0] lt $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
475 0 ▶ "le" => meta_bop {$_[0] le $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
476 0 ▶ "gt" => meta_bop {$_[0] gt $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
477 0 ▶ "ge" => meta_bop {$_[0] ge $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
478 0 ▶ "eq" => meta_bop {$_[0] eq $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
479 0 ▶ "ne" => meta_bop {$_[0] ne $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
480 0 ▶ "cmp" => meta_bop {$_[0] cmp $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
481 0 ▶ "\&" => meta_bop {$_[0] & $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
482 0 ▶ "^" => meta_bop {$_[0] ^ $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
483 0 ▶ "|" => meta_bop {$_[0] | $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
484 0 ▶ "atan2" => meta_bop {atan2 $_[0], $_[1]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
485  
486 0 ▶ "neg" => meta_uop {-$_[0]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
487 0 ▶ "!" => meta_uop {!$_[0]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
488 0 ▶ "~" => meta_uop {~$_[0]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
489 0 ▶ "cos" => meta_uop {cos $_[0]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
490 0 ▶ "sin" => meta_uop {sin $_[0]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
491 0 ▶ "exp" => meta_uop {exp $_[0]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
492 0 ▶ "abs" => meta_uop {abs $_[0]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
493 0 ▶ "log" => meta_uop {log $_[0]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
494 0 ▶ "sqrt" => meta_uop {sqrt $_[0]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
495 2 ▶ "bool" => sub { croak "Can't use && or || in expression containing __" },
Subroutine __ANON__: called CC=1 SCAR=0.0
496  
497 # "&()" => sub { $_[0]->{impl} },
498  
499 # "||" => meta_bop {$_[0] || $_[1]},
500 # "&&" => meta_bop {$_[0] && $_[1]},
501 # fallback => 1,
502 3 ;
503 3 1;
504  
505 __END__
↑ Summary