Expr/Compiler/perl.pm

filter: Statementstmt 98.2% 787 / 801 Branchbran 69.2% 97 / 140 Conditioncond 52.0% 13 / 25 MC/DCmcdc 7.6% 1 / 13 Subroutinesub 100% 197 / 197 Podpod 6.0% 2 / 33 totaltotal 90.7% 1097 / 1209 CC 97 SCAR 15.0
CC
97
Cov
93%
rule_comparison
27.1
_quote
9.1
rule_mult
8.0
CRAP 4.5
« Expr/EvaluatorRole.pm ↑ Summary Expr/Parser.pm »
1 package Language::Expr::Compiler::perl;
2  
3 3 our $DATE = '2016-07-03'; # DATE
4 3 our $VERSION = '0.29'; # VERSION
5  
6 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use parent 'Language::Expr::Compiler::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 with 'Language::Expr::CompilerRole';
13  
14 3 ▶use boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 10 ▶sub rule_pair_simple {
Subroutine rule_pair_simple: called CC=1 SCAR=0.0
Pod undocumented
17 10 my ($self, %args) = @_;
18 10 my $match = $args{match};
19 10 "$match->{key} => $match->{value}";
20 }
21  
22 6 ▶sub rule_pair_string {
Subroutine rule_pair_string: called CC=1 SCAR=0.0
Pod undocumented
23 6 my ($self, %args) = @_;
24 6 my $match = $args{match};
25 6 "$match->{key} => $match->{value}";
26 }
27  
28 8 ▶sub rule_or_xor {
Subroutine rule_or_xor: called CC=7 SCAR=20.3
Pod undocumented
29 8 my ($self, %args) = @_;
30 8 my $match = $args{match};
31 8 my @res;
32 8 push @res, shift @{$match->{operand}};
33 8 for my $term (@{$match->{operand}}) {
34 8 ▶ my $op = shift @{$match->{op}//=[]};
Condition50%1/2
$match->{"op"} //= []
l!l
80
MC/DC0%0/1
$match->{"op"} //= []
$match->{"op"}
Truth table50%1/2
A
A= $match->{"op"}
Aresult
11
00
35 8 ▶ last unless $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 8 8
36 8 ▶ if ($op eq '||') { push @res, " || $term" }
Branch: 3 branches
BranchTrueFalseTotal
if ($op eq '||') { } 4 4 8
elsif ($op eq '//') { } 4 0 4
elsif ($op eq '^^') { } 0 0 0
37 4 elsif ($op eq '//') { push @res, " // $term" }
38 # add parenthesis because perl's xor precendence is low
39 0 elsif ($op eq '^^') { @res = ("(", @res, " xor $term)") }
40 }
41 8 join "", grep {defined} @res;
42 }
43  
44 4 ▶sub rule_and {
Subroutine rule_and: called CC=5 SCAR=16.3
Pod undocumented
45 4 my ($self, %args) = @_;
46 4 my $match = $args{match};
47 4 my @res;
48 4 push @res, shift @{$match->{operand}};
49 4 for my $term (@{$match->{operand}}) {
50 4 ▶ my $op = shift @{$match->{op}//=[]};
Condition50%1/2
$match->{"op"} //= []
l!l
40
MC/DC0%0/1
$match->{"op"} //= []
$match->{"op"}
Truth table50%1/2
A
A= $match->{"op"}
Aresult
11
00
51 4 ▶ last unless $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 4 4
52 4 ▶ if ($op eq '&&') { @res = ("((", @res, " && $term) || false)") }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "&&") 4 0 4
53 }
54 4 join "", grep {defined} @res;
55 }
56  
57 10 ▶sub rule_ternary {
Subroutine rule_ternary: called CC=1 SCAR=0.0
Pod undocumented
58 10 my ($self, %args) = @_;
59 10 my $match = $args{match};
60 10 my $opd = $match->{operand};
61 10 "$opd->[0] ? $opd->[1] : $opd->[2]";
62 }
63  
64 2 ▶sub rule_bit_or_xor {
Subroutine rule_bit_or_xor: called CC=6 SCAR=18.0
Pod undocumented
65 2 my ($self, %args) = @_;
66 2 my $match = $args{match};
67 2 my @res;
68 2 push @res, shift @{$match->{operand}};
69 2 for my $term (@{$match->{operand}}) {
70 2 ▶ my $op = shift @{$match->{op}//=[]};
Condition50%1/2
$match->{"op"} //= []
l!l
20
MC/DC0%0/1
$match->{"op"} //= []
$match->{"op"}
Truth table50%1/2
A
A= $match->{"op"}
Aresult
11
00
71 2 ▶ last unless $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 2 2
72 2 ▶ if ($op eq '|') { push @res, " | $term" }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '|') { } 1 1 2
elsif ($op eq '^') { } 1 0 1
73 1 elsif ($op eq '^') { push @res, " ^ $term" }
74 }
75 2 join "", grep {defined} @res;
76 }
77  
78 1 ▶sub rule_bit_and {
Subroutine rule_bit_and: called CC=5 SCAR=16.3
Pod undocumented
79 1 my ($self, %args) = @_;
80 1 my $match = $args{match};
81 1 my @res;
82 1 push @res, shift @{$match->{operand}};
83 1 for my $term (@{$match->{operand}}) {
84 1 ▶ my $op = shift @{$match->{op}//=[]};
Condition50%1/2
$match->{"op"} //= []
l!l
10
MC/DC0%0/1
$match->{"op"} //= []
$match->{"op"}
Truth table50%1/2
A
A= $match->{"op"}
Aresult
11
00
85 1 ▶ last unless $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 1 1
86 1 ▶ if ($op eq '&') { push @res, " & $term" }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "&") 1 0 1
87 }
88 1 join "", grep {defined} @res;
89 }
90  
91 29 ▶sub rule_comparison3 {
Subroutine rule_comparison3: called CC=6 SCAR=18.0
Pod undocumented
92 29 my ($self, %args) = @_;
93 29 my $match = $args{match};
94 29 my @res;
95 29 push @res, shift @{$match->{operand}};
96 29 for my $term (@{$match->{operand}}) {
97 29 ▶ my $op = shift @{$match->{op}//=[]};
Condition50%1/2
$match->{"op"} //= []
l!l
290
MC/DC0%0/1
$match->{"op"} //= []
$match->{"op"}
Truth table50%1/2
A
A= $match->{"op"}
Aresult
11
00
98 29 ▶ last unless $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 29 29
99 29 ▶ if ($op eq '<=>') { push @res, " <=> $term" }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '<=>') { } 22 7 29
elsif ($op eq 'cmp') { } 7 0 7
100 7 elsif ($op eq 'cmp') { push @res, " cmp $term" }
101 }
102 29 join "", grep {defined} @res;
103 }
104  
105 53 ▶sub rule_comparison {
Subroutine rule_comparison: called CC=21 SCAR=33.0
Pod undocumented
106 53 my ($self, %args) = @_;
107 53 my $match = $args{match};
108 53 my @opds;
109 53 push @opds, shift @{$match->{operand}};
110 53 ▶ return '' unless defined $opds[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opds[0] 0 53 53
111 53 my @ops;
112 53 for my $term (@{$match->{operand}}) {
113 60 push @opds, $term;
114 60 ▶ my $op = shift @{$match->{op}//=[]};
Condition50%1/2
$match->{"op"} //= []
l!l
600
MC/DC0%0/1
$match->{"op"} //= []
$match->{"op"}
Truth table50%1/2
A
A= $match->{"op"}
Aresult
11
00
115 60 ▶ last unless $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 60 60
116 60 ▶ if ($op eq '==' ) { push @ops, '==' }
Branch: 12 branches
BranchTrueFalseTotal
if ($op eq '==') { } 17 43 60
elsif ($op eq '!=') { } 4 39 43
elsif ($op eq 'eq') { } 3 36 39
elsif ($op eq 'ne') { } 0 36 36
elsif ($op eq '<') { } 4 32 36
elsif ($op eq '<=') { } 3 29 32
elsif ($op eq '>') { } 24 5 29
elsif ($op eq '>=') { } 5 0 5
elsif ($op eq 'lt') { } 0 0 0
elsif ($op eq 'le') { } 0 0 0
elsif ($op eq 'gt') { } 0 0 0
elsif ($op eq 'ge') { } 0 0 0
117 4 elsif ($op eq '!=' ) { push @ops, '!=' }
118 3 elsif ($op eq 'eq' ) { push @ops, 'eq' }
119 0 elsif ($op eq 'ne' ) { push @ops, 'ne' }
120 4 elsif ($op eq '<' ) { push @ops, '<' }
121 3 elsif ($op eq '<=' ) { push @ops, '<=' }
122 24 elsif ($op eq '>' ) { push @ops, '>' }
123 5 elsif ($op eq '>=' ) { push @ops, '>=' }
124 0 elsif ($op eq 'lt' ) { push @ops, 'lt' }
125 0 elsif ($op eq 'le' ) { push @ops, 'le' }
126 0 elsif ($op eq 'gt' ) { push @ops, 'gt' }
127 0 elsif ($op eq 'ge' ) { push @ops, 'ge' }
128 }
129 53 ▶ return $opds[0] unless @ops;
Branch: 1 branch
BranchTrueFalseTotal
unless @ops 0 53 53
130 53 my @res;
131 my $lastopd;
132 53 my ($opd1, $opd2);
133 53 ▶ while (@ops) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ops) 60 53 113
134 60 my $op = pop @ops;
135 60 ▶ if (defined($lastopd)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lastopd) { } 7 53 60
136 7 $opd2 = $lastopd;
137 7 $opd1 = pop @opds;
138 } else {
139 53 $opd2 = pop @opds;
140 53 $opd1 = pop @opds;
141 }
142 60 ▶ if (@res) {
Branch: 1 branch
BranchTrueFalseTotal
if (@res) { } 7 53 60
143 7 @res = ("(($opd1 $op $opd2) ? ", @res, " : false)");
144 } else {
145 53 push @res, "($opd1 $op $opd2 ? true:false)";
146 }
147 60 $lastopd = $opd1;
148 }
149 53 join "", @res;
150 }
151  
152 4 ▶sub rule_bit_shift {
Subroutine rule_bit_shift: called CC=6 SCAR=18.0
Pod undocumented
153 4 my ($self, %args) = @_;
154 4 my $match = $args{match};
155 4 my @res;
156 4 push @res, shift @{$match->{operand}};
157 4 for my $term (@{$match->{operand}}) {
158 4 ▶ my $op = shift @{$match->{op}//=[]};
Condition50%1/2
$match->{"op"} //= []
l!l
40
MC/DC0%0/1
$match->{"op"} //= []
$match->{"op"}
Truth table50%1/2
A
A= $match->{"op"}
Aresult
11
00
159 4 ▶ last unless $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 4 4
160 4 ▶ if ($op eq '>>') { push @res, " >> $term" }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '>>') { } 2 2 4
elsif ($op eq '<<') { } 2 0 2
161 2 elsif ($op eq '<<') { push @res, " << $term" }
162 }
163 4 join "", grep {defined} @res;
164 }
165  
166 23 ▶sub rule_add {
Subroutine rule_add: called CC=7 SCAR=19.5
Pod undocumented
167 23 my ($self, %args) = @_;
168 23 my $match = $args{match};
169 23 my @res;
170 23 push @res, shift @{$match->{operand}};
171 23 for my $term (@{$match->{operand}}) {
172 40 ▶ my $op = shift @{$match->{op}//=[]};
Condition50%1/2
$match->{"op"} //= []
l!l
400
MC/DC0%0/1
$match->{"op"} //= []
$match->{"op"}
Truth table50%1/2
A
A= $match->{"op"}
Aresult
11
00
173 40 ▶ last unless $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 40 40
174 40 ▶ if ($op eq '.') { push @res, " . $term" }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq ".") 2 38 40
175 40 ▶ if ($op eq '+') { push @res, " + $term" }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "+") 33 7 40
176 40 ▶ if ($op eq '-') { push @res, " - $term" }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "-") 5 35 40
177 }
178 23 join "", grep {defined} @res;
179 }
180  
181 19 ▶sub rule_mult {
Subroutine rule_mult: called CC=8 SCAR=20.8
Pod undocumented
182 19 my ($self, %args) = @_;
183 19 my $match = $args{match};
184 19 my @res;
185 19 push @res, shift @{$match->{operand}};
186 19 for my $term (@{$match->{operand}}) {
187 27 ▶ my $op = shift @{$match->{op}//=[]};
Condition50%1/2
$match->{"op"} //= []
l!l
270
MC/DC0%0/1
$match->{"op"} //= []
$match->{"op"}
Truth table50%1/2
A
A= $match->{"op"}
Aresult
11
00
188 27 ▶ last unless $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 27 27
189 27 ▶ if ($op eq '*') { push @res, " * $term" }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "*") 13 14 27
190 27 ▶ if ($op eq '/') { push @res, " / $term" }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "/") 6 21 27
191 27 ▶ if ($op eq '%') { push @res, " % $term" }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "%") 3 24 27
192 27 ▶ if ($op eq 'x') { push @res, " x $term" }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "x") 5 22 27
193 }
194 19 join "", grep {defined} @res;
195 }
196  
197 12 ▶sub rule_unary {
Subroutine rule_unary: called CC=7 SCAR=19.5
Pod undocumented
198 12 my ($self, %args) = @_;
199 12 my $match = $args{match};
200 12 my @res;
201 12 push @res, $match->{operand};
202 12 ▶ for my $op (reverse @{$match->{op}//=[]}) {
Condition50%1/2
$match->{"op"} //= []
l!l
120
MC/DC0%0/1
$match->{"op"} //= []
$match->{"op"}
Truth table50%1/2
A
A= $match->{"op"}
Aresult
11
00
203 17 ▶ last unless $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 17 17
204 # use paren because --x or ++x is interpreted as pre-decrement/increment
205 17 ▶ if ($op eq '!') { @res = ("(", @res, " ? false:true)") }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "!") 5 12 17
206 17 ▶ if ($op eq '-') { @res = ("-(", @res, ")") }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "-") 11 6 17
207 17 ▶ if ($op eq '~') { @res = ("~(", @res, ")") }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "~") 1 16 17
208 }
209 12 join "", grep {defined} @res;
210 }
211  
212 3 ▶sub rule_power {
Subroutine rule_power: called CC=2 SCAR=6.9
Pod undocumented
213 3 my ($self, %args) = @_;
214 3 my $match = $args{match};
215 3 my @res;
216 3 push @res, shift @{$match->{operand}};
217 3 for my $term (@{$match->{operand}}) {
218 4 push @res, " ** $term";
219 }
220 3 join "", grep {defined} @res;
221 }
222  
223 8 ▶sub rule_subscripting_var {
Subroutine rule_subscripting_var: called CC=1 SCAR=0.0
Pod undocumented
224 8 my ($self, %args) = @_;
225 8 $self->rule_subscripting_expr(%args);
226 }
227  
228 27 ▶sub rule_subscripting_expr {
Subroutine rule_subscripting_expr: called CC=5 SCAR=16.2
Pod undocumented
229 27 my ($self, %args) = @_;
230 27 my $match = $args{match};
231 27 my $opd = $match->{operand};
232 27 ▶ my @ss = @{$match->{subscript}//=[]};
Condition50%1/2
$match->{"subscript"} //= []
l!l
270
MC/DC0%0/1
$match->{"subscript"} //= []
$match->{"subscript"}
Truth table50%1/2
A
A= $match->{"subscript"}
Aresult
11
00
233 27 ▶ return $opd unless @ss;
Branch: 1 branch
BranchTrueFalseTotal
unless @ss 0 27 27
234 27 my $res;
235 27 for my $s (@ss) {
236 28 ▶ $opd = $res if defined($res);
Branch: 1 branch
BranchTrueFalseTotal
if defined $res 1 27 28
237 28 $res = qq!(do { my (\$v) = ($opd); my (\$s) = ($s); !.
238 qq!if (ref(\$v) eq 'HASH') { \$v->{\$s} } !.
239 qq!elsif (ref(\$v) eq 'ARRAY') { \$v->[\$s] } else { !.
240 qq!die "Invalid subscript \$s for \$v" } })!;
241 }
242 27 $res;
243 }
244  
245 35 ▶sub rule_array {
Subroutine rule_array: called CC=1 SCAR=0.0
Pod undocumented
246 35 my ($self, %args) = @_;
247 35 my $match = $args{match};
248 35 "[" . join(", ", @{ $match->{element} }) . "]";
249 }
250  
251 12 ▶sub rule_hash {
Subroutine rule_hash: called CC=1 SCAR=0.0
Pod undocumented
252 12 my ($self, %args) = @_;
253 12 my $match = $args{match};
254 12 "{" . join(", ", @{ $match->{pair} }). "}";
255 }
256  
257 5 ▶sub rule_undef {
Subroutine rule_undef: called CC=1 SCAR=0.0
Pod undocumented
258 5 "undef";
259 }
260  
261 10 ▶sub rule_squotestr {
Subroutine rule_squotestr: called CC=1 SCAR=0.0
Pod undocumented
262 10 my ($self, %args) = @_;
263 join(" . ",
264 10 map { $self->_quote($_->{value}) }
265 10 @{ $self->parse_squotestr($args{match}{part}) });
266 }
267  
268 64 ▶sub rule_dquotestr {
Subroutine rule_dquotestr: called CC=3 SCAR=11.2
Pod undocumented
269 64 my ($self, %args) = @_;
270 my @tmp =
271 map { $_->{type} eq 'VAR' ?
272 $self->rule_var(match=>{var=>$_->{value}}) :
273 $self->_quote($_->{value})
274 64 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
$_->{'type'} eq 'VAR' ? : 2 62 64
275 64 @{ $self->parse_dquotestr($args{match}{part}) };
276 64 ▶ if (@tmp > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmp > 1) { } 0 64 64
277 0 "(". join(" . ", @tmp) . ")[0]";
278 } else {
279 64 $tmp[0];
280 }
281 }
282  
283 2 ▶sub rule_bool {
Subroutine rule_bool: called CC=2 SCAR=6.9
Pod undocumented
284 2 my ($self, %args) = @_;
285 2 my $match = $args{match};
286 2 ▶ if ($match->{bool} eq 'true') { "true" } else { "false" }
Branch: 1 branch
BranchTrueFalseTotal
if ($match->{'bool'} eq 'true') { } 1 1 2
287 }
288  
289 318 ▶sub rule_num {
Subroutine rule_num: called CC=3 SCAR=12.7
Pod undocumented
290 318 my ($self, %args) = @_;
291 318 my $match = $args{match};
292 0 ▶ if ($match->{num} eq 'inf') { '"Inf"' }
Branch: 2 branches
BranchTrueFalseTotal
if ($match->{'num'} eq 'inf') { } 0 318 318
elsif ($match->{'num'} eq 'nan') { } 0 318 318
293 0 elsif ($match->{num} eq 'nan') { '"NaN"' }
294 318 else { $match->{num}+0 }
295 }
296  
297 97 ▶sub rule_var {
Subroutine rule_var: called CC=3 SCAR=14.2
Pod undocumented
298 97 my ($self, %args) = @_;
299 97 my $match = $args{match};
300 97 ▶ if ($self->hook_var) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hook_var) 0 97 97
301 0 my $res = $self->hook_var->($match->{var});
302 0 ▶ return $res if defined($res);
Branch: 1 branch
BranchTrueFalseTotal
if defined $res 0 0 0
303 }
304 97 return "\$$match->{var}";
305 }
306  
307 37 ▶sub rule_func {
Subroutine rule_func: called CC=4 SCAR=15.8
Pod undocumented
308 37 my ($self, %args) = @_;
309 37 my $match = $args{match};
310 37 my $f = $match->{func_name};
311 37 my $args = $match->{args};
312 37 ▶ if ($self->hook_func) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hook_func) 0 37 37
313 0 my $res = $self->hook_func->($f, @$args);
314 0 ▶ return $res if defined($res);
Branch: 1 branch
BranchTrueFalseTotal
if defined $res 0 0 0
315 }
316 37 my $fmap = $self->func_mapping->{$f};
317 37 ▶ $f = $fmap if $fmap;
Branch: 1 branch
BranchTrueFalseTotal
if $fmap 0 37 37
318 37 "$f(".join(", ", @$args).")";
319 }
320  
321 31 ▶sub _map_grep_usort {
Subroutine _map_grep_usort: called CC=3 SCAR=11.0
322 31 my ($self, $which, %args) = @_;
323 31 my $match = $args{match};
324 31 my $ary = $match->{array};
325 31 my $expr = $match->{expr};
326  
327 31 ▶ my $perlop = $which eq 'map' ? 'map' : $which eq 'grep' ? 'grep' : 'sort';
Branch: 2 branches
BranchTrueFalseTotal
$which eq 'map' ? : 13 18 31
$which eq 'grep' ? : 6 12 18
328 31 my $uuid = $self->new_marker('subexpr', $expr);
329 31 "[$perlop({ TODO-$uuid } \@{$ary})]";
330 }
331  
332 13 ▶sub rule_func_map {
Subroutine rule_func_map: called CC=1 SCAR=0.0
Pod undocumented
333 13 my ($self, %args) = @_;
334 13 $self->_map_grep_usort('map', %args);
335 }
336  
337 6 ▶sub rule_func_grep {
Subroutine rule_func_grep: called CC=1 SCAR=0.0
Pod undocumented
338 6 my ($self, %args) = @_;
339 6 $self->_map_grep_usort('grep', %args);
340 }
341  
342 12 ▶sub rule_func_usort {
Subroutine rule_func_usort: called CC=1 SCAR=0.0
Pod undocumented
343 12 my ($self, %args) = @_;
344 12 $self->_map_grep_usort('usort', %args);
345 }
346  
347 31 ▶sub rule_parenthesis {
Subroutine rule_parenthesis: called CC=1 SCAR=0.0
Pod undocumented
348 31 my ($self, %args) = @_;
349 31 my $match = $args{match};
350 31 "(" . $match->{answer} . ")";
351 }
352  
353 221 ▶sub expr_preprocess {}
Subroutine expr_preprocess: called CC=1 SCAR=0.0
Pod undocumented
354  
355 188 ▶sub expr_postprocess {
Subroutine expr_postprocess: called CC=1 SCAR=0.0
Pod undocumented
356 188 my ($self, %args) = @_;
357 188 my $result = $args{result};
358 188 $result;
359 }
360  
361 # can't use regex here (perl segfaults), at least in 5.10.1, because
362 # we are in one big re::gr regex.
363 72 ▶sub _quote {
Subroutine _quote: called CC=9 SCAR=22.1
364 72 my ($self, $str) = @_;
365 72 my @c;
366 72 for my $c (split '', $str) {
367 156 my $o = ord($c);
368 156 ▶ if ($c eq '"') { push @c, '\\"' }
Branch: 6 branches
BranchTrueFalseTotal
if ($c eq '"') { } 3 153 156
elsif ($c eq '\\') { } 4 149 153
elsif ($c eq '$') { } 3 146 149
elsif ($c eq '@') { } 2 144 146
elsif ($o >= 32 and $o <= 127) { } 138 6 144
elsif ($o > 255) { } 0 6 6
369 4 elsif ($c eq "\\") { push @c, "\\\\" }
370 3 elsif ($c eq '$') { push @c, "\\\$" }
371 2 elsif ($c eq '@') { push @c, '\\@' }
372 138 ▶ elsif ($o >= 32 && $o <= 127) { push @c, $c }
Condition66%2/3
$o >= 32 and $o <= 127
!ll&&!rl&&r
60138
MC/DC50%1/2
$o >= 32 and $o <= 127
$o >= 32 $o <= 127
Truth table66%2/3
A and B
A= $o >= 32B= $o <= 127
ABresult
0X0
100
111
373 0 elsif ($o > 255) { push @c, sprintf("\\x{%04x}", $o) }
374 6 else { push @c, sprintf("\\x%02x", $o) }
375 }
376 72 '"' . join("", @c) . '"';
377 }
378  
379 190 ▶sub compile {
Subroutine compile: called CC=3 SCAR=11.0
Pod documented
380 190 require Language::Expr::Parser;
381  
382 190 my ($self, $expr) = @_;
383 190 my $res = Language::Expr::Parser::parse_expr($expr, $self);
384 157 for my $m (@{ $self->markers }) {
385 31 my $type = $m->[0];
386 31 ▶ next unless $type eq 'subexpr';
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "subexpr" 0 31 31
387 31 my $uuid = $m->[1];
388 31 my $subexpr = $m->[2];
389 31 my $subres = Language::Expr::Parser::parse_expr($subexpr, $self);
390 31 $res =~ s/TODO-$uuid/$subres/g;
391 }
392 157 $self->markers([]);
393 157 $res;
394 }
395  
396 156 ▶sub eval {
Subroutine eval: called CC=2 SCAR=6.9
Pod documented
397 156 my ($self, $expr) = @_;
398 156 ▶ my $res = eval "package Language::Expr::Compiler::perl; no strict; " . $self->compile($expr);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
399 156 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 7 149 156
400 149 $res;
401 }
402  
403 3 1;
404 # ABSTRACT: Compile Language::Expr expression to Perl
405  
406 __END__
« Expr/EvaluatorRole.pm ↑ Summary Expr/Parser.pm »