Expr/Compiler/js.pm

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