Perlish/Parse.pm

filter: Statementstmt 83.2% 1151 / 1382 Branchbran 69.0% 733 / 1062 Conditioncond 58.5% 247 / 422 MC/DCmcdc 35.0% 83 / 237 Subroutinesub 92.5% 100 / 108 Podpod 0.0% 0 / 90 totaltotal 70.1% 2314 / 3301 SCAR 90.7
CC
687
Cov
74%
get_value
904.6
parse_multideref
140.6
try_special_concat
109.3
CRAP 8647.6
↑ Summary Perlish.pm »
1 package DBIx::Perlish::Parse;
2 25 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 25 our $DEVEL;
7 25 our $_cover;
8  
9 25 ▶use B;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 25 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 25 ▶use Devel::Caller qw(caller_cv);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub _o($) { ref($_[0]) . sprintf (" (0x%x)", ${$_[0]}) . ( $_[0]->can('name') ? (" " . $_[0]->name) : '' ) }
Subroutine _o: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->can('name') ? : 0 0 0
14  
15 sub bailout
16 {
17 57 ▶ my ($S, @rest) = @_;
Subroutine bailout: called CC=4 SCAR=14.2
Pod undocumented
18 57 ▶ if ($DEVEL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DBIx::Perlish::Parse::DEVEL) { } 0 57 57
19 0 confess @rest;
20 } else {
21 57 my $args = join '', @rest;
22 57 ▶ $args = "Something's wrong" unless $args;
Branch: 1 branch
BranchTrueFalseTotal
unless $args 0 57 57
23 57 my $file = $S->{file};
24 57 my $line = $S->{line};
25 57 ▶ $args .= " at $file line $line.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless substr($args, length($args) - 1) eq "\n" 55 2 57
26 unless substr($args, length($args) -1) eq "\n";
27 57 CORE::die($args);
28 }
29 }
30  
31 # "is" checks
32  
33 sub is
34 {
35 55558 ▶ my ($optype, $op, $name) = @_;
Subroutine is: called CC=3 SCAR=11.0
Pod undocumented
36 55558 ▶ return 0 unless ref($op) eq $optype;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $op eq $optype 38454 17104 55558
37 17104 ▶ return 1 unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1886 15218 17104
38 15218 return $op->name eq $name;
39 }
40  
41 sub gen_is
42 {
43 350 ▶ my ($optype) = @_;
Subroutine gen_is: called CC=2 SCAR=6.9
Pod undocumented
44 350 my $pkg = "B::" . uc($optype);
45 350 ▶ eval qq[ sub is_$optype { is("$pkg", \@_) } ] unless __PACKAGE__->can("is_$optype");
Subroutine is_binop: called CC=1 SCAR=0.0
Subroutine is_cop: called CC=1 SCAR=0.0
Subroutine is_listop: called CC=1 SCAR=0.0
Subroutine is_logop: called CC=1 SCAR=0.0
Subroutine is_loop: called CC=1 SCAR=0.0
Subroutine is_methop: called CC=1 SCAR=0.0
Subroutine is_null: called CC=1 SCAR=0.0
Subroutine is_op: called CC=1 SCAR=0.0
Subroutine is_padop: called CC=1 SCAR=0.0
Subroutine is_pmop: called CC=1 SCAR=0.0
Subroutine is_pvop: called CC=1 SCAR=0.0
Subroutine is_svop: called CC=1 SCAR=0.0
Subroutine is_unop: called CC=1 SCAR=0.0
Subroutine is_unop_aux: called CC=1 SCAR=0.0
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless __PACKAGE__->can("is_$optype") 350 0 350
46 }
47  
48 25 gen_is("binop");
49 25 gen_is("pvop");
50 25 gen_is("cop");
51 25 gen_is("listop");
52 25 gen_is("logop");
53 25 gen_is("loop");
54 25 gen_is("null");
55 25 gen_is("op");
56 25 gen_is("padop");
57 25 gen_is("svop");
58 25 gen_is("unop");
59 25 gen_is("pmop");
60 25 gen_is("methop");
61 25 gen_is("unop_aux");
62  
63 sub is_const
64 {
65 1550 ▶ my ($S, $op) = @_;
Subroutine is_const: called CC=4 SCAR=13.9
Pod undocumented
66 1550 ▶ return () unless is_svop($op, "const");
Branch: 1 branch
BranchTrueFalseTotal
unless is_svop($op, "const") 598 952 1550
67 952 my $sv = $op->sv;
68 952 ▶ if (!$$sv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$sv) 0 952 952
69 0 $sv = $S->{padlist}->[1]->ARRAYelt($op->targ);
70 }
71 952 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 122 830 952
72 122 return (${$sv->object_2svref}, $sv);
73 } else {
74 830 return ${$sv->object_2svref};
75 }
76 }
77  
78 # "want" helpers
79  
80 sub gen_want
81 {
82 125 ▶ my ($optype, $return) = @_;
Subroutine gen_want: called CC=4 SCAR=18.7
Pod undocumented
83 125 ▶ if (!$return) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $return) { } 50 75 125
elsif ($return =~ /^\w+$/u) { } 50 25 75
84 50 $return = '$op';
85 } elsif ($return =~ /^\w+$/) {
86 50 $return = '$op->' . $return;
87 }
88 125 ▶ eval <<EOF unless __PACKAGE__->can("want_$optype");
Subroutine want_listop: called CC=3 SCAR=16.5
Subroutine want_null: called CC=3 SCAR=16.5
Subroutine want_op: not called CC=3 SCAR=16.5
Subroutine want_svop: called CC=3 SCAR=16.5
Subroutine want_unop: called CC=3 SCAR=16.5
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 11 branches
BranchTrueFalseTotal
unless __PACKAGE__->can("want_$optype") 125 0 125
unless (is_listop($op, $n)) 0 6 6
unless $n 0 0 0
unless (is_null($op, $n)) 0 382 382
unless $n 0 0 0
unless (is_op($op, $n)) 0 0 0
unless $n 0 0 0
unless (is_svop($op, $n)) 0 8 8
unless $n 0 0 0
unless (is_unop($op, $n)) 0 1043 1043
unless $n 0 0 0
89 sub want_$optype {
90 my (\$S, \$op, \$n) = \@_;
91 unless (is_$optype(\$op, \$n)) {
92 bailout \$S, "want $optype" unless \$n;
93 bailout \$S, "want $optype \$n";
94 }
95 $return;
96 }
97 EOF
98 }
99  
100 25 gen_want("op");
101 25 gen_want("unop", "first");
102 25 gen_want("listop", 'get_all_children($op)');
103 25 gen_want("svop", "sv");
104 25 gen_want("null");
105  
106 sub is_pushmark_or_padrange
107 {
108 3418 ▶ my $op = shift;
Subroutine is_pushmark_or_padrange: called CC=2 SCAR=6.9
Pod undocumented
109 3418 ▶ return is_op($op, "pushmark") || is_op($op, "padrange");
Condition100%3/3
is_op($op, 'pushmark') || is_op($op, 'padrange')
l!l&&r!l&&!r
120612211
MC/DC100%2/2
is_op($op, 'pushmark') || is_op($op, 'padrange')
is_op($op, 'pushmark') is_op($op, 'padrange')
Truth table100%3/3
A || B
A= is_op($op, 'pushmark')B= is_op($op, 'padrange')
ABresult
1X1
011
000
110 }
111  
112 sub want_pushmark_or_padrange
113 {
114 382 ▶ my ($S, $op) = @_;
Subroutine want_pushmark_or_padrange: called CC=2 SCAR=8.1
Pod undocumented
115 382 ▶ unless (is_pushmark_or_padrange($op)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_pushmark_or_padrange($op)) 0 382 382
116 0 bailout $S, "want op pushmark or op padrange, got " . _o $op;
117 }
118 }
119  
120 sub want_const
121 {
122 8 ▶ my ($S, $op) = @_;
Subroutine want_const: called CC=2 SCAR=7.2
Pod undocumented
123 8 my $sv = want_svop($S, $op, "const");
124 8 ▶ if (!$$sv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$sv) 0 8 8
125 0 $sv = $S->{padlist}->[1]->ARRAYelt($op->targ);
126 }
127 8 ${$sv->object_2svref};
128 }
129  
130 sub want_variable_method
131 {
132 2 ▶ my ($S, $op) = @_;
Subroutine want_variable_method: called CC=5 SCAR=17.5
Pod undocumented
133 2 ▶ return unless is_unop($op, "method") || is_methop($op, "method");
Branch: 1 branch
BranchTrueFalseTotal
unless is_unop($op, "method") or is_methop($op, "method") 0 2 2
Condition33%1/3
is_unop($op, "method") or is_methop($op, "method")
l!l&&r!l&&!r
020
MC/DC0%0/2
is_unop($op, "method") or is_methop($op, "method")
is_unop($op, "method") is_methop($op, "method")
Truth table33%1/3
A or B
A= is_unop($op, "method")B= is_methop($op, "method")
ABresult
1X1
011
000
134 2 $op = $op->first;
135 2 ▶ return unless is_null($op->sibling);
Branch: 1 branch
BranchTrueFalseTotal
unless is_null($op->sibling) 0 2 2
136 2 my ($name, $ok) = get_value($S, $op, soft => 1);
137 2 ▶ return unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 2 2
138 2 return $name;
139 }
140  
141 sub want_method
142 {
143 599 ▶ my ($S, $op) = @_;
Subroutine want_method: called CC=5 SCAR=16.8
Pod undocumented
144 599 my $sv;
145 599 ▶ if ( is_methop($op, "method_named")) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_methop($op, 'method_named')) { } 597 2 599
elsif (is_svop($op, 'method_named')) { } 0 2 2
146 597 $sv = $op->meth_sv;
147 } elsif ( is_svop($op, "method_named")) {
148 0 $sv = $op->sv;
149 } else {
150 2 my $r = want_variable_method($S, $op);
151 2 ▶ bailout $S, "method call syntax expected" unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 2 2
152 2 return $r;
153 }
154 597 ▶ if (!$$sv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$sv) 0 597 597
155 0 $sv = $S->{padlist}->[1]->ARRAYelt($op->targ);
156 }
157 597 ${$sv->object_2svref};
158 }
159  
160 # getters
161  
162 sub get_all_children
163 {
164 549 ▶ my ($op) = @_;
Subroutine get_all_children: called CC=3 SCAR=11.0
Pod undocumented
165 549 my $c = $op->children;
166 549 my @op;
167 549 ▶ return @op unless $c;
Branch: 1 branch
BranchTrueFalseTotal
unless $c 0 549 549
168 549 push @op, $op->first;
169 549 ▶ while (--$c) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$c) 1287 549 1836
170 1287 push @op, $op[-1]->sibling;
171 }
172 549 @op;
173 }
174  
175 sub padname
176 {
177 598 ▶ my ($S, $op, %p) = @_;
Subroutine padname: called CC=6 SCAR=19.6
Pod undocumented
178  
179 598 my $padname = $S->{padlist}->[0]->ARRAYelt($op->targ);
180 598 ▶ if ($padname && !$padname->isa("B::SPECIAL")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($padname and not $padname->isa('B::SPECIAL')) { } 598 0 598
Condition33%1/3
$padname and not $padname->isa("B::SPECIAL")
!ll&&!rl&&r
00598
MC/DC0%0/2
$padname and not $padname->isa("B::SPECIAL")
$padname not $padname->isa("B::SPECIAL")
Truth table33%1/3
A and not(B)
A= $padnameB= not $padname->isa("B::SPECIAL")
ABresult
0X0
100
111
181 598 ▶ return if $p{no_fakes} && $padname->FLAGS & B::SVf_FAKE;
Branch: 1 branch
BranchTrueFalseTotal
if $p{"no_fakes"} and $padname->FLAGS & 16777216 0 598 598
Condition66%2/3
$p{"no_fakes"} and $padname->FLAGS & 16777216
!ll&&!rl&&r
59530
MC/DC0%0/2
$p{"no_fakes"} and $padname->FLAGS & 16777216
$p{"no_fakes"} $padname->FLAGS & 16777216
Truth table66%2/3
A and B
A= $p{"no_fakes"}B= $padname->FLAGS & 16777216
ABresult
0X0
100
111
182 598 ▶ return unless defined $padname->PVX;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $padname->PVX 2 596 598
183 596 return "my " . $padname->PVX;
184 } else {
185 0 return "my #" . $op->targ;
186 }
187 }
188  
189 sub get_padlist_scalar_by_name
190 {
191 6 ▶ my ($S, $n) = @_;
Subroutine get_padlist_scalar_by_name: called CC=9 SCAR=23.0
Pod undocumented
192 6 my $padlist = $S->{padlist};
193 6 my @n = $padlist->[0]->ARRAY;
194 6 ▶ for (my $k = 0; $k < @n; $k++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k < @n) 34 0 34
195 34 ▶ next if $n[$k]->isa("B::SPECIAL");
Branch: 1 branch
BranchTrueFalseTotal
if $n[$k]->isa("B::SPECIAL") 0 34 34
196 34 ▶ next if $n[$k]->isa("B::NULL");
Branch: 1 branch
BranchTrueFalseTotal
if $n[$k]->isa("B::NULL") 0 34 34
197 34 ▶ if (($n[$k]->PVX // '') eq $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (($n[$k]->PVX // "") eq $n) 6 28 34
Condition100%2/2
$n[$k]->PVX // ""
l!l
1222
MC/DC100%1/1
$n[$k]->PVX // ""
$n[$k]->PVX
Truth table100%2/2
A
A= $n[$k]->PVX
Aresult
11
00
198 6 my $v = $padlist->[1]->ARRAYelt($k);
199 6 ▶ if (!$v->isa("B::SPECIAL")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v->isa("B::SPECIAL")) 3 3 6
200 3 return $v;
201 }
202 3 ▶ if ($n[$k]->FLAGS & B::SVf_FAKE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n[$k]->FLAGS & 16777216) 3 0 3
203 bailout $S, "internal error: cannot retrieve value of $n: no more scopes to check"
204 3 ▶ unless $S->{gen_args}->{prev_S};
Branch: 1 branch
BranchTrueFalseTotal
unless $S->{"gen_args"}{"prev_S"} 0 3 3
205 3 return get_padlist_scalar_by_name($S->{gen_args}->{prev_S}, $n);
206 }
207 0 bailout $S, "internal error: cannot retrieve value of $n: it's an in-scope SPECIAL";
208 }
209 }
210 0 bailout $S, "internal error: cannot retrieve value of $n: not found in outer scope";
211 }
212  
213 sub get_padlist_scalar
214 {
215 51 ▶ my ($S, $i, $ref_only) = @_;
Subroutine get_padlist_scalar: called CC=5 SCAR=16.3
Pod undocumented
216 51 my $padlist = $S->{padlist};
217 51 my $v = $padlist->[1]->ARRAYelt($i);
218 51 ▶ bailout $S, "internal error: no such pad element" unless $v;
Branch: 1 branch
BranchTrueFalseTotal
unless $v 0 51 51
219 51 ▶ if ($v->isa("B::SPECIAL")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->isa("B::SPECIAL")) 3 48 51
220 3 my $n = $padlist->[0]->ARRAYelt($i);
221 3 ▶ if ($n->FLAGS & B::SVf_FAKE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->FLAGS & 16777216) { } 3 0 3
222 3 $v = get_padlist_scalar_by_name($S, $n->PVX);
223 } else {
224 0 bailout $S, "internal error: cannot retrieve in-scope SPECIAL";
225 }
226 }
227 51 $v = $v->object_2svref;
228 51 ▶ return $v if $ref_only;
Branch: 1 branch
BranchTrueFalseTotal
if $ref_only 7 44 51
229 44 return $$v;
230 }
231  
232 sub bailout_multiref_vivify($)
233 {
234 5 ▶ my $S = shift;
Subroutine bailout_multiref_vivify: called CC=1 SCAR=0.0
Pod undocumented
235 5 bailout $S,
236 "accessing fields syntax is not supported anymore; for tables use methods instead, ".
237 "for arrayrefs and hashrefs don't leave them unassigned"
238 }
239  
240 sub aux_init_padsv
241 {
242 56 ▶ my ( $S ) = @_;
Subroutine aux_init_padsv: called CC=1 SCAR=0.0
Pod undocumented
243  
244 56 my $inner = $S->{curr_cv}->PADLIST;
245 return {
246 56 S => $S,
247 inner => $inner,
248 orig_pads => [ $inner->ARRAY ]->[1],
249 names => [ $inner->NAMES->ARRAY ],
250 outer_padlist => undef,
251 outer_padlist_array => undef,
252 padlist => [],
253 };
254 }
255  
256 sub aux_get_padsv
257 {
258 64 ▶ my ( $store, $index ) = @_;
Subroutine aux_get_padsv: called CC=10 SCAR=23.1
Pod undocumented
259  
260 64 ▶ unless ( defined $store->{padlist}->[$index] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $store->{"padlist"}[$index]) 64 0 64
261 64 my $padname = $store->{names}->[$index];
262 64 ▶ if ( $padname->FLAGS & B::SVf_FAKE && $store->{inner}->outid > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($padname->FLAGS & 16777216 and $store->{'inner'}->outid > 1) { } 3 61 64
Condition100%3/3
$padname->FLAGS & 16777216 and $store->{"inner"}->outid > 1
!ll&&!rl&&r
2593
MC/DC100%2/2
$padname->FLAGS & 16777216 and $store->{"inner"}->outid > 1
$padname->FLAGS & 16777216 $store->{"inner"}->outid > 1
Truth table100%3/3
A and B
A= $padname->FLAGS & 16777216B= $store->{"inner"}->outid > 1
ABresult
0X0
100
111
263 3 ▶ unless ($store->{outer_padlist}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($store->{"outer_padlist"}) 3 0 3
264 3 $store->{outer_padlist} = $store->{S}->{padlists}->{$store->{inner}->outid};
265 3 ▶ unless ($store->{outer_padlist}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($store->{"outer_padlist"}) 1 2 3
266 # hacky hacky - look up the caller stack to get their padlists, maybe?
267 1 my $id = 0;
268 1 while ( 1 ) {
269 14 ▶ my $sub = caller_cv($id++) or last;
Branch: 1 branch
BranchTrueFalseTotal
my $sub = caller_cv($id++) or last 0 14 14
270 14 my $padlist = B::svref_2object($sub)->PADLIST;
271 14 ▶ $store->{S}->{padlists}->{$padlist->id} //= [$padlist->ARRAY];
Condition100%2/2
$store->{"S"}{"padlists"}{$padlist->id} //= [$padlist->ARRAY]
l!l
212
MC/DC100%1/1
$store->{"S"}{"padlists"}{$padlist->id} //= [$padlist->ARRAY]
$store->{"S"}{"padlists"}{$padlist->id}
Truth table100%2/2
A
A= $store->{"S"}{"padlists"}{$padlist->id}
Aresult
11
00
272 14 ▶ next unless $padlist->id == $store->{inner}->outid;
Branch: 1 branch
BranchTrueFalseTotal
unless $padlist->id == $store->{"inner"}->outid 13 1 14
273 1 $store->{outer_padlist} = $store->{S}->{padlists}->{$store->{inner}->outid};
274 1 last;
275 }
276 }
277 3 ▶ goto DEFAULT_PADLIST unless $store->{outer_padlist};
Branch: 1 branch
BranchTrueFalseTotal
unless $store->{"outer_padlist"} 0 3 3
278 3 $store->{outer_padlist_array} = [$store->{outer_padlist}->[1]->ARRAY];
279 }
280 3 $store->{padlist}->[$index] = $store->{outer_padlist_array}->[ $padname->PARENT_PAD_INDEX ];
281 } else {
282 DEFAULT_PADLIST:
283 61 $store->{padlist}->[$index] = $store->{orig_pads}->ARRAYelt($index);
284 }
285 }
286  
287 64 return $store->{padlist}->[$index];
288 }
289  
290 sub parse_multideref
291 {
292 56 ▶ my ( $S, $aux ) = @_;
Subroutine parse_multideref: called CC=52 SCAR=49.5
Pod undocumented
293 56 my @items = $aux->aux_list($S->{curr_cv});
294 56 my @ret;
295  
296 56 my $AUX = aux_init_padsv($S);
297  
298 56 ▶ ITEMS: while ( @items ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@items) 56 49 105
299 56 my $actions = shift @items;
300  
301 56 my ($ref, $reftype);
302 56 ▶ my $sv = shift(@items) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $sv = shift @items or return undef 0 56 56
303  
304 56 ▶ while ( @items ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@items) 81 49 130
305 81 my $ptr = shift @items;
306 81 my $access = $actions & B::MDEREF_ACTION_MASK();
307 81 ▶ if ( $access == B::MDEREF_reload() ) { # XXX
Branch: 1 branch
BranchTrueFalseTotal
if ($access == 0) 0 81 81
308 0 $actions = $sv;
309 0 next;
310 }
311 81 ▶ unless ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ref) 57 24 81
312 57 ▶ if (
Branch: 4 branches
BranchTrueFalseTotal
if ($access == 12 or $access == 5 or $access == 10 or $access == 3) { } 52 5 57
elsif ($access == 8 or $access == 11 or $access == 13) { } 3 2 5
elsif ($access == 1 or $access == 4 or $access == 6) { } 2 0 2
elsif ($access == 2 or $access == 9) { } 0 0 0
Condition88%8/9
$access == 12 or $access == 5 or $access == 10 or $access == 3
l!l&&r!l&&!r
42105
$access == 12 or $access == 5 or $access == 10
l!l&&r!l&&!r
103215
$access == 12 or $access == 5
l!l&&r!l&&!r
10047
MC/DC75%3/4
$access == 12 or $access == 5 or $access == 10 or $access == 3
$access == 12 $access == 5 $access == 10 $access == 3
Truth table80%4/5
A or B or C or D
A= $access == 12B= $access == 5C= $access == 10D= $access == 3
ABCDresult
1XXX1
01XX1
001X1
00011
00000
313 $access == B::MDEREF_HV_padhv_helem() ||
314 $access == B::MDEREF_AV_padav_aelem() ||
315 $access == B::MDEREF_HV_padsv_vivify_rv2hv_helem() ||
316 $access == B::MDEREF_AV_padsv_vivify_rv2av_aelem()
317 ) {
318 52 $ref = aux_get_padsv($AUX, $sv)->object_2svref;
319 52 ▶ bailout_multiref_vivify $S
Branch: 1 branch
BranchTrueFalseTotal
if not $ref or ref $ref eq "SCALAR" and not $$ref 4 48 52
Condition66%4/6
not $ref or ref $ref eq "SCALAR" and not $$ref
l!l&&r!l&&!r
0547
ref $ref eq "SCALAR" and not $$ref
!ll&&!rl&&r
4804
MC/DC0%0/3
not $ref or ref $ref eq "SCALAR" and not $$ref
not $ref ref $ref eq "SCALAR" not $$ref
Truth table25%1/4
not(A) or B and not(C)
A= not $refB= ref $ref eq "SCALAR"C= not $$ref
ABCresult
1XX1
0111
00X0
0100
320 if !$ref || ((ref($ref) eq 'SCALAR') && !$$ref);
321 ▶ } elsif (
Condition83%5/6
$access == 8 or $access == 11 or $access == 13
l!l&&r!l&&!r
122
$access == 8 or $access == 11
l!l&&r!l&&!r
014
MC/DC66%2/3
$access == 8 or $access == 11 or $access == 13
$access == 8 $access == 11 $access == 13
Truth table75%3/4
A or B or C
A= $access == 8B= $access == 11C= $access == 13
ABCresult
1XX1
01X1
0011
0000
322 $access == B::MDEREF_HV_pop_rv2hv_helem() ||
323 $access == B::MDEREF_HV_vivify_rv2hv_helem() ||
324 $access == B::MDEREF_HV_gvhv_helem()
325 ) {
326 3 ▶ bailout_multiref_vivify $S unless ref($sv);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sv 1 2 3
327 2 $ref = $sv->HV->object_2svref;
328 ▶ } elsif (
Condition33%2/6
$access == 1 or $access == 4 or $access == 6
l!l&&r!l&&!r
020
$access == 1 or $access == 4
l!l&&r!l&&!r
002
MC/DC0%0/3
$access == 1 or $access == 4 or $access == 6
$access == 1 $access == 4 $access == 6
Truth table25%1/4
A or B or C
A= $access == 1B= $access == 4C= $access == 6
ABCresult
1XX1
01X1
0011
0000
329 $access == B::MDEREF_AV_pop_rv2av_aelem() ||
330 $access == B::MDEREF_AV_vivify_rv2av_aelem() ||
331 $access == B::MDEREF_AV_gvav_aelem()
332 ) {
333 2 ▶ bailout_multiref_vivify $S unless ref($sv);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sv 0 2 2
334 2 $ref = $sv->AV->object_2svref;
335 ▶ } elsif (
Condition0%0/3
$access == 2 or $access == 9
l!l&&r!l&&!r
000
MC/DC0%0/2
$access == 2 or $access == 9
$access == 2 $access == 9
Truth table0%0/3
A or B
A= $access == 2B= $access == 9
ABresult
1X1
011
000
336 $access == B::MDEREF_AV_gvsv_vivify_rv2av_aelem() ||
337 $access == B::MDEREF_HV_gvsv_vivify_rv2hv_helem()
338 ) {
339 0 $ref = $sv->object_2svref;
340 0 ▶ bailout_multiref_vivify $S
Branch: 1 branch
BranchTrueFalseTotal
if not $ref or ref $ref eq "SCALAR" and not $$ref 0 0 0
Condition0%0/6
not $ref or ref $ref eq "SCALAR" and not $$ref
l!l&&r!l&&!r
000
ref $ref eq "SCALAR" and not $$ref
!ll&&!rl&&r
000
MC/DC0%0/3
not $ref or ref $ref eq "SCALAR" and not $$ref
not $ref ref $ref eq "SCALAR" not $$ref
Truth table0%0/4
not(A) or B and not(C)
A= not $refB= ref $ref eq "SCALAR"C= not $$ref
ABCresult
1XX1
0111
00X0
0100
341 if !$ref || ((ref($ref) eq 'SCALAR') && !$$ref);
342 0 $ref = $$ref;
343 } else {
344 0 bailout $S, "don't quite know what to do with multideref access=$access";
345 }
346 }
347  
348 $reftype = (
349 76 ▶ $access == B::MDEREF_HV_padhv_helem() ||
Branch: 1 branch
BranchTrueFalseTotal
$access == 12 || $access == 9 || $access == 10 || $access == 8 || $access == 11 || $access == 13 ? : 56 20 76
Condition86%13/15
$access == 12 or $access == 9 or $access == 10 or $access == 8 or $access == 11 or $access == 13
l!l&&r!l&&!r
54220
$access == 12 or $access == 9 or $access == 10 or $access == 8 or $access == 11
l!l&&r!l&&!r
381622
$access == 12 or $access == 9 or $access == 10 or $access == 8
l!l&&r!l&&!r
38038
$access == 12 or $access == 9 or $access == 10
l!l&&r!l&&!r
102838
$access == 12 or $access == 9
l!l&&r!l&&!r
10066
MC/DC66%4/6
$access == 12 or $access == 9 or $access == 10 or $access == 8 or $access == 11 or $access == 13
$access == 12 $access == 9 $access == 10 $access == 8 $access == 11 $access == 13
Truth table71%5/7
A or B or C or D or E or F
A= $access == 12B= $access == 9C= $access == 10D= $access == 8E= $access == 11F= $access == 13
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
350 $access == B::MDEREF_HV_gvsv_vivify_rv2hv_helem() ||
351 $access == B::MDEREF_HV_padsv_vivify_rv2hv_helem() ||
352 $access == B::MDEREF_HV_pop_rv2hv_helem() ||
353 $access == B::MDEREF_HV_vivify_rv2hv_helem() ||
354 $access == B::MDEREF_HV_gvhv_helem()
355 ) ? 'HASH' : 'ARRAY';
356
357 76 my $key;
358 76 my $index = $actions & B::MDEREF_INDEX_MASK();
359  
360 76 ▶ if ( $index != B::MDEREF_INDEX_none() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index != 0) 76 0 76
361 76 ▶ if ( $index == B::MDEREF_INDEX_const() ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($index == 16) { } 64 12 76
elsif ($index == 32) { } 12 0 12
elsif ($index == 48) { } 0 0 0
362 64 ▶ $key = ref($ptr) ? $ptr->object_2svref : $ptr;
Branch: 1 branch
BranchTrueFalseTotal
ref $ptr ? : 52 12 64
363 } elsif ( $index == B::MDEREF_INDEX_padsv() ) {
364 12 $key = aux_get_padsv($AUX, $ptr)->object_2svref;
365 } elsif ( $index == B::MDEREF_INDEX_gvsv() ) {
366 0 ▶ $key = ref($ptr) ? $ptr->object_2svref : $ptr;
Branch: 1 branch
BranchTrueFalseTotal
ref $ptr ? : 0 0 0
367 }
368  
369 76 ▶ $ref = $$ref if ref($ref) =~ /REF|SCALAR/;
Branch: 1 branch
BranchTrueFalseTotal
if ref($ref) =~ /REF|SCALAR/u 38 38 76
370 76 ▶ $key = $$key if ref($key) =~ /REF|SCALAR/;
Branch: 1 branch
BranchTrueFalseTotal
if ref($key) =~ /REF|SCALAR/u 64 12 76
371  
372 76 ▶ if ( $reftype eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($reftype eq 'ARRAY') { } 20 56 76
373 20 $ref = $ref->[$key];
374 } else {
375 56 $ref = $ref->{$key};
376 }
377  
378 76 ▶ if (!defined($ref) && (
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ref and $access == 2 || $access == 3 || $access == 4 || $access == 9 || $access == 10 || $access == 11) 2 74 76
Condition50%9/18
not defined $ref and $access == 2 || $access == 3 || $access == 4 || $access == 9 || $access == 10 || $access == 11
!ll&&!rl&&r
7330
$access == 2 or $access == 3 or $access == 4 or $access == 9 or $access == 10 or $access == 11
l!l&&r!l&&!r
201
$access == 2 or $access == 3 or $access == 4 or $access == 9 or $access == 10
l!l&&r!l&&!r
021
$access == 2 or $access == 3 or $access == 4 or $access == 9
l!l&&r!l&&!r
003
$access == 2 or $access == 3 or $access == 4
l!l&&r!l&&!r
003
$access == 2 or $access == 3
l!l&&r!l&&!r
003
MC/DC0%0/7
not defined $ref and $access == 2 || $access == 3 || $access == 4 || $access == 9 || $access == 10 || $access == 11
not defined $ref $access == 2 $access == 3 $access == 4 $access == 9 $access == 10 $access == 11
Truth table25%2/8
not(A) and B or C or D or E or F or G
A= not defined $refB= $access == 2C= $access == 3D= $access == 4E= $access == 9F= $access == 10G= $access == 11
ABCDEFGresult
0XXXXXX0
10000000
11XXXXX1
101XXXX1
1001XXX1
10001XX1
100001X1
10000011
379 $access == B::MDEREF_AV_gvsv_vivify_rv2av_aelem () ||
380 $access == B::MDEREF_AV_padsv_vivify_rv2av_aelem() ||
381 $access == B::MDEREF_AV_vivify_rv2av_aelem () ||
382 $access == B::MDEREF_HV_gvsv_vivify_rv2hv_helem () ||
383 $access == B::MDEREF_HV_padsv_vivify_rv2hv_helem() ||
384 $access == B::MDEREF_HV_vivify_rv2hv_helem ()
385 )) {
386 2 push @ret, undef;
387 2 last ITEMS;
388 }
389 }
390 74 ▶ if ($index == B::MDEREF_INDEX_none() || $index & B::MDEREF_FLAG_last()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index == 0 or $index & 64) 0 74 74
Condition33%1/3
$index == 0 or $index & 64
l!l&&r!l&&!r
0074
MC/DC0%0/2
$index == 0 or $index & 64
$index == 0 $index & 64
Truth table33%1/3
A or B
A= $index == 0B= $index & 64
ABresult
1X1
011
000
391 0 push @ret, $ref;
392 0 last;
393 }
394 74 $actions >>= B::MDEREF_SHIFT();
395 }
396  
397 49 ▶ push @ret, $ref unless @ret;
Branch: 1 branch
BranchTrueFalseTotal
unless @ret 49 0 49
398 }
399  
400 51 ▶ bailout $S, "cannot infer single multideref value" unless 1 == @ret;
Branch: 1 branch
BranchTrueFalseTotal
unless 1 == @ret 0 51 51
401  
402 51 return $ret[0];
403 }
404  
405 sub get_concat_value
406 {
407 0 ▶ my ( $S, @args) = @_;
Subroutine get_concat_value: not called CC=4 SCAR=30.0
Pod undocumented
408 0 my $val = '';
409 0 for my $op ( @args ) {
410 0 my ($rv, $ok);
411 0 ▶ if ( $rv = is_const($S, $op)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv = is_const($S, $op)) { } 0 0 0
412 } else {
413 0 ($rv, $ok) = get_value($S, $op, soft => 1, eval => 1);
414 0 ▶ bailout $S, "cannot parse expression (near $val)" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
415 }
416 0 $val .= $rv;
417 }
418 0 return $val;
419 }
420  
421 sub get_value
422 {
423 279 ▶ my ($S, $op, %p) = @_;
Subroutine get_value: called CC=52 SCAR=68.1
Pod undocumented
424  
425 279 my $val;
426 279 ▶ if (is_op($op, "padsv")) {
Branch: 10 branches
BranchTrueFalseTotal
if (is_op($op, 'padsv')) { } 44 235 279
elsif (is_binop($op, 'helem')) { } 0 235 235
elsif (is_binop($op, 'aelem')) { } 0 235 235
elsif (is_svop($op, 'gvsv') or is_padop($op, 'gvsv')) { } 1 234 235
elsif (is_unop($op, 'null') and is_svop($op->first, 'gvsv') || is_padop($op->first, 'gvsv')) { } 1 233 234
elsif (is_unop($op, 'null') and is_unop_aux($op->first, 'multideref')) { } 13 220 233
elsif ($p{'eval'} and is_binop($op, 'concat')) { } 0 220 220
elsif ($p{'eval'} and is_unop_aux($op, 'multiconcat')) { } 1 219 220
elsif (is_op($op, 'aelemfast_lex')) { } 0 219 219
elsif (is_svop($op, 'aelemfast') or is_padop($op, 'aelemfast')) { } 2 217 219
427 44 ▶ if (find_aliased_tab($S, $op)) {
Branch: 1 branch
BranchTrueFalseTotal
if (find_aliased_tab($S, $op)) 0 44 44
428 0 bailout $S, "cannot use a table variable as a value";
429 }
430 44 $val = get_padlist_scalar($S, $op->targ);
431 } elsif (is_binop($op, "helem")) {
432 0 my @key = is_const($S, $op->last);
433 0 my $key = $key[0];
434 0 ▶ unless ( @key ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@key) 0 0 0
435 0 my $xop = $op->last;
436 0 ▶ if (is_op($xop, "padsv")) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_op($xop, 'padsv')) { } 0 0 0
437 0 ▶ if (find_aliased_tab($S, $xop)) {
Branch: 1 branch
BranchTrueFalseTotal
if (find_aliased_tab($S, $xop)) 0 0 0
438 0 bailout $S, "cannot use a table variable as a value";
439 }
440 0 $key = get_padlist_scalar($S, $xop->targ);
441 } else {
442 0 bailout $S, "hash key not understood";
443 }
444 }
445 0 $op = $op->first;
446  
447 0 my $vv;
448 0 ▶ if (is_op($op, "padhv")) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_op($op, 'padhv')) { } 0 0 0
elsif (is_unop($op, 'rv2hv')) { } 0 0 0
449 0 $vv = get_padlist_scalar($S, $op->targ, "ref only");
450 } elsif (is_unop($op, "rv2hv")) {
451 0 $op = $op->first;
452 0 ▶ if (is_op($op, "padsv")) {
Branch: 3 branches
BranchTrueFalseTotal
if (is_op($op, 'padsv')) { } 0 0 0
elsif (is_svop($op, 'gv') or is_padop($op, 'gv')) { } 0 0 0
elsif (is_binop($op, 'helem') or is_binop($op, 'aelem')) { } 0 0 0
453 0 ▶ if (find_aliased_tab($S, $op)) {
Branch: 1 branch
BranchTrueFalseTotal
if (find_aliased_tab($S, $op)) 0 0 0
454 0 bailout $S, "cannot use a table variable as a value";
455 }
456 0 $vv = get_padlist_scalar($S, $op->targ);
457 ▶ } elsif (is_svop($op, "gv") || is_padop($op, "gv")) {
Condition0%0/3
is_svop($op, "gv") or is_padop($op, "gv")
l!l&&r!l&&!r
000
MC/DC0%0/2
is_svop($op, "gv") or is_padop($op, "gv")
is_svop($op, "gv") is_padop($op, "gv")
Truth table0%0/3
A or B
A= is_svop($op, "gv")B= is_padop($op, "gv")
ABresult
1X1
011
000
458 0 my $gv = get_gv($S, $op, bailout => 1);
459 0 $vv = $gv->HV->object_2svref;
460 ▶ } elsif (is_binop($op, "helem") || is_binop($op, "aelem")) {
Condition0%0/3
is_binop($op, "helem") or is_binop($op, "aelem")
l!l&&r!l&&!r
000
MC/DC0%0/2
is_binop($op, "helem") or is_binop($op, "aelem")
is_binop($op, "helem") is_binop($op, "aelem")
Truth table0%0/3
A or B
A= is_binop($op, "helem")B= is_binop($op, "aelem")
ABresult
1X1
011
000
461 0 my ($nv, $ok) = get_value($S, $op, %p);
462 0 ▶ $vv = $nv if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
463 }
464 }
465 0 $val = $vv->{$key};
466 } elsif (is_binop($op, "aelem")) {
467 0 my @key = is_const($S, $op->last);
468 0 my $key = $key[0];
469 0 ▶ unless ( @key ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@key) 0 0 0
470 0 my $xop = $op->last;
471 0 ▶ if (is_op($xop, "padsv")) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_op($xop, 'padsv')) { } 0 0 0
472 0 ▶ if (find_aliased_tab($S, $xop)) {
Branch: 1 branch
BranchTrueFalseTotal
if (find_aliased_tab($S, $xop)) 0 0 0
473 0 bailout $S, "cannot use a table variable as a value";
474 }
475 0 $key = get_padlist_scalar($S, $xop->targ);
476 } else {
477 0 bailout $S, "array index not understood";
478 }
479 }
480 0 $op = $op->first;
481  
482 0 my $vv;
483 0 ▶ if (is_op($op, "padav")) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_op($op, 'padav')) { } 0 0 0
elsif (is_unop($op, 'rv2av')) { } 0 0 0
484 0 $vv = get_padlist_scalar($S, $op->targ, "ref only");
485 } elsif (is_unop($op, "rv2av")) {
486 0 $op = $op->first;
487 0 ▶ if (is_op($op, "padsv")) {
Branch: 3 branches
BranchTrueFalseTotal
if (is_op($op, 'padsv')) { } 0 0 0
elsif (is_svop($op, 'gv') or is_padop($op, 'gv')) { } 0 0 0
elsif (is_binop($op, 'helem') or is_binop($op, 'aelem')) { } 0 0 0
488 0 ▶ if (find_aliased_tab($S, $op)) {
Branch: 1 branch
BranchTrueFalseTotal
if (find_aliased_tab($S, $op)) 0 0 0
489 0 bailout $S, "cannot use a table variable as a value";
490 }
491 0 $vv = get_padlist_scalar($S, $op->targ);
492 ▶ } elsif (is_svop($op, "gv") || is_padop($op, "gv")) {
Condition0%0/3
is_svop($op, "gv") or is_padop($op, "gv")
l!l&&r!l&&!r
000
MC/DC0%0/2
is_svop($op, "gv") or is_padop($op, "gv")
is_svop($op, "gv") is_padop($op, "gv")
Truth table0%0/3
A or B
A= is_svop($op, "gv")B= is_padop($op, "gv")
ABresult
1X1
011
000
493 0 my $gv = get_gv($S, $op, bailout => 1);
494 0 $vv = $gv->AV->object_2svref;
495 ▶ } elsif (is_binop($op, "helem") || is_binop($op, "aelem")) {
Condition0%0/3
is_binop($op, "helem") or is_binop($op, "aelem")
l!l&&r!l&&!r
000
MC/DC0%0/2
is_binop($op, "helem") or is_binop($op, "aelem")
is_binop($op, "helem") is_binop($op, "aelem")
Truth table0%0/3
A or B
A= is_binop($op, "helem")B= is_binop($op, "aelem")
ABresult
1X1
011
000
496 0 my ($nv, $ok) = get_value($S, $op, %p);
497 0 ▶ $vv = $nv if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
498 }
499 }
500 0 $val = $vv->[$key];
501 ▶ } elsif (is_svop($op, "gvsv") || is_padop($op, "gvsv")) {
Condition66%2/3
is_svop($op, "gvsv") or is_padop($op, "gvsv")
l!l&&r!l&&!r
10234
MC/DC50%1/2
is_svop($op, "gvsv") or is_padop($op, "gvsv")
is_svop($op, "gvsv") is_padop($op, "gvsv")
Truth table66%2/3
A or B
A= is_svop($op, "gvsv")B= is_padop($op, "gvsv")
ABresult
1X1
011
000
502 1 my $gv = get_gv($S, $op, bailout => 1);
503 1 $val = ${$gv->SV->object_2svref};
504 ▶ } elsif (is_unop($op, "null") && (is_svop($op->first, "gvsv") || is_padop($op->first, "gvsv"))) {
Condition83%5/6
is_unop($op, "null") and is_svop($op->first, "gvsv") || is_padop($op->first, "gvsv")
!ll&&!rl&&r
216171
is_svop($op->first, "gvsv") or is_padop($op->first, "gvsv")
l!l&&r!l&&!r
1017
MC/DC66%2/3
is_unop($op, "null") and is_svop($op->first, "gvsv") || is_padop($op->first, "gvsv")
is_unop($op, "null") is_svop($op->first, "gvsv") is_padop($op->first, "gvsv")
Truth table75%3/4
A and B or C
A= is_unop($op, "null")B= is_svop($op->first, "gvsv")C= is_padop($op->first, "gvsv")
ABCresult
0XX0
1000
11X1
1011
505 1 my $gv = get_gv($S, $op->first, bailout => 1);
506 1 $val = ${$gv->SV->object_2svref};
507 ▶ } elsif (is_unop($op, "null") && is_unop_aux($op->first, "multideref")) {
Condition100%3/3
is_unop($op, "null") and is_unop_aux($op->first, "multideref")
!ll&&!rl&&r
216413
MC/DC100%2/2
is_unop($op, "null") and is_unop_aux($op->first, "multideref")
is_unop($op, "null") is_unop_aux($op->first, "multideref")
Truth table100%3/3
A and B
A= is_unop($op, "null")B= is_unop_aux($op->first, "multideref")
ABresult
0X0
100
111
508 13 $val = parse_multideref($S, $op->first);
509 ▶ } elsif ( $p{eval} && is_binop($op, "concat")) {
Condition66%2/3
$p{"eval"} and is_binop($op, "concat")
!ll&&!rl&&r
21910
MC/DC0%0/2
$p{"eval"} and is_binop($op, "concat")
$p{"eval"} is_binop($op, "concat")
Truth table66%2/3
A and B
A= $p{"eval"}B= is_binop($op, "concat")
ABresult
0X0
100
111
510 0 my @args = ($op->first);
511 0 ▶ push @args, $args[-1]->sibling while !is_null($args[-1]) && !is_null($args[-1]->sibling);
Branch: 1 branch
BranchTrueFalseTotal
is_null($args[-1]) or is_null($args[-1]->sibling) or do { push @args, $args[-1]->sibling } 0 0 0
Condition0%0/3
is_null($args[-1]) or is_null($args[-1]->sibling)
l!l&&r!l&&!r
000
MC/DC0%0/2
is_null($args[-1]) or is_null($args[-1]->sibling)
is_null($args[-1]) is_null($args[-1]->sibling)
Truth table0%0/3
A or B
A= is_null($args[-1])B= is_null($args[-1]->sibling)
ABresult
1X1
011
000
512 0 $val = get_concat_value($S, @args);
513 ▶ } elsif ( $p{eval} && is_unop_aux($op, "multiconcat")) {
Condition66%2/3
$p{"eval"} and is_unop_aux($op, "multiconcat")
!ll&&!rl&&r
21901
MC/DC50%1/2
$p{"eval"} and is_unop_aux($op, "multiconcat")
$p{"eval"} is_unop_aux($op, "multiconcat")
Truth table66%2/3
A and B
A= $p{"eval"}B= is_unop_aux($op, "multiconcat")
ABresult
0X0
100
111
514 1 ▶ my @terms = parse_multiconcat($S, $op, eval => 1) or goto BAILOUT;
Branch: 1 branch
BranchTrueFalseTotal
my(@terms) = parse_multiconcat($S, $op, "eval", 1) or goto BAILOUT 0 1 1
515 1 $val = join('', map { $_->{str} } @terms);
516 } elsif (is_op($op, "aelemfast_lex")) {
517 0 my $sv = $S->{padlist}->[1]->ARRAYelt($op->targ);
518 0 ▶ goto BAILOUT unless $sv;
Branch: 1 branch
BranchTrueFalseTotal
unless $sv 0 0 0
519 0 $sv = $sv->object_2svref;
520 0 $val = $sv->[$op->private];
521 ▶ } elsif (is_svop($op, "aelemfast") || is_padop($op, "aelemfast")) {
Condition66%2/3
is_svop($op, "aelemfast") or is_padop($op, "aelemfast")
l!l&&r!l&&!r
20217
MC/DC50%1/2
is_svop($op, "aelemfast") or is_padop($op, "aelemfast")
is_svop($op, "aelemfast") is_padop($op, "aelemfast")
Truth table66%2/3
A or B
A= is_svop($op, "aelemfast")B= is_padop($op, "aelemfast")
ABresult
1X1
011
000
522 my $sv = is_padop($op, "aelemfast") ?
523 2 ▶ $S->{padlist}->[1]->ARRAYelt($op->padix) :
Branch: 2 branches
BranchTrueFalseTotal
my $sv = is_padop($op, "aelemfast") ? $S->{"padlist"}[1]->ARRAYelt($op->padix) : $op->sv or goto BAILOUT 0 2 2
is_padop($op, 'aelemfast') ? : 0 2 2
524 $op->sv or goto BAILOUT;
525 2 ▶ $sv = $sv->object_2svref or goto BAILOUT;
Branch: 1 branch
BranchTrueFalseTotal
$sv = $sv->object_2svref or goto BAILOUT 0 2 2
526 2 ▶ $sv = ${$sv} or goto BAILOUT;
Branch: 1 branch
BranchTrueFalseTotal
$sv = ${$sv;} or goto BAILOUT 0 2 2
527 2 $val = $sv->[$op->private];
528 } else {
529 BAILOUT:
530 217 ▶ return () if $p{soft};
Branch: 1 branch
BranchTrueFalseTotal
if $p{"soft"} 217 0 217
531 0 bailout $S, "cannot parse \"", $op->name, "\" op as a value or value reference";
532 }
533 62 return ($val, 1);
534 }
535  
536 sub get_var
537 {
538 5 ▶ my ($S, $op) = @_;
Subroutine get_var: called CC=4 SCAR=22.1
Pod undocumented
539 5 ▶ if (is_op($op, "padsv") || is_unop($op, "padsv_store")) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_op($op, 'padsv') or is_unop($op, 'padsv_store')) { } 5 0 5
elsif (is_unop($op, 'null')) { } 0 0 0
Condition66%2/3
is_op($op, "padsv") or is_unop($op, "padsv_store")
l!l&&r!l&&!r
140
MC/DC0%0/2
is_op($op, "padsv") or is_unop($op, "padsv_store")
is_op($op, "padsv") is_unop($op, "padsv_store")
Truth table66%2/3
A or B
A= is_op($op, "padsv")B= is_unop($op, "padsv_store")
ABresult
1X1
011
000
540 5 return padname($S, $op);
541 } elsif (is_unop($op, "null")) {
542 0 $op = $op->first;
543 0 want_svop($S, $op, "gvsv");
544 0 return "*" . $op->gv->NAME;
545 } else {
546 # XXX
547 0 print "$op\n";
548 0 print "type: ", $op->type, "\n";
549 0 print "name: ", $op->name, "\n";
550 0 print "desc: ", $op->desc, "\n";
551 0 print "targ: ", $op->targ, "\n";
552 0 bailout $S, "cannot get var";
553 }
554 }
555  
556 sub find_aliased_tab
557 {
558 373 ▶ my ($S, $op) = @_;
Subroutine find_aliased_tab: called CC=5 SCAR=16.1
Pod undocumented
559 373 my $var = padname($S, $op);
560 373 ▶ return "" unless defined $var;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $var 2 371 373
561  
562 371 my $ss = $S;
563 371 ▶ while ($ss) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ss) 419 48 467
564 419 my $tab;
565 419 ▶ if ($ss->{operation} eq "select") {
Branch: 1 branch
BranchTrueFalseTotal
if ($ss->{'operation'} eq 'select') { } 419 0 419
566 419 $tab = $ss->{var_alias}{$var};
567 } else {
568 0 $tab = $ss->{vars}{$var};
569 }
570 419 ▶ return $tab if $tab;
Branch: 1 branch
BranchTrueFalseTotal
if $tab 323 96 419
571 96 $ss = $ss->{gen_args}->{prev_S};
572 }
573 48 return "";
574 }
575  
576 sub get_tab_field
577 {
578 382 ▶ my ($S, $unop, %p) = @_;
Subroutine get_tab_field: called CC=11 SCAR=24.8
Pod undocumented
579 382 my $op = want_unop($S, $unop, "entersub");
580 382 ▶ $op = $op->first if is_unop($op, 'null');
Branch: 1 branch
BranchTrueFalseTotal
if is_unop($op, "null") 0 382 382
581 382 want_pushmark_or_padrange($S, $op);
582 382 $op = $op->sibling;
583 382 my $tab = is_const($S, $op);
584 382 ▶ if ($tab) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tab) { } 150 232 382
elsif (is_op($op, 'padsv')) { } 232 0 232
585 150 $tab = new_tab($S, $tab);
586 } elsif (is_op($op, "padsv")) {
587 232 $tab = find_aliased_tab($S, $op);
588 }
589 382 ▶ unless ($tab) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tab) 0 382 382
590 0 bailout $S, "cannot get a table";
591 }
592 382 $op = $op->sibling;
593 382 my $field = want_method($S, $op);
594 382 $op = $op->sibling;
595 382 ▶ if ($p{lvalue} && is_unop($op, "rv2cv")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"lvalue"} and is_unop($op, "rv2cv")) 0 382 382
Condition66%2/3
$p{"lvalue"} and is_unop($op, "rv2cv")
!ll&&!rl&&r
359230
MC/DC0%0/2
$p{"lvalue"} and is_unop($op, "rv2cv")
$p{"lvalue"} is_unop($op, "rv2cv")
Truth table66%2/3
A and B
A= $p{"lvalue"}B= is_unop($op, "rv2cv")
ABresult
0X0
100
111
596 0 want_unop($S, $op, "rv2cv");
597 0 $op = $op->sibling;
598 }
599 382 want_null($S, $op);
600 382 ▶ if ($S->{parsing_return} && !$S->{inside_aggregate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{"parsing_return"} and not $S->{"inside_aggregate"}) 86 296 382
Condition100%3/3
$S->{"parsing_return"} and not $S->{"inside_aggregate"}
!ll&&!rl&&r
292486
MC/DC100%2/2
$S->{"parsing_return"} and not $S->{"inside_aggregate"}
$S->{"parsing_return"} not $S->{"inside_aggregate"}
Truth table100%3/3
A and not(B)
A= $S->{"parsing_return"}B= not $S->{"inside_aggregate"}
ABresult
0X0
100
111
601 86 ▶ my $ff = $S->{operation} eq "select" ? "$tab.$field" : $field;
Branch: 1 branch
BranchTrueFalseTotal
$S->{'operation'} eq 'select' ? : 86 0 86
602 86 ▶ push @{$S->{autogroup_by}}, $ff unless $S->{autogroup_fields}{$ff}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $S->{"autogroup_fields"}{$ff}++ 85 1 86
603 }
604 382 ($tab, $field);
605 }
606  
607 # helpers
608  
609 sub maybe_one_table_only
610 {
611 357 ▶ my ($S) = @_;
Subroutine maybe_one_table_only: called CC=6 SCAR=21.6
Pod undocumented
612 357 ▶ return if $S->{operation} eq "select";
Branch: 1 branch
BranchTrueFalseTotal
if $S->{"operation"} eq "select" 330 27 357
613 27 ▶ if ($S->{tabs} && keys %{$S->{tabs}} or $S->{vars} && keys %{$S->{vars}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{"tabs"} and keys %{$$S{"tabs"};} or $S->{"vars"} and keys %{$$S{"vars"};}) 0 27 27
Condition44%4/9
$S->{"tabs"} and keys %{$$S{"tabs"};} or $S->{"vars"} and keys %{$$S{"vars"};}
l!l&&r!l&&!r
0027
$S->{"tabs"} and keys %{$$S{"tabs"};}
!ll&&!rl&&r
5220
$S->{"vars"} and keys %{$$S{"vars"};}
!ll&&!rl&&r
2700
MC/DC0%0/4
$S->{"tabs"} and keys %{$$S{"tabs"};} or $S->{"vars"} and keys %{$$S{"vars"};}
$S->{"tabs"} keys %{$$S{"tabs"};} $S->{"vars"} keys %{$$S{"vars"};}
Truth table0%0/7
A and B or C and D
A= $S->{"tabs"}B= keys %{$$S{"tabs"};}C= $S->{"vars"}D= keys %{$$S{"vars"};}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
614 0 bailout $S, "a $S->{operation}'s query sub can only refer to a single table";
615 }
616 }
617  
618 sub incr_string
619 {
620 357 ▶ my ($s) = @_;
Subroutine incr_string: called CC=2 SCAR=6.9
Pod undocumented
621 357 my ($prefix, $suffix) = $s =~ /^(.*_)?(.*)$/;
622 357 ▶ $prefix ||= "";
Condition100%2/2
$prefix ||= ""
l!l
15342
MC/DC100%1/1
$prefix ||= ""
$prefix
Truth table100%2/2
A
A= $prefix
Aresult
11
00
623 357 $suffix++;
624 357 return "$prefix$suffix";
625 }
626  
627 sub new_tab
628 {
629 150 ▶ my ($S, $tab) = @_;
Subroutine new_tab: called CC=2 SCAR=6.9
Pod undocumented
630 150 ▶ unless ($S->{tabs}{$tab}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($S->{"tabs"}{$tab}) 137 13 150
631 137 maybe_one_table_only($S);
632 137 $S->{tabs}{$tab} = 1;
633 137 $S->{tab_alias}{$tab} = $S->{alias};
634 137 $S->{alias} = incr_string($S->{alias});
635 }
636 150 $S->{tab_alias}{$tab};
637 }
638  
639 sub new_var
640 {
641 220 ▶ my ($S, $var, $tab) = @_;
Subroutine new_var: called CC=2 SCAR=7.0
Pod undocumented
642 220 maybe_one_table_only($S);
643 bailout $S, "cannot reuse $var for table $tab, it's already used by $S->{vars}{$var}"
644 220 ▶ if $S->{vars}{$var};
Branch: 1 branch
BranchTrueFalseTotal
if $S->{"vars"}{$var} 0 220 220
645 220 $S->{vars}{$var} = $tab;
646 220 $S->{var_alias}{$var} = $S->{alias};
647 220 $S->{alias} = incr_string($S->{alias});
648 }
649  
650 # parsers
651  
652 sub try_parse_attr_assignment
653 {
654 227 ▶ my ($S, $op, $realname, %opt) = @_;
Subroutine try_parse_attr_assignment: called CC=18 SCAR=30.3
Pod undocumented
655 227 ▶ return unless is_unop($op, "entersub");
Branch: 1 branch
BranchTrueFalseTotal
unless is_unop($op, "entersub") 0 227 227
656 227 $op = want_unop($S, $op);
657 227 ▶ return unless is_pushmark_or_padrange($op);
Branch: 1 branch
BranchTrueFalseTotal
unless is_pushmark_or_padrange($op) 9 218 227
658 218 $op = $op->sibling;
659 218 my $c = is_const($S, $op);
660 218 ▶ return unless $c && $c eq "attributes";
Branch: 1 branch
BranchTrueFalseTotal
unless $c and $c eq "attributes" 1 217 218
Condition66%2/3
$c and $c eq "attributes"
!ll&&!rl&&r
01217
MC/DC50%1/2
$c and $c eq "attributes"
$c $c eq "attributes"
Truth table66%2/3
A and B
A= $cB= $c eq "attributes"
ABresult
0X0
100
111
661 217 $op = $op->sibling;
662 217 ▶ return unless is_const($S, $op);
Branch: 1 branch
BranchTrueFalseTotal
unless is_const($S, $op) 0 217 217
663 217 $op = $op->sibling;
664 217 ▶ return unless is_unop($op, "srefgen");
Branch: 1 branch
BranchTrueFalseTotal
unless is_unop($op, "srefgen") 0 217 217
665 217 my $op1 = want_unop($S, $op);
666 217 ▶ $op1 = want_unop($S, $op1) if is_unop($op1, "null");
Branch: 1 branch
BranchTrueFalseTotal
if is_unop($op1, "null") 217 0 217
667 217 ▶ return unless is_op($op1, "padsv");
Branch: 1 branch
BranchTrueFalseTotal
unless is_op($op1, "padsv") 0 217 217
668 217 my $varn = padname($S, $op1);
669 217 $op = $op->sibling;
670 217 my $attr = is_const($S, $op);
671 217 ▶ return unless $attr;
Branch: 1 branch
BranchTrueFalseTotal
unless $attr 0 217 217
672 217 my @attr = grep { length($_) } split /(?:[\(\)])/, $attr;
673 217 ▶ return unless @attr;
Branch: 1 branch
BranchTrueFalseTotal
unless @attr 0 217 217
674 217 $op = $op->sibling;
675 217 ▶ return unless is_methop($op, "method_named") || is_svop($op, "method_named");
Branch: 1 branch
BranchTrueFalseTotal
unless is_methop($op, "method_named") or is_svop($op, "method_named") 0 217 217
Condition33%1/3
is_methop($op, "method_named") or is_svop($op, "method_named")
l!l&&r!l&&!r
21700
MC/DC0%0/2
is_methop($op, "method_named") or is_svop($op, "method_named")
is_methop($op, "method_named") is_svop($op, "method_named")
Truth table33%1/3
A or B
A= is_methop($op, "method_named")B= is_svop($op, "method_named")
ABresult
1X1
011
000
676 217 ▶ return unless want_method($S, $op, "import");
Branch: 1 branch
BranchTrueFalseTotal
unless want_method($S, $op, "import") 0 217 217
677 217 ▶ if ($realname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($realname) { } 12 205 217
678 12 ▶ if (lc $attr[0] eq "table") {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $attr[0] eq 'table') { } 12 0 12
679 12 @attr = ($realname);
680 } else {
681 0 bailout $S, "cannot decide whether you refer to $realname table or to @attr table";
682 }
683 } else {
684 205 ▶ shift @attr if lc $attr[0] eq "table" && @attr > 1;
Branch: 1 branch
BranchTrueFalseTotal
if lc $attr[0] eq "table" and @attr > 1 1 204 205
Condition100%3/3
lc $attr[0] eq "table" and @attr > 1
!ll&&!rl&&r
20311
MC/DC100%2/2
lc $attr[0] eq "table" and @attr > 1
lc $attr[0] eq "table" @attr > 1
Truth table100%3/3
A and B
A= lc $attr[0] eq "table"B= @attr > 1
ABresult
0X0
100
111
685 }
686 217 $attr = join ".", @attr;
687 217 new_var($S, $varn, $attr);
688 217 return $varn;
689 }
690  
691 sub parse_list
692 {
693 387 ▶ my ($S, $op) = @_;
Subroutine parse_list: called CC=2 SCAR=6.9
Pod undocumented
694 387 my @op = get_all_children($op);
695 387 for $op (@op) {
696 1379 parse_op($S, $op);
697 }
698 }
699  
700 sub parse_return
701 {
702 100 ▶ my ($S, $op) = @_;
Subroutine parse_return: called CC=16 SCAR=27.8
Pod undocumented
703 100 my @op = get_all_children($op);
704 bailout $S, "there should be no \"return\" statements in $S->{operation}'s query sub"
705 100 ▶ unless $S->{operation} eq "select";
Branch: 1 branch
BranchTrueFalseTotal
unless $S->{"operation"} eq "select" 0 100 100
706 100 ▶ bailout $S, "there should be at most one return statement" if $S->{returns};
Branch: 1 branch
BranchTrueFalseTotal
if $S->{"returns"} 3 97 100
707 97 $S->{returns} = [];
708 97 my $last_alias;
709 97 for $op (@op) {
710 245 my %rv = parse_return_value($S, $op);
711 234 ▶ if (exists $rv{table}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $rv{'table'}) { } 15 219 234
elsif (exists $rv{'field'}) { } 106 113 219
elsif (exists $rv{'alias'}) { } 16 97 113
712 15 ▶ bailout $S, "cannot alias the whole table"
Branch: 1 branch
BranchTrueFalseTotal
if defined $last_alias 0 15 15
713 if defined $last_alias;
714 15 push @{$S->{returns}}, "$rv{table}.*";
715 15 $S->{no_autogroup} = 1;
716 } elsif (exists $rv{field}) {
717 106 ▶ if (defined $last_alias) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_alias) { } 9 97 106
718 9 ▶ bailout $S, "a key field cannot be aliased" if $rv{key_field};
Branch: 1 branch
BranchTrueFalseTotal
if $rv{"key_field"} 1 8 9
719 8 push @{$S->{returns}}, "$rv{field} as $last_alias";
720 8 undef $last_alias;
721 } else {
722 97 ▶ if ($rv{key_field}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv{'key_field'}) { } 11 86 97
723 11 my $kf = '$kf-' . $S->{key_field};
724 11 ▶ if ($S->{gen_args}{kf_convert}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{"gen_args"}{"kf_convert"}) 0 11 11
725 0 $kf = $S->{gen_args}{kf_convert}->($kf);
726 }
727 11 $S->{key_field}++;
728 11 push @{$S->{returns}}, "$rv{field} as \"$kf\"";
729 11 push @{$S->{key_fields}}, $kf;
730 } else {
731 86 push @{$S->{returns}}, $rv{field};
732 }
733 }
734 } elsif (exists $rv{alias}) {
735 16 ▶ if (defined $last_alias) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_alias) 3 13 16
736 # XXX maybe check whether it is a number and inline it?
737 3 push @{$S->{ret_values}}, $rv{alias};
738 3 push @{$S->{returns}}, "? as $last_alias";
739 3 undef $last_alias;
740 3 next;
741 }
742 bailout $S, "bad alias name \"$rv{alias}\""
743 13 ▶ unless $rv{alias} =~ /^\w+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $rv{"alias"} =~ /^\w+$/u 0 13 13
744 13 ▶ if (lc $rv{alias} eq "distinct") {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $rv{"alias"} eq "distinct") 1 12 13
745 1 ▶ bailout $S, "\"$rv{alias}\" is not a valid alias name" if @{$S->{returns}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$S->{"returns"};} 0 1 1
746 1 $S->{distinct}++;
747 1 next;
748 }
749 12 $last_alias = $rv{alias};
750 }
751 }
752 }
753  
754 sub parse_return_value
755 {
756 259 ▶ my ($S, $op) = @_;
Subroutine parse_return_value: called CC=7 SCAR=19.5
Pod undocumented
757  
758 259 ▶ if (is_op($op, "padsv")) {
Branch: 4 branches
BranchTrueFalseTotal
if (is_op($op, 'padsv')) { } 16 243 259
elsif (my $const = is_const($S, $op)) { } 17 226 243
elsif (is_pushmark_or_padrange($op)) { } 97 129 226
elsif (is_unop($op, 'ftsvtx')) { } 14 115 129
759 16 return table => find_aliased_tab($S, $op);
760 } elsif (my $const = is_const($S, $op)) {
761 17 return alias => $const;
762 } elsif (is_pushmark_or_padrange($op)) {
763 97 return ();
764 } elsif (is_unop($op, "ftsvtx")) {
765 14 my %r = parse_return_value($S, $op->first);
766 bailout $S, "only a single value return specification can be a key field"
767 14 ▶ unless $r{field};
Branch: 1 branch
BranchTrueFalseTotal
unless $r{"field"} 2 12 14
768 12 ▶ $r{key_field} = 1 unless $S->{gen_args}->{prev_S};
Branch: 1 branch
BranchTrueFalseTotal
unless $S->{"gen_args"}{"prev_S"} 12 0 12
769 12 return %r;
770 } else {
771 115 my $saved_values = $S->{values};
772 115 $S->{values} = [];
773 115 $S->{parsing_return} = 1;
774 115 my $ret = parse_term($S, $op);
775 106 $S->{parsing_return} = 0;
776 106 push @{$S->{ret_values}}, @{$S->{values}};
777 106 $S->{values} = $saved_values;
778 106 return field => $ret;
779 }
780 }
781  
782 sub parse_term
783 {
784 682 ▶ my ($S, $op, %p) = @_;
Subroutine parse_term: called CC=46 SCAR=39.1
Pod undocumented
785  
786 682 my $placeholder;
787 682 local $S->{in_term} = 1;
788 682 ▶ if (is_unop($op, "entersub")) {
Branch: 19 branches
BranchTrueFalseTotal
if (is_unop($op, 'entersub')) { } 382 300 682
elsif (is_unop($op, 'lc')) { } 0 300 300
elsif (is_unop($op, 'uc')) { } 0 300 300
elsif (is_unop($op, 'abs')) { } 1 299 300
elsif (is_unop($op, 'null')) { } 50 249 299
elsif (is_op($op, 'null')) { } 1 248 249
elsif (is_op($op, 'undef')) { } 4 244 248
elsif (is_unop($op, 'not')) { } 15 229 244
elsif (is_unop($op, 'defined')) { } 4 225 229
elsif (($placeholder) = get_value($S, $op, 'soft', 1)) { } 28 197 225
elsif (is_unop($op, 'backtick')) { } 4 193 197
elsif (is_binop($op)) { } 23 170 193
elsif (is_logop($op, 'or')) { } 2 168 170
elsif (is_logop($op, 'and')) { } 2 166 168
elsif (() = is_const($S, $op)) { } 97 69 166
elsif (is_pvop($op, 'next')) { } 12 57 69
elsif (is_pmop($op, 'match')) { } 2 55 57
elsif (is_unop_aux($op, 'multideref')) { } 41 14 55
elsif (is_unop_aux($op, 'multiconcat')) { } 13 1 14
789 382 my $funcall = try_funcall($S, $op);
790 381 ▶ return $funcall if defined $funcall;
Branch: 1 branch
BranchTrueFalseTotal
if defined $funcall 32 349 381
791 349 my ($t, $f) = get_tab_field($S, $op);
792 349 ▶ if ($S->{operation} eq "delete" || $S->{operation} eq "update") {
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{'operation'} eq 'delete' or $S->{'operation'} eq 'update') { } 7 342 349
Condition66%2/3
$S->{"operation"} eq "delete" or $S->{"operation"} eq "update"
l!l&&r!l&&!r
07342
MC/DC50%1/2
$S->{"operation"} eq "delete" or $S->{"operation"} eq "update"
$S->{"operation"} eq "delete" $S->{"operation"} eq "update"
Truth table66%2/3
A or B
A= $S->{"operation"} eq "delete"B= $S->{"operation"} eq "update"
ABresult
1X1
011
000
793 7 return $f;
794 } else {
795 342 return "$t.$f";
796 }
797 } elsif (is_unop($op, "lc")) {
798 0 my $term = parse_term($S, $op->first);
799 0 return "lower($term)";
800 } elsif (is_unop($op, "uc")) {
801 0 my $term = parse_term($S, $op->first);
802 0 return "upper($term)";
803 } elsif (is_unop($op, "abs")) {
804 1 my $term = parse_term($S, $op->first);
805 1 return "abs($term)";
806 } elsif (is_unop($op, "null")) {
807 50 return parse_term($S, $op->first, %p);
808 } elsif (is_op($op, "null")) {
809 1 return parse_term($S, $op->sibling, %p);
810 } elsif (is_op($op, "undef")) {
811 4 return "null";
812 } elsif (is_unop($op, "not")) {
813 15 my $subop = $op-> first;
814 15 ▶ if (is_pmop($subop, "match")) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_pmop($subop, 'match')) { } 2 13 15
815 2 return parse_regex( $S, $subop, 1);
816 } else {
817 13 my ($term, $with_not) = parse_term($S, $subop);
818 13 ▶ if ($p{not_after}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($p{'not_after'}) { } 7 6 13
elsif ($with_not) { } 2 4 6
819 7 return "$term not";
820 } elsif ($with_not) {
821 2 return $with_not;
822 } else {
823 4 return "not $term";
824 }
825 }
826 } elsif (is_unop($op, "defined")) {
827 4 my $term = parse_term($S, $op->first);
828 return wantarray ?
829 4 ▶ ("$term is not null", "$term is null") :
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 2 4
830 "$term is not null";
831 } elsif (($placeholder) = get_value($S, $op, soft => 1)) {
832 28 ▶ return 'null' if !defined($placeholder) && $S->{gen_args}->{inline};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $placeholder and $S->{"gen_args"}{"inline"} 4 24 28
Condition66%2/3
not defined $placeholder and $S->{"gen_args"}{"inline"}
!ll&&!rl&&r
2404
MC/DC50%1/2
not defined $placeholder and $S->{"gen_args"}{"inline"}
not defined $placeholder $S->{"gen_args"}{"inline"}
Truth table66%2/3
not(A) and B
A= not defined $placeholderB= $S->{"gen_args"}{"inline"}
ABresult
0X0
100
111
833 24 goto PLACEHOLDER;
834 } elsif (is_unop($op, "backtick")) {
835 4 my $fop = $op->first;
836 4 ▶ $fop = $fop->sibling while is_op($fop, "null");
Branch: 1 branch
BranchTrueFalseTotal
is_op($fop, "null") and do { $fop = $fop->sibling } 4 4 8
837 4 my $sql = is_const($S, $fop);
838 4 ▶ return $sql if $sql;
Branch: 1 branch
BranchTrueFalseTotal
if $sql 4 0 4
839 } elsif (is_binop($op)) {
840 23 my $expr = parse_expr($S, $op);
841 21 return "($expr)";
842 } elsif (is_logop($op, "or")) {
843 2 my $or = parse_or($S, $op);
844 2 ▶ bailout $S, "looks like a limiting range or a conditional inside an expression\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $or 0 2 2
845 unless $or;
846 2 return "($or)";
847 } elsif (is_logop($op, "and")) {
848 2 my $and = parse_and($S, $op);
849 2 ▶ bailout $S, "looks like a conditional inside an expression\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $and 0 2 2
850 unless $and;
851 2 return "($and)";
852 } elsif (my ($const,$sv) = is_const($S, $op)) {
853 97 ▶ if (($sv->isa("B::IV") && !$sv->isa("B::PVIV")) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($sv->isa('B::IV') and not $sv->isa('B::PVIV') or $sv->isa('B::NV') and not $sv->isa('B::PVNV')) { } 55 42 97
Condition55%5/9
$sv->isa("B::IV") and not $sv->isa("B::PVIV") or $sv->isa("B::NV") and not $sv->isa("B::PVNV")
l!l&&r!l&&!r
55042
$sv->isa("B::IV") and not $sv->isa("B::PVIV")
!ll&&!rl&&r
42055
$sv->isa("B::NV") and not $sv->isa("B::PVNV")
!ll&&!rl&&r
4200
MC/DC25%1/4
$sv->isa("B::IV") and not $sv->isa("B::PVIV") or $sv->isa("B::NV") and not $sv->isa("B::PVNV")
$sv->isa("B::IV") not $sv->isa("B::PVIV") $sv->isa("B::NV") not $sv->isa("B::PVNV")
Truth table28%2/7
A and not(B) or C and not(D)
A= $sv->isa("B::IV")B= not $sv->isa("B::PVIV")C= $sv->isa("B::NV")D= not $sv->isa("B::PVNV")
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
854 ($sv->isa("B::NV") && !$sv->isa("B::PVNV")))
855 {
856 # This is surely a number, so we can
857 # safely inline it in the SQL.
858 55 return $const;
859 } else {
860 # This will probably be represented by a string,
861 # we'll let DBI to handle the quoting of a bound
862 # value.
863 42 $placeholder = $const;
864 42 goto PLACEHOLDER;
865 }
866 } elsif (is_pvop($op, "next")) {
867 12 my $seq = $op->pv;
868 12 ▶ my $flavor = $S->{gen_args}->{flavor}||"";
Condition50%1/2
$S->{'gen_args'}{'flavor'} || ''
l!l
120
MC/DC0%0/1
$S->{'gen_args'}{'flavor'} || ''
$S->{'gen_args'}{'flavor'}
Truth table50%1/2
A
A= $S->{'gen_args'}{'flavor'}
Aresult
11
00
869 12 ▶ if ($flavor eq "oracle") {
Branch: 2 branches
BranchTrueFalseTotal
if ($flavor eq 'oracle') { } 5 7 12
elsif ($flavor eq 'pg' or $flavor eq 'pglite') { } 6 1 7
870 5 ▶ bailout $S, "Sequence name looks wrong" unless $seq =~ /^\w+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $seq =~ /^\w+$/u 1 4 5
871 4 return "$seq.nextval";
872 ▶ } elsif ($flavor eq "pg" || $flavor eq "pglite") {
Condition66%2/3
$flavor eq "pg" or $flavor eq "pglite"
l!l&&r!l&&!r
601
MC/DC50%1/2
$flavor eq "pg" or $flavor eq "pglite"
$flavor eq "pg" $flavor eq "pglite"
Truth table66%2/3
A or B
A= $flavor eq "pg"B= $flavor eq "pglite"
ABresult
1X1
011
000
873 6 ▶ bailout $S, "Sequence name looks wrong" if $seq =~ /'/; # XXX well, I am lazy
Branch: 1 branch
BranchTrueFalseTotal
if $seq =~ /'/u 1 5 6
874 5 return "nextval('$seq')";
875 } else {
876 1 bailout $S, "Sequences do not seem to be supported for this DBI flavor";
877 }
878 } elsif (is_pmop($op, "match")) {
879 2 return parse_regex($S, $op, 0);
880 } elsif (is_unop_aux($op, "multideref")) {
881 41 $placeholder = parse_multideref($S, $op);
882 38 goto PLACEHOLDER;
883 } elsif (is_unop_aux($op, "multiconcat")) {
884 13 my ($c, $v) = try_special_concat($S, $op);
885 11 ▶ if ($c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c) 11 0 11
886 11 push @{$S->{values}}, @$v;
887 11 return "($c)";
888 }
889 0 bailout $S, "unsupported multiconcat";
890 } else {
891 1 BAILOUT:
892 bailout $S, "cannot reconstruct term from operation \"",
893 $op->name, '"';
894 }
895  
896 PLACEHOLDER:
897 104 ▶ if ( $p{inline_placeholder}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{'inline_placeholder'}) { } 4 100 104
898 4 ▶ bailout $S, "cannot inline undefined value" unless defined $placeholder;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $placeholder 0 4 4
899 4 return $placeholder;
900 } else {
901 100 return placeholder_value($S, $placeholder);
902 }
903 }
904  
905 sub placeholder_value
906 {
907 100 ▶ my ($S, $val) = @_;
Subroutine placeholder_value: called CC=1 SCAR=0.0
Pod undocumented
908 100 my $pos = @{$S->{values}};
909 100 push @{$S->{values}}, $val;
910 100 return DBIx::Perlish::Placeholder->new($S, $pos);
911 }
912  
913 ## XXX above this point 80.parse_bad.t did not go
914  
915 sub parse_simple_term
916 {
917 14 ▶ my ($S, $op) = @_;
Subroutine parse_simple_term: called CC=3 SCAR=11.0
Pod undocumented
918 14 ▶ if (my ($const,$sv) = is_const($S, $op)) {
Branch: 2 branches
BranchTrueFalseTotal
if (() = is_const($S, $op)) { } 8 6 14
elsif (() = get_value($S, $op, 'soft', 1)) { } 4 2 6
919 8 return $const;
920 } elsif (my ($val, $ok) = get_value($S, $op, soft => 1)) {
921 4 return $val;
922 } else {
923 2 bailout $S, "cannot reconstruct simple term from operation \"",
924 $op->name, '"';
925 }
926 }
927  
928 sub parse_simple_eval
929 {
930 6 ▶ my ($S, $op) = @_;
Subroutine parse_simple_eval: called CC=3 SCAR=11.3
Pod undocumented
931 6 ▶ if (my ($const,$sv) = is_const($S, $op)) {
Branch: 2 branches
BranchTrueFalseTotal
if (() = is_const($S, $op)) { } 5 1 6
elsif (() = get_value($S, $op, 'eval', 1)) { } 1 0 1
932 5 return $const;
933 } elsif (my ($val, $ok) = get_value($S, $op, eval => 1)) {
934 1 return $val;
935 } else {
936 0 bailout $S, "cannot reconstruct simple term from operation \"",
937 $op->name, '"';
938 }
939 }
940  
941 sub get_gv
942 {
943 80 ▶ my ($S, $op, %p) = @_;
Subroutine get_gv: called CC=16 SCAR=38.3
Pod undocumented
944  
945 80 my ($gv_on_pad, $gv_idx);
946 80 ▶ if (is_svop($op, "gv") || is_svop($op, "gvsv")) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_svop($op, 'gv') or is_svop($op, 'gvsv')) { } 80 0 80
elsif (is_padop($op, 'gv') or is_padop($op, 'gvsv')) { } 0 0 0
Condition66%2/3
is_svop($op, "gv") or is_svop($op, "gvsv")
l!l&&r!l&&!r
7820
MC/DC0%0/2
is_svop($op, "gv") or is_svop($op, "gvsv")
is_svop($op, "gv") is_svop($op, "gvsv")
Truth table66%2/3
A or B
A= is_svop($op, "gv")B= is_svop($op, "gvsv")
ABresult
1X1
011
000
947 80 $gv_idx = $op->targ;
948 ▶ } elsif (is_padop($op, "gv") || is_padop($op, "gvsv")) {
Condition0%0/3
is_padop($op, "gv") or is_padop($op, "gvsv")
l!l&&r!l&&!r
000
MC/DC0%0/2
is_padop($op, "gv") or is_padop($op, "gvsv")
is_padop($op, "gv") is_padop($op, "gvsv")
Truth table0%0/3
A or B
A= is_padop($op, "gv")B= is_padop($op, "gvsv")
ABresult
1X1
011
000
949 0 $gv_idx = $op->padix;
950 0 $gv_on_pad = 1;
951 } else {
952 0 goto BAIL_OUT;
953 }
954 80 ▶ goto BAIL_OUT unless is_null($op->sibling);
Branch: 1 branch
BranchTrueFalseTotal
unless is_null($op->sibling) 0 80 80
955  
956 80 ▶ my $gv = $gv_on_pad ? "" : $op->sv;
Branch: 1 branch
BranchTrueFalseTotal
$gv_on_pad ? : 0 80 80
957 80 ▶ if (!$gv || !$$gv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gv and $$gv) 0 80 80
Condition33%1/3
$gv and $$gv
!ll&&!rl&&r
0080
MC/DC0%0/2
$gv and $$gv
$gv $$gv
Truth table33%1/3
A and B
A= $gvB= $$gv
ABresult
0X0
100
111
958 0 $gv = $S->{padlist}->[1]->ARRAYelt($gv_idx);
959 }
960 80 ▶ if ( $p{get_name} && $gv->isa("B::IV")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"get_name"} and $gv->isa("B::IV")) 78 2 80
Condition66%2/3
$p{"get_name"} and $gv->isa("B::IV")
!ll&&!rl&&r
2078
MC/DC50%1/2
$p{"get_name"} and $gv->isa("B::IV")
$p{"get_name"} $gv->isa("B::IV")
Truth table66%2/3
A and B
A= $p{"get_name"}B= $gv->isa("B::IV")
ABresult
0X0
100
111
961 78 my $subref = $gv->object_2svref;
962 78 ▶ if (ref($subref) eq 'REF' && ref($$subref) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $subref eq "REF" and ref $$subref eq "CODE") 0 78 78
Condition33%1/3
ref $subref eq "REF" and ref $$subref eq "CODE"
!ll&&!rl&&r
7800
MC/DC0%0/2
ref $subref eq "REF" and ref $$subref eq "CODE"
ref $subref eq "REF" ref $$subref eq "CODE"
Truth table33%1/3
A and B
A= ref $subref eq "REF"B= ref $$subref eq "CODE"
ABresult
0X0
100
111
963 0 my $cv = B::svref_2object($$subref);
964 0 return $cv->NAME_HEK;
965 }
966 }
967 80 ▶ goto BAIL_OUT unless $gv->isa("B::GV");
Branch: 1 branch
BranchTrueFalseTotal
unless $gv->isa("B::GV") 0 80 80
968 80 ▶ return $p{get_name} ? $gv->NAME : $gv;
Branch: 1 branch
BranchTrueFalseTotal
$p{'get_name'} ? : 78 2 80
969 BAIL_OUT:
970 0 ▶ bailout $S, "unable to get GV from \"", $op->name, "\"" if $p{bailout};
Branch: 1 branch
BranchTrueFalseTotal
if $p{"bailout"} 0 0 0
971 0 return;
972 }
973  
974 78 ▶sub get_gv_name { get_gv(@_, get_name => 1) }
Subroutine get_gv_name: called CC=1 SCAR=0.0
Pod undocumented
975  
976 sub try_get_subselect
977 {
978 44 ▶ my ($S, $sub) = @_;
Subroutine try_get_subselect: called CC=16 SCAR=34.2
Pod undocumented
979  
980 44 ▶ return unless is_unop($sub, "entersub");
Branch: 1 branch
BranchTrueFalseTotal
unless is_unop($sub, "entersub") 0 44 44
981 44 ▶ $sub = $sub->first if is_unop($sub->first, "null");
Branch: 1 branch
BranchTrueFalseTotal
if is_unop($sub->first, "null") 44 0 44
982 44 ▶ return unless is_pushmark_or_padrange($sub->first);
Branch: 1 branch
BranchTrueFalseTotal
unless is_pushmark_or_padrange($sub->first) 0 44 44
983  
984 44 my $rg = $sub->first->sibling;
985 44 ▶ return if is_null($rg);
Branch: 1 branch
BranchTrueFalseTotal
if is_null($rg) 0 44 44
986 44 my $dbfetch = $rg->sibling;
987 44 ▶ return if is_null($dbfetch);
Branch: 1 branch
BranchTrueFalseTotal
if is_null($dbfetch) 1 43 44
988 43 ▶ return unless is_null($dbfetch->sibling);
Branch: 1 branch
BranchTrueFalseTotal
unless is_null($dbfetch->sibling) 0 43 43
989  
990 43 my $codeop;
991 43 ▶ if ( $] < 5.037 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < 5.037) { } 0 43 43
992 0 ▶ return unless is_unop($rg, "refgen") || is_unop($rg, "srefgen");
Branch: 1 branch
BranchTrueFalseTotal
unless is_unop($rg, "refgen") or is_unop($rg, "srefgen") 0 0 0
Condition0%0/3
is_unop($rg, "refgen") or is_unop($rg, "srefgen")
l!l&&r!l&&!r
000
MC/DC0%0/2
is_unop($rg, "refgen") or is_unop($rg, "srefgen")
is_unop($rg, "refgen") is_unop($rg, "srefgen")
Truth table0%0/3
A or B
A= is_unop($rg, "refgen")B= is_unop($rg, "srefgen")
ABresult
1X1
011
000
993 0 ▶ $rg = $rg->first if is_unop($rg->first, "null");
Branch: 1 branch
BranchTrueFalseTotal
if is_unop($rg->first, "null") 0 0 0
994 0 $codeop = $rg->first;
995 } else {
996 43 $codeop = $sub->first->sibling;
997 }
998 43 ▶ $codeop = $codeop->sibling if is_pushmark_or_padrange($codeop);
Branch: 1 branch
BranchTrueFalseTotal
if is_pushmark_or_padrange($codeop) 0 43 43
999 43 ▶ return unless is_svop($codeop, "anoncode");
Branch: 1 branch
BranchTrueFalseTotal
unless is_svop($codeop, "anoncode") 6 37 43
1000  
1001 37 ▶ $dbfetch = $dbfetch->first if is_unop($dbfetch->first, "null");
Branch: 1 branch
BranchTrueFalseTotal
if is_unop($dbfetch->first, "null") 0 37 37
1002 37 $dbfetch = $dbfetch->first;
1003 37 ▶ return unless (get_gv_name($S, $dbfetch) // '') eq 'subselect';
Branch: 1 branch
BranchTrueFalseTotal
unless (get_gv_name($S, $dbfetch) // "") eq "subselect" 0 37 37
Condition50%1/2
get_gv_name($S, $dbfetch) // ""
l!l
370
MC/DC0%0/1
get_gv_name($S, $dbfetch) // ""
get_gv_name($S, $dbfetch)
Truth table50%1/2
A
A= get_gv_name($S, $dbfetch)
Aresult
11
00
1004  
1005 37 return $codeop;
1006 }
1007  
1008 sub try_parse_funcall
1009 {
1010 6 ▶ my ($S, $sub, %opt) = @_;
Subroutine try_parse_funcall: called CC=8 SCAR=21.1
Pod undocumented
1011 6 ▶ $opt{select} //= 1;
Condition100%2/2
$opt{"select"} //= 1
l!l
24
MC/DC100%1/1
$opt{"select"} //= 1
$opt{"select"}
Truth table100%2/2
A
A= $opt{"select"}
Aresult
11
00
1012 6 my $fn;
1013 6 my $sql = try_funcall($S, $sub, only_normal_funcs => 1, func_name_return => \$fn);
1014 6 ▶ return unless $sql;
Branch: 1 branch
BranchTrueFalseTotal
unless $sql 0 6 6
1015 6 ▶ if (($S->{gen_args}->{flavor}||"") eq "oracle") {
Branch: 2 branches
BranchTrueFalseTotal
if (($S->{'gen_args'}{'flavor'} || '') eq 'oracle') { } 3 3 6
elsif ($opt{'select'}) { } 2 1 3
Condition50%1/2
$S->{'gen_args'}{'flavor'} || ''
l!l
60
MC/DC0%0/1
$S->{'gen_args'}{'flavor'} || ''
$S->{'gen_args'}{'flavor'}
Truth table50%1/2
A
A= $S->{'gen_args'}{'flavor'}
Aresult
11
00
1016 3 my $cast;
1017 3 ▶ if ($cast = $S->{gen_args}{quirks}{oracle_table_func_cast}{$fn}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cast = $S->{"gen_args"}{"quirks"}{"oracle_table_func_cast"}{$fn}) 0 3 3
1018 0 $sql = "cast($sql as $cast)";
1019 }
1020 3 $sql = "table($sql)";
1021 3 ▶ $sql = "select * from $sql" if $opt{select};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"select"} 2 1 3
1022 } elsif ($opt{select}) {
1023 # XXX we know this works in postgres, what about the rest?
1024 2 $sql = "select $sql";
1025 }
1026 6 return $sql;
1027 }
1028  
1029 sub in_list
1030 {
1031 10 ▶ my ( $S, $sop, $list ) = @_;
Subroutine in_list: called CC=12 SCAR=26.7
Pod undocumented
1032 10 ▶ $list //= [];
Condition50%1/2
$list //= []
l!l
100
MC/DC0%0/1
$list //= []
$list
Truth table50%1/2
A
A= $list
Aresult
11
00
1033  
1034 10 my $sql = '';
1035 10 my $left = parse_term($S, $sop->first, not_after => 1);
1036 10 ▶ return '1=0' unless @$list;
Branch: 1 branch
BranchTrueFalseTotal
unless @$list 0 10 10
1037  
1038 my $arg_limit =
1039 $S->{gen_args}->{in_arg_limit} //
1040 10 ▶ ((($S->{gen_args}->{flavor}||"") eq "oracle") ? 500 : 2_000_000_000);
Branch: 1 branch
BranchTrueFalseTotal
($S->{'gen_args'}{'flavor'} || '') eq 'oracle' ? : 0 10 10
Condition40%2/5
$S->{"gen_args"}{"in_arg_limit"} // (($S->{"gen_args"}{"flavor"} || "") eq "oracle" ? 500 : 2000000000)
l!l&&r!l&&!r
0100
$S->{'gen_args'}{'flavor'} || ''
l!l
100
MC/DC0%0/2
$S->{"gen_args"}{"in_arg_limit"} // (($S->{"gen_args"}{"flavor"} || "") eq "oracle" ? 500 : 2000000000)
$S->{"gen_args"}{"in_arg_limit"} $S->{'gen_args'}{'flavor'}
Truth table33%1/3
A // B
A= $S->{"gen_args"}{"in_arg_limit"}B= $S->{'gen_args'}{'flavor'}
ABresult
1X1
011
000
1041 10 my @args = @$list;
1042 10 ▶ while ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 10 10 20
1043 10 my @placeholders;
1044 10 for my $val ( splice(@args, 0, $arg_limit) ) {
1045 30 ▶ if (( ref($val) // '') =~ /SCALAR/) {
Branch: 1 branch
BranchTrueFalseTotal
if ((ref $val // '') =~ /SCALAR/u) { } 7 23 30
Condition50%1/2
ref $val // ""
l!l
300
MC/DC0%0/1
ref $val // ""
ref $val
Truth table50%1/2
A
A= ref $val
Aresult
11
00
1046 7 push @placeholders, $$val;
1047 } else {
1048 23 push @placeholders, '?';
1049 23 push @{$S->{values}}, $val;
1050 }
1051 }
1052 10 ▶ $sql .= $left =~ / not$/ ? ' and ' : ' or ' if length $sql;
Branch: 2 branches
BranchTrueFalseTotal
if length $sql 0 10 10
$left =~ / not$/u ? : 0 0 0
1053 10 $sql .= "$left in (" . join(',', @placeholders) . ")";
1054 }
1055  
1056 10 return $sql;
1057 }
1058  
1059 sub try_parse_subselect
1060 {
1061 19 ▶ my ($S, $sop) = @_;
Subroutine try_parse_subselect: called CC=19 SCAR=32.2
Pod undocumented
1062 19 my $sql;
1063 my @vals;
1064  
1065 19 my $sub = $sop->last->first;
1066  
1067 19 ▶ if (is_op($sub, "padav")) {
Branch: 3 branches
BranchTrueFalseTotal
if (is_op($sub, 'padav')) { } 6 13 19
elsif (is_unop($sub, 'rv2av') and is_op($sub->first, 'padsv')) { } 1 12 13
elsif (is_listop($sub, 'anonlist') or is_unop($sub, 'srefgen') and is_unop($sub->first, 'null') and is_listop($sub->first->first, 'anonlist')) { } 3 9 12
1068 6 my $ary = get_padlist_scalar($S, $sub->targ, "ref only");
1069 6 return in_list( $S, $sop, $ary);
1070 ▶ } elsif (is_unop($sub, "rv2av") && is_op($sub->first, "padsv")) {
Condition66%2/3
is_unop($sub, "rv2av") and is_op($sub->first, "padsv")
!ll&&!rl&&r
1201
MC/DC50%1/2
is_unop($sub, "rv2av") and is_op($sub->first, "padsv")
is_unop($sub, "rv2av") is_op($sub->first, "padsv")
Truth table66%2/3
A and B
A= is_unop($sub, "rv2av")B= is_op($sub->first, "padsv")
ABresult
0X0
100
111
1071 1 my $ary = get_padlist_scalar($S, $sub->first->targ, "ref only");
1072 1 ▶ return in_list( $S, $sop, ${ $ary // \[] });
Condition50%1/2
$ary // \[]
l!l
10
MC/DC0%0/1
$ary // \[]
$ary
Truth table50%1/2
A
A= $ary
Aresult
11
00
1073 ▶ } elsif (is_listop($sub, "anonlist") or
Condition44%4/9
is_listop($sub, "anonlist") or is_unop($sub, "srefgen") and is_unop($sub->first, "null") and is_listop($sub->first->first, "anonlist")
l!l&&r!l&&!r
309
is_unop($sub, "srefgen") and is_unop($sub->first, "null") and is_listop($sub->first->first, "anonlist")
!ll&&!rl&&r
900
is_unop($sub, "srefgen") and is_unop($sub->first, "null")
!ll&&!rl&&r
900
MC/DC25%1/4
is_listop($sub, "anonlist") or is_unop($sub, "srefgen") and is_unop($sub->first, "null") and is_listop($sub->first->first, "anonlist")
is_listop($sub, "anonlist") is_unop($sub, "srefgen") is_unop($sub->first, "null") is_listop($sub->first->first, "anonlist")
Truth table40%2/5
A or B and C and D
A= is_listop($sub, "anonlist")B= is_unop($sub, "srefgen")C= is_unop($sub->first, "null")D= is_listop($sub->first->first, "anonlist")
ABCDresult
1XXX1
01111
00XX0
010X0
01100
1074 is_unop($sub, "srefgen") &&
1075 is_unop($sub->first, "null") &&
1076 is_listop($sub->first->first, "anonlist"))
1077 {
1078 3 my @what;
1079 3 ▶ my $alist = is_listop($sub, "anonlist") ? $sub : $sub->first->first;
Branch: 1 branch
BranchTrueFalseTotal
is_listop($sub, 'anonlist') ? : 3 0 3
1080 3 for my $v (get_all_children($alist)) {
1081 12 ▶ next if is_pushmark_or_padrange($v);
Branch: 1 branch
BranchTrueFalseTotal
if is_pushmark_or_padrange($v) 3 9 12
1082 9 ▶ if (my ($const,$sv) = is_const($S, $v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = is_const($S, $v)) { } 7 2 9
1083 7 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($sv->isa('B::IV') and not $sv->isa('B::PVIV') or $sv->isa('B::NV') and not $sv->isa('B::PVNV')) { } 7 0 7
Condition22%2/9
$sv->isa("B::IV") and not $sv->isa("B::PVIV") or $sv->isa("B::NV") and not $sv->isa("B::PVNV")
l!l&&r!l&&!r
700
$sv->isa("B::IV") and not $sv->isa("B::PVIV")
!ll&&!rl&&r
007
$sv->isa("B::NV") and not $sv->isa("B::PVNV")
!ll&&!rl&&r
000
MC/DC0%0/4
$sv->isa("B::IV") and not $sv->isa("B::PVIV") or $sv->isa("B::NV") and not $sv->isa("B::PVNV")
$sv->isa("B::IV") not $sv->isa("B::PVIV") $sv->isa("B::NV") not $sv->isa("B::PVNV")
Truth table14%1/7
A and not(B) or C and not(D)
A= $sv->isa("B::IV")B= not $sv->isa("B::PVIV")C= $sv->isa("B::NV")D= not $sv->isa("B::PVNV")
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
1084 ($sv->isa("B::IV") && !$sv->isa("B::PVIV")) ||
1085 ($sv->isa("B::NV") && !$sv->isa("B::PVNV"))
1086 ) {
1087 7 push @what, \$const;
1088 } else {
1089 0 push @what, $const;
1090 }
1091 } else {
1092 2 my ($val, $ok) = get_value($S, $v);
1093 2 push @what, $val;
1094 }
1095 }
1096 3 return in_list($S, $sop, \@what);
1097 } else {
1098 9 my $codeop = try_get_subselect( $S, $sub);
1099 9 ▶ if ($codeop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($codeop) { } 5 4 9
1100 5 $sql = handle_subselect($S, $codeop);
1101 } else {
1102 4 $sql = try_parse_funcall($S, $sub);
1103 }
1104 7 ▶ bailout $S, "unsupported syntax in subselect" unless $sql;
Branch: 1 branch
BranchTrueFalseTotal
unless $sql 0 7 7
1105 }
1106  
1107 7 my $left = parse_term($S, $sop->first, not_after => 1);
1108 7 push @{$S->{values}}, @vals;
1109 7 return "$left in ($sql)";
1110 }
1111  
1112 sub handle_subselect
1113 {
1114 10 ▶ my ($S, $codeop, %p) = @_;
Subroutine handle_subselect: called CC=6 SCAR=18.1
Pod undocumented
1115  
1116 10 my $cv = $codeop->sv;
1117 10 ▶ if (!$$cv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$cv) 10 0 10
1118 10 $cv = $S->{padlist}->[1]->ARRAYelt($codeop->targ);
1119 }
1120 10 my $subref = $cv->object_2svref;
1121  
1122 10 my %gen_args = %{$S->{gen_args}};
1123 10 $gen_args{prev_S} = $S;
1124 10 ▶ if ($gen_args{prefix}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gen_args{'prefix'}) { } 0 10 10
1125 0 $gen_args{prefix} = "$gen_args{prefix}_$S->{subselect}";
1126 } else {
1127 10 $gen_args{prefix} = $S->{subselect};
1128 }
1129 10 $S->{subselect}++;
1130 10 my ($sql, $vals, $nret, %flags) = DBIx::Perlish::gen_sql($subref, "select",
1131 %gen_args);
1132 10 ▶ if ($nret != 1 && !$p{returns_dont_care} && !$flags{returns_dont_care}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nret != 1 and not $p{"returns_dont_care"} and not $flags{"returns_dont_care"}) 2 8 10
Condition83%5/6
$nret != 1 and not $p{"returns_dont_care"} and not $flags{"returns_dont_care"}
!ll&&!rl&&r
802
$nret != 1 and not $p{"returns_dont_care"}
!ll&&!rl&&r
352
MC/DC66%2/3
$nret != 1 and not $p{"returns_dont_care"} and not $flags{"returns_dont_care"}
$nret != 1 not $p{"returns_dont_care"} not $flags{"returns_dont_care"}
Truth table75%3/4
A and not(B) and not(C)
A= $nret != 1B= not $p{"returns_dont_care"}C= not $flags{"returns_dont_care"}
ABCresult
0XX0
10X0
1100
1111
1133 2 bailout $S, "subselect query sub must return exactly one value\n";
1134 }
1135  
1136 8 push @{$S->{values}}, @$vals;
1137 8 return $sql;
1138 }
1139  
1140 sub parse_assign
1141 {
1142 27 ▶ my ($S, $op) = @_;
Subroutine parse_assign: called CC=17 SCAR=29.2
Pod undocumented
1143 27 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($op->name eq "sassign" and is_listop($op->last, "list") and is_pushmark_or_padrange($op->last->first) and is_unop($op->last->first->sibling, "entersub")) 12 15 27
Condition77%7/9
$op->name eq "sassign" and is_listop($op->last, "list") and is_pushmark_or_padrange($op->last->first) and is_unop($op->last->first->sibling, "entersub")
!ll&&!rl&&r
15012
$op->name eq "sassign" and is_listop($op->last, "list") and is_pushmark_or_padrange($op->last->first)
!ll&&!rl&&r
15012
$op->name eq "sassign" and is_listop($op->last, "list")
!ll&&!rl&&r
41112
MC/DC50%2/4
$op->name eq "sassign" and is_listop($op->last, "list") and is_pushmark_or_padrange($op->last->first) and is_unop($op->last->first->sibling, "entersub")
$op->name eq "sassign" is_listop($op->last, "list") is_pushmark_or_padrange($op->last->first) is_unop($op->last->first->sibling, "entersub")
Truth table60%3/5
A and B and C and D
A= $op->name eq "sassign"B= is_listop($op->last, "list")C= is_pushmark_or_padrange($op->last->first)D= is_unop($op->last->first->sibling, "entersub")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1144 $op->name eq 'sassign' &&
1145 is_listop($op->last, "list") &&
1146 is_pushmark_or_padrange($op->last->first) &&
1147 is_unop($op->last->first->sibling, "entersub"))
1148 {
1149 12 my ($val, $ok) = get_value($S, $op->first, soft => 1);
1150 12 ▶ if ($ok) {
Branch: 4 branches
BranchTrueFalseTotal
if ($ok) { } 6 6 12
elsif ($val = is_const($S, $op->first)) { } 1 5 6
elsif (my $codeop = try_get_subselect($S, $op->first)) { } 3 2 5
elsif (is_unop($op->first, 'entersub') and my $sql = try_parse_funcall($S, $op->first, 'select', 0)) { } 2 0 2
1151 6 my $tab = try_parse_attr_assignment($S,
1152 $op->last->first->sibling, $val);
1153 6 ▶ return if $tab;
Branch: 1 branch
BranchTrueFalseTotal
if $tab 6 0 6
1154 } elsif ($val = is_const($S, $op->first)) {
1155 1 my $tab = try_parse_attr_assignment($S,
1156 $op->last->first->sibling, $val);
1157 1 ▶ return if $tab;
Branch: 1 branch
BranchTrueFalseTotal
if $tab 1 0 1
1158 } elsif (my $codeop = try_get_subselect($S, $op->first)) {
1159 3 my $sql = handle_subselect($S, $codeop, returns_dont_care => 1);
1160 3 my $tab = try_parse_attr_assignment($S,
1161 $op->last->first->sibling, "($sql)");
1162 3 ▶ return if $tab;
Branch: 1 branch
BranchTrueFalseTotal
if $tab 3 0 3
1163 ▶ } elsif (
Condition33%1/3
is_unop($op->first, "entersub") and my $sql = try_parse_funcall($S, $op->first, "select", 0)
!ll&&!rl&&r
002
MC/DC0%0/2
is_unop($op->first, "entersub") and my $sql = try_parse_funcall($S, $op->first, "select", 0)
is_unop($op->first, "entersub") my $sql = try_parse_funcall($S, $op->first, "select", 0)
Truth table33%1/3
A and B
A= is_unop($op->first, "entersub")B= my $sql = try_parse_funcall($S, $op->first, "select", 0)
ABresult
0X0
100
111
1164 is_unop( $op->first, "entersub")
1165 && ( my $sql = try_parse_funcall($S, $op->first, select => 0))
1166 ) {
1167 # my $p : table = function(1,2,3);
1168 2 my $tab = try_parse_attr_assignment($S,
1169 $op->last->first->sibling, $sql);
1170 2 ▶ if ( $tab ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tab) 2 0 2
1171 2 my $alias = $S->{var_alias}->{$tab};
1172 2 $S->{returns_dont_care}->{$alias} = 1;
1173 2 return;
1174 }
1175 }
1176 }
1177 bailout $S, "assignments are not understood in $S->{operation}'s query sub"
1178 15 ▶ unless $S->{operation} eq "update";
Branch: 1 branch
BranchTrueFalseTotal
unless $S->{"operation"} eq "update" 2 13 15
1179 13 ▶ if (is_unop($op->first, "srefgen") || is_listop($op->first, "anonhash")) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_unop($op->first, 'srefgen') or is_listop($op->first, 'anonhash')) { } 6 7 13
Condition66%2/3
is_unop($op->first, "srefgen") or is_listop($op->first, "anonhash")
l!l&&r!l&&!r
067
MC/DC50%1/2
is_unop($op->first, "srefgen") or is_listop($op->first, "anonhash")
is_unop($op->first, "srefgen") is_listop($op->first, "anonhash")
Truth table66%2/3
A or B
A= is_unop($op->first, "srefgen")B= is_listop($op->first, "anonhash")
ABresult
1X1
011
000
1180 6 parse_multi_assign($S, $op);
1181 } else {
1182 7 parse_simple_assign($S, $op);
1183 }
1184 }
1185  
1186 sub parse_simple_assign
1187 {
1188 7 ▶ my ($S, $op) = @_;
Subroutine parse_simple_assign: called CC=1 SCAR=0.0
Pod undocumented
1189  
1190 7 my ($tab, $f) = get_tab_field($S, $op->last, lvalue => 1);
1191 7 my $saved_values = $S->{values};
1192 7 $S->{values} = [];
1193 7 my $set = parse_term($S, $op->first);
1194 7 push @{$S->{set_values}}, @{$S->{values}};
1195 7 $S->{values} = $saved_values;
1196 7 push @{$S->{sets}}, "$f = $set";
1197 }
1198  
1199 sub callarg
1200 {
1201 1175 ▶ my ($S, $op) = @_;
Subroutine callarg: called CC=5 SCAR=16.6
Pod undocumented
1202 1175 ▶ $op = $op->first if is_unop($op, "null");
Branch: 1 branch
BranchTrueFalseTotal
if is_unop($op, "null") 41 1134 1175
1203 1175 ▶ $op = $op->sibling if !is_null($op) && is_op($op, "null");
Branch: 1 branch
BranchTrueFalseTotal
if not is_null($op) and is_op($op, "null") 0 1175 1175
Condition33%1/3
not is_null($op) and is_op($op, "null")
!ll&&!rl&&r
011750
MC/DC0%0/2
not is_null($op) and is_op($op, "null")
not is_null($op) is_op($op, "null")
Truth table33%1/3
not(A) and B
A= not is_null($op)B= is_op($op, "null")
ABresult
0X0
100
111
1204 1175 ▶ return () if is_pushmark_or_padrange($op);
Branch: 1 branch
BranchTrueFalseTotal
if is_pushmark_or_padrange($op) 390 785 1175
1205 785 return $op;
1206 }
1207  
1208 sub get_codeop
1209 {
1210 11 ▶ my $op = shift;
Subroutine get_codeop: called CC=7 SCAR=28.2
Pod undocumented
1211 11 my $codeop;
1212 11 ▶ if ( $] < 5.037 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < 5.037) { } 0 11 11
1213 0 my $rg = $op;
1214 0 ▶ return unless is_unop($rg, "refgen") || is_unop($rg, "srefgen");
Branch: 1 branch
BranchTrueFalseTotal
unless is_unop($rg, "refgen") or is_unop($rg, "srefgen") 0 0 0
Condition0%0/3
is_unop($rg, "refgen") or is_unop($rg, "srefgen")
l!l&&r!l&&!r
000
MC/DC0%0/2
is_unop($rg, "refgen") or is_unop($rg, "srefgen")
is_unop($rg, "refgen") is_unop($rg, "srefgen")
Truth table0%0/3
A or B
A= is_unop($rg, "refgen")B= is_unop($rg, "srefgen")
ABresult
1X1
011
000
1215 0 ▶ $rg = $rg->first if is_unop($rg->first, "null");
Branch: 1 branch
BranchTrueFalseTotal
if is_unop($rg->first, "null") 0 0 0
1216 0 $codeop = $rg->first;
1217 } else {
1218 11 $codeop = $op;
1219 }
1220 11 ▶ $codeop = $codeop->sibling if is_pushmark_or_padrange($codeop);
Branch: 1 branch
BranchTrueFalseTotal
if is_pushmark_or_padrange($codeop) 0 11 11
1221 11 ▶ return unless is_svop($codeop, "anoncode");
Branch: 1 branch
BranchTrueFalseTotal
unless is_svop($codeop, "anoncode") 0 11 11
1222 11 return $codeop;
1223 }
1224  
1225 sub try_funcall
1226 {
1227 390 ▶ my ($S, $op, %p) = @_;
Subroutine try_funcall: called CC=47 SCAR=40.2
Pod undocumented
1228 390 my @args;
1229 390 ▶ if (is_unop($op, "entersub")) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_unop($op, "entersub")) 390 0 390
1230 390 $op = $op->first;
1231 390 ▶ $op = $op->first if is_unop($op, "null");
Branch: 1 branch
BranchTrueFalseTotal
if is_unop($op, "null") 41 349 390
1232 390 while (1) {
1233 1565 ▶ last if is_null($op);
Branch: 1 branch
BranchTrueFalseTotal
if is_null($op) 390 1175 1565
1234 1175 push @args, callarg($S, $op);
1235 1175 $op = $op->sibling;
1236 }
1237 390 ▶ return unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 390 390
1238 390 $op = pop @args;
1239 390 ▶ return unless is_svop($op, "gv") || is_padop($op, "gv");
Branch: 1 branch
BranchTrueFalseTotal
unless is_svop($op, "gv") or is_padop($op, "gv") 349 41 390
Condition66%2/3
is_svop($op, "gv") or is_padop($op, "gv")
l!l&&r!l&&!r
410349
MC/DC50%1/2
is_svop($op, "gv") or is_padop($op, "gv")
is_svop($op, "gv") is_padop($op, "gv")
Truth table66%2/3
A or B
A= is_svop($op, "gv")B= is_padop($op, "gv")
ABresult
1X1
011
000
1240 41 my $func = get_gv_name( $S, $op);
1241 41 ▶ return unless defined $func;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $func 0 41 41
1242 41 ▶ ${$p{func_name_return}} = $func if $p{func_name_return};
Branch: 1 branch
BranchTrueFalseTotal
if $p{"func_name_return"} 6 35 41
1243 41 ▶ if ($func =~ /^(union|intersect|except)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($func =~ /^(union|intersect|except)$/u) 9 32 41
1244 9 ▶ return if $p{only_normal_funcs};
Branch: 1 branch
BranchTrueFalseTotal
if $p{"only_normal_funcs"} 0 9 9
1245 9 ▶ return unless @args == 1 || @args == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 or @args == 2 0 9 9
Condition66%2/3
@args == 1 or @args == 2
l!l&&r!l&&!r
720
MC/DC0%0/2
@args == 1 or @args == 2
@args == 1 @args == 2
Truth table66%2/3
A or B
A= @args == 1B= @args == 2
ABresult
1X1
011
000
1246 9 ▶ my $codeop = get_codeop($args[0]) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $codeop = get_codeop($args[0]) or return 0 9 9
1247 9 ▶ return unless $S->{operation} eq "select";
Branch: 1 branch
BranchTrueFalseTotal
unless $S->{"operation"} eq "select" 0 9 9
1248 9 my $cv = $codeop->sv;
1249 9 ▶ if (!$$cv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$cv) 9 0 9
1250 9 $cv = $S->{padlist}->[1]->ARRAYelt($codeop->targ);
1251 }
1252 9 my $subref = $cv->object_2svref;
1253 9 my %gen_args = %{$S->{gen_args}};
1254 9 $gen_args{prev_S} = $S; # XXX maybe different key than prevS?
1255 9 my ($sql, $vals, $nret) = DBIx::Perlish::gen_sql($subref, "select",
1256 %gen_args);
1257 # XXX maybe check for nret validity
1258 9 ▶ push @{$S->{additions}}, {
Branch: 1 branch
BranchTrueFalseTotal
($S->{'gen_args'}{'flavor'} || '') eq 'oracle' && $func eq 'except' ? : 0 9 9
Condition40%2/5
($S->{"gen_args"}{"flavor"} || "") eq "oracle" and $func eq "except"
!ll&&!rl&&r
900
$S->{'gen_args'}{'flavor'} || ''
l!l
90
MC/DC0%0/2
($S->{"gen_args"}{"flavor"} || "") eq "oracle" and $func eq "except"
$S->{'gen_args'}{'flavor'} $func eq "except"
Truth table0%0/3
A and B
A= $S->{'gen_args'}{'flavor'}B= $func eq "except"
ABresult
0X0
100
111
1259 9 type => ((($S->{gen_args}->{flavor}||"") eq "oracle" && $func eq 'except') ?
1260 'minus' : $func),
1261 sql => $sql,
1262 vals => $vals,
1263 };
1264 9 ▶ if (@args > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args > 1) 2 7 9
1265 # must be another union|intersect|except
1266 2 my $r = try_funcall($S, $args[1], union_or_friends => $func);
1267 # something went wrong if it is not ""
1268 1 ▶ return unless defined $r && $r eq "";
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r and $r eq "" 0 1 1
Condition33%1/3
defined $r and $r eq ""
!ll&&!rl&&r
001
MC/DC0%0/2
defined $r and $r eq ""
defined $r $r eq ""
Truth table33%1/3
A and B
A= defined $rB= $r eq ""
ABresult
0X0
100
111
1269 }
1270 8 return "";
1271 }
1272 32 ▶ if ($p{union_or_friends}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"union_or_friends"}) 1 31 32
1273 1 bailout $S, "missing semicolon after $p{union_or_friends} sub";
1274 }
1275 31 ▶ if ($func eq 'subselect') {
Branch: 2 branches
BranchTrueFalseTotal
if ($func eq 'subselect') { } 2 29 31
elsif ($func eq 'sql') { } 6 23 29
1276 2 ▶ return if $p{only_normal_funcs};
Branch: 1 branch
BranchTrueFalseTotal
if $p{"only_normal_funcs"} 0 2 2
1277 2 ▶ return unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 2 2
1278 2 ▶ my $codeop = get_codeop($args[0]) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $codeop = get_codeop($args[0]) or return 0 2 2
1279 2 my $sql = handle_subselect($S, $codeop, returns_dont_care => 1);
1280 2 return "exists ($sql)";
1281 } elsif ($func eq "sql") {
1282 6 ▶ return if $p{only_normal_funcs};
Branch: 1 branch
BranchTrueFalseTotal
if $p{"only_normal_funcs"} 0 6 6
1283 6 ▶ return unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 6 6
1284 # XXX understand more complex expressions here
1285 6 my $sql;
1286 6 ▶ return unless $sql = parse_simple_eval($S, $args[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless $sql = parse_simple_eval($S, $args[0]) 0 6 6
1287 6 return $sql;
1288 }
1289 23 ▶ if ($S->{parsing_return} && $S->{aggregates}{lc $func}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{"parsing_return"} and $S->{"aggregates"}{lc $func}) 4 19 23
Condition100%3/3
$S->{"parsing_return"} and $S->{"aggregates"}{lc $func}
!ll&&!rl&&r
1094
MC/DC100%2/2
$S->{"parsing_return"} and $S->{"aggregates"}{lc $func}
$S->{"parsing_return"} $S->{"aggregates"}{lc $func}
Truth table100%3/3
A and B
A= $S->{"parsing_return"}B= $S->{"aggregates"}{lc $func}
ABresult
0X0
100
111
1290 4 $S->{autogroup_needed} = 1;
1291 4 $S->{inside_aggregate} = 1;
1292 }
1293 23 ▶ if (!$S->{parsing_return} && $S->{aggregates}{lc $func}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $S->{"parsing_return"} and $S->{"aggregates"}{lc $func}) 1 22 23
Condition100%3/3
not $S->{"parsing_return"} and $S->{"aggregates"}{lc $func}
!ll&&!rl&&r
1391
MC/DC100%2/2
not $S->{"parsing_return"} and $S->{"aggregates"}{lc $func}
not $S->{"parsing_return"} $S->{"aggregates"}{lc $func}
Truth table100%3/3
not(A) and B
A= not $S->{"parsing_return"}B= $S->{"aggregates"}{lc $func}
ABresult
0X0
100
111
1294 1 $S->{this_is_having} = 1;
1295 1 $S->{autogroup_needed} = 1;
1296 }
1297  
1298 23 my @terms = map { scalar parse_term($S, $_) } @args;
1299  
1300 23 ▶ if ($S->{parsing_return} && $S->{aggregates}{lc $func}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{"parsing_return"} and $S->{"aggregates"}{lc $func}) 4 19 23
Condition100%3/3
$S->{"parsing_return"} and $S->{"aggregates"}{lc $func}
!ll&&!rl&&r
1094
MC/DC100%2/2
$S->{"parsing_return"} and $S->{"aggregates"}{lc $func}
$S->{"parsing_return"} $S->{"aggregates"}{lc $func}
Truth table100%3/3
A and B
A= $S->{"parsing_return"}B= $S->{"aggregates"}{lc $func}
ABresult
0X0
100
111
1301 4 $S->{inside_aggregate} = 0;
1302 }
1303  
1304 return "sysdate"
1305 23 ▶ if ($S->{gen_args}->{flavor}||"") eq "oracle" &&
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{"gen_args"}{"flavor"} || "") eq "oracle" and lc $func eq "sysdate" and not @terms 1 22 23
Condition75%6/8
($S->{"gen_args"}{"flavor"} || "") eq "oracle" and lc $func eq "sysdate" and not @terms
!ll&&!rl&&r
2201
($S->{"gen_args"}{"flavor"} || "") eq "oracle" and lc $func eq "sysdate"
!ll&&!rl&&r
1931
$S->{'gen_args'}{'flavor'} || ''
l!l
230
MC/DC33%1/3
($S->{"gen_args"}{"flavor"} || "") eq "oracle" and lc $func eq "sysdate" and not @terms
$S->{'gen_args'}{'flavor'} lc $func eq "sysdate" not @terms
Truth table50%2/4
A and B and not(C)
A= $S->{'gen_args'}{'flavor'}B= lc $func eq "sysdate"C= not @terms
ABCresult
0XX0
10X0
1100
1111
1306 lc $func eq "sysdate" && !@terms;
1307 22 ▶ if (lc $func eq "extract" && @terms == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $func eq "extract" and @terms == 2) 3 19 22
Condition100%3/3
lc $func eq "extract" and @terms == 2
!ll&&!rl&&r
1633
MC/DC100%2/2
lc $func eq "extract" and @terms == 2
lc $func eq "extract" @terms == 2
Truth table100%3/3
A and B
A= lc $func eq "extract"B= @terms == 2
ABresult
0X0
100
111
1308 3 ▶ if (UNIVERSAL::isa($terms[0], "DBIx::Perlish::Placeholder")) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($terms[0], "DBIx::Perlish::Placeholder")) 2 1 3
1309 2 my $val = $terms[0]->undo;
1310 2 @terms = ("$val from $terms[1]");
1311 }
1312 }
1313 22 ▶ if (lc($func) eq 'cast' && @terms == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $func eq "cast" and @terms == 2) 2 20 22
Condition66%2/3
lc $func eq "cast" and @terms == 2
!ll&&!rl&&r
2002
MC/DC50%1/2
lc $func eq "cast" and @terms == 2
lc $func eq "cast" @terms == 2
Truth table66%2/3
A and B
A= lc $func eq "cast"B= @terms == 2
ABresult
0X0
100
111
1314 2 ▶ $terms[1] = $terms[1]->undo if UNIVERSAL::isa($terms[1], "DBIx::Perlish::Placeholder");
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($terms[1], "DBIx::Perlish::Placeholder") 2 0 2
1315 2 return "cast($terms[0] as $terms[1])";
1316 }
1317 20 return "$func(" . join(", ", @terms) . ")";
1318 }
1319 }
1320  
1321 sub parse_multi_assign
1322 {
1323 6 ▶ my ($S, $op) = @_;
Subroutine parse_multi_assign: called CC=20 SCAR=32.7
Pod undocumented
1324  
1325 6 my $hashop = $op->first;
1326 6 ▶ unless (is_listop($hashop, "anonhash")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_listop($hashop, "anonhash")) 0 6 6
1327 0 want_unop($S, $hashop, "srefgen");
1328 0 $hashop = $hashop->first;
1329 0 ▶ $hashop = $hashop->first while is_unop($hashop, "null");
Branch: 1 branch
BranchTrueFalseTotal
is_unop($hashop, "null") and do { $hashop = $hashop->first } 0 0 0
1330 }
1331 6 want_listop($S, $hashop, "anonhash");
1332  
1333 6 my $saved_values = $S->{values};
1334 6 $S->{values} = [];
1335  
1336 6 my $want_const = 1;
1337 6 my $field;
1338 6 for my $c (get_all_children($hashop)) {
1339 22 ▶ next if is_pushmark_or_padrange($c);
Branch: 1 branch
BranchTrueFalseTotal
if is_pushmark_or_padrange($c) 6 16 22
1340  
1341 16 ▶ if ($want_const) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_const) { } 10 6 16
1342 10 my $hash;
1343 10 ▶ if (is_op($c, "padhv")) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_op($c, 'padhv')) { } 2 8 10
elsif (is_unop($c, 'rv2hv') and is_op($c->first, 'padsv')) { } 2 12 14
1344 2 $hash = $S->{padlist}->[1]->ARRAYelt($c->targ)->object_2svref;
1345 ▶ } elsif (is_unop($c, "rv2hv") && is_op($c->first, "padsv")) {
Condition66%2/3
is_unop($c, "rv2hv") and is_op($c->first, "padsv")
!ll&&!rl&&r
602
MC/DC50%1/2
is_unop($c, "rv2hv") and is_op($c->first, "padsv")
is_unop($c, "rv2hv") is_op($c->first, "padsv")
Truth table66%2/3
A and B
A= is_unop($c, "rv2hv")B= is_op($c->first, "padsv")
ABresult
0X0
100
111
1346 2 $hash = $S->{padlist}->[1]->ARRAYelt($c->first->targ)->object_2svref;
1347 2 $hash = $$hash;
1348 }
1349 10 ▶ if ($hash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash) { } 4 6 10
1350 4 ▶ while (my ($k, $v) = each %$hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$hash) 8 4 12
1351 8 push @{$S->{set_values}}, $v;
1352 8 push @{$S->{sets}}, "$k = ?";
1353 }
1354 } else {
1355 6 $field = want_const($S, $c);
1356 6 $want_const = 0;
1357 }
1358 } else {
1359 6 my $set = parse_term($S, $c);
1360 6 push @{$S->{set_values}}, @{$S->{values}};
1361 6 push @{$S->{sets}}, "$field = $set";
1362 6 $S->{values} = [];
1363 6 $want_const = 1;
1364 6 $field = undef;
1365 }
1366 }
1367  
1368 6 $S->{values} = $saved_values;
1369 6 ▶ if ( !is_unop($op, 'padsv_store')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_unop($op, "padsv_store")) 2 4 6
1370 2 $op = $op->last;
1371 }
1372  
1373 6 my $tab;
1374 6 ▶ if (is_op($op, "padsv") || is_unop($op, "padsv_store")) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_op($op, 'padsv') or is_unop($op, 'padsv_store')) { } 5 1 6
elsif (is_unop($op, 'entersub')) { } 0 1 1
Condition100%3/3
is_op($op, "padsv") or is_unop($op, "padsv_store")
l!l&&r!l&&!r
141
MC/DC100%2/2
is_op($op, "padsv") or is_unop($op, "padsv_store")
is_op($op, "padsv") is_unop($op, "padsv_store")
Truth table100%3/3
A or B
A= is_op($op, "padsv")B= is_unop($op, "padsv_store")
ABresult
1X1
011
000
1375 5 my $var = get_var($S, $op);
1376 5 $tab = $S->{vars}{$var};
1377 } elsif (is_unop($op, "entersub")) {
1378 0 $op = $op->first;
1379 0 ▶ $op = $op->first if is_unop($op, "null");
Branch: 1 branch
BranchTrueFalseTotal
if is_unop($op, "null") 0 0 0
1380 0 ▶ $op = $op->sibling if is_pushmark_or_padrange($op);
Branch: 1 branch
BranchTrueFalseTotal
if is_pushmark_or_padrange($op) 0 0 0
1381 0 ▶ $op = $op->first if is_unop($op, "rv2cv");
Branch: 1 branch
BranchTrueFalseTotal
if is_unop($op, "rv2cv") 0 0 0
1382 0 my $gv = get_gv_name($S, $op);
1383 0 ▶ $tab = $gv if defined $gv;
Branch: 1 branch
BranchTrueFalseTotal
if defined $gv 0 0 0
1384 }
1385 6 ▶ bailout $S, "cannot get a table to update" unless $tab;
Branch: 1 branch
BranchTrueFalseTotal
unless $tab 2 4 6
1386 }
1387  
1388 25 my %binop_map = (
1389 eq => "=",
1390 seq => "=",
1391 ne => "<>",
1392 sne => "<>",
1393 slt => "<",
1394 gt => ">",
1395 sgt => ">",
1396 le => "<=",
1397 sle => "<=",
1398 ge => ">=",
1399 sge => ">=",
1400 add => "+",
1401 subtract => "-",
1402 multiply => "*",
1403 divide => "/",
1404 concat => "||",
1405 pow => "^",
1406 );
1407 25 my %binop2_map = (
1408 add => "+",
1409 subtract => "-",
1410 multiply => "*",
1411 divide => "/",
1412 concat => "||",
1413 multiconcat => "||",
1414 pow => "^",
1415 );
1416  
1417 sub parse_expr
1418 {
1419 240 ▶ my ($S, $op) = @_;
Subroutine parse_expr: called CC=34 SCAR=39.9
Pod undocumented
1420 240 my $sqlop;
1421 240 ▶ if (($op->flags & B::OPf_STACKED) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($op->flags & 64 and not $S->{"parsing_return"} and $binop2_map{$op->name} and is_unop($op->first, "entersub")) 11 229 240
Condition77%7/9
$op->flags & 64 and not $S->{"parsing_return"} and $binop2_map{$op->name} and is_unop($op->first, "entersub")
!ll&&!rl&&r
229011
$op->flags & 64 and not $S->{"parsing_return"} and $binop2_map{$op->name}
!ll&&!rl&&r
2022711
$op->flags & 64 and not $S->{"parsing_return"}
!ll&&!rl&&r
202038
MC/DC50%2/4
$op->flags & 64 and not $S->{"parsing_return"} and $binop2_map{$op->name} and is_unop($op->first, "entersub")
$op->flags & 64 not $S->{"parsing_return"} $binop2_map{$op->name} is_unop($op->first, "entersub")
Truth table60%3/5
A and not(B) and C and D
A= $op->flags & 64B= not $S->{"parsing_return"}C= $binop2_map{$op->name}D= is_unop($op->first, "entersub")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1422 !$S->{parsing_return} &&
1423 $binop2_map{$op->name} &&
1424 is_unop($op->first, "entersub"))
1425 {
1426 #printf STDERR "entersub flags: %08x\n", $op->first->flags;
1427 #printf STDERR "entersub private flags: %08x\n", $op->first->private;
1428 11 my $is_lvalue;
1429 11 ▶ if ($op->first->private & 128) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->first->private & 128) { } 11 0 11
1430 11 $is_lvalue = 1;
1431 } else {
1432 0 my $lc = $op->first->first;
1433 0 ▶ $lc = $lc->sibling until is_null($lc->sibling);
Branch: 1 branch
BranchTrueFalseTotal
is_null($lc->sibling) or do { $lc = $lc->sibling } 0 0 0
1434 0 $is_lvalue = is_unop($lc, "rv2cv");
1435 }
1436 11 ▶ if ($is_lvalue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_lvalue) 11 0 11
1437 11 my ($tab, $f) = get_tab_field($S, $op->first, lvalue => 1);
1438 bailout $S, "self-modifications are not understood in $S->{operation}'s query sub"
1439 11 ▶ unless $S->{operation} eq "update";
Branch: 1 branch
BranchTrueFalseTotal
unless $S->{"operation"} eq "update" 1 10 11
1440 bailout $S, "self-modifications inside an expression is illegal"
1441 10 ▶ if $S->{in_term};
Branch: 1 branch
BranchTrueFalseTotal
if $S->{"in_term"} 1 9 10
1442 9 my $saved_values = $S->{values};
1443 9 $S->{values} = [];
1444 9 my $set;
1445 9 ▶ if ( is_unop_aux($op, 'multiconcat')) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_unop_aux($op, 'multiconcat')) { } 1 8 9
1446 1 my $v;
1447 1 ($set, $v) = try_special_concat($S, $op, multiconcat => { skip_first => 1 });
1448 1 ▶ bailout $S, "unsupported multiconcat" unless $set;
Branch: 1 branch
BranchTrueFalseTotal
unless $set 0 1 1
1449 1 push @{$S->{values}}, @$v;
1450 } else {
1451 8 $set = parse_term($S, $op->last);
1452 }
1453 9 push @{$S->{set_values}}, @{$S->{values}};
1454 9 $S->{values} = $saved_values;
1455 9 ▶ if ($op->name eq "pow") {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->name eq 'pow') { } 0 9 9
1456 0 ▶ my $flavor = lc($S->{gen_args}->{flavor} || '');
Condition0%0/2
$S->{'gen_args'}{'flavor'} || ''
l!l
00
MC/DC0%0/1
$S->{'gen_args'}{'flavor'} || ''
$S->{'gen_args'}{'flavor'}
Truth table0%0/2
A
A= $S->{'gen_args'}{'flavor'}
Aresult
11
00
1457 0 ▶ if ($flavor eq "pg" || $flavor eq "pglite") {
Branch: 1 branch
BranchTrueFalseTotal
if ($flavor eq 'pg' or $flavor eq 'pglite') { } 0 0 0
Condition0%0/3
$flavor eq "pg" or $flavor eq "pglite"
l!l&&r!l&&!r
000
MC/DC0%0/2
$flavor eq "pg" or $flavor eq "pglite"
$flavor eq "pg" $flavor eq "pglite"
Truth table0%0/3
A or B
A= $flavor eq "pg"B= $flavor eq "pglite"
ABresult
1X1
011
000
1458 0 push @{$S->{sets}}, "$f = pow($f, $set)";
1459 } else {
1460 0 bailout $S, "exponentiation is not supported for $flavor DB driver";
1461 }
1462 } else {
1463 9 push @{$S->{sets}}, "$f = $f $binop2_map{$op->name} $set";
1464 }
1465 9 return ();
1466 }
1467 }
1468 229 ▶ if (is_binop($op, "concat") || is_unop_aux($op, "multiconcat")) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_binop($op, "concat") or is_unop_aux($op, "multiconcat")) 0 229 229
Condition33%1/3
is_binop($op, "concat") or is_unop_aux($op, "multiconcat")
l!l&&r!l&&!r
00229
MC/DC0%0/2
is_binop($op, "concat") or is_unop_aux($op, "multiconcat")
is_binop($op, "concat") is_unop_aux($op, "multiconcat")
Truth table33%1/3
A or B
A= is_binop($op, "concat")B= is_unop_aux($op, "multiconcat")
ABresult
1X1
011
000
1469 0 my ($c, $v) = try_special_concat($S, $op);
1470 0 ▶ if ($c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c) 0 0 0
1471 0 push @{$S->{values}}, @$v;
1472 0 return $c;
1473 }
1474 }
1475 229 ▶ if ($sqlop = $binop_map{$op->name}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($sqlop = $binop_map{$op->name}) { } 177 52 229
elsif ($op->name eq 'lt') { } 24 28 52
elsif ($op->name eq 'sassign' or $op->name eq 'padsv_store') { } 27 1 28
1476 177 my $left = parse_term($S, $op->first);
1477 176 my $right = parse_term($S, $op->last);
1478 175 ▶ if ($sqlop eq "=" || $sqlop eq "<>") {
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlop eq "=" or $sqlop eq "<>") 148 27 175
Condition100%3/3
$sqlop eq "=" or $sqlop eq "<>"
l!l&&r!l&&!r
140827
MC/DC100%2/2
$sqlop eq "=" or $sqlop eq "<>"
$sqlop eq "=" $sqlop eq "<>"
Truth table100%3/3
A or B
A= $sqlop eq "="B= $sqlop eq "<>"
ABresult
1X1
011
000
1479 148 ▶ my $not = $sqlop eq "<>" ? " not" : "";
Branch: 1 branch
BranchTrueFalseTotal
$sqlop eq '<>' ? : 8 140 148
1480 148 ▶ if ($right eq "null") {
Branch: 2 branches
BranchTrueFalseTotal
if ($right eq 'null') { } 4 144 148
elsif ($left eq 'null') { } 4 140 144
1481 4 return "$left is$not null";
1482 } elsif ($left eq "null") {
1483 4 return "$right is$not null";
1484 }
1485 }
1486 167 ▶ if ($op->name eq "pow") {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->name eq "pow") 2 165 167
1487 2 ▶ my $flavor = lc($S->{gen_args}->{flavor} || '');
Condition50%1/2
$S->{'gen_args'}{'flavor'} || ''
l!l
20
MC/DC0%0/1
$S->{'gen_args'}{'flavor'} || ''
$S->{'gen_args'}{'flavor'}
Truth table50%1/2
A
A= $S->{'gen_args'}{'flavor'}
Aresult
11
00
1488 2 ▶ if ($flavor eq "pg" || $flavor eq "pglite") {
Branch: 1 branch
BranchTrueFalseTotal
if ($flavor eq 'pg' or $flavor eq 'pglite') { } 1 1 2
Condition66%2/3
$flavor eq "pg" or $flavor eq "pglite"
l!l&&r!l&&!r
101
MC/DC50%1/2
$flavor eq "pg" or $flavor eq "pglite"
$flavor eq "pg" $flavor eq "pglite"
Truth table66%2/3
A or B
A= $flavor eq "pg"B= $flavor eq "pglite"
ABresult
1X1
011
000
1489 1 return "pow($left, $right)";
1490 } else {
1491 1 bailout $S, "exponentiation is not supported for $flavor DB driver";
1492 }
1493 }
1494 165 return "$left $sqlop $right";
1495 } elsif ($op->name eq "lt") {
1496 24 ▶ if (is_unop($op->last, "negate")) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_unop($op->last, "negate")) 19 5 24
1497 19 my $r = try_parse_subselect($S, $op);
1498 17 ▶ return $r if $r;
Branch: 1 branch
BranchTrueFalseTotal
if $r 17 0 17
1499 }
1500 # if the "subselect theory" fails, try a normal binop
1501 5 my $left = parse_term($S, $op->first);
1502 5 my $right = parse_term($S, $op->last);
1503 5 return "$left < $right";
1504 ▶ } elsif ($op->name eq "sassign" || $op->name eq 'padsv_store') {
Condition100%3/3
$op->name eq "sassign" or $op->name eq "padsv_store"
l!l&&r!l&&!r
2341
MC/DC100%2/2
$op->name eq "sassign" or $op->name eq "padsv_store"
$op->name eq "sassign" $op->name eq "padsv_store"
Truth table100%3/3
A or B
A= $op->name eq "sassign"B= $op->name eq "padsv_store"
ABresult
1X1
011
000
1505 27 parse_assign($S, $op);
1506 23 return ();
1507 } else {
1508 1 BAILOUT:
1509 bailout $S, "unsupported binop " . $op->name;
1510 }
1511 }
1512  
1513 sub parse_multiconcat
1514 {
1515 17 ▶ my ( $S, $aux, %opt) = @_;
Subroutine parse_multiconcat: called CC=11 SCAR=24.0
Pod undocumented
1516 17 my @concats;
1517  
1518 17 my @args = ($aux->first);
1519 17 ▶ push @args, $args[-1]->sibling while !is_null($args[-1]) && !is_null($args[-1]->sibling);
Branch: 1 branch
BranchTrueFalseTotal
is_null($args[-1]) or is_null($args[-1]->sibling) or do { push @args, $args[-1]->sibling } 29 17 46
Condition66%2/3
is_null($args[-1]) or is_null($args[-1]->sibling)
l!l&&r!l&&!r
01729
MC/DC50%1/2
is_null($args[-1]) or is_null($args[-1]->sibling)
is_null($args[-1]) is_null($args[-1]->sibling)
Truth table66%2/3
A or B
A= is_null($args[-1])B= is_null($args[-1]->sibling)
ABresult
1X1
011
000
1520 17 ▶ shift @args while @args && is_op($args[0], 'null');
Branch: 1 branch
BranchTrueFalseTotal
@args and is_op($args[0], "null") and do { shift @args } 23 17 40
Condition66%2/3
@args and is_op($args[0], "null")
!ll&&!rl&&r
01723
MC/DC50%1/2
@args and is_op($args[0], "null")
@args is_op($args[0], "null")
Truth table66%2/3
A and B
A= @argsB= is_op($args[0], "null")
ABresult
0X0
100
111
1521 17 ▶ shift @args if $opt{skip_first};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"skip_first"} 1 16 17
1522  
1523 17 my ($nargs, $pv, @lengths) = $aux->aux_list($S->{curr_cv});
1524 17 ▶ while ( defined (my $l = shift @lengths )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = shift @lengths)) 38 1 39
1525 38 ▶ if ( $l >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l >= 0) 31 7 38
1526 31 my $str = substr( $pv, 0, $l, '');
1527 31 push @concats, { str => $str };
1528 }
1529 38 ▶ my $op = shift(@args) or last;
Branch: 1 branch
BranchTrueFalseTotal
my $op = shift @args or last 16 22 38
1530 22 ▶ if ( $opt{eval}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{'eval'}) { } 1 21 22
1531 1 my ($rv, $ok) = get_value($S, $op, soft => 1, eval => 1);
1532 1 ▶ bailout $S, "cannot parse expression (near $pv)" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 1 1
1533 1 push @concats, { str => $rv };
1534 } else {
1535 21 push @concats, { op => $op };
1536 }
1537 }
1538  
1539 17 return @concats;
1540 }
1541  
1542 sub try_special_concat
1543 {
1544 37 ▶ my ($S, $op, %opt) = @_;
Subroutine try_special_concat: called CC=41 SCAR=46.9
Pod undocumented
1545 37 my @terms;
1546 my $str;
1547 37 ▶ if (is_binop($op, "concat")) {
Branch: 9 branches
BranchTrueFalseTotal
if (is_binop($op, 'concat')) { } 0 37 37
elsif ($str = is_const($S, $op)) { } 0 37 37
elsif (is_unop($op, 'null')) { } 2 35 37
elsif (is_op($op, 'null')) { } 1 34 35
elsif (is_binop($op, 'helem')) { } 0 34 34
elsif (is_unop($op, 'entersub')) { } 6 28 34
elsif (is_op($op, 'padsv')) { } 10 18 28
elsif (is_unop_aux($op, 'multiconcat')) { } 16 2 18
elsif (is_unop_aux($op, 'multideref')) { } 2 0 2
1548 0 my @t = try_special_concat($S, $op->first, terms_only => 1);
1549 0 ▶ return () unless @t;
Branch: 1 branch
BranchTrueFalseTotal
unless @t 0 0 0
1550 0 push @terms, @t;
1551 0 @t = try_special_concat($S, $op->last, terms_only => 1);
1552 0 ▶ return () unless @t;
Branch: 1 branch
BranchTrueFalseTotal
unless @t 0 0 0
1553 0 push @terms, @t;
1554 } elsif (($str = is_const($S, $op))) {
1555 0 push @terms, {str => $str};
1556 } elsif (is_unop($op, "null")) {
1557 2 $op = $op->first;
1558 2 ▶ while (!is_null($op)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_null($op)) 2 0 2
1559 2 my @t = try_special_concat($S, $op, terms_only => 1);
1560 0 ▶ return () unless @t;
Branch: 1 branch
BranchTrueFalseTotal
unless @t 0 0 0
1561 0 push @terms, @t;
1562 0 $op = $op->sibling;
1563 }
1564 } elsif (is_op($op, "null")) {
1565 1 return {skip => 1};
1566 } elsif (is_binop($op, "helem")) {
1567 0 my $f = is_const($S, $op->last);
1568 0 ▶ return () unless $f;
Branch: 1 branch
BranchTrueFalseTotal
unless $f 0 0 0
1569 0 $op = $op->first;
1570 0 ▶ return () unless is_unop($op, "rv2hv");
Branch: 1 branch
BranchTrueFalseTotal
unless is_unop($op, "rv2hv") 0 0 0
1571 0 $op = $op->first;
1572 0 ▶ return () unless is_op($op, "padsv");
Branch: 1 branch
BranchTrueFalseTotal
unless is_op($op, "padsv") 0 0 0
1573 0 my $tab = find_aliased_tab($S, $op);
1574 0 ▶ return () unless $tab;
Branch: 1 branch
BranchTrueFalseTotal
unless $tab 0 0 0
1575 0 push @terms, {tab => $tab, field => $f};
1576 } elsif (is_unop($op, "entersub")) {
1577 6 my ($t, $f) = eval { get_tab_field($S, $op) };
1578 6 ▶ return () unless $f;
Branch: 1 branch
BranchTrueFalseTotal
unless $f 0 6 6
1579 6 push @terms, {tab => $t, field => $f};
1580 } elsif (is_op($op, "padsv")) {
1581 10 my $tab = find_aliased_tab($S, $op);
1582 10 ▶ return () unless $tab;
Branch: 1 branch
BranchTrueFalseTotal
unless $tab 0 10 10
1583 10 push @terms, {tab => $tab};
1584 } elsif (is_unop_aux($op, "multiconcat")) {
1585 16 ▶ my @subterms = parse_multiconcat($S, $op, %{ $opt{multiconcat} // {}});
Condition100%2/2
$opt{"multiconcat"} // {}
l!l
115
MC/DC100%1/1
$opt{"multiconcat"} // {}
$opt{"multiconcat"}
Truth table100%2/2
A
A= $opt{"multiconcat"}
Aresult
11
00
1586 16 ▶ return () unless @subterms;
Branch: 1 branch
BranchTrueFalseTotal
unless @subterms 0 16 16
1587 16 for my $st (@subterms) {
1588 48 ▶ if ( defined $st->{str} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $st->{'str'}) { } 27 21 48
1589 27 push @terms, $st;
1590 } else {
1591 21 my @t = try_special_concat($S, $st->{op}, terms_only => 1);
1592 19 ▶ return () unless @t;
Branch: 1 branch
BranchTrueFalseTotal
unless @t 0 19 19
1593 19 push @terms, @t;
1594 }
1595 }
1596 } elsif (is_unop_aux($op, "multideref")) {
1597 2 push @terms, { str => parse_multideref($S, $op ) };
1598 } else {
1599 0 return ();
1600 }
1601 30 ▶ return @terms if $opt{terms_only};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"terms_only"} 18 12 30
1602 12 $str = "";
1603 12 my @sql;
1604 my @v;
1605 12 @terms = grep { !$_->{skip} } @terms;
1606 12 ▶ while (@terms) {
Branch: 1 branch
BranchTrueFalseTotal
if (@terms) 31 12 43
1607 31 my $t = shift @terms;
1608 31 ▶ if (exists $t->{str}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $t->{'str'}) { } 15 16 31
elsif (exists $t->{'field'}) { } 6 10 16
1609 15 $str .= $t->{str};
1610 } elsif (exists $t->{field}) {
1611 6 ▶ if (length($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $str) 4 2 6
1612 4 push @v, $str;
1613 4 push @sql, '?';
1614 }
1615 6 ▶ if ($S->{operation} eq "delete" || $S->{operation} eq "update") {
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{'operation'} eq 'delete' or $S->{'operation'} eq 'update') { } 0 6 6
Condition33%1/3
$S->{"operation"} eq "delete" or $S->{"operation"} eq "update"
l!l&&r!l&&!r
006
MC/DC0%0/2
$S->{"operation"} eq "delete" or $S->{"operation"} eq "update"
$S->{"operation"} eq "delete" $S->{"operation"} eq "update"
Truth table33%1/3
A or B
A= $S->{"operation"} eq "delete"B= $S->{"operation"} eq "update"
ABresult
1X1
011
000
1616 0 push @sql, $t->{field};
1617 } else {
1618 6 push @sql, "$t->{tab}.$t->{field}";
1619 }
1620 6 $str = "";
1621 } else {
1622 10 my $t2 = shift @terms;
1623 10 ▶ return () unless $t2;
Branch: 1 branch
BranchTrueFalseTotal
unless $t2 0 10 10
1624 10 ▶ return () unless defined $t2->{str};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t2->{"str"} 0 10 10
1625 10 ▶ return () unless $t2->{str} =~ s/^->(\w+)//;
Branch: 1 branch
BranchTrueFalseTotal
unless $t2->{"str"} =~ s/^->(\w+)//u 0 10 10
1626 10 my $f = $1;
1627 10 ▶ if (length($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $str) 9 1 10
1628 9 push @v, $str;
1629 9 push @sql, '?';
1630 }
1631 10 ▶ if ($S->{operation} eq "delete" || $S->{operation} eq "update") {
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{'operation'} eq 'delete' or $S->{'operation'} eq 'update') { } 0 10 10
Condition33%1/3
$S->{"operation"} eq "delete" or $S->{"operation"} eq "update"
l!l&&r!l&&!r
0010
MC/DC0%0/2
$S->{"operation"} eq "delete" or $S->{"operation"} eq "update"
$S->{"operation"} eq "delete" $S->{"operation"} eq "update"
Truth table33%1/3
A or B
A= $S->{"operation"} eq "delete"B= $S->{"operation"} eq "update"
ABresult
1X1
011
000
1632 0 push @sql, $f;
1633 } else {
1634 10 push @sql, "$t->{tab}.$f";
1635 }
1636 10 $str = $t2->{str};
1637 }
1638 }
1639 12 ▶ if (length($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $str) 11 1 12
1640 11 push @v, $str;
1641 11 push @sql, '?';
1642 }
1643 12 my $sql;
1644 12 ▶ if (lc($S-> {gen_args}-> {flavor} || '') eq "mysql") {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($S->{'gen_args'}{'flavor'} || '') eq 'mysql') { } 5 7 12
Condition50%1/2
$S->{'gen_args'}{'flavor'} || ''
l!l
120
MC/DC0%0/1
$S->{'gen_args'}{'flavor'} || ''
$S->{'gen_args'}{'flavor'}
Truth table50%1/2
A
A= $S->{'gen_args'}{'flavor'}
Aresult
11
00
1645 5 $sql = "concat(" . join(", ", @sql) . ")";
1646 } else {
1647 7 $sql = join " || ", @sql;
1648 }
1649 12 return ($sql, \@v);
1650 }
1651  
1652 sub parse_entersub
1653 {
1654 215 ▶ my ($S, $op) = @_;
Subroutine parse_entersub: called CC=2 SCAR=6.9
Pod undocumented
1655 215 my $tab = try_parse_attr_assignment($S, $op);
1656 215 ▶ return () if $tab;
Branch: 1 branch
BranchTrueFalseTotal
if $tab 205 10 215
1657 10 return scalar parse_term($S, $op);
1658 }
1659  
1660 sub parse_complex_regex
1661 {
1662 8 ▶ my ($S, $op) = @_;
Subroutine parse_complex_regex: called CC=12 SCAR=32.0
Pod undocumented
1663  
1664 8 ▶ if (is_unop($op, "regcreset")) {
Branch: 5 branches
BranchTrueFalseTotal
if (is_unop($op, 'regcreset')) { } 0 8 8
elsif (is_binop($op, 'concat')) { } 0 8 8
elsif (is_svop($op, 'const')) { } 2 6 8
elsif (() = get_value($S, $op, 'soft', 1)) { } 4 2 6
elsif (is_unop($op, 'null')) { } 2 0 2
1665 0 ▶ if (is_unop($op->first, "null")) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_unop($op->first, 'null')) { } 0 0 0
1666 0 my $rx = "";
1667 0 my $rxop = $op->first->first;
1668 0 ▶ while (!is_null($rxop)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_null($rxop)) 0 0 0
1669 0 ▶ $rx .= parse_complex_regex($S, $rxop)
Branch: 1 branch
BranchTrueFalseTotal
unless is_pushmark_or_padrange($rxop) 0 0 0
1670 unless is_pushmark_or_padrange($rxop);
1671 0 $rxop = $rxop->sibling;
1672 }
1673 0 return $rx;
1674 } else {
1675 0 return parse_complex_regex( $S, $op-> first);
1676 }
1677 } elsif ( is_binop( $op, 'concat')) {
1678 0 $op = $op-> first;
1679 return
1680 0 parse_complex_regex( $S, $op) .
1681 parse_complex_regex( $S, $op-> sibling)
1682 ;
1683 } elsif ( is_svop( $op, 'const')) {
1684 2 return want_const( $S, $op);
1685 } elsif (my ($rx, $ok) = get_value($S, $op, soft => 1)) {
1686 4 ▶ return undef unless $rx;
Branch: 1 branch
BranchTrueFalseTotal
unless $rx 1 3 4
1687 3 $rx =~ s/^\(\?\-\w*\:(.*)\)$/$1/; # (?-xism:moo) -> moo
1688 3 return $rx;
1689 } elsif (is_unop($op, "null")) {
1690 2 my $rx = "";
1691 2 my $rxop = $op->first;
1692 2 ▶ while (!is_null($rxop)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_null($rxop)) 6 2 8
1693 6 ▶ $rx .= parse_complex_regex($S, $rxop)
Branch: 1 branch
BranchTrueFalseTotal
unless is_pushmark_or_padrange($rxop) 4 2 6
1694 unless is_pushmark_or_padrange($rxop);
1695 6 $rxop = $rxop->sibling;
1696 }
1697 2 return $rx;
1698 } else {
1699 0 bailout $S, "unsupported op " . ref($op) . '/' . $op->name;
1700 }
1701 }
1702  
1703 sub parse_regex
1704 {
1705 20 ▶ my ( $S, $op, $neg) = @_;
Subroutine parse_regex: called CC=31 SCAR=45.1
Pod undocumented
1706 20 my ( $like, $case) = ( $op->precomp, $op-> pmflags & B::PMf_FOLD);
1707  
1708 20 ▶ unless ( defined $like) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $like) 4 16 20
1709 4 my $logop = $op-> first-> sibling;
1710 4 ▶ bailout $S, "strange regex " . $op->name
Branch: 1 branch
BranchTrueFalseTotal
unless $logop and is_logop($logop, "regcomp") 0 4 4
Condition33%1/3
$logop and is_logop($logop, "regcomp")
!ll&&!rl&&r
004
MC/DC0%0/2
$logop and is_logop($logop, "regcomp")
$logop is_logop($logop, "regcomp")
Truth table33%1/3
A and B
A= $logopB= is_logop($logop, "regcomp")
ABresult
0X0
100
111
1711 unless $logop and is_logop( $logop, 'regcomp');
1712 4 $like = parse_complex_regex( $S, $logop-> first);
1713 4 ▶ return "" unless defined $like; # explicitly nulled like
Branch: 1 branch
BranchTrueFalseTotal
unless defined $like 1 3 4
1714 }
1715  
1716 19 my $lhs = parse_term($S, $op->first);
1717  
1718 19 ▶ my $flavor = lc($S-> {gen_args}-> {flavor} || '');
Condition50%1/2
$S->{'gen_args'}{'flavor'} || ''
l!l
190
MC/DC0%0/1
$S->{'gen_args'}{'flavor'} || ''
$S->{'gen_args'}{'flavor'}
Truth table50%1/2
A
A= $S->{'gen_args'}{'flavor'}
Aresult
11
00
1719 19 my $what = 'like';
1720  
1721 19 $like =~ s/\(\?\^\w+\:((?:[^\\]|\\.)*)\)/$1/g; # ignore ?^flags:
1722  
1723 19 my $can_like = $like =~ /^\^?(?:[-!%\s\w]|\\.)*\$?$/; # like that begins with non-% can use indexes
1724  
1725 19 ▶ if ( $flavor eq 'mysql') {
Branch: 3 branches
BranchTrueFalseTotal
if ($flavor eq 'mysql') { } 0 19 19
elsif ($flavor eq 'pg' or $flavor eq 'pglite') { } 18 1 19
elsif ($flavor eq 'sqlite') { } 0 1 1
1726 # mysql LIKE is case-insensitive
1727 0 ▶ goto LIKE if not $case and $can_like;
Branch: 1 branch
BranchTrueFalseTotal
if not $case and $can_like 0 0 0
Condition0%0/3
not $case and $can_like
!ll&&!rl&&r
000
MC/DC0%0/2
not $case and $can_like
not $case $can_like
Truth table0%0/3
not(A) and B
A= not $caseB= $can_like
ABresult
0X0
100
111
1728 0 $like =~ s/'/''/g;
1729  
1730 return
1731 0 ▶ "$lhs ".
Branch: 2 branches
BranchTrueFalseTotal
$neg ? : 0 0 0
$case ? : 0 0 0
1732 ( $neg ? 'not ' : '') .
1733 'regexp ' .
1734 ( $case ? '' : 'binary ') .
1735 "'$like'"
1736 ;
1737 ▶ } elsif ( $flavor eq 'pg' || $flavor eq "pglite") {
Condition66%2/3
$flavor eq "pg" or $flavor eq "pglite"
l!l&&r!l&&!r
1801
MC/DC50%1/2
$flavor eq "pg" or $flavor eq "pglite"
$flavor eq "pg" $flavor eq "pglite"
Truth table66%2/3
A or B
A= $flavor eq "pg"B= $flavor eq "pglite"
ABresult
1X1
011
000
1738 # LIKE is case-sensitive
1739 18 ▶ if ( $can_like) {
Branch: 1 branch
BranchTrueFalseTotal
if ($can_like) 18 0 18
1740 18 ▶ $what = 'ilike' if $case;
Branch: 1 branch
BranchTrueFalseTotal
if $case 2 16 18
1741 18 goto LIKE;
1742 }
1743 0 $like =~ s/'/''/g;
1744 return
1745 0 ▶ "$lhs ".
Branch: 2 branches
BranchTrueFalseTotal
$neg ? : 0 0 0
$case ? : 0 0 0
1746 ( $neg ? '!' : '') .
1747 '~' .
1748 ( $case ? '*' : '') .
1749 " '$like'"
1750 ;
1751 } elsif ($flavor eq "sqlite") {
1752 # SQLite as it is now is a bit tricky:
1753 # - there is support for REGEXP with a func provided the user
1754 # supplies his own function;
1755 # - LIKE is case-insensitive (for ASCII, anyway, there's a bug there);
1756 # - GLOB is case-sensitive;
1757 # - there is also support for MATCH - with a user func
1758 # - except that in recent version it is used for FTS
1759 # Since it does not appear that SQLite can use indices
1760 # for prefix matches with simple LIKE statements, we
1761 # just use user-defined functions PRE_N and PRE_I for
1762 # case-sensitive and case-insensitive cases.
1763 # If I am wrong on that, or if SQLite gets and ability to
1764 # do index-based prefix matching, this logic can be
1765 # modified accordingly in at a future date.
1766 0 ▶ if ($case) {
Branch: 1 branch
BranchTrueFalseTotal
if ($case) { } 0 0 0
1767 0 $what = "pre_i";
1768 $S->{gen_args}->{dbh}->func($what, 2, sub {
1769 0 ▶ return scalar $_[1] =~ /$_[0]/i;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1770 0 }, "create_function");
1771 } else {
1772 0 $what = "pre_n";
1773 $S->{gen_args}->{dbh}->func($what, 2, sub {
1774 0 ▶ return scalar $_[1] =~ /$_[0]/;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1775 0 }, "create_function");
1776 }
1777 0 push @{$S->{values}}, $like;
1778 # $what = $neg ? "not $what" : $what;
1779 # return "$lhs $what ?";
1780 0 ▶ return ($neg ? "not " : "") . "$what(?, $lhs)";
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 0 0 0
1781 } else {
1782 # XXX is SQL-standard LIKE case-sensitive or not?
1783 1 ▶ if ($case) {
Branch: 1 branch
BranchTrueFalseTotal
if ($case) 1 0 1
1784 1 $lhs = "lower($lhs)";
1785 1 $like = lc $like;
1786 }
1787 1 ▶ bailout $S, "Regex too complex for implementation using LIKE keyword: $like"
Branch: 1 branch
BranchTrueFalseTotal
if $like =~ /(?<!\\)[\[\]\(\)\{\}\?\|]/u 0 1 1
1788 if $like =~ /(?<!\\)[\[\]\(\)\{\}\?\|]/;
1789 19 LIKE:
1790 $like =~ s/'/''/g;
1791 19 $like =~ s/\\([^A-Za-z_0-9])/$1/g; # de-quotemeta
1792 19 my $escape = "";
1793 19 ▶ if ($flavor eq "pg" || $flavor eq "oracle") {
Branch: 1 branch
BranchTrueFalseTotal
if ($flavor eq 'pg' or $flavor eq 'oracle') { } 19 0 19
Condition66%2/3
$flavor eq "pg" or $flavor eq "oracle"
l!l&&r!l&&!r
1810
MC/DC0%0/2
$flavor eq "pg" or $flavor eq "oracle"
$flavor eq "pg" $flavor eq "oracle"
Truth table66%2/3
A or B
A= $flavor eq "pg"B= $flavor eq "oracle"
ABresult
1X1
011
000
1794 # XXX it is possible that more flavors support like...escape
1795 19 my $need_esc;
1796 19 ▶ $need_esc = 1 if $like =~ s/!/!!/g;
Branch: 1 branch
BranchTrueFalseTotal
if $like =~ s/!/!!/gu 3 16 19
1797 19 ▶ $need_esc = 1 if $like =~ s/%/!%/g;
Branch: 1 branch
BranchTrueFalseTotal
if $like =~ s/%/!%/gu 4 15 19
1798 19 ▶ $need_esc = 1 if $like =~ s/_/!_/g;
Branch: 1 branch
BranchTrueFalseTotal
if $like =~ s/_/!_/gu 3 16 19
1799 19 ▶ $escape = " escape '!'" if $need_esc;
Branch: 1 branch
BranchTrueFalseTotal
if $need_esc 6 13 19
1800 } else {
1801 0 $like =~ s/%/\\%/g;
1802 0 $like =~ s/_/\\_/g;
1803 }
1804 19 $like =~ s/\.\*/%/g;
1805 19 $like =~ s/(?<!\\)\./_/g;
1806 19 $like =~ s/\\\././g;
1807 19 ▶ $like = "%$like" unless $like =~ s|^\^||;
Branch: 1 branch
BranchTrueFalseTotal
unless $like =~ s/^\^//u 5 14 19
1808 19 ▶ $like = "$like%" unless $like =~ s|\$$||;
Branch: 1 branch
BranchTrueFalseTotal
unless $like =~ s/\$$//u 18 1 19
1809 19 ▶ return "$lhs " .
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 2 17 19
1810 ( $neg ? 'not ' : '') .
1811 "$what '$like'$escape"
1812 ;
1813 }
1814 }
1815  
1816 25 my %join_map = (
1817 bit_and => "inner",
1818 multiply => "inner",
1819 repeat => "inner",
1820 bit_or => "full outer",
1821 add => "full outer",
1822 lt => "left outer",
1823 gt => "right outer",
1824 );
1825  
1826 sub parse_join
1827 {
1828 40 ▶ my ($S, $op) = @_;
Subroutine parse_join: called CC=24 SCAR=32.0
Pod undocumented
1829 40 my @op = get_all_children( $op);
1830  
1831  
1832 # allow 2-arg syntax for cross joins:
1833 # join $a * $b
1834 # and 3-arg syntax for all other joins:
1835 # join $a * $b => subselect { ... }
1836 40 ▶ bailout $S, "not a valid join() syntax"
Branch: 1 branch
BranchTrueFalseTotal
unless 2 <= @op and 3 >= @op and is_pushmark_or_padrange($op[0]) and is_binop($op[1]) 0 37 37
Condition66%6/9
2 <= @op and 3 >= @op and is_pushmark_or_padrange($op[0]) and is_binop($op[1])
!ll&&!rl&&r
3037
2 <= @op and 3 >= @op and is_pushmark_or_padrange($op[0])
!ll&&!rl&&r
3037
2 <= @op and 3 >= @op
!ll&&!rl&&r
0337
MC/DC25%1/4
2 <= @op and 3 >= @op and is_pushmark_or_padrange($op[0]) and is_binop($op[1])
2 <= @op 3 >= @op is_pushmark_or_padrange($op[0]) is_binop($op[1])
Truth table40%2/5
A and B and C and D
A= 2 <= @opB= 3 >= @opC= is_pushmark_or_padrange($op[0])D= is_binop($op[1])
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1837 unless 2 <= @op and 3 >= @op and
1838 is_pushmark_or_padrange($op[0]) and
1839 is_binop( $op[1]);
1840 37 my $jointype;
1841
1842 37 ▶ if ($op[1]-> name eq 'le') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op[1]->name eq "le") 6 31 37
1843 # support <= as well as =>
1844 6 ▶ bailout $S, "not a valid join() syntax"
Branch: 1 branch
BranchTrueFalseTotal
unless @op == 2 1 5 6
1845 unless @op == 2;
1846 5 @op[1,2] = ( $op[1]-> first, $op[1]-> last);
1847 5 ▶ bailout $S, "not a valid join() syntax"
Branch: 1 branch
BranchTrueFalseTotal
unless is_binop($op[1]) 0 5 5
1848 unless is_binop( $op[1]);
1849 }
1850  
1851 36 ▶ if ( 2 == @op) {
Branch: 1 branch
BranchTrueFalseTotal
if (2 == @op) { } 4 32 36
1852 bailout $S, "not a valid join() syntax: one of &,*,x is expected"
1853 unless
1854 exists $join_map{ $op[1]-> name } and
1855 4 ▶ $join_map{ $op[1]-> name } eq 'inner';
Branch: 1 branch
BranchTrueFalseTotal
unless exists $join_map{$op[1]->name} and $join_map{$op[1]->name} eq "inner" 1 3 4
Condition66%2/3
exists $join_map{$op[1]->name} and $join_map{$op[1]->name} eq "inner"
!ll&&!rl&&r
103
MC/DC50%1/2
exists $join_map{$op[1]->name} and $join_map{$op[1]->name} eq "inner"
exists $join_map{$op[1]->name} $join_map{$op[1]->name} eq "inner"
Truth table66%2/3
A and B
A= exists $join_map{$op[1]->name}B= $join_map{$op[1]->name} eq "inner"
ABresult
0X0
100
111
1856 3 $jointype = 'cross';
1857 } else {
1858 bailout $S, "not a valid join() syntax: one of &,|,x,+,*,<,> is expected"
1859 32 ▶ unless exists $join_map{ $op[1]-> name };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $join_map{$op[1]->name} 1 31 32
1860 31 ▶ bailout $S, "not a valid join() syntax"
Branch: 1 branch
BranchTrueFalseTotal
unless is_unop($op[2]) and $op[2]->name eq "entersub" 1 30 31
Condition66%2/3
is_unop($op[2]) and $op[2]->name eq "entersub"
!ll&&!rl&&r
1030
MC/DC50%1/2
is_unop($op[2]) and $op[2]->name eq "entersub"
is_unop($op[2]) $op[2]->name eq "entersub"
Truth table66%2/3
A and B
A= is_unop($op[2])B= $op[2]->name eq "entersub"
ABresult
0X0
100
111
1861 unless is_unop( $op[2]) and $op[2]-> name eq 'entersub';
1862 30 $jointype = $join_map{ $op[1]-> name };
1863 }
1864  
1865 # table names
1866 33 my @tab;
1867 33 ▶ $tab[0] = find_aliased_tab($S, $op[1]-> first) or
Branch: 1 branch
BranchTrueFalseTotal
$tab[0] = find_aliased_tab($S, $op[1]->first) or bailout($S, "first argument of join() is not a table") 1 32 33
1868 bailout $S, "first argument of join() is not a table";
1869 32 ▶ $tab[1] = find_aliased_tab($S, $op[1]-> last) or
Branch: 1 branch
BranchTrueFalseTotal
$tab[1] = find_aliased_tab($S, $op[1]->last) or bailout($S, "second argument of join() is not a table") 1 31 32
1870 bailout $S, "second argument of join() is not a table";
1871
1872 # subselect
1873 31 my ( $condition, $codeop);
1874 31 ▶ if ( $op[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op[2]) 30 1 31
1875 30 $codeop = try_get_subselect( $S, $op[2]);
1876 30 ▶ bailout $S, "third argument to join is not a subselect expression"
Branch: 1 branch
BranchTrueFalseTotal
unless $codeop 1 29 30
1877 unless $codeop;
1878  
1879 29 my $cv = $codeop->sv;
1880 29 ▶ if (!$$cv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$cv) 29 0 29
1881 29 $cv = $S->{padlist}->[1]->ARRAYelt($codeop->targ);
1882 }
1883 29 my $subref = $cv->object_2svref;
1884 my $S2 = init(
1885 29 %{$S->{gen_args}},
1886 operation => 'select',
1887 values => [],
1888 join_values => [],
1889 prev_S => $S,
1890 );
1891 29 $S2-> {alias} = $S-> {alias};
1892 29 parse_sub($S2, $subref);
1893 bailout $S,
1894 "join() subselect expression cannot contain anything ".
1895 "but conditional expressions on already declared tables"
1896 145 if scalar( grep { @{ $S2-> {$_} } } qw(
1897 group_by order_by autogroup_by ret_values joins
1898 29 ▶ )) or $S2->{alias} ne $S->{alias};
Branch: 1 branch
BranchTrueFalseTotal
if scalar grep({@{$S2->{$_};};} "group_by", "order_by", "autogroup_by", "ret_values", "joins") or $S2->{"alias"} ne $S->{"alias"} 4 25 29
Condition100%3/3
scalar grep({@{$S2->{$_};};} "group_by", "order_by", "autogroup_by", "ret_values", "joins") or $S2->{"alias"} ne $S->{"alias"}
l!l&&r!l&&!r
3125
MC/DC100%2/2
scalar grep({@{$S2->{$_};};} "group_by", "order_by", "autogroup_by", "ret_values", "joins") or $S2->{"alias"} ne $S->{"alias"}
scalar grep({@{$S2->{$_};};} "group_by", "order_by", "autogroup_by", "ret_values", "joins") $S2->{"alias"} ne $S->{"alias"}
Truth table100%3/3
A or B
A= scalar grep({@{$S2->{$_};};} "group_by", "order_by", "autogroup_by", "ret_values", "joins")B= $S2->{"alias"} ne $S->{"alias"}
ABresult
1X1
011
000
1899  
1900 25 ▶ unless ( @{ $S2->{where}||[] }) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$S2->{'where'} or [];}) { } 22 3 25
$S2->{"where"} or [] 0 25 25
1901 3 ▶ bailout $S,
Branch: 1 branch
BranchTrueFalseTotal
unless $jointype eq "inner" 1 2 3
1902 "join() subselect expression must contain ".
1903 "at least one conditional expression"
1904 unless $jointype eq 'inner';
1905 2 $jointype = 'cross';
1906 } else {
1907 22 $condition = join(' and ', @{ $S2-> {where} });
1908 22 push @{$S->{join_values}}, @{$S2->{values}};
1909 }
1910 }
1911  
1912 25 return [ $jointype, @tab, $condition ];
1913 }
1914  
1915 sub try_parse_range
1916 {
1917 13 ▶ my ($S, $op) = @_;
Subroutine try_parse_range: called CC=5 SCAR=16.2
Pod undocumented
1918 13 ▶ return try_parse_range($S, $op->first) if is_unop($op, "null");
Branch: 1 branch
BranchTrueFalseTotal
if is_unop($op, "null") 6 7 13
1919 7 ▶ return unless is_unop($op, "flop");
Branch: 1 branch
BranchTrueFalseTotal
unless is_unop($op, "flop") 1 6 7
1920 6 $op = $op->first;
1921 6 ▶ return unless is_unop($op, "flip");
Branch: 1 branch
BranchTrueFalseTotal
unless is_unop($op, "flip") 0 6 6
1922 6 $op = $op->first;
1923 6 ▶ return unless is_logop($op, "range");
Branch: 1 branch
BranchTrueFalseTotal
unless is_logop($op, "range") 0 6 6
1924 6 return (parse_simple_term($S, $op->first),
1925 parse_simple_term($S, $op->first->sibling));
1926 }
1927  
1928 sub parse_or
1929 {
1930 19 ▶ my ($S, $op) = @_;
Subroutine parse_or: called CC=5 SCAR=16.1
Pod undocumented
1931 19 ▶ if (is_op($op->first->sibling, "last")) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_op($op->first->sibling, 'last')) { } 9 10 19
elsif (() = get_value($S, $op->first, 'soft', 1)) { } 4 6 10
1932 bailout $S, "there should be no \"last\" statements in $S->{operation}'s query sub"
1933 9 ▶ unless $S->{operation} eq "select";
Branch: 1 branch
BranchTrueFalseTotal
unless $S->{"operation"} eq "select" 2 7 9
1934 7 my ($from, $to) = try_parse_range($S, $op->first);
1935 5 ▶ bailout $S, "range operator expected" unless defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to 1 4 5
1936 4 $S->{offset} = $from;
1937 4 $S->{limit} = $to-$from+1;
1938 4 return;
1939 } elsif (my ($val, $ok) = get_value($S, $op->first, soft => 1)) {
1940 4 return compile_conditionally($S, $op, !$val);
1941 } else {
1942 6 my $left = parse_term($S, $op->first);
1943 6 my $right = parse_term($S, $op->first->sibling);
1944 6 return "$left or $right";
1945 }
1946 }
1947  
1948 sub parse_and
1949 {
1950 14 ▶ my ($S, $op) = @_;
Subroutine parse_and: called CC=2 SCAR=6.9
Pod undocumented
1951 14 ▶ if (my ($val, $ok) = get_value($S, $op->first, soft => 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = get_value($S, $op->first, 'soft', 1)) { } 10 4 14
1952 10 return compile_conditionally($S, $op, $val);
1953 } else {
1954 4 my $left = parse_term($S, $op->first);
1955 4 my $right = parse_term($S, $op->first->sibling);
1956 4 return "$left and $right";
1957 }
1958 }
1959  
1960 sub compile_conditionally
1961 {
1962 14 ▶ my ($S, $op, $val) = @_;
Subroutine compile_conditionally: called CC=7 SCAR=20.0
Pod undocumented
1963 14 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) { } 9 5 14
1964 9 $op = $op->first->sibling;
1965 # This strangeness is for suppressing () when parsing
1966 # expr via parse_term. There must be a better way.
1967 9 ▶ if (is_binop($op) || $op->name eq "sassign") {
Branch: 3 branches
BranchTrueFalseTotal
if (is_binop($op) or $op->name eq 'sassign') { } 1 8 9
elsif (is_listop($op, 'return')) { } 6 2 8
elsif (is_listop($op, 'leave') or is_listop($op, 'scope')) { } 2 0 2
Condition66%2/3
is_binop($op) or $op->name eq "sassign"
l!l&&r!l&&!r
108
MC/DC50%1/2
is_binop($op) or $op->name eq "sassign"
is_binop($op) $op->name eq "sassign"
Truth table66%2/3
A or B
A= is_binop($op)B= $op->name eq "sassign"
ABresult
1X1
011
000
1968 1 return parse_expr($S, $op);
1969 } elsif (is_listop($op, "return")) {
1970 # conditional returns are nice
1971 6 parse_return($S, $op);
1972 4 return ();
1973 ▶ } elsif (is_listop($op, "leave") || is_listop($op, "scope")) {
Condition33%1/3
is_listop($op, "leave") or is_listop($op, "scope")
l!l&&r!l&&!r
200
MC/DC0%0/2
is_listop($op, "leave") or is_listop($op, "scope")
is_listop($op, "leave") is_listop($op, "scope")
Truth table33%1/3
A or B
A= is_listop($op, "leave")B= is_listop($op, "scope")
ABresult
1X1
011
000
1974 2 parse_list($S, $op);
1975 2 return ();
1976 } else {
1977 0 return scalar parse_term($S, $op);
1978 }
1979 } else {
1980 5 return ();
1981 }
1982 }
1983  
1984 sub parse_fieldlist_label
1985 {
1986 3 ▶ my ($S, $label, $lop, $op) = @_;
Subroutine parse_fieldlist_label: called CC=6 SCAR=18.1
Pod undocumented
1987  
1988 3 my @op;
1989 3 ▶ if (is_listop($op, "list")) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_listop($op, 'list')) { } 1 2 3
1990 1 @op = get_all_children($op);
1991 } else {
1992 2 push @op, $op;
1993 }
1994 3 for $op (@op) {
1995 5 ▶ next if is_pushmark_or_padrange($op);
Branch: 1 branch
BranchTrueFalseTotal
if is_pushmark_or_padrange($op) 1 4 5
1996 4 my ($t, $f) = get_tab_field($S, $op);
1997 4 ▶ push @{$S->{$label->{key}}},
Branch: 1 branch
BranchTrueFalseTotal
$S->{'operation'} eq 'delete' || $S->{'operation'} eq 'update' ? : 0 4 4
Condition33%1/3
$S->{"operation"} eq "delete" or $S->{"operation"} eq "update"
l!l&&r!l&&!r
004
MC/DC0%0/2
$S->{"operation"} eq "delete" or $S->{"operation"} eq "update"
$S->{"operation"} eq "delete" $S->{"operation"} eq "update"
Truth table33%1/3
A or B
A= $S->{"operation"} eq "delete"B= $S->{"operation"} eq "update"
ABresult
1X1
011
000
1998 4 ($S->{operation} eq "delete" || $S->{operation} eq "update") ?
1999 $f : "$t.$f";
2000 }
2001 3 $S->{skipnext} = 1;
2002 }
2003  
2004 sub parse_sort
2005 {
2006 3 ▶ my ($S, $op) = @_;
Subroutine parse_sort: called CC=1 SCAR=0.0
Pod undocumented
2007 3 parse_orderby_label($S, "order_by", undef, $op);
2008 3 delete $S->{skipnext};
2009 }
2010  
2011 sub parse_orderby_label
2012 {
2013 9 ▶ my ($S, $label, $lop, $op) = @_;
Subroutine parse_orderby_label: called CC=13 SCAR=25.7
Pod undocumented
2014  
2015 9 ▶ my $key = ref $label ? $label->{key} : $label;
Branch: 1 branch
BranchTrueFalseTotal
ref $label ? : 6 3 9
2016  
2017 9 my @op;
2018 9 ▶ if (is_listop($op, "list") || is_listop($op, "sort")) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_listop($op, 'list') or is_listop($op, 'sort')) { } 6 3 9
elsif (is_unop($op, 'null')) { } 1 2 3
Condition100%3/3
is_listop($op, "list") or is_listop($op, "sort")
l!l&&r!l&&!r
333
MC/DC100%2/2
is_listop($op, "list") or is_listop($op, "sort")
is_listop($op, "list") is_listop($op, "sort")
Truth table100%3/3
A or B
A= is_listop($op, "list")B= is_listop($op, "sort")
ABresult
1X1
011
000
2019 6 @op = get_all_children($op);
2020 } elsif ( is_unop($op, "null")) {
2021 1 $op = $op->first;
2022 1 ▶ while ( $op && !is_null($op)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op and not is_null($op)) 3 1 4
Condition66%2/3
$op and not is_null($op)
!ll&&!rl&&r
013
MC/DC50%1/2
$op and not is_null($op)
$op not is_null($op)
Truth table66%2/3
A and not(B)
A= $opB= not is_null($op)
ABresult
0X0
100
111
2023 3 push @op, $op;
2024 3 $op = $op->sibling;
2025 }
2026 } else {
2027 2 push @op, $op;
2028 }
2029 9 my $order = "";
2030 9 for $op (@op) {
2031 26 ▶ next if is_pushmark_or_padrange($op);
Branch: 1 branch
BranchTrueFalseTotal
if is_pushmark_or_padrange($op) 6 20 26
2032 # XXX next if is_op($op, "null");
2033 20 my $term;
2034 20 ▶ $term = parse_term($S, $op, inline_placeholder => 1)
Branch: 1 branch
BranchTrueFalseTotal
unless $term = is_const($S, $op) 14 6 20
2035 unless $term = is_const($S, $op);
2036 20 ▶ if ($term =~ /^asc/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($term =~ /^asc/iu) { } 2 18 20
elsif ($term =~ /^desc/iu) { } 7 11 18
2037 2 next; # skip "ascending"
2038 } elsif ($term =~ /^desc/i) {
2039 7 $order = "desc";
2040 7 next;
2041 } else {
2042 11 ▶ if ($order) {
Branch: 1 branch
BranchTrueFalseTotal
if ($order) { } 6 5 11
2043 6 push @{$S->{$key}}, "$term $order";
2044 6 $order = "";
2045 } else {
2046 5 push @{$S->{$key}}, $term;
2047 }
2048 }
2049 }
2050 9 $S->{skipnext} = 1;
2051 }
2052  
2053 sub parse_numassign_label
2054 {
2055 11 ▶ my ($S, $label, $lop, $op) = @_;
Subroutine parse_numassign_label: called CC=8 SCAR=21.2
Pod undocumented
2056  
2057 # TODO more generic values
2058 11 my ($const,$sv) = is_const($S, $op);
2059 11 ▶ if (!$sv && is_op($op, "padsv")) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $sv and is_op($op, "padsv")) 6 5 11
Condition66%2/3
not $sv and is_op($op, "padsv")
!ll&&!rl&&r
506
MC/DC50%1/2
not $sv and is_op($op, "padsv")
not $sv is_op($op, "padsv")
Truth table66%2/3
not(A) and B
A= not $svB= is_op($op, "padsv")
ABresult
0X0
100
111
2060 6 ▶ if (find_aliased_tab($S, $op)) {
Branch: 1 branch
BranchTrueFalseTotal
if (find_aliased_tab($S, $op)) 2 4 6
2061 2 bailout $S, "cannot use table variable after ", $lop->label;
2062 }
2063 4 $sv = $S->{padlist}->[1]->ARRAYelt($op->targ);
2064 4 $const = ${$sv->object_2svref};
2065 }
2066 9 ▶ bailout $S, "label ", $lop->label, " must be followed by an integer or integer variable"
Branch: 1 branch
BranchTrueFalseTotal
unless $sv and $const and $const =~ /^\d+$/u and $const > 0 2 7 9
Condition55%5/9
$sv and $const and $const =~ /^\d+$/u and $const > 0
!ll&&!rl&&r
207
$sv and $const and $const =~ /^\d+$/u
!ll&&!rl&&r
027
$sv and $const
!ll&&!rl&&r
009
MC/DC25%1/4
$sv and $const and $const =~ /^\d+$/u and $const > 0
$sv $const $const =~ /^\d+$/u $const > 0
Truth table40%2/5
A and B and C and D
A= $svB= $constC= $const =~ /^\d+$/uD= $const > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2067 unless $sv && $const && $const =~ /^\d+$/ && $const > 0;
2068 7 $S->{$label->{key}} = $const;
2069 7 $S->{skipnext} = 1;
2070 }
2071  
2072 sub parse_notice_label
2073 {
2074 1 ▶ my ($S, $label, $lop, $op) = @_;
Subroutine parse_notice_label: called CC=1 SCAR=0.0
Pod undocumented
2075 1 $S->{$label->{key}}++;
2076 }
2077  
2078 sub parse_table_label
2079 {
2080 6 ▶ my ($S, $label, $lop, $op) = @_;
Subroutine parse_table_label: called CC=8 SCAR=26.1
Pod undocumented
2081  
2082 6 ▶ if ( $] >= 5.037 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.037) { } 6 0 6
2083 6 ▶ bailout $S, "label ", $lop->label, " must be followed by an assignment"
Branch: 1 branch
BranchTrueFalseTotal
unless $op->name eq "padsv_store" 3 3 6
2084 unless $op->name eq "padsv_store";
2085 } else {
2086 0 ▶ bailout $S, "label ", $lop->label, " must be followed by an assignment"
Branch: 1 branch
BranchTrueFalseTotal
unless $op->name eq "sassign" 0 0 0
2087 unless $op->name eq "sassign";
2088 }
2089 3 my $attr = parse_simple_term($S, $op->first);
2090 3 my $varn;
2091 3 ▶ if ( $] >= 5.037 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.037) { } 3 0 3
2092 3 $varn = padname($S, $op, no_fakes => 1);
2093 3 ▶ bailout $S, "label ", $lop->label, " must be followed by a lexical variable declaration"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $varn 0 3 3
2094 unless defined $varn;
2095 } else {
2096 0 ▶ bailout $S, "label ", $lop->label, " must be followed by a lexical variable declaration"
Branch: 1 branch
BranchTrueFalseTotal
unless is_op($op->last, "padsv") and $varn = padname($S, $op->last, "no_fakes", 1) 0 0 0
Condition0%0/3
is_op($op->last, "padsv") and $varn = padname($S, $op->last, "no_fakes", 1)
!ll&&!rl&&r
000
MC/DC0%0/2
is_op($op->last, "padsv") and $varn = padname($S, $op->last, "no_fakes", 1)
is_op($op->last, "padsv") $varn = padname($S, $op->last, "no_fakes", 1)
Truth table0%0/3
A and B
A= is_op($op->last, "padsv")B= $varn = padname($S, $op->last, "no_fakes", 1)
ABresult
0X0
100
111
2097 unless is_op($op->last, "padsv") && ($varn = padname($S, $op->last, no_fakes => 1));
2098 }
2099 3 new_var($S, $varn, $attr);
2100 3 $S->{skipnext} = 1;
2101 }
2102  
2103 25 my $action_orderby = {
2104 kind => 'termlist',
2105 key => 'order_by',
2106 handler => \&parse_orderby_label,
2107 };
2108 25 my $action_groupby = {
2109 kind => 'fieldlist',
2110 key => 'group_by',
2111 handler => \&parse_fieldlist_label,
2112 };
2113 25 my $action_limit = {
2114 kind => 'numassign',
2115 key => 'limit',
2116 handler => \&parse_numassign_label,
2117 };
2118 25 my $action_offset = {
2119 kind => 'numassign',
2120 key => 'offset',
2121 handler => \&parse_numassign_label,
2122 };
2123 25 my $action_distinct = {
2124 kind => 'notice',
2125 key => 'distinct',
2126 handler => \&parse_notice_label,
2127 };
2128 25 my %labelmap = (
2129 select => {
2130 orderby => $action_orderby,
2131 order_by => $action_orderby,
2132 order => $action_orderby,
2133 sortby => $action_orderby,
2134 sort_by => $action_orderby,
2135 sort => $action_orderby,
2136  
2137 groupby => $action_groupby,
2138 group_by => $action_groupby,
2139 group => $action_groupby,
2140  
2141 limit => $action_limit,
2142  
2143 offset => $action_offset,
2144  
2145 distinct => $action_distinct,
2146 },
2147 );
2148  
2149 sub parse_labels
2150 {
2151 28 ▶ my ($S, $lop) = @_;
Subroutine parse_labels: called CC=5 SCAR=16.2
Pod undocumented
2152 28 my $label = $labelmap{$S->{operation}}->{lc $lop->label};
2153 28 ▶ if (!$label && lc $lop->label eq "table") {
Branch: 1 branch
BranchTrueFalseTotal
if (not $label and lc $lop->label eq "table") 6 22 28
Condition100%3/3
not $label and lc $lop->label eq "table"
!ll&&!rl&&r
2116
MC/DC100%2/2
not $label and lc $lop->label eq "table"
not $label lc $lop->label eq "table"
Truth table100%3/3
not(A) and B
A= not $labelB= lc $lop->label eq "table"
ABresult
0X0
100
111
2154 6 $label = { kind => 'table', handler => \&parse_table_label };
2155 }
2156 28 ▶ bailout $S, "label ", $lop->label, " is not understood"
Branch: 1 branch
BranchTrueFalseTotal
unless $label 1 27 28
2157 unless $label;
2158 27 my $op = $lop->sibling;
2159 27 ▶ if ($label->{handler}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($label->{'handler'}) { } 27 0 27
2160 27 $label->{handler}->($S, $label, $lop, $op);
2161 } else {
2162 0 bailout $S, "internal error parsing label ", $op->label;
2163 }
2164 }
2165  
2166 sub parse_selfmod
2167 {
2168 5 ▶ my ($S, $op, $oper) = @_;
Subroutine parse_selfmod: called CC=2 SCAR=6.9
Pod undocumented
2169  
2170 5 my ($tab, $f) = get_tab_field($S, $op, lvalue => 1);
2171 bailout $S, "self-modifications are not understood in $S->{operation}'s query sub"
2172 5 ▶ unless $S->{operation} eq "update";
Branch: 1 branch
BranchTrueFalseTotal
unless $S->{"operation"} eq "update" 1 4 5
2173 4 return "$f = $f $oper";
2174 }
2175  
2176 sub where_or_having
2177 {
2178 451 ▶ my ($S, @what) = @_;
Subroutine where_or_having: called CC=2 SCAR=6.9
Pod undocumented
2179 451 ▶ push @{$S->{$S->{this_is_having} ? "having" : "where"}}, @what;
Branch: 1 branch
BranchTrueFalseTotal
$S->{'this_is_having'} ? : 1 450 451
2180 451 $S->{this_is_having} = 0;
2181 }
2182  
2183 sub parse_op
2184 {
2185 2550 ▶ my ($S, $op) = @_;
Subroutine parse_op: called CC=38 SCAR=36.8
Pod undocumented
2186  
2187 2550 ▶ return if $S->{seen}->{$$op}++;
Branch: 1 branch
BranchTrueFalseTotal
if $S->{"seen"}{$$op}++ 0 2550 2550
2188  
2189 2550 ▶ if ($S->{skipnext}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{"skipnext"}) 19 2531 2550
2190 19 delete $S->{skipnext};
2191 19 return;
2192 }
2193 2531 ▶ if (is_listop($op, "list")) {
Branch: 28 branches
BranchTrueFalseTotal
if (is_listop($op, 'list')) { } 9 2522 2531
elsif (is_listop($op, 'lineseq')) { } 368 2154 2522
elsif (is_binop($op, 'leaveloop') and is_loop($op->first, 'enterloop') and is_listop($op->last, 'lineseq')) { } 8 2146 2154
elsif (is_listop($op, 'return')) { } 94 2052 2146
elsif (is_binop($op) or is_unop($op, 'padsv_store')) { } 215 1837 2052
elsif (is_unop($op, 'not')) { } 6 1831 1837
elsif (is_logop($op, 'or')) { } 17 1814 1831
elsif (is_logop($op, 'and')) { } 12 1802 1814
elsif (is_unop($op, 'leavesub')) { } 374 1428 1802
elsif (is_unop($op, 'null')) { } 226 1202 1428
elsif (is_unop($op, 'defined')) { } 2 1200 1202
elsif (is_op($op, 'padsv')) { } 8 1192 1200
elsif (is_op($op, 'last')) { } 2 1190 1192
elsif (is_pushmark_or_padrange($op)) { } 9 1181 1190
elsif (is_op($op, 'enter')) { } 2 1179 1181
elsif (is_op($op, 'null')) { } 197 982 1179
elsif (is_cop($op, 'nextstate')) { } 685 297 982
elsif (is_cop($op)) { } 0 297 297
elsif (is_unop($op, 'entersub')) { } 215 82 297
elsif (is_pmop($op, 'match')) { } 16 66 82
elsif ($op->name eq 'join') { } 40 26 66
elsif ($op->name eq 'sort') { } 3 23 26
elsif (is_unop($op, 'postinc')) { } 1 22 23
elsif (is_unop($op, 'postdec')) { } 0 22 22
elsif (is_unop($op, 'preinc')) { } 2 20 22
elsif (is_unop($op, 'predec')) { } 2 18 20
elsif (is_listop($op, 'exec')) { } 17 1 18
elsif (is_unop_aux($op, 'multiconcat')) { } 1 0 1
2194 9 parse_list($S, $op);
2195 } elsif (is_listop($op, "lineseq")) {
2196 368 parse_list($S, $op);
2197 ▶ } elsif (is_binop($op, "leaveloop") &&
Condition66%4/6
is_binop($op, "leaveloop") and is_loop($op->first, "enterloop") and is_listop($op->last, "lineseq")
!ll&&!rl&&r
214608
is_binop($op, "leaveloop") and is_loop($op->first, "enterloop")
!ll&&!rl&&r
214608
MC/DC33%1/3
is_binop($op, "leaveloop") and is_loop($op->first, "enterloop") and is_listop($op->last, "lineseq")
is_binop($op, "leaveloop") is_loop($op->first, "enterloop") is_listop($op->last, "lineseq")
Truth table50%2/4
A and B and C
A= is_binop($op, "leaveloop")B= is_loop($op->first, "enterloop")C= is_listop($op->last, "lineseq")
ABCresult
0XX0
10X0
1100
1111
2198 is_loop($op->first, "enterloop") &&
2199 is_listop($op->last, "lineseq"))
2200 {
2201 8 parse_list($S, $op->last);
2202 } elsif (is_listop($op, "return")) {
2203 94 parse_return($S, $op);
2204 ▶ } elsif (is_binop($op) || is_unop($op, 'padsv_store') ) {
Condition100%3/3
is_binop($op) or is_unop($op, "padsv_store")
l!l&&r!l&&!r
21141837
MC/DC100%2/2
is_binop($op) or is_unop($op, "padsv_store")
is_binop($op) is_unop($op, "padsv_store")
Truth table100%3/3
A or B
A= is_binop($op)B= is_unop($op, "padsv_store")
ABresult
1X1
011
000
2205 215 where_or_having($S, parse_expr($S, $op));
2206 } elsif (is_unop($op, "not")) {
2207 6 where_or_having($S, scalar parse_term($S, $op));
2208 } elsif (is_logop($op, "or")) {
2209 17 my $or = parse_or($S, $op);
2210 11 ▶ where_or_having($S, "($or)") if $or;
Branch: 1 branch
BranchTrueFalseTotal
if $or 4 7 11
2211 11 $S->{this_is_having} = 0;
2212 } elsif (is_logop($op, "and")) {
2213 12 my $and = parse_and($S, $op);
2214 11 ▶ where_or_having($S, $and) if $and;
Branch: 1 branch
BranchTrueFalseTotal
if $and 3 8 11
2215 11 $S->{this_is_having} = 0;
2216 } elsif (is_unop($op, "leavesub")) {
2217 374 parse_op($S, $op->first);
2218 } elsif (is_unop($op, "null")) {
2219 226 parse_op($S, $op->first);
2220 } elsif (is_unop($op, "defined")) {
2221 2 where_or_having($S, scalar parse_term($S, $op));
2222 } elsif (is_op($op, "padsv")) {
2223 # XXX Skip for now, it is either a variable
2224 # that does not represent a table, or else
2225 # it is already associated with a table in $S.
2226 } elsif (is_op($op, "last")) {
2227 bailout $S, "there should be no \"last\" statements in $S->{operation}'s query sub"
2228 2 ▶ unless $S->{operation} eq "select";
Branch: 1 branch
BranchTrueFalseTotal
unless $S->{"operation"} eq "select" 2 0 2
2229 0 $S->{limit} = 1;
2230 } elsif (is_pushmark_or_padrange($op)) {
2231 # skip
2232 } elsif (is_op($op, "enter")) {
2233 # skip
2234 } elsif (is_op($op, "null")) {
2235 # skip
2236 197 parse_op($S, $op->sibling);
2237 } elsif (is_cop($op, "nextstate")) {
2238 685 $S->{file} = $op->file;
2239 685 $S->{line} = $op->line;
2240 685 $_cover->($op);
2241 685 ▶ if ($op->label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->label) 28 657 685
2242 28 parse_labels($S, $op);
2243 }
2244 } elsif (is_cop($op)) {
2245 # XXX any other things?
2246 0 $S->{file} = $op->file;
2247 0 $S->{line} = $op->line;
2248 # skip
2249 } elsif (is_unop($op, "entersub")) {
2250 215 where_or_having($S, parse_entersub($S, $op));
2251 } elsif (is_pmop($op, "match")) {
2252 16 where_or_having($S, parse_regex($S, $op, 0));
2253 } elsif ( $op->name eq 'join') {
2254 40 push @{$S->{joins}}, parse_join($S, $op);
2255 } elsif ($op->name eq 'sort') {
2256 3 parse_sort($S, $op);
2257 } elsif (is_unop($op, "postinc")) {
2258 1 push @{$S->{sets}}, parse_selfmod($S, $op->first, "+ 1");
2259 } elsif (is_unop($op, "postdec")) {
2260 0 push @{$S->{sets}}, parse_selfmod($S, $op->first, "- 1");
2261 } elsif (is_unop($op, "preinc")) {
2262 2 push @{$S->{sets}}, parse_selfmod($S, $op->first, "+ 1");
2263 } elsif (is_unop($op, "predec")) {
2264 2 push @{$S->{sets}}, parse_selfmod($S, $op->first, "- 1");
2265 } elsif (is_listop($op, "exec")) {
2266 17 $S->{seen_exec}++;
2267 } elsif (is_unop_aux($op, "multiconcat")) {
2268 1 where_or_having($S, parse_expr($S, $op));
2269 } else {
2270 0 bailout $S, "don't quite know what to do with op \"" . $op->name . "\"";
2271 }
2272 }
2273  
2274 sub parse_sub
2275 {
2276 374 ▶ my ($S, $sub) = @_;
Subroutine parse_sub: called CC=3 SCAR=13.3
Pod undocumented
2277 374 ▶ if ($DEVEL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DEVEL) 0 374 374
2278 0 $Carp::Verbose = 1;
2279 0 require B::Concise;
2280 #my $walker = B::Concise::compile('-terse', $sub);
2281 0 my $walker = B::Concise::compile('-concise', $sub);
2282 0 print "CODE DUMP:\n";
2283 0 $walker->();
2284 0 print "\n\n";
2285 }
2286 374 my $root = B::svref_2object($sub);
2287 374 $S->{padlist} = [$root->PADLIST->ARRAY];
2288 374 $S->{curr_cv} = $root;
2289 374 ▶ $S->{padlists}->{ $root->PADLIST->id } = $S->{padlist} if $root->PADLIST->can('id');
Branch: 1 branch
BranchTrueFalseTotal
if $root->PADLIST->can("id") 374 0 374
2290 374 $root = $root->ROOT;
2291 374 parse_op($S, $root);
2292 }
2293  
2294 sub B::OP::foo
2295 {
2296 0 ▶ printf "%s 0x%x\n", _o($_[0]), ${$_[0]};
Subroutine foo: not called CC=1 SCAR=6.9
2297 }
2298  
2299 sub init
2300 {
2301 374 ▶ my %args = @_;
Subroutine init: called CC=3 SCAR=11.0
Pod undocumented
2302 my $S = {
2303 gen_args => \%args,
2304 file => '??',
2305 line => '??',
2306 subselect => 's01',
2307 operation => $args{operation},
2308 values => [],
2309 join_values => [],
2310 sets => [],
2311 set_values => [],
2312 ret_values => [],
2313 where => [],
2314 order_by => [],
2315 group_by => [],
2316 additions => [],
2317 joins => [],
2318 key_field => 1,
2319 aggregates => { avg => 1, count => 1, max => 1, min => 1, sum => 1 },
2320 autogroup_by => [],
2321 autogroup_fields => {},
2322 seen => {},
2323 padlists => $args{prev_S} ? $args{prev_S}->{padlists} : {},
2324 374 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$args{'prev_S'} ? : 48 326 374
2325 374 ▶ $S->{alias} = $args{prefix} ? "$args{prefix}_t01" : "t01";
Branch: 1 branch
BranchTrueFalseTotal
$args{'prefix'} ? : 11 363 374
2326 374 $S;
2327 }
2328  
2329 # Borrowed from IO::All by Ingy döt Net.
2330 25 my $old_warn_handler = $SIG{__WARN__};
2331 $SIG{__WARN__} = sub {
2332 85 ▶ if ($_[0] !~ /^Useless use of .+ in void context/) {
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
if (not $_[0] =~ /^Useless use of .+ in void context/u) 9 76 85
2333 9 ▶ goto &$old_warn_handler if $old_warn_handler;
Branch: 1 branch
BranchTrueFalseTotal
if $old_warn_handler 0 9 9
2334 9 warn(@_);
2335 }
2336 25 };
2337  
2338 25 ▶$_cover = sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
2339 25 ▶if (*Devel::Cover::coverage{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*Devel::Cover::coverage{"CODE"}) 25 0 25
2340 25 my $Coverage = Devel::Cover::coverage(0);
2341 685 ▶ $_cover = sub { $Coverage->{statement}{Devel::Cover::get_key($_[0])} ||= 1 };
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$Coverage->{"statement"}{&Devel::Cover::get_key($_[0])} ||= 1
l!l
3682
MC/DC100%1/1
$Coverage->{"statement"}{&Devel::Cover::get_key($_[0])} ||= 1
$Coverage->{"statement"}{&Devel::Cover::get_key($_[0])}
Truth table100%2/2
A
A= $Coverage->{"statement"}{&Devel::Cover::get_key($_[0])}
Aresult
11
00
2342 }
2343  
2344 package
2345 DBIx::Perlish::Placeholder;
2346  
2347 25 ▶use overload '""' => sub { "?" }, eq => sub { "$_[0]" eq "$_[1]" };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
2348  
2349 sub new
2350 {
2351 100 ▶ my ($class, $S, $pos) = @_;
Subroutine new: called CC=1 SCAR=0.0
2352 100 bless { S => $S, position => $pos }, $class;
2353 }
2354  
2355 sub value
2356 {
2357 0 ▶ my $me = shift;
Subroutine value: not called CC=1 SCAR=6.9
2358 0 return $me->{S}{values}[$me->{position}];
2359 }
2360  
2361 sub undo
2362 {
2363 4 ▶ my $me = shift;
Subroutine undo: called CC=1 SCAR=0.0
2364 4 splice @{$me->{S}{values}}, $me->{position}, 1;
2365 }
2366  
2367 25 "the magic stops here; welcome to the real world";
↑ Summary Perlish.pm »