SQL/Abstract.pm

filter: Statementstmt 86.2% 913 / 1058 Branchbran 81.3% 493 / 606 Conditioncond 76.2% 269 / 353 MC/DCmcdc 55.0% 104 / 189 Subroutinesub 81.5% 159 / 195 Podpod 95.0% 58 / 61 totaltotal 81.0% 1996 / 2462 CC 452 SCAR 22.5
CC
452
Cov
83%
generate
30.7
__ANON__
21.5
_expand_op_andor
21.5
CRAP 9.5
« SQL/Abstract/Plugin/BangOverrides.pm ↑ Summary DBIx/Class/Storage/Debug/PrettyPrint.pm »
1 package SQL::Abstract; # see doc at end of file
2  
3 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 20 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 20 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 20 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 20 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 20 our @EXPORT_OK = qw(is_plain_value is_literal_value is_undef_value);
11  
12 20 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=12.5
13 20 ▶ if ($] < 5.009_005) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < 5.009005) { } 0 20 20
14 0 require MRO::Compat;
15 }
16 else {
17 20 require mro;
18 }
19  
20 *SQL::Abstract::_ENV_::DETECT_AUTOGENERATED_STRINGIFICATION = $ENV{SQLA_ISVALUE_IGNORE_AUTOGENERATED_STRINGIFICATION}
21 ? sub () { 0 }
22 : sub () { 1 }
23 20 ▶ ;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'SQLA_ISVALUE_IGNORE_AUTOGENERATED_STRINGIFICATION'} ? : 0 20 20
24 }
25  
26 #======================================================================
27 # GLOBALS
28 #======================================================================
29  
30 20 our $VERSION = '2.000003';
31  
32 # This would confuse some packagers
33 20 ▶$VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
Branch: 1 branch
BranchTrueFalseTotal
if $SQL::Abstract::VERSION =~ /_/ 0 20 20
34  
35 20 our $AUTOLOAD;
36  
37 # special operators (-in, -between). May be extended/overridden by user.
38 # See section WHERE: BUILTIN SPECIAL OPERATORS below for implementation.
39 # Single precompiled alternation of the builtin special-op names, used only
40 # to reject their top-level use under the old special-op compat path; this is
41 # equivalent to (and much faster than) a List::Util::first over one regex each.
42 20 my $BUILTIN_SPECIAL_OP_RE = qr/^
43 (?:
44 (?: not \s )? between
45 | is (?: \s+ not )?
46 | (?: not \s )? in
47 | ident
48 | value
49 )
50 $/ix;
51  
52 #======================================================================
53 # DEBUGGING AND ERROR REPORTING
54 #======================================================================
55  
56 72 ▶sub _debug {
Subroutine _debug: called CC=2 SCAR=11.6
57 0 ▶ return unless $_[0]->{debug}; shift; # a little faster
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"debug"} 72 0 72
58 0 my $func = (caller(1))[3];
59 0 warn "[$func] ", @_, "\n";
60 }
61  
62 150 ▶sub belch (@) {
Subroutine belch: called CC=3 SCAR=12.5
Pod undocumented
63 150 ▶ Scalar::Util::blessed($_[0]) and $_[0]->isa(__PACKAGE__) and shift;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__) and shift() 150 0 150
Condition33%1/3
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
!ll&&!rl&&r
00150
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
builtin::blessed($_[0]) $_[0]->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa(__PACKAGE__)
ABresult
0X0
100
111
64 150 my($func) = (caller(1))[3];
65 150 Carp::carp "[$func] Warning: ", @_;
66 }
67  
68 123 ▶sub puke (@) {
Subroutine puke: called CC=3 SCAR=11.0
Pod undocumented
69 123 ▶ Scalar::Util::blessed($_[0]) and $_[0]->isa(__PACKAGE__) and shift;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__) and shift() 121 2 123
Condition66%2/3
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
!ll&&!rl&&r
20121
MC/DC50%1/2
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
builtin::blessed($_[0]) $_[0]->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa(__PACKAGE__)
ABresult
0X0
100
111
70 123 my($func) = (caller(1))[3];
71 123 Carp::croak "[$func] Fatal: ", @_;
72 }
73  
74 2521 ▶sub is_literal_value ($) {
Subroutine is_literal_value: called CC=4 SCAR=13.9
Pod documented
75 104 ▶ ref $_[0] eq 'SCALAR' ? [ ${$_[0]} ]
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'REF' && ref ${$_[0];} eq 'ARRAY' ? : 131 2286 2417
Condition66%2/3
ref $_[0] eq "REF" and ref ${$_[0];} eq "ARRAY"
!ll&&!rl&&r
22860131
MC/DC50%1/2
ref $_[0] eq "REF" and ref ${$_[0];} eq "ARRAY"
ref $_[0] eq "REF" ref ${$_[0];} eq "ARRAY"
Truth table66%2/3
A and B
A= ref $_[0] eq "REF"B= ref ${$_[0];} eq "ARRAY"
ABresult
0X0
100
111
76 2521 ▶ : ( ref $_[0] eq 'REF' and ref ${$_[0]} eq 'ARRAY' ) ? [ @${ $_[0] } ]
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'SCALAR' ? : 104 2417 2521
77 : undef;
78 }
79  
80 2337 ▶sub is_undef_value ($) {
Subroutine is_undef_value: called CC=4 SCAR=13.9
Pod documented
81 !defined($_[0])
82 or (
83 ref($_[0]) eq 'HASH'
84 and exists $_[0]->{-value}
85 and not defined $_[0]->{-value}
86 2337 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
not defined $_[0] or ref $_[0] eq "HASH" and exists $_[0]{"-value"} and not defined $_[0]{"-value"} 107 2230 2337
Condition100%9/9
!defined($_[0]) || ref $_[0] eq 'HASH' && exists $_[0]{'-value'} && !defined($_[0]{'-value'})
l!l&&r!l&&!r
107242206
ref $_[0] eq "HASH" and exists $_[0]{"-value"} and not defined $_[0]{"-value"}
!ll&&!rl&&r
21911524
ref $_[0] eq "HASH" and exists $_[0]{"-value"}
!ll&&!rl&&r
871132039
MC/DC100%4/4
!defined($_[0]) || ref $_[0] eq 'HASH' && exists $_[0]{'-value'} && !defined($_[0]{'-value'})
!defined($_[0]) ref $_[0] eq "HASH" exists $_[0]{"-value"} not defined $_[0]{"-value"}
Truth table100%5/5
not(A) || B and C and not(D)
A= !defined($_[0])B= ref $_[0] eq "HASH"C= exists $_[0]{"-value"}D= not defined $_[0]{"-value"}
ABCDresult
1XXX1
01111
00XX0
010X0
01100
87 }
88  
89 # FIXME XSify - this can be done so much more efficiently
90 47 ▶sub is_plain_value ($) {
Subroutine is_plain_value: called CC=12 SCAR=24.9
Pod documented
91 20 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
92 ! length ref $_[0] ? \($_[0])
93 : (
94 3 ▶ ref $_[0] eq 'HASH' and keys %{$_[0]} == 1
Branch: 1 branch
BranchTrueFalseTotal
defined($_[1] = builtin::blessed($_[0])) && (grep({*{qq[${_}::(""];}{'CODE'};} @{$_[2] = &mro::get_linear_isa($_[1]);}) || (grep({*{"${_}::(0+";}{'CODE'};} @{$_[2];}) || grep({*{"${_}::(bool";}{'CODE'};} @{$_[2];})) && !((($_[3]) = grep({*{"${_}::()";}{'CODE'};} @{$_[2];})) && defined ${"$_[3]::()";} && !${"$_[3]::()";})) ? : 32 11 43
Condition100%6/6
defined($_[1] = builtin::blessed($_[0])) and grep({*{qq[${_}::(""];}{"CODE"};} @{$_[2] = &mro::get_linear_isa($_[1]);}) || (grep({*{"${_}::(0+";}{"CODE"};} @{$_[2];}) || grep({*{"${_}::(bool";}{"CODE"};} @{$_[2];})) && !((($_[3]) = grep({*{"${_}::()";}{"CODE"};} @{$_[2];})) && defined ${"$_[3]::()";} && !${"$_[3]::()";})
!ll&&!rl&&r
3832
grep {*{qq[${_}::(""];}{"CODE"};} @{$_[2] = &mro::get_linear_isa($_[1]);} or grep({*{"${_}::(0+";}{"CODE"};} @{$_[2];}) || grep({*{"${_}::(bool";}{"CODE"};} @{$_[2];}) and not +(($_[3]) = grep({*{"${_}::()";}{"CODE"};} @{$_[2];})) && defined ${"$_[3]::()";} && !${"$_[3]::()";}
l!l&&r!l&&!r
8248
MC/DC100%3/3
defined($_[1] = builtin::blessed($_[0])) and grep({*{qq[${_}::(""];}{"CODE"};} @{$_[2] = &mro::get_linear_isa($_[1]);}) || (grep({*{"${_}::(0+";}{"CODE"};} @{$_[2];}) || grep({*{"${_}::(bool";}{"CODE"};} @{$_[2];})) && !((($_[3]) = grep({*{"${_}::()";}{"CODE"};} @{$_[2];})) && defined ${"$_[3]::()";} && !${"$_[3]::()";})
defined($_[1] = builtin::blessed($_[0])) grep {*{qq[${_}::(""];}{"CODE"};} @{$_[2] = &mro::get_linear_isa($_[1]);} grep({*{"${_}::(0+";}{"CODE"};} @{$_[2];}) || grep({*{"${_}::(bool";}{"CODE"};} @{$_[2];}) and not +(($_[3]) = grep({*{"${_}::()";}{"CODE"};} @{$_[2];})) && defined ${"$_[3]::()";} && !${"$_[3]::()";}
Truth table100%4/4
A and B or C
A= defined($_[1] = builtin::blessed($_[0]))B= grep {*{qq[${_}::(""];}{"CODE"};} @{$_[2] = &mro::get_linear_isa($_[1]);}C= grep({*{"${_}::(0+";}{"CODE"};} @{$_[2];}) || grep({*{"${_}::(bool";}{"CODE"};} @{$_[2];}) and not +(($_[3]) = grep({*{"${_}::()";}{"CODE"};} @{$_[2];})) && defined ${"$_[3]::()";} && !${"$_[3]::()";}
ABCresult
0XX0
1000
11X1
1011
95 and
96 exists $_[0]->{-value}
97 ) ? \($_[0]->{-value})
98 : (
99 # reuse @_ for even moar speedz
100 defined ( $_[1] = Scalar::Util::blessed $_[0] )
101 and
102 # deliberately not using Devel::OverloadInfo - the checks we are
103 # intersted in are much more limited than the fullblown thing, and
104 # this is a very hot piece of code
105 (
106 # simply using ->can('(""') can leave behind stub methods that
107 # break actually using the overload later (see L<perldiag/Stub
108 # found while resolving method "%s" overloading "%s" in package
109 # "%s"> and the source of overload::mycan())
110 #
111 # either has stringification which DBI SHOULD prefer out of the box
112 60 ▶ grep { *{ (qq[${_}::(""]) }{CODE} } @{ $_[2] = mro::get_linear_isa( $_[1] ) }
Condition100%6/6
grep({*{"${_}::(0+";}{"CODE"};} @{$_[2];}) || grep({*{"${_}::(bool";}{"CODE"};} @{$_[2];}) and not +(($_[3]) = grep({*{"${_}::()";}{"CODE"};} @{$_[2];})) && defined ${"$_[3]::()";} && !${"$_[3]::()";}
!ll&&!rl&&r
2624
grep {*{"${_}::(0+";}{"CODE"};} @{$_[2];} or grep {*{"${_}::(bool";}{"CODE"};} @{$_[2];}
l!l&&r!l&&!r
2282
MC/DC0%0/3
grep({*{"${_}::(0+";}{"CODE"};} @{$_[2];}) || grep({*{"${_}::(bool";}{"CODE"};} @{$_[2];}) and not +(($_[3]) = grep({*{"${_}::()";}{"CODE"};} @{$_[2];})) && defined ${"$_[3]::()";} && !${"$_[3]::()";}
grep {*{"${_}::(0+";}{"CODE"};} @{$_[2];} grep {*{"${_}::(bool";}{"CODE"};} @{$_[2];} not +(($_[3]) = grep({*{"${_}::()";}{"CODE"};} @{$_[2];})) && defined ${"$_[3]::()";} && !${"$_[3]::()";}
Truth table0%0/5
A or B and not(C)
A= grep {*{"${_}::(0+";}{"CODE"};} @{$_[2];}B= grep {*{"${_}::(bool";}{"CODE"};} @{$_[2];}C= not +(($_[3]) = grep({*{"${_}::()";}{"CODE"};} @{$_[2];})) && defined ${"$_[3]::()";} && !${"$_[3]::()";}
ABCresult
00X0
1X00
0100
1X11
0111
113 or
114 # has nummification or boolification, AND fallback is *not* disabled
115 (
116 SQL::Abstract::_ENV_::DETECT_AUTOGENERATED_STRINGIFICATION
117 and
118 (
119 48 grep { *{"${_}::(0+"}{CODE} } @{$_[2]}
120 or
121 14 ▶ grep { *{"${_}::(bool"}{CODE} } @{$_[2]}
Condition83%5/6
(($_[3]) = grep({*{"${_}::()";}{'CODE'};} @{$_[2];})) && defined ${"$_[3]::()";} && !${"$_[3]::()";}
!ll&&!rl&&r
1686
($_[3]) = grep({*{"${_}::()";}{"CODE"};} @{$_[2];}) and defined ${"$_[3]::()";}
!ll&&!rl&&r
16014
MC/DC0%0/3
(($_[3]) = grep({*{"${_}::()";}{'CODE'};} @{$_[2];})) && defined ${"$_[3]::()";} && !${"$_[3]::()";}
($_[3]) = grep({*{"${_}::()";}{"CODE"};} @{$_[2];}) defined ${"$_[3]::()";} !${"$_[3]::()";}
Truth table0%0/4
A and B && not(C)
A= ($_[3]) = grep({*{"${_}::()";}{"CODE"};} @{$_[2];})B= defined ${"$_[3]::()";}C= !${"$_[3]::()";}
ABCresult
0XX0
10X0
1100
1111
122 )
123 and
124 (
125 # no fallback specified at all
126 46 ! ( ($_[3]) = grep { *{"${_}::()"}{CODE} } @{$_[2]} )
127 or
128 # fallback explicitly undef
129 14 ! defined ${"$_[3]::()"}
130 or
131 # explicitly true
132 47 ▶ !! ${"$_[3]::()"}
Branch: 2 branches
BranchTrueFalseTotal
!length(ref $_[0]) ? : 2 45 47
ref $_[0] eq 'HASH' && keys %{$_[0];} == 1 && exists $_[0]{'-value'} ? : 2 43 45
Condition83%5/6
ref $_[0] eq "HASH" and keys %{$_[0];} == 1 and exists $_[0]{"-value"}
!ll&&!rl&&r
4302
ref $_[0] eq "HASH" and keys %{$_[0];} == 1
!ll&&!rl&&r
4212
MC/DC66%2/3
ref $_[0] eq "HASH" and keys %{$_[0];} == 1 and exists $_[0]{"-value"}
ref $_[0] eq "HASH" keys %{$_[0];} == 1 exists $_[0]{"-value"}
Truth table75%3/4
A and B and C
A= ref $_[0] eq "HASH"B= keys %{$_[0];} == 1C= exists $_[0]{"-value"}
ABCresult
0XX0
10X0
1100
1111
133 )
134 )
135 )
136 ) ? \($_[0])
137 : undef;
138 }
139  
140  
141  
142 #======================================================================
143 # NEW
144 #======================================================================
145  
146 our %Defaults = (
147 expand => {
148 bool => '_expand_bool',
149 row => '_expand_row',
150 op => '_expand_op',
151 func => '_expand_func',
152 values => '_expand_values',
153 list => '_expand_list',
154 },
155 expand_op => {
156 (map +($_ => __PACKAGE__->make_binop_expander('_expand_between')),
157 qw(between not_between)),
158 (map +($_ => __PACKAGE__->make_binop_expander('_expand_in')),
159 qw(in not_in)),
160 (map +($_ => '_expand_op_andor'), ('and', 'or')),
161 (map +($_ => '_expand_op_is'), ('is', 'is_not')),
162 (map +($_ => __PACKAGE__->make_unop_expander("_expand_${_}")),
163 qw(ident value nest)),
164 644 ▶ bind => __PACKAGE__->make_unop_expander(sub { +{ -bind => $_[2] } }),
Subroutine __ANON__: called CC=1 SCAR=0.0
165 },
166 render => {
167 (map +($_, "_render_$_"),
168 qw(op func bind ident literal row values keyword)),
169 },
170 render_op => {
171 (map +($_ => '_render_op_between'), 'between', 'not_between'),
172 (map +($_ => '_render_op_in'), 'in', 'not_in'),
173 (map +($_ => '_render_unop_postfix'),
174 'is_null', 'is_not_null', 'asc', 'desc', 'nulls_first', 'nulls_last',
175 ),
176 (not => '_render_unop_paren'),
177 (map +($_ => '_render_op_andor'), qw(and or)),
178 ',' => '_render_op_multop',
179 },
180 clauses_of => {
181 delete => [ qw(target where returning) ],
182 update => [ qw(target set where returning) ],
183 insert => [ qw(target fields from returning) ],
184 select => [ qw(select from where order_by) ],
185 },
186 expand_clause => {
187 'delete.from' => '_expand_delete_clause_target',
188 'update.update' => '_expand_update_clause_target',
189 'insert.into' => '_expand_insert_clause_target',
190 'insert.values' => '_expand_insert_clause_from',
191 },
192 render_clause => {
193 'delete.target' => '_render_delete_clause_target',
194 'update.target' => '_render_update_clause_target',
195 'insert.target' => '_render_insert_clause_target',
196 'insert.fields' => '_render_insert_clause_fields',
197 'insert.from' => '_render_insert_clause_from',
198 },
199 );
200  
201 20 foreach my $stmt (keys %{$Defaults{clauses_of}}) {
202 80 $Defaults{expand}{$stmt} = '_expand_statement';
203 80 $Defaults{render}{$stmt} = '_render_statement';
204 80 foreach my $clause (@{$Defaults{clauses_of}{$stmt}}) {
205 300 $Defaults{expand_clause}{"${stmt}.${clause}"}
206 = "_expand_${stmt}_clause_${clause}";
207 }
208 }
209  
210 {
211 0 ▶ my $expand_ident = sub { $_[2] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
212  
213 my %render_returning = (
214 map {
215 20 my $method = "_${_}_returning";
216 0 ▶ ($_ => sub { [ $_[0]->$method($_[3]) ] });
Subroutine __ANON__: not called CC=1 SCAR=1.2
217 } qw(insert update delete)
218 );
219  
220 0 ▶ my $expand_table = sub { +{ -literal => [ $_[0]->_table($_[2]) ] } };
Subroutine __ANON__: not called CC=1 SCAR=1.2
221  
222 0 ▶ my $render_order_by = sub { [ $_[0]->_order_by($_[2]) ] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
223  
224 0 ▶ my $render_select_select = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
225 0 my @super = $_[0]->_select_fields($_[2]);
226 0 ▶ my $effort = [
Branch: 1 branch
BranchTrueFalseTotal
ref $super[0] eq 'HASH' ? : 0 0 0
227 ref($super[0]) eq 'HASH'
228 ? $_[0]->render_expr($super[0])
229 : @super
230 ];
231 0 return $_[0]->join_query_parts(
232 ' ', { -keyword => 'select' }, $effort
233 );
234 20 };
235  
236 my %expand_field_type = map {
237 20 my $type = $_;
238 40 my $meth = "_where_field_".uc($type);
239 4 ▶ my $exp = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
240 4 my ($self, $op, $v, $k) = @_;
241 4 $op = join ' ', split '_', $op;
242 4 return +{ -literal => [
243 $self->$meth($k, $op, $v)
244 ] };
245 40 };
246 40 ($type => $exp)
247 } qw(in between);
248  
249 0 ▶ my $dbic_select_where = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
250 0 my ($sql, @bind) = $_[0]->where($_[2]);
251 0 s/\A\s+//, s/\s+\Z// for $sql;
252 0 return [ $sql, @bind ];
253 20 };
254  
255 0 ▶ my $dbic_expand_ident = __PACKAGE__->make_unop_expander(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
256 0 my ($self, undef, $body) = @_;
257 0 ▶ $body = $body->from if Scalar::Util::blessed($body);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($body) 0 0 0
258 0 $self->_expand_ident(ident => $body);
259 20 });
260  
261 823 ▶ sub __maybe_setup_subclass_overrides {
Subroutine __maybe_setup_subclass_overrides: called CC=11 SCAR=29.5
262 823 my ($class, $opts) = @_;
263  
264 823 ▶ return if $class eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if $class eq __PACKAGE__ 817 6 823
265  
266 # we are a subclass, so check for overriden methods
267  
268 6 ▶ my $subclassed = sub { __PACKAGE__->can($_[0]) != $class->can($_[0]) };
Subroutine __ANON__: called CC=1 SCAR=0.0
269  
270 6 foreach my $type (qw(insert update delete)) {
271 18 my $method = "_${type}_returning";
272 18 ▶ if ($subclassed->($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$subclassed($method)) 0 18 18
273 0 my $clause = "${type}.returning";
274 0 $opts->{expand_clause}{$clause} = $expand_ident;
275 0 $opts->{render_clause}{$clause} = $render_returning{$type};
276 }
277 }
278 6 ▶ if ($subclassed->('_table')) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$subclassed("_table")) 0 6 6
279 0 $opts->{expand_clause}{'select.from'} = $expand_table;
280 }
281 6 ▶ if ($subclassed->('_order_by')) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$subclassed("_order_by")) 0 6 6
282 0 $opts->{expand_clause}{'select.order_by'} = $expand_ident;
283 0 $opts->{render_clause}{'select.order_by'} = $render_order_by;
284 }
285 6 ▶ if ($subclassed->('_select_fields')) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$subclassed("_select_fields")) 0 6 6
286 0 $opts->{expand_clause}{'select.select'} = $expand_ident;
287 0 $opts->{render_clause}{'select.select'} = $render_select_select;
288 }
289 6 foreach my $type (qw(in between)) {
290 12 my $meth = "_where_field_".uc($type);
291 12 ▶ if ($subclassed->($meth)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$subclassed($meth)) 4 8 12
292 4 my $exp = $expand_field_type{$type};
293 4 $opts->{expand_op}{$_} = $exp for $type, "not_${type}";
294 }
295 }
296 6 ▶ if ($class->isa('DBIx::Class::SQLMaker')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->isa("DBIx::Class::SQLMaker")) 0 6 6
297 0 $opts->{warn_once_on_nest} = 1;
298 0 $opts->{disable_old_special_ops} = 1;
299 0 $opts->{render_clause}{'select.where'} = $dbic_select_where;
300 0 $opts->{expand_op}{ident} = $dbic_expand_ident;
301 }
302 }
303 }
304  
305 20 ▶sub new {
Subroutine new: called CC=19 SCAR=29.9
Pod documented
306 823 my $self = shift;
307 823 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
08230
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
308 823 ▶ my %opt = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 251 572 823
309  
310 # choose our case by keeping an option around
311 823 ▶ delete $opt{case} if $opt{case} && $opt{case} ne 'lower';
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"case"} and $opt{"case"} ne "lower" 2 821 823
Condition100%3/3
$opt{"case"} and $opt{"case"} ne "lower"
!ll&&!rl&&r
81562
MC/DC100%2/2
$opt{"case"} and $opt{"case"} ne "lower"
$opt{"case"} $opt{"case"} ne "lower"
Truth table100%3/3
A and B
A= $opt{"case"}B= $opt{"case"} ne "lower"
ABresult
0X0
100
111
312  
313 # default logic for interpreting arrayrefs
314 823 ▶ $opt{logic} = $opt{logic} ? uc $opt{logic} : 'OR';
Branch: 1 branch
BranchTrueFalseTotal
$opt{'logic'} ? : 9 814 823
315  
316 # an arrayref as a column value in insert / update is one bind value;
317 # literal SQL is \[ $sql, @bind ] (array_datatypes => 0 for the old way)
318 823 ▶ $opt{array_datatypes} = 1 unless defined $opt{array_datatypes};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt{"array_datatypes"} 813 10 823
319  
320 # how to return bind vars
321 823 ▶ $opt{bindtype} ||= 'normal';
Condition100%2/2
$opt{"bindtype"} ||= "normal"
l!l
56767
MC/DC100%1/1
$opt{"bindtype"} ||= "normal"
$opt{"bindtype"}
Truth table100%2/2
A
A= $opt{"bindtype"}
Aresult
11
00
322  
323 # default comparison is "=", but can be overridden
324 823 ▶ $opt{cmp} ||= '=';
Condition100%2/2
$opt{"cmp"} ||= "="
l!l
10813
MC/DC100%1/1
$opt{"cmp"} ||= "="
$opt{"cmp"}
Truth table100%2/2
A
A= $opt{"cmp"}
Aresult
11
00
325  
326 # try to recognize which are the 'equality' and 'inequality' ops
327 # (temporary quickfix (in 2007), should go through a more seasoned API)
328 823 $opt{equality_op} = qr/^( \Q$opt{cmp}\E | \= )$/ix;
329 823 $opt{inequality_op} = qr/^( != | <> )$/ix;
330  
331 823 $opt{like_op} = qr/^ (is_)?r?like $/xi;
332 823 $opt{not_like_op} = qr/^ (is_)?not_r?like $/xi;
333  
334 # SQL booleans
335 823 ▶ $opt{sqltrue} ||= '1=1';
Condition50%1/2
$opt{"sqltrue"} ||= "1=1"
l!l
0823
MC/DC0%0/1
$opt{"sqltrue"} ||= "1=1"
$opt{"sqltrue"}
Truth table50%1/2
A
A= $opt{"sqltrue"}
Aresult
11
00
336 823 ▶ $opt{sqlfalse} ||= '0=1';
Condition50%1/2
$opt{"sqlfalse"} ||= "0=1"
l!l
0823
MC/DC0%0/1
$opt{"sqlfalse"} ||= "0=1"
$opt{"sqlfalse"}
Truth table50%1/2
A
A= $opt{"sqlfalse"}
Aresult
11
00
337  
338 # special operators
339 823 ▶ $opt{special_ops} ||= [];
Condition100%2/2
$opt{"special_ops"} ||= []
l!l
1822
MC/DC100%1/1
$opt{"special_ops"} ||= []
$opt{"special_ops"}
Truth table100%2/2
A
A= $opt{"special_ops"}
Aresult
11
00
340  
341 # unary operators
342 823 ▶ $opt{unary_ops} ||= [];
Condition100%2/2
$opt{"unary_ops"} ||= []
l!l
1822
MC/DC100%1/1
$opt{"unary_ops"} ||= []
$opt{"unary_ops"}
Truth table100%2/2
A
A= $opt{"unary_ops"}
Aresult
11
00
343  
344 # rudimentary sanity-check for user supplied bits treated as functions/operators
345 # If a purported function matches this regular expression, an exception is thrown.
346 # Literal SQL is *NOT* subject to this check, only functions (and column names
347 # when quoting is not in effect)
348  
349 # FIXME
350 # need to guard against ()'s in column names too, but this will break tons of
351 # hacks... ideas anyone?
352 823 ▶ $opt{injection_guard} ||= qr/
Condition50%1/2
$opt{"injection_guard"} ||= qr/ \; | ^ \s* go \s /mix
l!l
0823
MC/DC0%0/1
$opt{"injection_guard"} ||= qr/ \; | ^ \s* go \s /mix
$opt{"injection_guard"}
Truth table50%1/2
A
A= $opt{"injection_guard"}
Aresult
11
00
353 \;
354 |
355 ^ \s* go \s
356 /xmi;
357  
358 823 $opt{expand_unary} = {};
359  
360 823 foreach my $name (sort keys %Defaults) {
361 5761 ▶ $opt{$name} = { %{$Defaults{$name}}, %{$opt{$name}||{}} };
Condition50%1/2
$opt{$name} || {}
l!l
05761
MC/DC0%0/1
$opt{$name} || {}
$opt{$name}
Truth table50%1/2
A
A= $opt{$name}
Aresult
11
00
362 }
363  
364 823 $class->__maybe_setup_subclass_overrides(\%opt);
365  
366 823 ▶ if ($opt{lazy_join_sql_parts}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"lazy_join_sql_parts"}) 1 822 823
367 1 require SQL::Abstract::Parts;
368 1 ▶ $opt{join_sql_parts} ||= sub { SQL::Abstract::Parts->new(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$opt{"join_sql_parts"} ||= sub { "SQL::Abstract::Parts"->new(@_); }
l!l&&r!l&&!r
010
MC/DC0%0/2
$opt{"join_sql_parts"} ||= sub { "SQL::Abstract::Parts"->new(@_); }
$opt{"join_sql_parts"} sub { "SQL::Abstract::Parts"->new(@_); }
Truth table33%1/3
A ||= B
A= $opt{"join_sql_parts"}B= sub { "SQL::Abstract::Parts"->new(@_); }
ABresult
1X1
011
000
369 }
370  
371 823 ▶ $opt{join_sql_parts} ||= $class->can('default_join_sql_parts');
Condition66%2/3
$opt{"join_sql_parts"} ||= $class->can("default_join_sql_parts")
l!l&&r!l&&!r
18220
MC/DC0%0/2
$opt{"join_sql_parts"} ||= $class->can("default_join_sql_parts")
$opt{"join_sql_parts"} $class->can("default_join_sql_parts")
Truth table66%2/3
A ||= B
A= $opt{"join_sql_parts"}B= $class->can("default_join_sql_parts")
ABresult
1X1
011
000
372  
373 823 return bless \%opt, $class;
374 }
375  
376 140 ▶sub _ext_rw {
Subroutine _ext_rw: called CC=2 SCAR=6.9
377 140 my ($self, $name, $key, $value) = @_;
378 140 ▶ return $self->{$name}{$key} unless @_ > 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 3 22 118 140
379 118 $self->{$name}{$key} = $value;
380 118 return $self;
381 }
382  
383 100 ▶sub make_unop_expander {
Subroutine make_unop_expander: called CC=1 SCAR=0.0
Pod documented
384 100 my (undef, $exp) = @_;
385 4677 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
386 4677 my ($self, $name, $body, $k) = @_;
387 4677 ▶ return $self->_expand_hashpair_cmp($k, { "-${name}" => $body })
Branch: 1 branch
BranchTrueFalseTotal
if defined $k 15 4662 4677
388 if defined($k);
389 4662 return $self->$exp($name, $body);
390 }
391 100 }
392  
393 82 ▶sub make_binop_expander {
Subroutine make_binop_expander: called CC=1 SCAR=0.0
Pod documented
394 82 my (undef, $exp) = @_;
395 169 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
396 169 my ($self, $name, $body, $k) = @_;
397 169 ▶ $k = shift @{$body = [ @$body ]} unless defined $k;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k 49 120 169
398 169 ▶ $k = ref($k) ? $k : { -ident => $k };
Branch: 1 branch
BranchTrueFalseTotal
ref $k ? : 45 124 169
399 169 return $self->$exp($name, $body, $k);
400 }
401 82 }
402  
403 2 ▶sub plugin {
Subroutine plugin: called CC=2 SCAR=7.0
Pod documented
404 2 my ($self, $plugin, @args) = @_;
405 2 ▶ unless (ref $plugin) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $plugin) 2 0 2
406 2 $plugin =~ s/\A\+/${\__PACKAGE__}::Plugin::/;
407 2 require(join('/', split '::', $plugin).'.pm');
408 }
409 2 $plugin->apply_to($self, @args);
410 2 return $self;
411 }
412  
413 20 ▶BEGIN {
Subroutine BEGIN: called CC=10 SCAR=30.2
414 20 foreach my $type (qw(
415 expand op_expand render op_render clause_expand clause_render
416 )) {
417 120 my $name = join '_', reverse split '_', $type;
418 120 my $singular = "${type}er";
419  
420 0 ▶ eval qq{sub ${singular} {
Subroutine clause_expander: called CC=2 SCAR=9.0
Subroutine clause_renderer: called CC=2 SCAR=9.0
Subroutine expander: called CC=2 SCAR=9.0
Subroutine op_expander: not called CC=2 SCAR=9.0
Subroutine op_renderer: not called CC=2 SCAR=9.0
Subroutine renderer: called CC=2 SCAR=9.0
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 7 branches
BranchTrueFalseTotal
eval "sub $singular {\n my \$self = shift;\n return \$self->_ext_rw('${name}', \@_) if \@_ == 1;\n return \$self->${singular}s(\@_)\n }; 1 " or die "Method builder failed for ${singular}: $@" 120 0 120
if @_ == 1 2 0 2
if @_ == 1 0 10 10
if @_ == 1 0 22 22
if @_ == 1 0 0 0
if @_ == 1 0 0 0
if @_ == 1 0 14 14
421 my \$self = shift;
422 return \$self->_ext_rw('${name}', \@_) if \@_ == 1;
423 return \$self->${singular}s(\@_)
424 }; 1 } or die "Method builder failed for ${singular}: $@";
425 0 ▶ eval qq{sub wrap_${singular} {
Subroutine wrap_clause_expander: called CC=1 SCAR=1.6
Subroutine wrap_clause_renderer: not called CC=1 SCAR=1.6
Subroutine wrap_expander: called CC=1 SCAR=1.6
Subroutine wrap_op_expander: not called CC=1 SCAR=1.6
Subroutine wrap_op_renderer: not called CC=1 SCAR=1.6
Subroutine wrap_renderer: not called CC=1 SCAR=1.6
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
eval "sub wrap_$singular {\n shift->wrap_${singular}s(\@_)\n }; 1 " or die "Method builder failed for wrap_${singular}: $@" 120 0 120
426 shift->wrap_${singular}s(\@_)
427 }; 1 } or die "Method builder failed for wrap_${singular}: $@";
428  
429 0 ▶ eval qq{sub ${singular}s {
Subroutine clause_expanders: called CC=2 SCAR=7.6
Subroutine clause_renderers: called CC=2 SCAR=7.6
Subroutine expanders: called CC=2 SCAR=7.6
Subroutine op_expanders: not called CC=2 SCAR=7.6
Subroutine op_renderers: not called CC=2 SCAR=7.6
Subroutine renderers: called CC=2 SCAR=7.6
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 7 branches
BranchTrueFalseTotal
eval "sub ${singular}s {\n my (\$self, \@args) = \@_;\n while (my (\$this_key, \$this_value) = splice(\@args, 0, 2)) {\n \$self->_ext_rw('${name}', \$this_key, \$this_value);\n }\n return \$self;\n }; 1 " or die "Method builder failed for ${singular}s: $@" 120 0 120
if (() = splice(@args, 0, 2)) 50 34 84
if (() = splice(@args, 0, 2)) 10 10 20
if (() = splice(@args, 0, 2)) 22 22 44
if (() = splice(@args, 0, 2)) 0 0 0
if (() = splice(@args, 0, 2)) 0 0 0
if (() = splice(@args, 0, 2)) 14 14 28
430 my (\$self, \@args) = \@_;
431 while (my (\$this_key, \$this_value) = splice(\@args, 0, 2)) {
432 \$self->_ext_rw('${name}', \$this_key, \$this_value);
433 }
434 return \$self;
435 }; 1 } or die "Method builder failed for ${singular}s: $@";
436 0 ▶ eval qq{sub wrap_${singular}s {
Subroutine wrap_clause_expanders: called CC=2 SCAR=9.0
Subroutine wrap_clause_renderers: not called CC=2 SCAR=9.0
Subroutine wrap_expanders: called CC=2 SCAR=9.0
Subroutine wrap_op_expanders: called CC=2 SCAR=9.0
Subroutine wrap_op_renderers: not called CC=2 SCAR=9.0
Subroutine wrap_renderers: not called CC=2 SCAR=9.0
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 7 branches
BranchTrueFalseTotal
eval "sub wrap_${singular}s {\n my (\$self, \@args) = \@_;\n while (my (\$this_key, \$this_builder) = splice(\@args, 0, 2)) {\n my \$orig = \$self->_ext_rw('${name}', \$this_key);\n \$self->_ext_rw(\n '${name}', \$this_key,\n \$this_builder->(\$orig, '${name}', \$this_key),\n );\n }\n return \$self;\n }; 1 " or die "Method builder failed for wrap_${singular}s: $@" 120 0 120
if (() = splice(@args, 0, 2)) 2 2 4
if (() = splice(@args, 0, 2)) 0 0 0
if (() = splice(@args, 0, 2)) 10 10 20
if (() = splice(@args, 0, 2)) 8 4 12
if (() = splice(@args, 0, 2)) 0 0 0
if (() = splice(@args, 0, 2)) 0 0 0
437 my (\$self, \@args) = \@_;
438 while (my (\$this_key, \$this_builder) = splice(\@args, 0, 2)) {
439 my \$orig = \$self->_ext_rw('${name}', \$this_key);
440 \$self->_ext_rw(
441 '${name}', \$this_key,
442 \$this_builder->(\$orig, '${name}', \$this_key),
443 );
444 }
445 return \$self;
446 }; 1 } or die "Method builder failed for wrap_${singular}s: $@";
447 0 ▶ eval qq{sub ${singular}_list { sort keys %{\$_[0]->{\$name}} }; 1; }
Subroutine clause_expander_list: not called CC=1 SCAR=5.0
Subroutine clause_renderer_list: not called CC=1 SCAR=5.0
Subroutine expander_list: not called CC=1 SCAR=5.0
Subroutine op_expander_list: not called CC=1 SCAR=5.0
Subroutine op_renderer_list: not called CC=1 SCAR=5.0
Subroutine renderer_list: not called CC=1 SCAR=5.0
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
eval "sub ${singular}_list { sort keys %{\$_[0]->{\$name}} }; 1; " or die "Method builder failed for ${singular}_list: $@" 120 0 120
448 or die "Method builder failed for ${singular}_list: $@";
449 }
450 20 foreach my $singular (qw(unop_expander binop_expander)) {
451 0 ▶ eval qq{sub ${singular} { shift->${singular}s(\@_) }; 1 }
Subroutine binop_expander: called CC=1 SCAR=0.6
Subroutine unop_expander: not called CC=1 SCAR=0.6
Pod documented
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
eval "sub $singular { shift->${singular}s(\@_) }; 1 " or die "Method builder failed for ${singular}: $@" 40 0 40
452 or die "Method builder failed for ${singular}: $@";
453 0 ▶ eval qq{sub ${singular}s {
Subroutine binop_expanders: called CC=2 SCAR=8.8
Subroutine unop_expanders: not called CC=2 SCAR=8.8
Pod documented
Pod documented
Branch: 3 branches
BranchTrueFalseTotal
eval "sub ${singular}s {\n my (\$self, \@args) = \@_;\n while (my (\$this_key, \$this_value) = splice(\@args, 0, 2)) {\n \$self->_ext_rw(\n expand_op => \$this_key,\n \$self->make_$singular(\$this_value),\n );\n }\n return \$self;\n }; 1 " or die "Method builder failed for ${singular}s: $@" 40 0 40
if (() = splice(@args, 0, 2)) 2 2 4
if (() = splice(@args, 0, 2)) 0 0 0
454 my (\$self, \@args) = \@_;
455 while (my (\$this_key, \$this_value) = splice(\@args, 0, 2)) {
456 \$self->_ext_rw(
457 expand_op => \$this_key,
458 \$self->make_${singular}(\$this_value),
459 );
460 }
461 return \$self;
462 }; 1 } or die "Method builder failed for ${singular}s: $@";
463 }
464 }
465  
466 1 ▶sub statement_list { sort keys %{$_[0]->{clauses_of}} }
Subroutine statement_list: called CC=1 SCAR=0.0
Pod documented
467  
468 26 ▶sub clauses_of {
Subroutine clauses_of: called CC=5 SCAR=16.2
Pod documented
469 26 my ($self, $of, @clauses) = @_;
470 26 ▶ unless (@clauses) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@clauses) 11 15 26
471 11 ▶ return @{$self->{clauses_of}{$of}||[]};
Condition50%1/2
$self->{'clauses_of'}{$of} || []
l!l
110
MC/DC0%0/1
$self->{'clauses_of'}{$of} || []
$self->{'clauses_of'}{$of}
Truth table50%1/2
A
A= $self->{'clauses_of'}{$of}
Aresult
11
00
472 }
473 15 ▶ if (ref($clauses[0]) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $clauses[0] eq "CODE") 4 11 15
474 4 ▶ @clauses = $self->${\($clauses[0])}(@{$self->{clauses_of}{$of}||[]});
Condition50%1/2
$self->{'clauses_of'}{$of} || []
l!l
40
MC/DC0%0/1
$self->{'clauses_of'}{$of} || []
$self->{'clauses_of'}{$of}
Truth table50%1/2
A
A= $self->{'clauses_of'}{$of}
Aresult
11
00
475 }
476 15 $self->{clauses_of}{$of} = \@clauses;
477 15 return $self;
478 }
479  
480 5 ▶sub clone {
Subroutine clone: called CC=2 SCAR=6.9
Pod documented
481 5 my ($self) = @_;
482 bless(
483 {
484 (map +($_ => (
485 ref($self->{$_}) eq 'HASH'
486 40 ? { %{$self->{$_}} }
487 5 ▶ : $self->{$_}
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{$_} eq 'HASH' ? : 40 80 120
488 )), keys %$self),
489 },
490 ref($self)
491 );
492 }
493  
494 28 ▶sub sqltrue { +{ -literal => [ $_[0]->{sqltrue} ] } }
Subroutine sqltrue: called CC=1 SCAR=0.0
Pod documented
495 22 ▶sub sqlfalse { +{ -literal => [ $_[0]->{sqlfalse} ] } }
Subroutine sqlfalse: called CC=1 SCAR=0.0
Pod documented
496  
497 9877 ▶sub _assert_pass_injection_guard {
Subroutine _assert_pass_injection_guard: called CC=2 SCAR=6.9
498 9877 ▶ if ($_[1] =~ $_[0]->{injection_guard}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] =~ /$_[0]{"injection_guard"}/mix) 9 9868 9877
499 9 my $class = ref $_[0];
500 9 $_[0]->puke("Possible SQL injection attempt '$_[1]'. If this is indeed a part of the "
501 . "desired SQL use literal SQL ( \'...' or \[ '...' ] ) or supply your own "
502 . "{injection_guard} attribute to ${class}->new()")
503 }
504 }
505  
506  
507 #======================================================================
508 # INSERT methods
509 #======================================================================
510  
511 60 ▶sub insert {
Subroutine insert: called CC=4 SCAR=13.9
Pod documented
512 60 my ($self, $table, $data, $options) = @_;
513  
514 60 my $stmt = do {
515 60 ▶ if (ref($table) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $table eq 'HASH') { } 4 56 60
516 4 $table;
517 } else {
518 56 ▶ my %clauses = (target => $table, values => $data, %{$options||{}});
Condition100%2/2
$options || {}
l!l
1145
MC/DC100%1/1
$options || {}
$options
Truth table100%2/2
A
A= $options
Aresult
11
00
519 56 \%clauses;
520 }
521 };
522 60 my @rendered = $self->render_statement({ -insert => $stmt });
523 58 ▶ return wantarray ? @rendered : $rendered[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 58 0 58
524 }
525  
526 61 ▶sub _expand_insert_clause_target {
Subroutine _expand_insert_clause_target: called CC=1 SCAR=0.0
527 61 +(target => $_[0]->expand_expr($_[2], -ident));
528 }
529  
530 3 ▶sub _expand_insert_clause_fields {
Subroutine _expand_insert_clause_fields: called CC=2 SCAR=9.2
531 3 ▶ return +{ -row => [
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[2] eq "ARRAY" 3 0 3
532 $_[0]->expand_expr({ -list => $_[2] }, -ident)
533 ] } if ref($_[2]) eq 'ARRAY';
534 0 return $_[2]; # should maybe still expand somewhat?
535 }
536  
537 56 ▶sub _expand_insert_clause_from {
Subroutine _expand_insert_clause_from: called CC=5 SCAR=16.4
538 56 my ($self, undef, $data) = @_;
539 56 ▶ if (ref($data) eq 'HASH' and (keys(%$data))[0] =~ /^-/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq "HASH" and (keys %$data)[0] =~ /^-/) 0 56 56
Condition66%2/3
ref $data eq "HASH" and (keys %$data)[0] =~ /^-/
!ll&&!rl&&r
23330
MC/DC0%0/2
ref $data eq "HASH" and (keys %$data)[0] =~ /^-/
ref $data eq "HASH" (keys %$data)[0] =~ /^-/
Truth table66%2/3
A and B
A= ref $data eq "HASH"B= (keys %$data)[0] =~ /^-/
ABresult
0X0
100
111
540 0 return $self->expand_expr($data);
541 }
542 56 ▶ if (my $literal = is_literal_value($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $literal = &is_literal_value($data)) 1 55 56
543 1 return (from => { -literal => $literal });
544 }
545 55 my ($f_aqt, $v_aqt) = $self->_expand_insert_values($data);
546 return (
547 55 ▶ from => { -values => [ $v_aqt ] },
Branch: 1 branch
BranchTrueFalseTotal
$f_aqt ? : 33 22 55
548 ($f_aqt ? (fields => $f_aqt) : ()),
549 );
550 }
551  
552 12 ▶sub _expand_insert_clause_returning {
Subroutine _expand_insert_clause_returning: called CC=1 SCAR=0.0
553 12 +(returning => $_[0]->expand_expr({ -list => $_[2] }, -ident));
554 }
555  
556 55 ▶sub _expand_insert_values {
Subroutine _expand_insert_values: called CC=6 SCAR=18.8
557 55 my ($self, $data) = @_;
558 55 ▶ if (is_literal_value($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&is_literal_value($data)) { } 0 55 55
559 0 (undef, $self->expand_expr($data));
560 } else {
561 my ($fields, $values) = (
562 ref($data) eq 'HASH' ?
563 55 ▶ ([ sort keys %$data ], [ @{$data}{sort keys %$data} ])
Branch: 1 branch
BranchTrueFalseTotal
ref $data eq 'HASH' ? : 33 22 55
564 : ([], $data)
565 );
566  
567 # no names (arrayref) means can't generate bindtype
568 55 ▶ !($fields) && $self->{bindtype} eq 'columns'
Branch: 1 branch
BranchTrueFalseTotal
not $fields and $self->{"bindtype"} eq "columns" and $self->belch("can't do 'columns' bindtype when called with arrayref") 0 55 55
Condition33%1/3
not $fields and $self->{"bindtype"} eq "columns"
!ll&&!rl&&r
5500
MC/DC0%0/2
not $fields and $self->{"bindtype"} eq "columns"
not $fields $self->{"bindtype"} eq "columns"
Truth table33%1/3
not(A) and B
A= not $fieldsB= $self->{"bindtype"} eq "columns"
ABresult
0X0
100
111
569 && $self->belch("can't do 'columns' bindtype when called with arrayref");
570  
571 +(
572 (@$fields
573 ? $self->expand_expr({ -row => $fields }, -ident)
574 : undef
575 ),
576 +{ -row => [
577 map {
578 55 ▶ local our $Cur_Col_Meta = $fields->[$_];
Branch: 1 branch
BranchTrueFalseTotal
@$fields ? : 33 22 55
579 260 $self->_expand_insert_value($values->[$_])
580 } 0..$#$values
581 ] },
582 );
583 }
584 }
585  
586 36 ▶sub _render_insert_clause_fields {
Subroutine _render_insert_clause_fields: called CC=1 SCAR=0.0
587 36 return $_[0]->render_aqt($_[2]);
588 }
589  
590 61 ▶sub _render_insert_clause_target {
Subroutine _render_insert_clause_target: called CC=1 SCAR=0.0
591 61 my ($self, undef, $from) = @_;
592 61 $self->join_query_parts(' ', { -keyword => 'insert into' }, $from);
593 }
594  
595 61 ▶sub _render_insert_clause_from {
Subroutine _render_insert_clause_from: called CC=1 SCAR=0.0
596 61 return $_[0]->render_aqt($_[2], 1);
597 }
598  
599 # So that subclasses can override INSERT ... RETURNING separately from
600 # UPDATE and DELETE (e.g. DBIx::Class::SQLMaker::Oracle does this)
601 0 ▶sub _insert_returning { shift->_returning(@_) }
Subroutine _insert_returning: not called CC=1 SCAR=6.9
602  
603 0 ▶sub _redispatch_returning {
Subroutine _redispatch_returning: not called CC=1 SCAR=6.9
604 0 my ($self, $type, undef, $returning) = @_;
605 0 [ $self->${\"_${type}_returning"}({ returning => $returning }) ];
606 }
607  
608 0 ▶sub _returning {
Subroutine _returning: not called CC=2 SCAR=17.9
609 0 my ($self, $options) = @_;
610  
611 0 my $f = $options->{returning};
612  
613 0 my ($sql, @bind) = @{ $self->render_aqt(
614 $self->expand_expr({ -list => $f }, -ident)
615 ) };
616 0 my $rsql = $self->_sqlcase(' returning ').$sql;
617 0 ▶ return wantarray ? ($rsql, @bind) : $rsql;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
618 }
619  
620 260 ▶sub _expand_insert_value {
Subroutine _expand_insert_value: called CC=6 SCAR=17.9
621 260 my ($self, $v) = @_;
622  
623 260 my $k = our $Cur_Col_Meta;
624  
625 260 ▶ if (ref($v) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "ARRAY") 8 252 260
626 8 ▶ if ($self->{array_datatypes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"array_datatypes"}) 6 2 8
627 6 return +{ -bind => [ $k, $v ] };
628 }
629 2 my ($sql, @bind) = @$v;
630 2 $self->_assert_bindval_matches_bindtype(@bind);
631 2 return +{ -literal => $v };
632 }
633 252 ▶ if (ref($v) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "HASH") 2 250 252
634 2 ▶ if (grep !/^-/, keys %$v) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep((!/^-/), keys %$v)) 2 0 2
635 # pass a plain hashref straight through as a bind value; this is how
636 # e.g. a Postgres json/jsonb column value is supplied (GH#18, RT#120676)
637 2 return +{ -bind => [ $k, $v ] };
638 }
639 }
640 250 ▶ if (!defined($v)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 8 242 250
641 8 return +{ -bind => [ $k, undef ] };
642 }
643 242 return $self->expand_expr($v);
644 }
645  
646  
647  
648 #======================================================================
649 # UPDATE methods
650 #======================================================================
651  
652 51 ▶sub update {
Subroutine update: called CC=4 SCAR=13.9
Pod documented
653 51 my ($self, $table, $set, $where, $options) = @_;
654  
655 51 my $stmt = do {
656 51 ▶ if (ref($table) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $table eq 'HASH') { } 4 47 51
657 4 $table
658 } else {
659 47 my %clauses;
660 47 @clauses{qw(target set where)} = ($table, $set, $where);
661 $self->puke("Unsupported data type specified to \$sql->update")
662 47 ▶ unless ref($clauses{set}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $clauses{"set"} eq "HASH" 0 47 47
663 47 @clauses{keys %$options} = values %$options;
664 47 \%clauses;
665 }
666 };
667 51 my @rendered = $self->render_statement({ -update => $stmt });
668 49 ▶ return wantarray ? @rendered : $rendered[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 48 1 49
669 }
670  
671 52 ▶sub _render_update_clause_target {
Subroutine _render_update_clause_target: called CC=1 SCAR=0.0
672 52 my ($self, undef, $target) = @_;
673 52 $self->join_query_parts(' ', { -keyword => 'update' }, $target);
674 }
675  
676 0 ▶sub _update_set_values {
Subroutine _update_set_values: not called CC=1 SCAR=6.9
677 0 my ($self, $data) = @_;
678  
679 0 return @{ $self->render_aqt(
680 $self->_expand_update_set_values(undef, $data),
681 ) };
682 }
683  
684 52 ▶sub _expand_update_set_values {
Subroutine _expand_update_set_values: called CC=4 SCAR=13.9
685 52 my ($self, undef, $data) = @_;
686 $self->expand_expr({ -list => [
687 map {
688 98 my ($k, $set) = @$_;
689 98 ▶ $set = { -bind => $_ } unless defined $set;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $set 2 96 98
690 98 +{ -op => [ '=', { -ident => $k }, $set ] };
691 }
692 map {
693 52 my $k = $_;
694 98 my $v = $data->{$k};
695 (ref($v) eq 'ARRAY'
696 ? ($self->{array_datatypes}
697 ? [ $k, +{ -bind => [ $k, $v ] } ]
698 : [ $k, +{ -literal => $v } ])
699 98 ▶ : do {
Branch: 2 branches
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 6 92 98
$self->{'array_datatypes'} ? : 5 1 6
700 92 local our $Cur_Col_Meta = $k;
701 92 [ $k, $self->_expand_expr($v) ]
702 }
703 );
704 } sort keys %$data
705 ] });
706 }
707  
708 47 ▶sub _expand_update_clause_target {
Subroutine _expand_update_clause_target: called CC=1 SCAR=0.0
709 47 my ($self, undef, $target) = @_;
710 47 +(target => $self->expand_expr({ -list => $target }, -ident));
711 }
712  
713 52 ▶sub _expand_update_clause_set {
Subroutine _expand_update_clause_set: called CC=4 SCAR=16.9
714 52 ▶ return $_[2] if ref($_[2]) eq 'HASH' and ($_[2]->{-op}||[''])->[0] eq ',';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[2] eq "HASH" and +($_[2]{"-op"} || [""])->[0] eq "," 0 52 52
Condition40%2/5
ref $_[2] eq "HASH" and +($_[2]{"-op"} || [""])->[0] eq ","
!ll&&!rl&&r
0520
$_[2]{'-op'} || ['']
l!l
052
MC/DC0%0/2
ref $_[2] eq "HASH" and +($_[2]{"-op"} || [""])->[0] eq ","
ref $_[2] eq "HASH" $_[2]{'-op'}
Truth table33%1/3
A and B
A= ref $_[2] eq "HASH"B= $_[2]{'-op'}
ABresult
0X0
100
111
715 52 +(set => $_[0]->_expand_update_set_values($_[1], $_[2]));
716 }
717  
718 42 ▶sub _expand_update_clause_where {
Subroutine _expand_update_clause_where: called CC=1 SCAR=0.0
719 42 +(where => $_[0]->expand_expr($_[2]));
720 }
721  
722 7 ▶sub _expand_update_clause_returning {
Subroutine _expand_update_clause_returning: called CC=1 SCAR=0.0
723 7 +(returning => $_[0]->expand_expr({ -list => $_[2] }, -ident));
724 }
725  
726 # So that subclasses can override UPDATE ... RETURNING separately from
727 # INSERT and DELETE
728 0 ▶sub _update_returning { shift->_returning(@_) }
Subroutine _update_returning: not called CC=1 SCAR=6.9
729  
730  
731  
732 #======================================================================
733 # SELECT
734 #======================================================================
735  
736 161 ▶sub select {
Subroutine select: called CC=6 SCAR=17.9
Pod documented
737 161 my ($self, @args) = @_;
738 161 my $stmt = do {
739 161 ▶ if (ref(my $sel = $args[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref(my $sel = $args[0]) eq 'HASH') { } 20 141 161
740 20 $sel
741 } else {
742 # a flat list of clause pairs (select => ..., from => ..., ...) would
743 # otherwise be taken as the positional form and produce garbage SQL
744 # (RT#148271)
745 141 ▶ $self->puke(
Branch: 1 branch
BranchTrueFalseTotal
if @args > 4 1 140 141
746 'select() takes a single hashref of clauses or up to four positional'
747 . ' arguments (source, fields, where, order), got ' . @args
748 ) if @args > 4;
749 140 my %clauses;
750 140 @clauses{qw(from select where order_by)} = @args;
751  
752 # This oddity is to literalify since historically SQLA doesn't quote
753 # a single identifier argument, so we convert it into a literal
754  
755 $clauses{select} = { -literal => [ $clauses{select}||'*' ] }
756 140 ▶ unless ref($clauses{select});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $clauses{"select"} 104 36 140
Condition50%1/2
$clauses{'select'} || '*'
l!l
1040
MC/DC0%0/1
$clauses{'select'} || '*'
$clauses{'select'}
Truth table50%1/2
A
A= $clauses{'select'}
Aresult
11
00
757 140 \%clauses;
758 }
759 };
760  
761 160 my @rendered = $self->render_statement({ -select => $stmt });
762 140 ▶ return wantarray ? @rendered : $rendered[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 117 23 140
763 }
764  
765 194 ▶sub _expand_select_clause_select {
Subroutine _expand_select_clause_select: called CC=1 SCAR=0.0
766 194 my ($self, undef, $select) = @_;
767 194 +(select => $self->expand_expr({ -list => $select }, -ident));
768 }
769  
770 170 ▶sub _expand_select_clause_from {
Subroutine _expand_select_clause_from: called CC=1 SCAR=0.0
771 170 my ($self, undef, $from) = @_;
772 170 +(from => $self->expand_expr({ -list => $from }, -ident));
773 }
774  
775 634 ▶sub _expand_select_clause_where {
Subroutine _expand_select_clause_where: called CC=2 SCAR=7.8
776 634 my ($self, undef, $where) = @_;
777  
778 634 my $sqla = do {
779 634 ▶ if (my $conv = $self->{convert}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $conv = $self->{'convert'}) { } 4 630 634
780 12 ▶ my $_wrap = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
781 12 my $orig = shift;
782 52 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
783 52 my $self = shift;
784 52 +{ -func => [
785 $conv,
786 $self->$orig(@_)
787 ] };
788 12 };
789 4 };
790 $self->clone
791 ->wrap_expander(bind => $_wrap)
792 ->wrap_op_expanders(map +($_ => $_wrap), qw(ident value))
793 4 ▶ ->wrap_expander(func => sub {
Subroutine __ANON__: called CC=1 SCAR=1.3
794 4 my $orig = shift;
795 16 ▶ sub {
Subroutine __ANON__: called CC=8 SCAR=30.3
796 16 my ($self, $type, $thing) = @_;
797 16 ▶ if (ref($thing) eq 'ARRAY' and $thing->[0] eq $conv
Branch: 1 branch
BranchTrueFalseTotal
if (ref $thing eq "ARRAY" and $thing->[0] eq $conv and @$thing == 2 and ref $thing->[1] eq "HASH" and $thing->[1]{"-ident"} || $thing->[1]{"-value"} || $thing->[1]{"-bind"}) 16 0 16
Condition33%6/18
ref $thing eq "ARRAY" and $thing->[0] eq $conv and @$thing == 2 and ref $thing->[1] eq "HASH" and $thing->[1]{"-ident"} || $thing->[1]{"-value"} || $thing->[1]{"-bind"}
!ll&&!rl&&r
0016
ref $thing eq "ARRAY" and $thing->[0] eq $conv and @$thing == 2 and ref $thing->[1] eq "HASH"
!ll&&!rl&&r
0016
ref $thing eq "ARRAY" and $thing->[0] eq $conv and @$thing == 2
!ll&&!rl&&r
0016
ref $thing eq "ARRAY" and $thing->[0] eq $conv
!ll&&!rl&&r
0016
$thing->[1]{"-ident"} or $thing->[1]{"-value"} or $thing->[1]{"-bind"}
l!l&&r!l&&!r
0160
$thing->[1]{"-ident"} or $thing->[1]{"-value"}
l!l&&r!l&&!r
0016
MC/DC0%0/7
ref $thing eq "ARRAY" and $thing->[0] eq $conv and @$thing == 2 and ref $thing->[1] eq "HASH" and $thing->[1]{"-ident"} || $thing->[1]{"-value"} || $thing->[1]{"-bind"}
ref $thing eq "ARRAY" $thing->[0] eq $conv @$thing == 2 ref $thing->[1] eq "HASH" $thing->[1]{"-ident"} $thing->[1]{"-value"} $thing->[1]{"-bind"}
Truth table12%1/8
A and B and C and D and E or F or G
A= ref $thing eq "ARRAY"B= $thing->[0] eq $convC= @$thing == 2D= ref $thing->[1] eq "HASH"E= $thing->[1]{"-ident"}F= $thing->[1]{"-value"}G= $thing->[1]{"-bind"}
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110000
11111XX1
111101X1
11110011
798 and @$thing == 2 and ref($thing->[1]) eq 'HASH'
799 and (
800 $thing->[1]{-ident}
801 or $thing->[1]{-value}
802 or $thing->[1]{-bind})
803 ) {
804 16 return { -func => $thing }; # already went through our expander
805 }
806 0 return $self->$orig($type, $thing);
807 }
808 4 });
809 } else {
810 630 $self;
811 }
812 };
813  
814 634 return +(where => $sqla->expand_expr($where));
815 }
816  
817 18 ▶sub _expand_select_clause_order_by {
Subroutine _expand_select_clause_order_by: called CC=1 SCAR=0.0
818 18 my ($self, undef, $order_by) = @_;
819 18 +(order_by => $self->_expand_order_by($order_by));
820 }
821  
822 0 ▶sub _select_fields {
Subroutine _select_fields: not called CC=3 SCAR=24.8
823 0 my ($self, $fields) = @_;
824 0 ▶ return $fields unless ref($fields);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $fields 0 0 0
825 0 my ($sql, @bind) = @{ $self->render_aqt(
826 $self->expand_expr({ -list => $fields }, '-ident')
827 ) };
828 0 ▶ return wantarray ? ($sql, @bind) : $sql;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
829 }
830  
831 #======================================================================
832 # DELETE
833 #======================================================================
834  
835 16 ▶sub delete {
Subroutine delete: called CC=4 SCAR=13.9
Pod documented
836 16 my ($self, $table, $where, $options) = @_;
837  
838 16 my $stmt = do {
839 16 ▶ if (ref($table) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $table eq 'HASH') { } 2 14 16
840 2 $table;
841 } else {
842 14 ▶ my %clauses = (target => $table, where => $where, %{$options||{}});
Condition100%2/2
$options || {}
l!l
68
MC/DC100%1/1
$options || {}
$options
Truth table100%2/2
A
A= $options
Aresult
11
00
843 14 \%clauses;
844 }
845 };
846 16 my @rendered = $self->render_statement({ -delete => $stmt });
847 16 ▶ return wantarray ? @rendered : $rendered[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 16 0 16
848 }
849  
850 # So that subclasses can override DELETE ... RETURNING separately from
851 # INSERT and UPDATE
852 0 ▶sub _delete_returning { shift->_returning(@_) }
Subroutine _delete_returning: not called CC=1 SCAR=6.9
853  
854 16 ▶sub _expand_delete_clause_target {
Subroutine _expand_delete_clause_target: called CC=1 SCAR=0.0
855 16 +(target => $_[0]->expand_expr({ -list => $_[2] }, -ident));
856 }
857  
858 16 ▶sub _expand_delete_clause_where { +(where => $_[0]->expand_expr($_[2])); }
Subroutine _expand_delete_clause_where: called CC=1 SCAR=0.0
859  
860 6 ▶sub _expand_delete_clause_returning {
Subroutine _expand_delete_clause_returning: called CC=1 SCAR=0.0
861 6 +(returning => $_[0]->expand_expr({ -list => $_[2] }, -ident));
862 }
863  
864 16 ▶sub _render_delete_clause_target {
Subroutine _render_delete_clause_target: called CC=1 SCAR=0.0
865 16 my ($self, undef, $from) = @_;
866 16 $self->join_query_parts(' ', { -keyword => 'delete from' }, $from);
867 }
868  
869 #======================================================================
870 # WHERE: entry point
871 #======================================================================
872  
873  
874  
875 # Finally, a separate routine just to handle WHERE clauses
876 535 ▶sub where {
Subroutine where: called CC=6 SCAR=18.0
Pod documented
877 535 my ($self, $where, $order) = @_;
878  
879 535 local $self->{convert_where} = $self->{convert};
880  
881 # where ?
882 535 ▶ my ($sql, @bind) = defined($where)
Branch: 1 branch
BranchTrueFalseTotal
defined $where ? : 489 46 535
883 ? $self->_recurse_where($where)
884 : (undef);
885 443 ▶ $sql = (defined $sql and length $sql) ? $self->_sqlcase(' where ') . "( $sql )" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $sql && length $sql ? : 394 49 443
Condition66%2/3
defined $sql and length $sql
!ll&&!rl&&r
490394
MC/DC50%1/2
defined $sql and length $sql
defined $sql length $sql
Truth table66%2/3
A and B
A= defined $sqlB= length $sql
ABresult
0X0
100
111
886  
887 # order by?
888 443 ▶ if ($order) {
Branch: 1 branch
BranchTrueFalseTotal
if ($order) 55 388 443
889 55 my ($order_sql, @order_bind) = $self->_order_by($order);
890 55 $sql .= $order_sql;
891 55 push @bind, @order_bind;
892 }
893  
894 443 ▶ return wantarray ? ($sql, @bind) : $sql;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 443 0 443
895 }
896  
897 20 { our $Default_Scalar_To = -value }
898  
899 4248 ▶sub expand_expr {
Subroutine expand_expr: called CC=2 SCAR=6.9
Pod documented
900 4248 my ($self, $expr, $default_scalar_to) = @_;
901 4248 ▶ local our $Default_Scalar_To = $default_scalar_to if $default_scalar_to;
Branch: 1 branch
BranchTrueFalseTotal
if $default_scalar_to 1626 2622 4248
902 4248 $self->_expand_expr($expr);
903 }
904  
905 9363 ▶sub render_aqt {
Subroutine render_aqt: called CC=5 SCAR=16.8
Pod documented
906 9363 my ($self, $aqt, $top_level) = @_;
907 9363 my ($k, $v, @rest) = %$aqt;
908 9363 ▶ die "No" if @rest;
Branch: 1 branch
BranchTrueFalseTotal
if @rest 0 9363 9363
909 9363 ▶ die "Not a node type: $k" unless $k =~ s/^-//;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ s/^-// 0 9363 9363
910 9363 ▶ if (my $meth = $self->{render}{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $meth = $self->{"render"}{$k}) 9363 0 9363
911 9363 local our $Render_Top_Level = $top_level;
912 9363 ▶ return $self->$meth($k, $v)||[];
Condition100%2/2
$self->$meth($k, $v) || []
l!l
932110
MC/DC100%1/1
$self->$meth($k, $v) || []
$self->$meth($k, $v)
Truth table100%2/2
A
A= $self->$meth($k, $v)
Aresult
11
00
913 }
914 0 die "notreached: $k";
915 }
916  
917 0 ▶sub render_expr {
Subroutine render_expr: not called CC=1 SCAR=6.9
Pod documented
918 0 my ($self, $expr, $default_scalar_to) = @_;
919 0 return @{ $self->render_aqt(
920 $self->expand_expr($expr, $default_scalar_to)
921 ) };
922 }
923  
924 287 ▶sub render_statement {
Subroutine render_statement: called CC=1 SCAR=0.0
Pod documented
925 287 my ($self, $expr, $default_scalar_to) = @_;
926 287 @{$self->render_aqt(
927 $self->expand_expr($expr, $default_scalar_to), 1
928 )};
929 }
930  
931 325 ▶sub _expand_statement {
Subroutine _expand_statement: called CC=6 SCAR=17.9
932 325 my ($self, $type, $args) = @_;
933 # a statement can sit where plain scalars are identifiers (select list,
934 # order by, from ...), but its own where/set/values scalars are values
935 325 local our $Default_Scalar_To = -value;
936 325 my $ec = $self->{expand_clause};
937 325 ▶ if ($args->{_}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"_"}) 9 316 325
938 9 $args = { %$args };
939 $args->{$type} = delete $args->{_}
940 9 }
941 325 my %has_clause = map +($_ => 1), @{$self->{clauses_of}{$type}};
942 return +{ "-${type}" => +{
943 map {
944 325 my $val = $args->{$_};
945 1048 ▶ if (defined($val) and my $exp = $ec->{"${type}.$_"}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $val and my $exp = $$ec{"$type.$_"}) { } 894 154 1048
elsif ($has_clause{$_}) { } 154 0 154
Condition100%3/3
defined $val and my $exp = $$ec{"$type.$_"}
!ll&&!rl&&r
1513894
MC/DC100%2/2
defined $val and my $exp = $$ec{"$type.$_"}
defined $val my $exp = $$ec{"$type.$_"}
Truth table100%3/3
A and B
A= defined $valB= my $exp = $$ec{"$type.$_"}
ABresult
0X0
100
111
946 894 ▶ if ((my (@exp) = $self->$exp($_ => $val)) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my(@exp) = $self->$exp($_, $val)) == 1) { } 35 843 878
947 35 ($_ => $exp[0])
948 } else {
949 @exp
950 843 }
951 } elsif ($has_clause{$_}) {
952 154 ($_ => $self->expand_expr($val))
953 } else {
954 0 ($_ => $val)
955 }
956 } sort keys %$args
957 } };
958 }
959  
960 304 ▶sub _render_statement {
Subroutine _render_statement: called CC=7 SCAR=19.5
961 304 my ($self, $type, $args) = @_;
962 304 my @parts;
963 304 foreach my $clause (@{$self->{clauses_of}{$type}}) {
964 1387 ▶ next unless my $clause_expr = $args->{$clause};
Branch: 1 branch
BranchTrueFalseTotal
unless my $clause_expr = $args->{$clause} 528 859 1387
965 859 my $part = do {
966 859 ▶ if (my $rdr = $self->{render_clause}{"${type}.${clause}"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rdr = $self->{'render_clause'}{"$type.$clause"}) { } 233 626 859
967 233 $self->$rdr($clause, $clause_expr, $args);
968 } else {
969 626 my $r = $self->render_aqt($clause_expr, 1);
970 620 ▶ next unless defined $r->[0] and length $r->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r->[0] and length $r->[0] 2 618 620
Condition66%2/3
defined $r->[0] and length $r->[0]
!ll&&!rl&&r
20618
MC/DC50%1/2
defined $r->[0] and length $r->[0]
defined $r->[0] length $r->[0]
Truth table66%2/3
A and B
A= defined $r->[0]B= length $r->[0]
ABresult
0X0
100
111
971 618 $self->join_query_parts(' ',
972 { -keyword => $clause },
973 $r
974 );
975 }
976 };
977 849 push @parts, $part;
978 }
979 296 my $q = $self->join_query_parts(' ', @parts);
980 296 ▶ return $self->join_query_parts('',
Branch: 1 branch
BranchTrueFalseTotal
our $Render_Top_Level ? : 266 30 296
981 (our $Render_Top_Level ? $q : ('(', $q, ')'))
982 );
983 }
984  
985 7864 ▶sub _normalize_op {
Subroutine _normalize_op: called CC=3 SCAR=11.0
986 7864 my ($self, $raw) = @_;
987 7864 my $op = lc $raw;
988 7864 ▶ return $op if grep $_->{$op}, @{$self}{qw(expand_op render_op)};
Branch: 1 branch
BranchTrueFalseTotal
if grep $_->{$op}, @{$self;}{"expand_op", "render_op"} 95 7769 7864
989 7769 s/^-(?=.)//, s/\s+/_/g for $op;
990 7769 $op;
991 }
992  
993 10142 ▶sub _expand_expr {
Subroutine _expand_expr: called CC=12 SCAR=24.9
994 10142 my ($self, $expr) = @_;
995 10142 ▶ our $Expand_Depth ||= 0; local $Expand_Depth = $Expand_Depth + 1;
Condition100%2/2
our $Expand_Depth ||= 0
l!l
84651677
MC/DC100%1/1
our $Expand_Depth ||= 0
our $Expand_Depth
Truth table100%2/2
A
A= our $Expand_Depth
Aresult
11
00
996 10142 ▶ return undef unless defined($expr);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 162 9980 10142
997 9980 ▶ if (ref($expr) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $expr eq "HASH") 7959 2021 9980
998 7959 ▶ return undef unless my $kc = keys %$expr;
Branch: 1 branch
BranchTrueFalseTotal
unless my $kc = keys %$expr 6 7953 7959
999 7953 ▶ if ($kc > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kc > 1) 175 7778 7953
1000 175 return $self->_expand_logop(and => $expr);
1001 }
1002 7778 my ($key, $value) = %$expr;
1003 7778 ▶ if ($key =~ /^-/ and $key =~ s/ [_\s]? \d+ $//x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^-/ and $key =~ s/ [_\s]? \d+ $//x) 9 7769 7778
Condition100%3/3
$key =~ /^-/ and $key =~ s/ [_\s]? \d+ $//x
!ll&&!rl&&r
139863719
MC/DC100%2/2
$key =~ /^-/ and $key =~ s/ [_\s]? \d+ $//x
$key =~ /^-/ $key =~ s/ [_\s]? \d+ $//x
Truth table100%3/3
A and B
A= $key =~ /^-/B= $key =~ s/ [_\s]? \d+ $//x
ABresult
0X0
100
111
1004 9 $self->belch('Use of [and|or|nest]_N modifiers is deprecated and will be removed in a future version. '
1005 . "You probably wanted ...-and => [ $key => COND1, $key => COND2 ... ]");
1006 }
1007 7778 return $self->_expand_hashpair($key, $value);
1008 }
1009 2021 ▶ if (ref($expr) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $expr eq "ARRAY") 133 1888 2021
1010 133 return $self->_expand_logop(lc($self->{logic}), $expr);
1011 }
1012 1888 ▶ if (my $literal = is_literal_value($expr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $literal = &is_literal_value($expr)) 155 1733 1888
1013 155 return +{ -literal => $literal };
1014 }
1015 1733 ▶ if (!ref($expr) or Scalar::Util::blessed($expr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $expr or builtin::blessed($expr)) 1733 0 1733
Condition66%2/3
not ref $expr or builtin::blessed($expr)
l!l&&r!l&&!r
173210
MC/DC0%0/2
not ref $expr or builtin::blessed($expr)
not ref $expr builtin::blessed($expr)
Truth table66%2/3
not(A) or B
A= not ref $exprB= builtin::blessed($expr)
ABresult
1X1
011
000
1016 1733 return $self->_expand_scalar($expr);
1017 }
1018 0 die "notreached";
1019 }
1020  
1021 7882 ▶sub _expand_hashpair {
Subroutine _expand_hashpair: called CC=8 SCAR=20.8
1022 7882 my ($self, $k, $v) = @_;
1023 7882 ▶ unless (defined($k) and length($k)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $k and length $k) 52 7830 7882
Condition66%2/3
defined $k and length $k
!ll&&!rl&&r
0527830
MC/DC50%1/2
defined $k and length $k
defined $k length $k
Truth table66%2/3
A and B
A= defined $kB= length $k
ABresult
0X0
100
111
1024 52 ▶ if (defined($k) and my $literal = is_literal_value($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $k and my $literal = &is_literal_value($v)) 24 28 52
Condition66%2/3
defined $k and my $literal = &is_literal_value($v)
!ll&&!rl&&r
02824
MC/DC50%1/2
defined $k and my $literal = &is_literal_value($v)
defined $k my $literal = &is_literal_value($v)
Truth table66%2/3
A and B
A= defined $kB= my $literal = &is_literal_value($v)
ABresult
0X0
100
111
1025 24 $self->belch('Hash-pairs consisting of an empty string with a literal are deprecated, and will be removed in a future version: use -and => [ $literal ] instead');
1026 24 return { -literal => $literal };
1027 }
1028 28 $self->puke("Supplying an empty left hand side argument is not supported");
1029 }
1030 7830 ▶ if ($k =~ /^-./) {
Branch: 2 branches
BranchTrueFalseTotal
if ($k =~ /^-./) { } 6380 1450 7830
elsif ($k =~ /^\W+$/) { } 3 1447 1450
1031 6380 return $self->_expand_hashpair_op($k, $v);
1032 } elsif ($k =~ /^\W+$/) {
1033 3 ▶ my ($lhs, @rhs) = ref($v) eq 'ARRAY' ? @$v : $v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 2 1 3
1034 3 return $self->_expand_op(
1035 -op, [ $k, $self->expand_expr($lhs, -ident), @rhs ]
1036 );
1037 }
1038 1447 return $self->_expand_hashpair_ident($k, $v);
1039 }
1040  
1041 1447 ▶sub _expand_hashpair_ident {
Subroutine _expand_hashpair_ident: called CC=18 SCAR=29.1
1042 1447 my ($self, $k, $v) = @_;
1043  
1044 1447 local our $Cur_Col_Meta = $k;
1045  
1046 # hash with multiple or no elements is andor
1047  
1048 1447 ▶ if (ref($v) eq 'HASH' and keys %$v != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "HASH" and keys %$v != 1) 7 1440 1447
Condition100%3/3
ref $v eq "HASH" and keys %$v != 1
!ll&&!rl&&r
6697717
MC/DC100%2/2
ref $v eq "HASH" and keys %$v != 1
ref $v eq "HASH" keys %$v != 1
Truth table100%3/3
A and B
A= ref $v eq "HASH"B= keys %$v != 1
ABresult
0X0
100
111
1049 7 return $self->_expand_logop(and => $v, $k);
1050 }
1051  
1052 # undef needs to be re-sent with cmp to achieve IS/IS NOT NULL
1053  
1054 1440 ▶ if (is_undef_value($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&is_undef_value($v)) 27 1413 1440
1055 27 return $self->_expand_hashpair_cmp($k => undef);
1056 }
1057  
1058 # scalars and objects get expanded as whatever requested or values
1059  
1060 1413 ▶ if (!ref($v) or Scalar::Util::blessed($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $v or builtin::blessed($v)) 531 882 1413
Condition100%3/3
not ref $v or builtin::blessed($v)
l!l&&r!l&&!r
5301882
MC/DC100%2/2
not ref $v or builtin::blessed($v)
not ref $v builtin::blessed($v)
Truth table100%3/3
not(A) or B
A= not ref $vB= builtin::blessed($v)
ABresult
1X1
011
000
1061 531 return $self->_expand_hashpair_scalar($k, $v);
1062 }
1063  
1064 # single key hashref is a hashtriple
1065  
1066 882 ▶ if (ref($v) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "HASH") 767 115 882
1067 767 return $self->_expand_hashtriple($k, %$v);
1068 }
1069  
1070 # arrayref needs re-engineering over the elements
1071  
1072 115 ▶ if (ref($v) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "ARRAY") 74 41 115
1073 74 ▶ return $self->sqlfalse unless @$v;
Branch: 1 branch
BranchTrueFalseTotal
unless @$v 2 72 74
1074 72 $self->_debug("ARRAY($k) means distribute over elements");
1075 my $logic = lc(
1076 ($v->[0]||'') =~ /^-(and|or)$/i
1077 24 ▶ ? (shift(@{$v = [ @$v ]}), $1)
Condition50%1/2
$self->{'logic'} || 'OR'
l!l
480
MC/DC0%0/1
$self->{'logic'} || 'OR'
$self->{'logic'}
Truth table50%1/2
A
A= $self->{'logic'}
Aresult
11
00
1078 72 ▶ : lc($self->{logic} || 'OR')
Branch: 1 branch
BranchTrueFalseTotal
($v->[0] || '') =~ /^-(and|or)$/i ? : 24 48 72
Condition100%2/2
$v->[0] || ''
l!l
693
MC/DC100%1/1
$v->[0] || ''
$v->[0]
Truth table100%2/2
A
A= $v->[0]
Aresult
11
00
1079 );
1080 72 ▶ if ($logic eq 'or' and my $in = $self->_array_as_in($k, $v)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logic eq "or" and my $in = $self->_array_as_in($k, $v)) 13 59 72
Condition100%3/3
$logic eq "or" and my $in = $self->_array_as_in($k, $v)
!ll&&!rl&&r
174213
MC/DC100%2/2
$logic eq "or" and my $in = $self->_array_as_in($k, $v)
$logic eq "or" my $in = $self->_array_as_in($k, $v)
Truth table100%3/3
A and B
A= $logic eq "or"B= my $in = $self->_array_as_in($k, $v)
ABresult
0X0
100
111
1081 13 return $in;
1082 }
1083 59 return $self->_expand_logop(
1084 $logic => $v, $k
1085 );
1086 }
1087  
1088 41 ▶ if (my $literal = is_literal_value($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $literal = &is_literal_value($v)) 41 0 41
1089 41 ▶ unless (length $k) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $k) 0 41 41
1090 0 $self->belch('Hash-pairs consisting of an empty string with a literal are deprecated, and will be removed in a future version: use -and => [ $literal ] instead');
1091 0 return \$literal;
1092 }
1093 41 my ($sql, @bind) = @$literal;
1094 41 ▶ if ($self->{bindtype} eq 'columns') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bindtype"} eq "columns") 6 35 41
1095 6 for (@bind) {
1096 6 $self->_assert_bindval_matches_bindtype($_);
1097 }
1098 }
1099 39 return +{ -literal => [ $self->_quote($k).' '.$sql, @bind ] };
1100 }
1101 0 die "notreached";
1102 }
1103  
1104 # array_as_in: turn col => [ 1, 2, undef ] into col IN (1, 2) OR col IS NULL,
1105 # but only when that means exactly the same as the OR-of-equalities
1106 # expansion: equality cmp, every element a bind value or undef, and at
1107 # least two values for the IN. Returns nothing when it does not apply.
1108 55 ▶sub _array_as_in {
Subroutine _array_as_in: called CC=8 SCAR=20.8
1109 55 my ($self, $k, $v) = @_;
1110 55 ▶ return unless $self->{array_as_in} and $self->{cmp} eq '=';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"array_as_in"} and $self->{"cmp"} eq "=" 36 19 55
Condition100%3/3
$self->{"array_as_in"} and $self->{"cmp"} eq "="
!ll&&!rl&&r
35119
MC/DC100%2/2
$self->{"array_as_in"} and $self->{"cmp"} eq "="
$self->{"array_as_in"} $self->{"cmp"} eq "="
Truth table100%3/3
A and B
A= $self->{"array_as_in"}B= $self->{"cmp"} eq "="
ABresult
0X0
100
111
1111 19 my $values = 0;
1112 19 for my $el (@$v) {
1113 39 ▶ next unless defined $el;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $el 7 32 39
1114 32 ▶ return if ref($el) and !Scalar::Util::blessed($el);
Branch: 1 branch
BranchTrueFalseTotal
if ref $el and not builtin::blessed($el) 3 29 32
Condition100%3/3
ref $el and not builtin::blessed($el)
!ll&&!rl&&r
2813
MC/DC100%2/2
ref $el and not builtin::blessed($el)
ref $el not builtin::blessed($el)
Truth table100%3/3
A and not(B)
A= ref $elB= not builtin::blessed($el)
ABresult
0X0
100
111
1115 29 $values++;
1116 }
1117 16 ▶ return unless $values > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $values > 1 3 13 16
1118 # -in turns undef elements into an extra OR col IS NULL
1119 13 return $self->_expand_expr({ $k => { -in => $v } });
1120 }
1121  
1122 2264 ▶sub _expand_scalar {
Subroutine _expand_scalar: called CC=1 SCAR=0.0
1123 2264 my ($self, $expr) = @_;
1124  
1125 2264 return $self->_expand_expr({ (our $Default_Scalar_To) => $expr });
1126 }
1127  
1128 531 ▶sub _expand_hashpair_scalar {
Subroutine _expand_hashpair_scalar: called CC=1 SCAR=0.0
1129 531 my ($self, $k, $v) = @_;
1130  
1131 531 return $self->_expand_hashpair_cmp(
1132 $k, $self->_expand_scalar($v),
1133 );
1134 }
1135  
1136 6380 ▶sub _expand_hashpair_op {
Subroutine _expand_hashpair_op: called CC=20 SCAR=30.0
1137 6380 my ($self, $k, $v) = @_;
1138  
1139 6380 $self->_assert_pass_injection_guard($k =~ /\A-(.*)\Z/s);
1140  
1141 6378 my $op = $self->_normalize_op($k);
1142  
1143 75 ▶ my $is_special = List::Util::first { $op =~ $_->{regex} }
Subroutine __ANON__: called CC=1 SCAR=0.0
1144 6378 @{$self->{special_ops}};
1145  
1146 { # Old SQLA compat
1147  
1148 # the old special op system requires illegality for top-level use
1149  
1150 6378 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (our $Expand_Depth == 1 and $is_special || $self->{"disable_old_special_ops"} && $op =~ /$BUILTIN_SPECIAL_OP_RE/) 4 6374 6378
Condition88%8/9
our $Expand_Depth == 1 and $is_special || $self->{"disable_old_special_ops"} && $op =~ /$BUILTIN_SPECIAL_OP_RE/
!ll&&!rl&&r
58385364
$is_special or $self->{"disable_old_special_ops"} and $op =~ /$BUILTIN_SPECIAL_OP_RE/
l!l&&r!l&&!r
04536
$self->{"disable_old_special_ops"} and $op =~ /$BUILTIN_SPECIAL_OP_RE/
!ll&&!rl&&r
52884
MC/DC75%3/4
our $Expand_Depth == 1 and $is_special || $self->{"disable_old_special_ops"} && $op =~ /$BUILTIN_SPECIAL_OP_RE/
our $Expand_Depth == 1 $is_special $self->{"disable_old_special_ops"} $op =~ /$BUILTIN_SPECIAL_OP_RE/
Truth table80%4/5
A and B or C and D
A= our $Expand_Depth == 1B= $is_specialC= $self->{"disable_old_special_ops"}D= $op =~ /$BUILTIN_SPECIAL_OP_RE/
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1151 (our $Expand_Depth) == 1
1152 and (
1153 $is_special
1154 or (
1155 $self->{disable_old_special_ops}
1156 and $op =~ $BUILTIN_SPECIAL_OP_RE
1157 )
1158 )
1159 ) {
1160 4 $self->puke("Illegal use of top-level '-$op'")
1161 }
1162 }
1163  
1164 6374 ▶ if (my $exp = $self->{expand}{$op}||$self->{expand_op}{$op}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $exp = $self->{"expand"}{$op} || $self->{"expand_op"}{$op}) 6168 206 6374
Condition100%3/3
$self->{'expand'}{$op} || $self->{'expand_op'}{$op}
l!l&&r!l&&!r
13114857206
MC/DC100%2/2
$self->{'expand'}{$op} || $self->{'expand_op'}{$op}
$self->{'expand'}{$op} $self->{'expand_op'}{$op}
Truth table100%3/3
A || B
A= $self->{'expand'}{$op}B= $self->{'expand_op'}{$op}
ABresult
1X1
011
000
1165 6168 return $self->$exp($op, $v);
1166 }
1167  
1168 206 ▶ if ($self->{render}{$op}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"render"}{$op}) 147 59 206
1169 147 return { "-${op}" => $v };
1170 }
1171  
1172 # Ops prefixed with -not_ get converted
1173  
1174 59 ▶ if (my ($rest) = $op =~/^not_(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($rest) = $op =~ /^not_(.*)$/) 15 44 59
1175 15 return +{ -op => [
1176 'not',
1177 $self->_expand_expr({ "-${rest}", $v })
1178 ] };
1179 }
1180  
1181 { # Old SQLA compat
1182  
1183 # the old unary op system means we should touch nothing and let it work
1184  
1185 44 my $op = join(' ', split '_', $op);
1186  
1187 44 ▶ if (my $us = List::Util::first { $op =~ $_->{regex} } @{$self->{unary_ops}}) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (my $us = &List::Util::first(sub { $op =~ /$_->{"regex"}/; } , @{$$self{"unary_ops"};})) 1 43 44
1188 1 return { -op => [ $op, $v ] };
1189 }
1190 }
1191  
1192 43 ▶ my $type = $is_special || $self->{render_op}{$op} ? -op : -func;
Branch: 1 branch
BranchTrueFalseTotal
$is_special || $self->{'render_op'}{$op} ? : 12 31 43
Condition100%3/3
$is_special or $self->{"render_op"}{$op}
l!l&&r!l&&!r
11131
MC/DC100%2/2
$is_special or $self->{"render_op"}{$op}
$is_special $self->{"render_op"}{$op}
Truth table100%3/3
A or B
A= $is_specialB= $self->{"render_op"}{$op}
ABresult
1X1
011
000
1193  
1194 43 ▶ if ($self->{restore_old_unop_handling}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"restore_old_unop_handling"}) 11 32 43
1195  
1196 # Old SQLA compat
1197  
1198 11 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq 'HASH' and keys %$v == 1 and (keys %$v)[0] =~ /^-/ and not $self->{'render_op'}{$op} and not $is_special) { } 4 7 11
Condition66%8/12
ref $v eq "HASH" and keys %$v == 1 and (keys %$v)[0] =~ /^-/ and not $self->{"render_op"}{$op} and not $is_special
!ll&&!rl&&r
704
ref $v eq "HASH" and keys %$v == 1 and (keys %$v)[0] =~ /^-/ and not $self->{"render_op"}{$op}
!ll&&!rl&&r
704
ref $v eq "HASH" and keys %$v == 1 and (keys %$v)[0] =~ /^-/
!ll&&!rl&&r
704
ref $v eq "HASH" and keys %$v == 1
!ll&&!rl&&r
704
MC/DC20%1/5
ref $v eq "HASH" and keys %$v == 1 and (keys %$v)[0] =~ /^-/ and not $self->{"render_op"}{$op} and not $is_special
ref $v eq "HASH" keys %$v == 1 (keys %$v)[0] =~ /^-/ not $self->{"render_op"}{$op} not $is_special
Truth table33%2/6
A and B and C and not(D) and not(E)
A= ref $v eq "HASH"B= keys %$v == 1C= (keys %$v)[0] =~ /^-/D= not $self->{"render_op"}{$op}E= not $is_special
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1199 ref($v) eq 'HASH'
1200 and keys %$v == 1
1201 and (keys %$v)[0] =~ /^-/
1202 and not $self->{render_op}{$op}
1203 and not $is_special
1204 ) {
1205 4 $type = -func;
1206 } else {
1207 7 $type = -op;
1208 }
1209 }
1210  
1211 43 ▶ if ($type eq -func and ref($v) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "-func" and ref $v eq "ARRAY") 1 42 43
Condition100%3/3
$type eq "-func" and ref $v eq "ARRAY"
!ll&&!rl&&r
19231
MC/DC100%2/2
$type eq "-func" and ref $v eq "ARRAY"
$type eq "-func" ref $v eq "ARRAY"
Truth table100%3/3
A and B
A= $type eq "-func"B= ref $v eq "ARRAY"
ABresult
0X0
100
111
1212 1 return $self->_expand_expr({ -func => [ $op, @$v ] });
1213 }
1214  
1215 42 return $self->_expand_expr({ $type => [ $op, $v ] });
1216 }
1217  
1218 573 ▶sub _expand_hashpair_cmp {
Subroutine _expand_hashpair_cmp: called CC=1 SCAR=0.0
1219 573 my ($self, $k, $v) = @_;
1220 573 $self->_expand_hashtriple($k, $self->{cmp}, $v);
1221 }
1222  
1223 1340 ▶sub _expand_hashtriple {
Subroutine _expand_hashtriple: called CC=16 SCAR=27.7
1224 1340 my ($self, $k, $vk, $vv) = @_;
1225  
1226 1340 my $ik = $self->_expand_expr({ -ident => $k });
1227  
1228 1339 my $op = $self->_normalize_op($vk);
1229 1339 $self->_assert_pass_injection_guard($op);
1230  
1231 1337 ▶ if ($op =~ s/ _? \d+ $//x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ s/ _? \d+ $//x) 0 1337 1337
1232 0 return $self->_expand_expr($k, { $vk, $vv });
1233 }
1234 1337 ▶ if (my $x = $self->{expand_op}{$op}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"expand_op"}{$op}) 284 1053 1337
1235 284 local our $Cur_Col_Meta = $k;
1236 284 return $self->$x($op, $vv, $k);
1237 }
1238 { # Old SQLA compat
1239  
1240 1053 ▶ if (my $us = List::Util::first { $op =~ $_->{regex} } @{$self->{special_ops}}) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (my $us = &List::Util::first(sub { $op =~ /$_->{"regex"}/; } , @{$$self{"special_ops"};})) 5 1048 1053
1241 5 return { -op => [ $op, $ik, $vv ] };
1242 }
1243 1048 ▶ if (my $us = List::Util::first { $op =~ $_->{regex} } @{$self->{unary_ops}}) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (my $us = &List::Util::first(sub { $op =~ /$_->{"regex"}/; } , @{$$self{"unary_ops"};})) 1 1047 1048
1244 return { -op => [
1245 $self->{cmp},
1246 1 $ik,
1247 { -op => [ $op, $vv ] }
1248 ] };
1249 }
1250 }
1251 1047 ▶ if (ref($vv) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $vv eq "ARRAY") 150 897 1047
1252 150 my @raw = @$vv;
1253 150 ▶ my $logic = (defined($raw[0]) and $raw[0] =~ /^-(and|or)$/i)
Branch: 1 branch
BranchTrueFalseTotal
defined $raw[0] && $raw[0] =~ /^-(and|or)$/i ? : 2 148 150
Condition100%3/3
defined $raw[0] and $raw[0] =~ /^-(and|or)$/i
!ll&&!rl&&r
75732
MC/DC100%2/2
defined $raw[0] and $raw[0] =~ /^-(and|or)$/i
defined $raw[0] $raw[0] =~ /^-(and|or)$/i
Truth table100%3/3
A and B
A= defined $raw[0]B= $raw[0] =~ /^-(and|or)$/i
ABresult
0X0
100
111
1254 ? (shift(@raw), lc $1) : 'or';
1255 150 my @values = map +{ $vk => $_ }, @raw;
1256 150 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /$self->{"inequality_op"}/xi or $op =~ /$self->{"not_like_op"}/) 127 23 150
Condition100%3/3
$op =~ /$self->{"inequality_op"}/xi or $op =~ /$self->{"not_like_op"}/
l!l&&r!l&&!r
309723
MC/DC100%2/2
$op =~ /$self->{"inequality_op"}/xi or $op =~ /$self->{"not_like_op"}/
$op =~ /$self->{"inequality_op"}/xi $op =~ /$self->{"not_like_op"}/
Truth table100%3/3
A or B
A= $op =~ /$self->{"inequality_op"}/xiB= $op =~ /$self->{"not_like_op"}/
ABresult
1X1
011
000
1257 $op =~ $self->{inequality_op}
1258 or $op =~ $self->{not_like_op}
1259 ) {
1260 127 ▶ if (lc($logic) eq 'or' and @values > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $logic eq "or" and @values > 1) 36 91 127
Condition100%3/3
lc $logic eq "or" and @values > 1
!ll&&!rl&&r
28936
MC/DC100%2/2
lc $logic eq "or" and @values > 1
lc $logic eq "or" @values > 1
Truth table100%3/3
A and B
A= lc $logic eq "or"B= @values > 1
ABresult
0X0
100
111
1261 36 $self->belch("A multi-element arrayref as an argument to the inequality op '${\uc(join ' ', split '_', $op)}' "
1262 . 'is technically equivalent to an always-true 1=1 (you probably wanted '
1263 . "to say ...{ \$inequality_op => [ -and => \@values ] }... instead)"
1264 );
1265 }
1266 }
1267 150 ▶ unless (@values) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@values) 43 107 150
1268 # try to DWIM on equality operators
1269 43 ▶ return ($self->_dwim_op_to_is($op,
Branch: 1 branch
BranchTrueFalseTotal
$self->_dwim_op_to_is($op, q[Supplying an empty arrayref to '%s' is deprecated], "operator '%s' applied on an empty array (field '${k}')") ? : 16 25 41
1270 "Supplying an empty arrayref to '%s' is deprecated",
1271 "operator '%s' applied on an empty array (field '$k')"
1272 ) ? $self->sqlfalse : $self->sqltrue);
1273 }
1274 107 return $self->_expand_logop($logic => \@values, $k);
1275 }
1276 897 ▶ if (is_undef_value($vv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&is_undef_value($vv)) 104 793 897
1277 104 ▶ my $is = ($self->_dwim_op_to_is($op,
Branch: 1 branch
BranchTrueFalseTotal
$self->_dwim_op_to_is($op, q[Supplying an undefined argument to '%s' is deprecated], q[unexpected operator '%s' with undef operand]) ? : 44 60 104
1278 "Supplying an undefined argument to '%s' is deprecated",
1279 "unexpected operator '%s' with undef operand",
1280 ) ? 'is' : 'is not');
1281  
1282 104 return $self->_expand_hashpair($k => { $is, undef });
1283 }
1284 793 local our $Cur_Col_Meta = $k;
1285 793 return +{ -op => [
1286 $op,
1287 $ik,
1288 $self->_expand_expr($vv)
1289 ] };
1290 }
1291  
1292 147 ▶sub _dwim_op_to_is {
Subroutine _dwim_op_to_is: called CC=6 SCAR=17.9
1293 147 my ($self, $raw, $empty, $fail) = @_;
1294  
1295 147 my $op = $self->_normalize_op($raw);
1296  
1297 147 ▶ if ($op =~ /^not$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /^not$/i) 8 139 147
1298 8 return 0;
1299 }
1300 139 ▶ if ($op =~ $self->{equality_op}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /$self->{"equality_op"}/) 35 104 139
1301 35 return 1;
1302 }
1303 104 ▶ if ($op =~ $self->{like_op}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /$self->{"like_op"}/) 25 79 104
1304 25 $self->belch(sprintf $empty, uc(join ' ', split '_', $op));
1305 25 return 1;
1306 }
1307 79 ▶ if ($op =~ $self->{inequality_op}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /$self->{"inequality_op"}/) 21 58 79
1308 21 return 0;
1309 }
1310 58 ▶ if ($op =~ $self->{not_like_op}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /$self->{"not_like_op"}/) 56 2 58
1311 56 $self->belch(sprintf $empty, uc(join ' ', split '_', $op));
1312 56 return 0;
1313 }
1314 2 $self->puke(sprintf $fail, $op);
1315 }
1316  
1317 36 ▶sub _expand_func {
Subroutine _expand_func: called CC=1 SCAR=0.0
1318 36 my ($self, undef, $args) = @_;
1319 36 my ($func, @args) = @$args;
1320 36 $self->_assert_pass_injection_guard($func);
1321 32 return +{ -func => [ $func, map $self->expand_expr($_), @args ] };
1322 }
1323  
1324 2759 ▶sub _expand_ident {
Subroutine _expand_ident: called CC=10 SCAR=23.3
1325 2759 my ($self, undef, $body) = @_;
1326 2759 ▶ unless (defined($body) or (ref($body) and ref($body) eq 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $body or ref $body and ref $body eq "ARRAY") 2 2757 2759
Condition50%3/6
defined $body or ref $body and ref $body eq "ARRAY"
l!l&&r!l&&!r
275702
ref $body and ref $body eq "ARRAY"
!ll&&!rl&&r
200
MC/DC33%1/3
defined $body or ref $body and ref $body eq "ARRAY"
defined $body ref $body ref $body eq "ARRAY"
Truth table50%2/4
A or B and C
A= defined $bodyB= ref $bodyC= ref $body eq "ARRAY"
ABCresult
1XX1
0111
00X0
0100
1327 2 $self->puke("-ident requires a single plain scalar argument (a quotable identifier) or an arrayref of identifier parts");
1328 }
1329 2757 ▶ my ($sep) = map +(defined() ? $_ : '.') , $self->{name_sep};
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 742 2015 2757
1330 2757 ▶ my @parts = map +($sep
Branch: 2 branches
BranchTrueFalseTotal
$sep ? : 2676 81 2757
ref $body ? : 127 2630 2757
1331 ? map split(/\Q${sep}\E/, $_), @$_
1332 : @$_
1333 ), ref($body) ? $body : [ $body ];
1334 2757 ▶ return { -ident => $parts[-1] } if $self->{_dequalify_idents};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_dequalify_idents"} 0 2757 2757
1335 2757 ▶ unless ($self->{quote_char}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"quote_char"}) 1955 802 2757
1336 1955 $self->_assert_pass_injection_guard($_) for @parts;
1337 }
1338 2756 return +{ -ident => \@parts };
1339 }
1340  
1341 1233 ▶sub _expand_value {
Subroutine _expand_value: called CC=1 SCAR=0.0
1342 1233 +{ -bind => [ our $Cur_Col_Meta, $_[2] ] };
1343 }
1344  
1345 49 ▶sub _expand_row {
Subroutine _expand_row: called CC=2 SCAR=6.9
1346 49 my ($self, undef, $args) = @_;
1347 +{ -row => [
1348 map {
1349 # a row is positional, so an undef element is a NULL value and must
1350 # keep its placeholder and bind slot rather than being expanded to
1351 # nothing and silently dropped by the renderer (RT#137357)
1352 49 ▶ defined($_)
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 133 3 136
1353 ? $self->expand_expr($_)
1354 : +{ -bind => [ our $Cur_Col_Meta, undef ] }
1355 } @$args
1356 ] };
1357 }
1358  
1359 139 ▶sub _expand_op {
Subroutine _expand_op: called CC=3 SCAR=11.1
1360 139 my ($self, undef, $args) = @_;
1361 139 my ($op, @opargs) = @$args;
1362 139 ▶ if (my $exp = $self->{expand_op}{$op}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $exp = $self->{"expand_op"}{$op}) 1 138 139
1363 1 return $self->$exp($op, \@opargs);
1364 }
1365 138 ▶ if (List::Util::first { $op =~ $_->{regex} } @{$self->{unary_ops}}) {
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
if (&List::Util::first(sub { $op =~ /$_->{"regex"}/; } , @{$$self{"unary_ops"};})) 0 138 138
1366 0 return { -op => [ $op, @opargs ] };
1367 }
1368 138 +{ -op => [ $op, map $self->expand_expr($_), @opargs ] };
1369 }
1370  
1371 28 ▶sub _expand_bool {
Subroutine _expand_bool: called CC=3 SCAR=11.0
1372 28 my ($self, undef, $v) = @_;
1373 28 ▶ if (ref($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) 10 18 28
1374 10 return $self->_expand_expr($v);
1375 }
1376 18 ▶ $self->puke("-bool => undef not supported") unless defined($v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 18 18
1377 18 return $self->_expand_expr({ -ident => $v });
1378 }
1379  
1380 511 ▶sub _expand_list {
Subroutine _expand_list: called CC=5 SCAR=16.1
1381 511 my ($self, undef, $expr) = @_;
1382 return { -op => [
1383 ',', map $self->expand_expr($_),
1384 7 @{$expr->{-op}}[1..$#{$expr->{-op}}]
1385 511 ▶ ] } if ref($expr) eq 'HASH' and ($expr->{-op}||[''])->[0] eq ',';
Branch: 1 branch
BranchTrueFalseTotal
if ref $expr eq "HASH" and +($expr->{"-op"} || [""])->[0] eq "," 7 504 511
Condition100%5/5
ref $expr eq "HASH" and +($expr->{"-op"} || [""])->[0] eq ","
!ll&&!rl&&r
3971077
$expr->{'-op'} || ['']
l!l
7107
MC/DC100%2/2
ref $expr eq "HASH" and +($expr->{"-op"} || [""])->[0] eq ","
ref $expr eq "HASH" $expr->{'-op'}
Truth table100%3/3
A and B
A= ref $expr eq "HASH"B= $expr->{'-op'}
ABresult
0X0
100
111
1386 504 ▶ return +{ -op => [ ',',
Branch: 1 branch
BranchTrueFalseTotal
ref $expr eq 'ARRAY' ? : 120 384 504
1387 map $self->expand_expr($_),
1388 ref($expr) eq 'ARRAY' ? @$expr : $expr
1389 ] };
1390 }
1391  
1392 481 ▶sub _expand_logop {
Subroutine _expand_logop: called CC=1 SCAR=0.0
1393 481 my ($self, $logop, $v, $k) = @_;
1394 481 $self->${\$self->{expand_op}{$logop}}($logop, $v, $k);
1395 }
1396  
1397 628 ▶sub _expand_op_andor {
Subroutine _expand_op_andor: called CC=21 SCAR=30.7
1398 628 my ($self, $logop, $v, $k) = @_;
1399 628 ▶ if (defined $k) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $k) 174 454 628
1400 $v = [ map +{ $k, $_ },
1401 (ref($v) eq 'HASH')
1402 174 ▶ ? (map +{ $_ => $v->{$_} }, sort keys %$v)
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'HASH' ? : 8 166 174
1403 : @$v,
1404 ];
1405 }
1406 628 ▶ if (ref($v) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "HASH") 223 405 628
1407 223 ▶ return undef unless keys %$v;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$v 0 223 223
1408 return +{ -op => [
1409 $logop,
1410 223 map $self->_expand_expr({ $_ => $v->{$_} }),
1411 sort keys %$v
1412 ] };
1413 }
1414 405 ▶ if (ref($v) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "ARRAY") 405 0 405
1415 405 ▶ $logop eq 'and' or $logop eq 'or' or $self->puke("unknown logic: $logop");
Branch: 1 branch
BranchTrueFalseTotal
$logop eq "and" or $logop eq "or" or $self->puke("unknown logic: $logop") 405 0 405
Condition66%2/3
$logop eq "and" or $logop eq "or"
l!l&&r!l&&!r
863190
MC/DC0%0/2
$logop eq "and" or $logop eq "or"
$logop eq "and" $logop eq "or"
Truth table66%2/3
A or B
A= $logop eq "and"B= $logop eq "or"
ABresult
1X1
011
000
1416  
1417 my @expr = grep {
1418 405 ▶ (ref($_) eq 'ARRAY' and @$_)
Condition100%11/11
ref $_ eq 'ARRAY' && @$_ || ref $_ eq 'HASH' && %$_ || 1
l!l
479605
ref $_ eq "ARRAY" and @$_ or ref $_ eq "HASH" and %$_
l!l&&r!l&&!r
75404605
ref $_ eq "ARRAY" and @$_
!ll&&!rl&&r
1006375
ref $_ eq "HASH" and %$_
!ll&&!rl&&r
6023404
MC/DC100%4/4
ref $_ eq 'ARRAY' && @$_ || ref $_ eq 'HASH' && %$_ || 1
ref $_ eq "ARRAY" @$_ ref $_ eq "HASH" %$_
Truth table71%5/7
A and B or C and D
A= ref $_ eq "ARRAY"B= @$_C= ref $_ eq "HASH"D= %$_
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
1419 or (ref($_) eq 'HASH' and %$_)
1420 or 1
1421 } @$v;
1422  
1423 405 my @res;
1424  
1425 405 ▶ while (my ($el) = splice @expr, 0, 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($el) = splice(@expr, 0, 1)) 709 345 1054
1426 709 ▶ $self->puke("Supplying an empty left hand side argument is not supported in array-pairs")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $el and length $el 44 665 709
Condition100%3/3
defined $el and length $el
!ll&&!rl&&r
2222665
MC/DC100%2/2
defined $el and length $el
defined $el length $el
Truth table100%3/3
A and B
A= defined $elB= length $el
ABresult
0X0
100
111
1427 unless defined($el) and length($el);
1428 665 my $elref = ref($el);
1429 665 ▶ if (!$elref) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $elref) { } 287 378 665
elsif ($elref eq 'ARRAY') { } 18 360 378
elsif (my $l = &is_literal_value($el)) { } 1 359 360
elsif ($elref eq 'HASH') { } 359 0 359
1430 287 local our $Expand_Depth = 0;
1431 287 push(@res, grep defined, $self->_expand_expr({ $el, shift(@expr) }));
1432 } elsif ($elref eq 'ARRAY') {
1433 18 ▶ push(@res, grep defined, $self->_expand_expr($el)) if @$el;
Branch: 1 branch
BranchTrueFalseTotal
if @$el 16 2 18
1434 } elsif (my $l = is_literal_value($el)) {
1435 1 push @res, { -literal => $l };
1436 } elsif ($elref eq 'HASH') {
1437 359 local our $Expand_Depth = 0;
1438 359 ▶ push @res, grep defined, $self->_expand_expr($el) if %$el;
Branch: 1 branch
BranchTrueFalseTotal
if %$el 356 3 359
1439 } else {
1440 0 die "notreached";
1441 }
1442 }
1443 # ???
1444 # return $res[0] if @res == 1;
1445 345 return { -op => [ $logop, @res ] };
1446 }
1447 0 die "notreached";
1448 }
1449  
1450 145 ▶sub _expand_op_is {
Subroutine _expand_op_is: called CC=6 SCAR=20.3
1451 145 my ($self, $op, $vv, $k) = @_;
1452 145 ▶ ($k, $vv) = @$vv unless defined $k;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k 1 144 145
1453 $self->puke("$op can only take undef as argument")
1454 if defined($vv)
1455 and not (
1456 ref($vv) eq 'HASH'
1457 and exists($vv->{-value})
1458 and !defined($vv->{-value})
1459 145 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
if defined $vv and not ref $vv eq "HASH" && exists $vv->{"-value"} && !defined($vv->{"-value"}) 0 145 145
Condition44%4/9
defined $vv and not ref $vv eq "HASH" && exists $vv->{"-value"} && !defined($vv->{"-value"})
!ll&&!rl&&r
13780
ref $vv eq 'HASH' && exists $vv->{'-value'} && !defined($vv->{'-value'})
!ll&&!rl&&r
008
ref $vv eq "HASH" and exists $vv->{"-value"}
!ll&&!rl&&r
008
MC/DC0%0/4
defined $vv and not ref $vv eq "HASH" && exists $vv->{"-value"} && !defined($vv->{"-value"})
defined $vv ref $vv eq "HASH" exists $vv->{"-value"} !defined($vv->{'-value'})
Truth table40%2/5
A and not(B and C && not(D))
A= defined $vvB= ref $vv eq "HASH"C= exists $vv->{"-value"}D= !defined($vv->{'-value'})
ABCDresult
0XXX0
11110
10XX1
110X1
11101
1460 145 return +{ -op => [ $op.'_null', $self->expand_expr($k, -ident) ] };
1461 }
1462  
1463 60 ▶sub _expand_between {
Subroutine _expand_between: called CC=8 SCAR=20.8
1464 60 my ($self, $op, $vv, $k) = @_;
1465 60 ▶ my @rhs = map $self->_expand_expr($_),
Branch: 1 branch
BranchTrueFalseTotal
ref $vv eq 'ARRAY' ? : 46 14 60
1466 ref($vv) eq 'ARRAY' ? @$vv : $vv;
1467 60 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless (@rhs == 1 and ref $rhs[0] eq "HASH" and $rhs[0]{"-literal"} or @rhs == 2 and defined $rhs[0] and defined $rhs[1]) 13 47 60
Condition100%15/15
@rhs == 1 and ref $rhs[0] eq "HASH" and $rhs[0]{"-literal"} or @rhs == 2 and defined $rhs[0] and defined $rhs[1]
l!l&&r!l&&!r
123513
@rhs == 1 and ref $rhs[0] eq "HASH" and $rhs[0]{"-literal"}
!ll&&!rl&&r
45312
@rhs == 1 and ref $rhs[0] eq "HASH"
!ll&&!rl&&r
43215
@rhs == 2 and defined $rhs[0] and defined $rhs[1]
!ll&&!rl&&r
12135
@rhs == 2 and defined $rhs[0]
!ll&&!rl&&r
10236
MC/DC100%6/6
@rhs == 1 and ref $rhs[0] eq "HASH" and $rhs[0]{"-literal"} or @rhs == 2 and defined $rhs[0] and defined $rhs[1]
@rhs == 1 ref $rhs[0] eq "HASH" $rhs[0]{"-literal"} @rhs == 2 defined $rhs[0] defined $rhs[1]
Truth table53%7/13
A and B and C or D and E and F
A= @rhs == 1B= ref $rhs[0] eq "HASH"C= $rhs[0]{"-literal"}D= @rhs == 2E= defined $rhs[0]F= defined $rhs[1]
ABCDEFresult
111XXX1
0XX1111
10X1111
1101111
0XX0XX0
0XX10X0
0XX1100
10X0XX0
10X10X0
10X1100
1100XX0
11010X0
1101100
1468 (@rhs == 1 and ref($rhs[0]) eq 'HASH' and $rhs[0]->{-literal})
1469 or
1470 (@rhs == 2 and defined($rhs[0]) and defined($rhs[1]))
1471 ) {
1472 13 $self->puke("Operator '${\uc($op)}' requires either an arrayref with two defined values or expressions, or a single literal scalarref/arrayref-ref");
1473 }
1474 47 return +{ -op => [
1475 $op,
1476 $self->expand_expr($k),
1477 map $self->expand_expr($_, -value), @rhs
1478 ] }
1479 }
1480  
1481 63 ▶sub _expand_in {
Subroutine _expand_in: called CC=11 SCAR=24.0
1482 63 my ($self, $op, $vv, $k) = @_;
1483 63 ▶ if (my $literal = is_literal_value($vv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $literal = &is_literal_value($vv)) 11 52 63
1484 11 my ($sql, @bind) = @$literal;
1485 11 my $opened_sql = $self->_open_outer_paren($sql);
1486 11 return +{ -op => [
1487 $op, $self->expand_expr($k, -ident),
1488 { -literal => [ $opened_sql, @bind ] }
1489 ] };
1490 }
1491 52 ▶ $self->puke("Argument passed to the '${\uc($op)}' operator can not be undefined")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vv 1 51 52
1492 if !defined($vv);
1493 51 my $not = $op =~ /^not/;
1494 51 ▶ my @values = ref($vv) eq 'ARRAY' ? @$vv : $vv;
Branch: 1 branch
BranchTrueFalseTotal
ref $vv eq 'ARRAY' ? : 48 3 51
1495  
1496 # undef elements mean NULL, which IN never matches: turn them into
1497 # col IN (...) OR col IS NULL, and col NOT IN (...) AND col IS NOT NULL
1498 51 my $has_undef = grep !defined, @values;
1499 51 my @rhs = map $self->expand_expr($_, -value), grep defined, @values;
1500  
1501 51 ▶ my $null = $has_undef && { -op => [
Branch: 1 branch
BranchTrueFalseTotal
$not ? : 3 7 10
Condition100%2/2
$has_undef && {'-op', [$not ? 'is_not_null' : 'is_null', $self->expand_expr($k, '-ident')]}
!ll
4110
MC/DC100%1/1
$has_undef && {'-op', [$not ? 'is_not_null' : 'is_null', $self->expand_expr($k, '-ident')]}
$has_undef
Truth table100%2/2
A
A= $has_undef
Aresult
00
11
1502 ($not ? 'is_not_null' : 'is_null'), $self->expand_expr($k, -ident)
1503 ] };
1504 51 ▶ unless (@rhs) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@rhs) 7 44 51
1505 7 ▶ return $null || $self->${\($not ? 'sqltrue' : 'sqlfalse')};
Branch: 1 branch
BranchTrueFalseTotal
$not ? : 2 3 5
Condition66%2/3
$null || $self->${\($not ? 'sqltrue' : 'sqlfalse');}
l!l&&r!l&&!r
250
MC/DC0%0/2
$null || $self->${\($not ? 'sqltrue' : 'sqlfalse');}
$null $self->${\($not ? 'sqltrue' : 'sqlfalse');}
Truth table66%2/3
A || B
A= $nullB= $self->${\($not ? 'sqltrue' : 'sqlfalse');}
ABresult
1X1
011
000
1506 }
1507  
1508 44 my $in = { -op => [
1509 $op,
1510 $self->expand_expr($k, -ident),
1511 @rhs
1512 ] };
1513 44 ▶ return $in unless $null;
Branch: 1 branch
BranchTrueFalseTotal
unless $null 36 8 44
1514 8 ▶ return { -op => [ ($not ? 'and' : 'or'), $in, $null ] };
Branch: 1 branch
BranchTrueFalseTotal
$not ? : 2 6 8
1515 }
1516  
1517 26 ▶sub _expand_nest {
Subroutine _expand_nest: called CC=3 SCAR=16.0
1518 26 my ($self, undef, $v) = @_;
1519 # DBIx::Class requires a nest warning to be emitted once but the private
1520 # method it overrode to do so no longer exists
1521 26 ▶ if ($self->{warn_once_on_nest}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"warn_once_on_nest"}) 0 26 26
1522 0 ▶ unless (our $Nest_Warned) {
Branch: 1 branch
BranchTrueFalseTotal
unless (our $Nest_Warned) 0 0 0
1523 0 $self->belch(
1524 "-nest in search conditions is deprecated, you most probably wanted:\n"
1525 .q|{..., -and => [ \%cond0, \@cond1, \'cond2', \[ 'cond3', [ col => bind ] ], etc. ], ... }|
1526 );
1527 0 $Nest_Warned = 1;
1528 }
1529 }
1530 26 return $self->_expand_expr($v);
1531 }
1532  
1533 6 ▶sub _expand_values {
Subroutine _expand_values: called CC=3 SCAR=11.1
1534 6 my ($self, undef, $values) = @_;
1535 # VALUES rows hold values, even in an identifier context like from
1536 6 local our $Default_Scalar_To = -value;
1537 6 ▶ return { -values => [
Branch: 2 branches
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 3 8 11
ref $values eq 'ARRAY' ? : 6 0 6
1538 map +(
1539 ref($_) eq 'HASH'
1540 ? $self->expand_expr($_)
1541 : $self->_expand_row(undef, $_)
1542 ), ref($values) eq 'ARRAY' ? @$values : $values
1543 ] };
1544 }
1545  
1546 491 ▶sub _recurse_where {
Subroutine _recurse_where: called CC=5 SCAR=17.5
1547 491 my ($self, $where) = @_;
1548  
1549 # Special case: top level simple string treated as literal
1550  
1551 491 ▶ my $where_exp = (ref($where)
Branch: 1 branch
BranchTrueFalseTotal
ref $where ? : 490 1 491
1552 ? $self->_expand_select_clause_where(undef, $where)
1553 : { -literal => [ $where ] });
1554  
1555 # dispatch expanded expression
1556  
1557 399 ▶ my ($sql, @bind) = defined($where_exp) ? @{ $self->render_aqt($where_exp) || [] } : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $where_exp ? : 399 0 399
Condition50%1/2
$self->render_aqt($where_exp) || []
l!l
3990
MC/DC0%0/1
$self->render_aqt($where_exp) || []
$self->render_aqt($where_exp)
Truth table50%1/2
A
A= $self->render_aqt($where_exp)
Aresult
11
00
1558 # DBIx::Class used to call _recurse_where in scalar context
1559 # something else might too...
1560 399 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 399 0 399
1561 399 return ($sql, @bind);
1562 }
1563 else {
1564 0 $self->belch("Calling _recurse_where in scalar context is deprecated and will go away in a future version");
1565 0 return $sql;
1566 }
1567 }
1568  
1569 2032 ▶sub _render_ident {
Subroutine _render_ident: called CC=1 SCAR=0.0
1570 2032 my ($self, undef, $ident) = @_;
1571  
1572 2032 return [ $self->_quote($ident) ];
1573 }
1574  
1575 104 ▶sub _render_row {
Subroutine _render_row: called CC=1 SCAR=0.0
1576 104 my ($self, undef, $values) = @_;
1577 104 return $self->join_query_parts('',
1578 '(',
1579 $self->_render_op(undef, [ ',', @$values ]),
1580 ')'
1581 );
1582 }
1583  
1584 73 ▶sub _render_func {
Subroutine _render_func: called CC=1 SCAR=0.0
1585 73 my ($self, undef, $rest) = @_;
1586 73 my ($func, @args) = @$rest;
1587 73 return $self->join_query_parts('',
1588 $self->_sqlcase($func),
1589 $self->join_query_parts('',
1590 '(',
1591 $self->join_query_parts(', ', @args),
1592 ')'
1593 ),
1594 );
1595 }
1596  
1597 1220 ▶sub _render_bind {
Subroutine _render_bind: called CC=1 SCAR=0.0
1598 1220 my ($self, undef, $bind) = @_;
1599 1220 return [ '?', $self->_bindtype(@$bind) ];
1600 }
1601  
1602 387 ▶sub _render_literal {
Subroutine _render_literal: called CC=1 SCAR=0.0
1603 387 my ($self, undef, $literal) = @_;
1604 387 $self->_assert_bindval_matches_bindtype(@{$literal}[1..$#$literal]);
1605 379 return $literal;
1606 }
1607  
1608 2653 ▶sub _render_keyword {
Subroutine _render_keyword: called CC=2 SCAR=6.9
1609 2653 my ($self, undef, $keyword) = @_;
1610 2653 ▶ return [ $self->_sqlcase(
Branch: 1 branch
BranchTrueFalseTotal
ref $keyword ? : 28 2625 2653
1611 ref($keyword) ? $$keyword : join ' ', split '_', $keyword
1612 ) ];
1613 }
1614  
1615 2578 ▶sub _render_op {
Subroutine _render_op: called CC=9 SCAR=22.0
1616 2578 my ($self, undef, $v) = @_;
1617 2578 my ($op, @args) = @$v;
1618 2578 ▶ if (my $r = $self->{render_op}{$op}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = $self->{"render_op"}{$op}) 1693 885 2578
1619 1693 return $self->$r($op, \@args);
1620 }
1621  
1622 { # Old SQLA compat
1623  
1624 885 ▶ my $ss = List::Util::first { $op =~ $_->{regex} } @{$self->{special_ops}};
Subroutine __ANON__: called CC=1 SCAR=0.0
1625 885 ▶ if ($ss and @args > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ss and @args > 1) 5 880 885
Condition100%3/3
$ss and @args > 1
!ll&&!rl&&r
87915
MC/DC100%2/2
$ss and @args > 1
$ss @args > 1
Truth table100%3/3
A and B
A= $ssB= @args > 1
ABresult
0X0
100
111
1626 $self->puke("Special op '${op}' requires first value to be identifier")
1627 5 ▶ unless my ($ident) = map $_->{-ident}, grep ref($_) eq 'HASH', $args[0];
Branch: 1 branch
BranchTrueFalseTotal
unless my($ident) = map($_->{"-ident"}, grep((ref $_ eq "HASH"), $args[0])) 0 5 5
1628 5 ▶ my $k = join(($self->{name_sep}||'.'), @$ident);
Condition50%1/2
$self->{'name_sep'} || '.'
l!l
05
MC/DC0%0/1
$self->{'name_sep'} || '.'
$self->{'name_sep'}
Truth table50%1/2
A
A= $self->{'name_sep'}
Aresult
11
00
1629 5 local our $Expand_Depth = 1;
1630 5 return [ $self->${\($ss->{handler})}($k, $op, $args[1]) ];
1631 }
1632 880 ▶ if (my $us = List::Util::first { $op =~ $_->{regex} } @{$self->{unary_ops}}) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (my $us = &List::Util::first(sub { $op =~ /$_->{"regex"}/; } , @{$$self{"unary_ops"};})) 2 878 880
1633 2 return [ $self->${\($us->{handler})}($op, $args[0]) ];
1634 }
1635 878 ▶ if ($ss) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ss) 1 877 878
1636 1 return $self->_render_unop_paren($op, \@args);
1637 }
1638 }
1639 877 ▶ if (@args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1) { } 8 869 877
1640 8 return $self->_render_unop_prefix($op, \@args);
1641 } else {
1642 869 return $self->_render_op_multop($op, \@args);
1643 }
1644 0 die "notreached";
1645 }
1646  
1647  
1648 47 ▶sub _render_op_between {
Subroutine _render_op_between: called CC=5 SCAR=16.2
1649 47 my ($self, $op, $args) = @_;
1650 47 my ($left, $low, $high) = @$args;
1651 47 my @rh = do {
1652 47 ▶ if (@$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args == 2) { } 12 35 47
1653 $self->puke("Single arg to between must be a literal")
1654 12 ▶ unless $low->{-literal};
Branch: 1 branch
BranchTrueFalseTotal
unless $low->{"-literal"} 0 12 12
1655 12 $low;
1656 } else {
1657 35 ▶ puke "Arguments to between must be defined"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $low and defined $high 2 33 35
Condition66%2/3
defined $low and defined $high
!ll&&!rl&&r
2033
MC/DC50%1/2
defined $low and defined $high
defined $low defined $high
Truth table66%2/3
A and B
A= defined $lowB= defined $high
ABresult
0X0
100
111
1658 unless defined $low && defined $high;
1659 33 +($low, { -keyword => 'and' }, $high);
1660 }
1661 };
1662 45 return $self->join_query_parts(' ',
1663 '(', $left, { -keyword => $op }, @rh, ')',
1664 );
1665 }
1666  
1667 57 ▶sub _render_op_in {
Subroutine _render_op_in: called CC=3 SCAR=11.0
1668 57 my ($self, $op, $args) = @_;
1669 57 my ($lhs, @rhs) = @$args;
1670  
1671 return $self->join_query_parts(' ',
1672 @rhs
1673 ? (
1674 $lhs,
1675 { -keyword => $op },
1676 $self->join_query_parts(' ',
1677 '(',
1678 $self->join_query_parts(', ', @rhs),
1679 ')'
1680 )
1681 )
1682 57 ▶ : $self->${\($op =~ /^not/ ? 'sqltrue' : 'sqlfalse')}
Branch: 2 branches
BranchTrueFalseTotal
@rhs ? : 55 2 57
$op =~ /^not/ ? : 1 1 2
1683 );
1684 }
1685  
1686 556 ▶sub _render_op_andor {
Subroutine _render_op_andor: called CC=5 SCAR=16.1
1687 556 my ($self, $op, $args) = @_;
1688 556 ▶ return undef unless @$args;
Branch: 1 branch
BranchTrueFalseTotal
unless @$args 8 548 556
1689 548 ▶ return $self->join_query_parts('', $args->[0]) if @$args == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$args == 1 125 423 548
1690 423 my $inner = $self->_render_op_multop($op, $args);
1691 419 ▶ return undef unless defined($inner->[0]) and length($inner->[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $inner->[0] and length $inner->[0] 2 417 419
Condition66%2/3
defined $inner->[0] and length $inner->[0]
!ll&&!rl&&r
02417
MC/DC50%1/2
defined $inner->[0] and length $inner->[0]
defined $inner->[0] length $inner->[0]
Truth table66%2/3
A and B
A= defined $inner->[0]B= length $inner->[0]
ABresult
0X0
100
111
1692 417 return $self->join_query_parts(' ',
1693 '(', $inner, ')'
1694 );
1695 }
1696  
1697 1974 ▶sub _render_op_multop {
Subroutine _render_op_multop: called CC=4 SCAR=13.9
1698 1974 my ($self, $op, $args) = @_;
1699 1974 my @parts = @$args;
1700 1974 ▶ return undef unless @parts;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts 0 1974 1974
1701 1974 ▶ return $self->render_aqt($parts[0]) if @parts == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @parts == 1 483 1491 1974
1702 1491 ▶ my $join = ($op eq ','
Branch: 1 branch
BranchTrueFalseTotal
$op eq ',' ? : 199 1292 1491
1703 ? ', '
1704 : { -keyword => " ${op} " }
1705 );
1706 1491 return $self->join_query_parts($join, @parts);
1707 }
1708  
1709 59 ▶sub _render_values {
Subroutine _render_values: called CC=3 SCAR=11.1
1710 59 my ($self, undef, $values) = @_;
1711 59 ▶ my $inner = $self->join_query_parts(' ',
Branch: 1 branch
BranchTrueFalseTotal
ref $values eq 'ARRAY' ? : 59 0 59
1712 { -keyword => 'values' },
1713 $self->join_query_parts(', ',
1714 ref($values) eq 'ARRAY' ? @$values : $values
1715 ),
1716 );
1717 57 ▶ return $self->join_query_parts('',
Branch: 1 branch
BranchTrueFalseTotal
our $Render_Top_Level ? : 55 2 57
1718 (our $Render_Top_Level ? $inner : ('(', $inner, ')'))
1719 );
1720 }
1721  
1722 4374 ▶sub default_join_sql_parts { join $_[0], @_[1..$#_] }
Subroutine default_join_sql_parts: called CC=1 SCAR=0.0
Pod undocumented
1723  
1724 4539 ▶sub join_query_parts {
Subroutine join_query_parts: called CC=5 SCAR=16.1
Pod documented
1725 4539 my ($self, $join, @parts) = @_;
1726 4539 ▶ if (ref($join) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $join eq "HASH") 1295 3244 4539
1727 1295 $join = $self->render_aqt($join)->[0];
1728 }
1729 4539 ▶ my @final = map +(
Branch: 2 branches
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 5943 4260 10203
ref $_ eq 'ARRAY' ? : 2674 1586 4260
1730 ref($_) eq 'HASH'
1731 ? $self->render_aqt($_)
1732 : ((ref($_) eq 'ARRAY') ? $_ : [ $_ ])
1733 ), @parts;
1734 return [
1735 $self->{join_sql_parts}->(
1736 $join, grep defined && length, map $_->[0], @final
1737 ),
1738 4523 ▶ (map @{$_}[1..$#$_], @final),
Condition66%2/3
defined $_ && length $_
!ll&&!rl&&r
7010172
MC/DC50%1/2
defined $_ && length $_
defined $_ length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1739 ];
1740 }
1741  
1742 27 ▶sub _render_unop_paren {
Subroutine _render_unop_paren: called CC=1 SCAR=0.0
1743 27 my ($self, $op, $v) = @_;
1744 27 return $self->join_query_parts('',
1745 '(', $self->_render_unop_prefix($op, $v), ')'
1746 );
1747 }
1748  
1749 35 ▶sub _render_unop_prefix {
Subroutine _render_unop_prefix: called CC=2 SCAR=6.9
1750 35 my ($self, $op, $v) = @_;
1751 return $self->join_query_parts(' ',
1752 ($self->{restore_old_unop_handling}
1753 35 ▶ ? $self->_sqlcase($op)
Branch: 1 branch
BranchTrueFalseTotal
$self->{'restore_old_unop_handling'} ? : 7 28 35
1754 : { -keyword => \$op }),
1755 $v->[0]
1756 );
1757 }
1758  
1759 329 ▶sub _render_unop_postfix {
Subroutine _render_unop_postfix: called CC=1 SCAR=0.0
1760 329 my ($self, $op, $v) = @_;
1761 329 return $self->join_query_parts(' ',
1762 $v->[0], { -keyword => $op },
1763 );
1764 }
1765  
1766 # Some databases (SQLite) treat col IN (1, 2) different from
1767 # col IN ( (1, 2) ). Use this to strip all outer parens while
1768 # adding them back in the corresponding method
1769 11 ▶sub _open_outer_paren {
Subroutine _open_outer_paren: called CC=5 SCAR=16.1
1770 11 my ($self, $sql) = @_;
1771  
1772 11 ▶ while (my ($inner) = $sql =~ /^ \s* \( (.*) \) \s* $/xs) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($inner) = $sql =~ /^ \s* \( (.*) \) \s* $/sx) 9 10 19
1773  
1774 # there are closing parens inside, need the heavy duty machinery
1775 # to reevaluate the extraction starting from $sql (full reevaluation)
1776 9 ▶ if ($inner =~ /\)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inner =~ /\)/) 8 1 9
1777 8 require Text::Balanced;
1778  
1779 8 my (undef, $remainder) = do {
1780 # idiotic design - writes to $@ but *DOES NOT* throw exceptions
1781 8 local $@;
1782 8 Text::Balanced::extract_bracketed($sql, '()', qr/\s*/);
1783 };
1784  
1785 # the entire expression needs to be a balanced bracketed thing
1786 # (after an extract no remainder sans trailing space)
1787 8 ▶ last if defined $remainder and $remainder =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $remainder and $remainder =~ /\S/ 1 7 8
Condition66%2/3
defined $remainder and $remainder =~ /\S/
!ll&&!rl&&r
071
MC/DC50%1/2
defined $remainder and $remainder =~ /\S/
defined $remainder $remainder =~ /\S/
Truth table66%2/3
A and B
A= defined $remainderB= $remainder =~ /\S/
ABresult
0X0
100
111
1788 }
1789  
1790 8 $sql = $inner;
1791 }
1792  
1793 11 $sql;
1794 }
1795  
1796 2 ▶sub _where_field_IN {
Subroutine _where_field_IN: called CC=2 SCAR=7.1
1797 2 my ($self, $k, $op, $vals) = @_;
1798 2 ▶ @{$self->_render_op_in(
Branch: 1 branch
BranchTrueFalseTotal
ref $vals eq 'ARRAY' ? : 2 0 2
1799 $op,
1800 [
1801 $self->expand_expr($k, -ident),
1802 map $self->expand_expr($_, -value),
1803 ref($vals) eq 'ARRAY' ? @$vals : $vals
1804 ]
1805 )};
1806 }
1807  
1808 2 ▶sub _where_field_BETWEEN {
Subroutine _where_field_BETWEEN: called CC=2 SCAR=7.1
1809 2 my ($self, $k, $op, $vals) = @_;
1810 2 ▶ @{$self->_render_op_between(
Branch: 1 branch
BranchTrueFalseTotal
ref $vals eq 'ARRAY' ? : 2 0 2
1811 $op,
1812 [ $self->expand_expr($k, -ident), ref($vals) eq 'ARRAY' ? @$vals : $vals ]
1813 )};
1814 }
1815  
1816 #======================================================================
1817 # ORDER BY
1818 #======================================================================
1819  
1820 220 ▶sub _expand_order_by {
Subroutine _expand_order_by: called CC=7 SCAR=19.6
1821 220 my ($self, $arg) = @_;
1822  
1823 220 ▶ return undef unless defined($arg) and not (ref($arg) eq 'ARRAY' and !@$arg);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg and not ref $arg eq "ARRAY" && !@$arg 7 213 220
Condition83%5/6
defined $arg and not ref $arg eq "ARRAY" && !@$arg
!ll&&!rl&&r
07213
ref $arg eq 'ARRAY' && !@$arg
!ll&&!rl&&r
311827
MC/DC66%2/3
defined $arg and not ref $arg eq "ARRAY" && !@$arg
defined $arg ref $arg eq 'ARRAY' !@$arg
Truth table75%3/4
A and not(B && not(C))
A= defined $argB= ref $arg eq 'ARRAY'C= !@$arg
ABCresult
0XX0
1110
10X1
1101
1824  
1825 return $self->expand_expr({ -list => $arg })
1826 213 ▶ if ref($arg) eq 'HASH' and ($arg->{-op}||[''])->[0] eq ',';
Branch: 1 branch
BranchTrueFalseTotal
if ref $arg eq "HASH" and +($arg->{"-op"} || [""])->[0] eq "," 0 213 213
Condition60%3/5
ref $arg eq "HASH" and +($arg->{"-op"} || [""])->[0] eq ","
!ll&&!rl&&r
194190
$arg->{'-op'} || ['']
l!l
019
MC/DC0%0/2
ref $arg eq "HASH" and +($arg->{"-op"} || [""])->[0] eq ","
ref $arg eq "HASH" $arg->{'-op'}
Truth table66%2/3
A and B
A= ref $arg eq "HASH"B= $arg->{'-op'}
ABresult
0X0
100
111
1827  
1828 336 ▶ my $expander = sub {
Subroutine __ANON__: called CC=21 SCAR=30.7
1829 336 my ($self, $dir, $expr) = @_;
1830 336 ▶ my @to_expand = ref($expr) eq 'ARRAY' ? @$expr : $expr;
Branch: 1 branch
BranchTrueFalseTotal
ref $expr eq 'ARRAY' ? : 226 110 336
1831 336 foreach my $arg (@to_expand) {
1832 414 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq "HASH" and not exists $arg->{"-nulls"} and keys %$arg > 1 and grep /^-(asc|desc)$/, keys %$arg) 3 411 414
Condition88%8/9
ref $arg eq "HASH" and not exists $arg->{"-nulls"} and keys %$arg > 1 and grep /^-(asc|desc)$/, keys %$arg
!ll&&!rl&&r
41103
ref $arg eq "HASH" and not exists $arg->{"-nulls"} and keys %$arg > 1
!ll&&!rl&&r
323883
ref $arg eq "HASH" and not exists $arg->{"-nulls"}
!ll&&!rl&&r
3091491
MC/DC75%3/4
ref $arg eq "HASH" and not exists $arg->{"-nulls"} and keys %$arg > 1 and grep /^-(asc|desc)$/, keys %$arg
ref $arg eq "HASH" not exists $arg->{"-nulls"} keys %$arg > 1 grep /^-(asc|desc)$/, keys %$arg
Truth table80%4/5
A and not(B) and C and D
A= ref $arg eq "HASH"B= not exists $arg->{"-nulls"}C= keys %$arg > 1D= grep /^-(asc|desc)$/, keys %$arg
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1833 ref($arg) eq 'HASH'
1834 and !exists $arg->{-nulls}
1835 and keys %$arg > 1
1836 and grep /^-(asc|desc)$/, keys %$arg
1837 ) {
1838 3 $self->puke("ordering direction hash passed to order by must have exactly one key (-asc or -desc)");
1839 }
1840 }
1841 333 my @exp;
1842 333 ▶ foreach my $arg (map ref($_) eq 'ARRAY' ? @$_ : $_, @to_expand) {
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 34 377 411
1843 445 ▶ if (ref($arg) eq 'HASH' and exists $arg->{-nulls}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq "HASH" and exists $arg->{"-nulls"}) 14 431 445
Condition100%3/3
ref $arg eq "HASH" and exists $arg->{"-nulls"}
!ll&&!rl&&r
31112014
MC/DC100%2/2
ref $arg eq "HASH" and exists $arg->{"-nulls"}
ref $arg eq "HASH" exists $arg->{"-nulls"}
Truth table100%3/3
A and B
A= ref $arg eq "HASH"B= exists $arg->{"-nulls"}
ABresult
0X0
100
111
1844 # { -asc => $col, -nulls => 'first' } => col ASC NULLS FIRST
1845 14 my %by = %$arg;
1846 14 my $nulls = delete $by{-nulls};
1847 14 ▶ $self->puke("invalid value for -nulls in order by: must be 'first' or 'last'")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nulls and not ref $nulls and $nulls =~ /\A(?:first|last)\z/i 1 13 14
Condition50%3/6
defined $nulls and not ref $nulls and $nulls =~ /\A(?:first|last)\z/i
!ll&&!rl&&r
0113
defined $nulls and not ref $nulls
!ll&&!rl&&r
0014
MC/DC33%1/3
defined $nulls and not ref $nulls and $nulls =~ /\A(?:first|last)\z/i
defined $nulls not ref $nulls $nulls =~ /\A(?:first|last)\z/i
Truth table50%2/4
A and not(B) and C
A= defined $nullsB= not ref $nullsC= $nulls =~ /\A(?:first|last)\z/i
ABCresult
0XX0
10X0
1100
1111
1848 unless defined($nulls) and !ref($nulls) and $nulls =~ /\A(?:first|last)\z/i;
1849 13 my ($by_dir) = keys %by;
1850 13 ▶ $self->puke("-nulls in an order by hash needs exactly one of -asc or -desc")
Branch: 1 branch
BranchTrueFalseTotal
unless keys %by == 1 and $by_dir =~ /\A-(?:asc|desc)\z/ 2 11 13
Condition66%2/3
keys %by == 1 and $by_dir =~ /\A-(?:asc|desc)\z/
!ll&&!rl&&r
2011
MC/DC50%1/2
keys %by == 1 and $by_dir =~ /\A-(?:asc|desc)\z/
keys %by == 1 $by_dir =~ /\A-(?:asc|desc)\z/
Truth table66%2/3
A and B
A= keys %by == 1B= $by_dir =~ /\A-(?:asc|desc)\z/
ABresult
0X0
100
111
1851 unless keys %by == 1 and $by_dir =~ /\A-(?:asc|desc)\z/;
1852 # goes through the -asc / -desc expander installed below
1853 11 ▶ my $sorted = $self->expand_expr({ $by_dir => $by{$by_dir} }) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $sorted = $self->expand_expr({$by_dir, $by{$by_dir}}) or next 11 0 11
1854 11 my (undef, @cols) = @{$sorted->{-op}};
1855 11 push @exp, map +{ -op => [ 'nulls_'.lc($nulls), $_ ] }, @cols;
1856 11 next;
1857 }
1858 431 my $e = $self->expand_expr($arg, -ident);
1859 431 ▶ push @exp, defined($dir) ? { -op => [ $dir =~ /^-?(.*)$/ ,=> $e ] } : $e;
Branch: 1 branch
BranchTrueFalseTotal
defined $dir ? : 161 270 431
1860 }
1861 330 ▶ return undef unless @exp;
Branch: 1 branch
BranchTrueFalseTotal
unless @exp 0 330 330
1862 330 ▶ return undef if @exp == 1 and not defined($exp[0]);
Branch: 1 branch
BranchTrueFalseTotal
if @exp == 1 and not defined $exp[0] 5 325 330
Condition100%3/3
@exp == 1 and not defined $exp[0]
!ll&&!rl&&r
972285
MC/DC100%2/2
@exp == 1 and not defined $exp[0]
@exp == 1 not defined $exp[0]
Truth table100%3/3
A and not(B)
A= @exp == 1B= not defined $exp[0]
ABresult
0X0
100
111
1863 325 return +{ -op => [ ',', @exp ] };
1864 213 };
1865  
1866 213 local @{$self->{expand}}{qw(asc desc)} = (($expander) x 2);
1867  
1868 213 return $self->$expander(undef, $arg);
1869 }
1870  
1871 61 ▶sub _order_by {
Subroutine _order_by: called CC=4 SCAR=14.0
1872 61 my ($self, $arg) = @_;
1873  
1874 61 ▶ return '' unless defined(my $expanded = $self->_expand_order_by($arg));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $expanded = $self->_expand_order_by($arg)) 7 48 55
1875  
1876 48 my ($sql, @bind) = @{ $self->render_aqt($expanded) };
1877  
1878 48 ▶ return '' unless length($sql);
Branch: 1 branch
BranchTrueFalseTotal
unless length $sql 0 48 48
1879  
1880 48 my $final_sql = $self->_sqlcase(' order by ').$sql;
1881  
1882 48 ▶ return $final_sql unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 48 48
1883  
1884 48 return ($final_sql, @bind);
1885 }
1886  
1887 # _order_by no longer needs to call this so doesn't but DBIC uses it.
1888  
1889 141 ▶sub _order_by_chunks {
Subroutine _order_by_chunks: called CC=4 SCAR=13.9
1890 141 my ($self, $arg) = @_;
1891  
1892 141 ▶ return () unless defined(my $expanded = $self->_expand_order_by($arg));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $expanded = $self->_expand_order_by($arg)) 1 140 141
1893  
1894 140 my @res = $self->_chunkify_order_by($expanded);
1895 140 ▶ (ref() ? $_->[0] : $_) .= '' for @res;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 102 96 198
1896 140 return @res;
1897 }
1898  
1899 408 ▶sub _chunkify_order_by {
Subroutine _chunkify_order_by: called CC=8 SCAR=20.8
1900 408 my ($self, $expanded) = @_;
1901  
1902 96 return grep length, @{ $self->render_aqt($expanded) }
1903 408 ▶ if $expanded->{-ident} or @{$expanded->{-literal}||[]} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $expanded->{"-ident"} or @{$expanded->{"-literal"} or [];} == 1 96 312 408
Condition100%5/5
$expanded->{"-ident"} or @{$expanded->{"-literal"} or [];} == 1
l!l&&r!l&&!r
924312
$expanded->{'-literal'} || []
l!l
12304
MC/DC100%2/2
$expanded->{"-ident"} or @{$expanded->{"-literal"} or [];} == 1
$expanded->{"-ident"} @{$expanded->{"-literal"} or [];} == 1
MC/DC100%1/1
$expanded->{'-literal'} || []
$expanded->{'-literal'}
Truth table100%3/3
A or B
A= $expanded->{"-ident"}B= @{$expanded->{"-literal"} or [];} == 1
ABresult
1X1
011
000
Truth table100%2/2
A
A= $expanded->{'-literal'}
Aresult
11
00
1904  
1905 312 for ($expanded) {
1906 312 ▶ if (ref() eq 'HASH' and $_->{-op} and $_->{-op}[0] eq ',') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq "HASH" and $_->{"-op"} and $_->{"-op"}[0] eq ",") 210 102 312
Condition83%5/6
ref $_ eq "HASH" and $_->{"-op"} and $_->{"-op"}[0] eq ","
!ll&&!rl&&r
894210
ref $_ eq "HASH" and $_->{"-op"}
!ll&&!rl&&r
08304
MC/DC66%2/3
ref $_ eq "HASH" and $_->{"-op"} and $_->{"-op"}[0] eq ","
ref $_ eq "HASH" $_->{"-op"} $_->{"-op"}[0] eq ","
Truth table75%3/4
A and B and C
A= ref $_ eq "HASH"B= $_->{"-op"}C= $_->{"-op"}[0] eq ","
ABCresult
0XX0
10X0
1100
1111
1907 210 my ($comma, @list) = @{$_->{-op}};
1908 210 return map $self->_chunkify_order_by($_), @list;
1909 }
1910 102 return $self->render_aqt($_);
1911 }
1912 }
1913  
1914 #======================================================================
1915 # DATASOURCE (FOR NOW, JUST PLAIN TABLE OR LIST OF TABLES)
1916 #======================================================================
1917  
1918 0 ▶sub _table {
Subroutine _table: not called CC=1 SCAR=6.9
1919 0 my $self = shift;
1920 0 my $from = shift;
1921 0 $self->render_aqt(
1922 $self->expand_expr({ -list => $from }, -ident)
1923 )->[0];
1924 }
1925  
1926  
1927 #======================================================================
1928 # UTILITY FUNCTIONS
1929 #======================================================================
1930  
1931 # highly optimized, as it's called way too often
1932 2080 ▶sub _quote {
Subroutine _quote: called CC=15 SCAR=28.7
1933 # my ($self, $label) = @_;
1934  
1935 2080 ▶ return '' unless defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 2080 2080
1936 0 ▶ return ${$_[1]} if ref($_[1]) eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[1] eq "SCALAR" 0 2080 2080
1937 2080 ▶ $_[0]->puke('Identifier cannot be hashref') if ref($_[1]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[1] eq "HASH" 0 2080 2080
1938  
1939 2080 ▶ unless ($_[0]->{quote_char}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[0]{"quote_char"}) 1488 592 2080
1940 1488 ▶ if (ref($_[1]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[1] eq 'ARRAY') { } 1456 32 1488
1941 1456 ▶ return join($_[0]->{name_sep}||'.', @{$_[1]});
Condition50%1/2
$_[0]{'name_sep'} || '.'
l!l
01456
MC/DC0%0/1
$_[0]{'name_sep'} || '.'
$_[0]{'name_sep'}
Truth table50%1/2
A
A= $_[0]{'name_sep'}
Aresult
11
00
1942 } else {
1943 32 $_[0]->_assert_pass_injection_guard($_[1]);
1944 32 return $_[1];
1945 }
1946 }
1947  
1948 592 my $qref = ref $_[0]->{quote_char};
1949 my ($l, $r) =
1950 !$qref ? ($_[0]->{quote_char}, $_[0]->{quote_char})
1951 0 ▶ : ($qref eq 'ARRAY') ? @{$_[0]->{quote_char}}
Branch: 2 branches
BranchTrueFalseTotal
!$qref ? : 592 0 592
$qref eq 'ARRAY' ? : 0 0 0
1952 : $_[0]->puke("Unsupported quote_char format: $_[0]->{quote_char}");
1953  
1954 592 ▶ my $esc = $_[0]->{escape_char} || $r;
Condition66%2/3
$_[0]{'escape_char'} || $r
l!l&&r!l&&!r
25900
MC/DC0%0/2
$_[0]{'escape_char'} || $r
$_[0]{'escape_char'} $r
Truth table66%2/3
A || B
A= $_[0]{'escape_char'}B= $r
ABresult
1X1
011
000
1955  
1956 # an unset name_sep means '.' (as in _expand_ident); an empty one only
1957 # keeps plain names from being split
1958 592 ▶ my $sep = defined $_[0]->{name_sep} ? $_[0]->{name_sep} : '.';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'name_sep'} ? : 463 129 592
1959  
1960 # parts containing * are naturally unquoted
1961 return join(
1962 (length $sep ? $sep : '.'),
1963 map +(
1964 $_ eq '*'
1965 ? $_
1966 612 ▶ : do { (my $n = $_) =~ s/(\Q$esc\E|\Q$r\E)/$esc$1/g; $l . $n . $r }
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] eq 'ARRAY' ? : 576 16 592
1967 ),
1968 (ref($_[1]) eq 'ARRAY'
1969 592 ▶ ? @{$_[1]}
Branch: 3 branches
BranchTrueFalseTotal
length $sep ? : 589 3 592
$_ eq '*' ? : 1 612 613
length $sep ? : 16 0 16
1970 : (
1971 length $sep
1972 ? split (/\Q$sep\E/, $_[1] )
1973 : $_[1]
1974 )
1975 )
1976 );
1977 }
1978  
1979  
1980 # Conversion, if applicable
1981 3 ▶sub _convert {
Subroutine _convert: called CC=2 SCAR=9.2
1982 #my ($self, $arg) = @_;
1983 3 ▶ if (my $conv = $_[0]->{convert_where}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $conv = $_[0]{"convert_where"}) 0 3 3
1984 0 return @{ $_[0]->join_query_parts('',
1985 $_[0]->_sqlcase($conv),
1986 '(' , $_[1] , ')'
1987 ) };
1988 }
1989 3 return $_[1];
1990 }
1991  
1992 # And bindtype
1993 1260 ▶sub _bindtype {
Subroutine _bindtype: called CC=2 SCAR=6.9
1994 #my ($self, $col, @vals) = @_;
1995 # called often - tighten code
1996 return $_[0]->{bindtype} eq 'columns'
1997 1260 ▶ ? map {[$_[1], $_]} @_[2 .. $#_]
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'bindtype'} eq 'columns' ? : 115 1145 1260
1998 : @_[2 .. $#_]
1999 ;
2000 }
2001  
2002 # Dies if any element of @bind is not in [colname => value] format
2003 # if bindtype is 'columns'.
2004 402 ▶sub _assert_bindval_matches_bindtype {
Subroutine _assert_bindval_matches_bindtype: called CC=6 SCAR=18.1
2005 # my ($self, @bind) = @_;
2006 402 my $self = shift;
2007 402 ▶ if ($self->{bindtype} eq 'columns') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bindtype"} eq "columns") 68 334 402
2008 68 for (@_) {
2009 40 ▶ if (!defined $_ || ref($_) ne 'ARRAY' || @$_ != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_ or ref $_ ne "ARRAY" or @$_ != 2) 10 30 40
Condition66%4/6
not defined $_ or ref $_ ne "ARRAY" or @$_ != 2
l!l&&r!l&&!r
10030
not defined $_ or ref $_ ne "ARRAY"
l!l&&r!l&&!r
01030
MC/DC33%1/3
not defined $_ or ref $_ ne "ARRAY" or @$_ != 2
not defined $_ ref $_ ne "ARRAY" @$_ != 2
Truth table50%2/4
not(A) or B or C
A= not defined $_B= ref $_ ne "ARRAY"C= @$_ != 2
ABCresult
1XX1
01X1
0011
0000
2010 10 $self->puke("bindtype 'columns' selected, you need to pass: [column_name => bind_value]")
2011 }
2012 }
2013 }
2014 }
2015  
2016 # Fix SQL case, if so requested
2017 3193 ▶sub _sqlcase {
Subroutine _sqlcase: called CC=2 SCAR=6.9
2018 # LDNOTE: if $self->{case} is true, then it contains 'lower', so we
2019 # don't touch the argument ... crooked logic, but let's not change it!
2020 3193 ▶ return $_[0]->{case} ? $_[1] : uc($_[1]);
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'case'} ? : 42 3151 3193
2021 }
2022  
2023 #======================================================================
2024 # DISPATCHING FROM REFKIND
2025 #======================================================================
2026  
2027 53 ▶sub _refkind {
Subroutine _refkind: called CC=8 SCAR=20.8
2028 53 my ($self, $data) = @_;
2029  
2030 53 ▶ return 'UNDEF' unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 4 49 53
2031  
2032 # blessed objects are treated like scalars
2033 49 ▶ my $ref = (Scalar::Util::blessed $data) ? '' : ref $data;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($data) ? : 1 48 49
2034  
2035 49 ▶ return 'SCALAR' unless $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 33 16 49
2036  
2037 16 my $n_steps = 1;
2038 16 ▶ while ($ref eq 'REF') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref eq "REF") 11 16 27
2039 11 $data = $$data;
2040 11 ▶ $ref = (Scalar::Util::blessed $data) ? '' : ref $data;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($data) ? : 2 9 11
2041 11 ▶ $n_steps++ if $ref;
Branch: 1 branch
BranchTrueFalseTotal
if $ref 9 2 11
2042 }
2043  
2044 16 ▶ return ($ref||'SCALAR') . ('REF' x $n_steps);
Condition100%2/2
$ref || 'SCALAR'
l!l
142
MC/DC100%1/1
$ref || 'SCALAR'
$ref
Truth table100%2/2
A
A= $ref
Aresult
11
00
2045 }
2046  
2047 40 ▶sub _try_refkind {
Subroutine _try_refkind: called CC=3 SCAR=11.0
2048 40 my ($self, $data) = @_;
2049 40 my @try = ($self->_refkind($data));
2050 40 ▶ push @try, 'SCALAR_or_UNDEF' if $try[0] eq 'SCALAR' || $try[0] eq 'UNDEF';
Branch: 1 branch
BranchTrueFalseTotal
if $try[0] eq "SCALAR" or $try[0] eq "UNDEF" 34 6 40
Condition100%3/3
$try[0] eq "SCALAR" or $try[0] eq "UNDEF"
l!l&&r!l&&!r
3136
MC/DC100%2/2
$try[0] eq "SCALAR" or $try[0] eq "UNDEF"
$try[0] eq "SCALAR" $try[0] eq "UNDEF"
Truth table100%3/3
A or B
A= $try[0] eq "SCALAR"B= $try[0] eq "UNDEF"
ABresult
1X1
011
000
2051 40 push @try, 'FALLBACK';
2052 40 return \@try;
2053 }
2054  
2055 0 ▶sub _METHOD_FOR_refkind {
Subroutine _METHOD_FOR_refkind: not called CC=4 SCAR=30.0
2056 0 my ($self, $meth_prefix, $data) = @_;
2057  
2058 0 my $method;
2059 0 for (@{$self->_try_refkind($data)}) {
2060 0 ▶ $method = $self->can($meth_prefix."_".$_)
Branch: 1 branch
BranchTrueFalseTotal
$method = $self->can($meth_prefix . '_' . $_) and last 0 0 0
2061 and last;
2062 }
2063  
2064 0 ▶ return $method || $self->puke("cannot dispatch on '$meth_prefix' for ".$self->_refkind($data));
Condition0%0/3
$method || $self->puke("cannot dispatch on '${meth_prefix}' for " . $self->_refkind($data))
l!l&&r!l&&!r
000
MC/DC0%0/2
$method || $self->puke("cannot dispatch on '${meth_prefix}' for " . $self->_refkind($data))
$method $self->puke("cannot dispatch on '${meth_prefix}' for " . $self->_refkind($data))
Truth table0%0/3
A || B
A= $methodB= $self->puke("cannot dispatch on '${meth_prefix}' for " . $self->_refkind($data))
ABresult
1X1
011
000
2065 }
2066  
2067  
2068 40 ▶sub _SWITCH_refkind {
Subroutine _SWITCH_refkind: called CC=4 SCAR=13.9
2069 40 my ($self, $data, $dispatch_table) = @_;
2070  
2071 40 my $coderef;
2072 40 for (@{$self->_try_refkind($data)}) {
2073 74 ▶ $coderef = $dispatch_table->{$_}
Branch: 1 branch
BranchTrueFalseTotal
$coderef = $dispatch_table->{$_} and last 40 34 74
2074 and last;
2075 }
2076  
2077 40 ▶ $self->puke("no dispatch entry for ".$self->_refkind($data))
Branch: 1 branch
BranchTrueFalseTotal
unless $coderef 0 40 40
2078 unless $coderef;
2079  
2080 40 $coderef->();
2081 }
2082  
2083  
2084  
2085  
2086 #======================================================================
2087 # VALUES, GENERATE, AUTOLOAD
2088 #======================================================================
2089  
2090 # LDNOTE: original code from nwiger, didn't touch code in that section
2091 # I feel the AUTOLOAD stuff should not be the default, it should
2092 # only be activated on explicit demand by user.
2093  
2094 8 ▶sub values {
Subroutine values: called CC=4 SCAR=13.9
Pod documented
2095 8 my $self = shift;
2096 8 ▶ my $data = shift || return;
Condition50%1/2
shift() || (return)
l!l
80
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
2097 8 ▶ $self->puke("Argument to ", __PACKAGE__, "->values must be a \\%hash")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 0 8 8
2098 unless ref $data eq 'HASH';
2099  
2100 8 my @all_bind;
2101 8 foreach my $k (sort keys %$data) {
2102 40 my $v = $data->{$k};
2103 $self->_SWITCH_refkind($v, {
2104 3 ▶ ARRAYREF => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
2105 3 ▶ if ($self->{array_datatypes}) { # array datatype
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'array_datatypes'}) { } 1 2 3
2106 1 push @all_bind, $self->_bindtype($k, $v);
2107 }
2108 else { # literal SQL with bind
2109 2 my ($sql, @bind) = @$v;
2110 2 $self->_assert_bindval_matches_bindtype(@bind);
2111 2 push @all_bind, @bind;
2112 }
2113 },
2114 1 ▶ ARRAYREFREF => sub { # literal SQL with bind
Subroutine __ANON__: called CC=1 SCAR=0.0
2115 1 my ($sql, @bind) = @${$v};
2116 1 $self->_assert_bindval_matches_bindtype(@bind);
2117 1 push @all_bind, @bind;
2118 },
2119 2 ▶ SCALARREF => sub { # literal SQL without bind
Subroutine __ANON__: called CC=1 SCAR=0.0
2120 },
2121 34 ▶ SCALAR_or_UNDEF => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2122 34 push @all_bind, $self->_bindtype($k, $v);
2123 },
2124 40 });
2125 }
2126  
2127 8 return @all_bind;
2128 }
2129  
2130 8 ▶sub generate {
Subroutine generate: called CC=23 SCAR=34.2
Pod documented
2131 8 my $self = shift;
2132  
2133 8 my(@sql, @sqlq, @sqlv);
2134  
2135 8 for (@_) {
2136 16 my $ref = ref $_;
2137 16 ▶ if ($ref eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if ($ref eq 'HASH') { } 5 11 16
elsif ($ref eq 'ARRAY') { } 3 8 11
elsif ($ref eq 'SCALAR') { } 0 8 8
2138 5 for my $k (sort keys %$_) {
2139 5 my $v = $_->{$k};
2140 5 my $r = ref $v;
2141 5 my $label = $self->_quote($k);
2142 5 ▶ if ($r eq 'ARRAY' && $self->{array_datatypes}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($r eq 'ARRAY' and $self->{'array_datatypes'}) { } 3 2 5
elsif ($r eq 'ARRAY' or $r eq 'REF' and ref $$v eq 'ARRAY') { } 2 0 2
elsif ($r eq 'SCALAR') { } 0 0 0
Condition100%3/3
$r eq "ARRAY" and $self->{"array_datatypes"}
!ll&&!rl&&r
113
MC/DC100%2/2
$r eq "ARRAY" and $self->{"array_datatypes"}
$r eq "ARRAY" $self->{"array_datatypes"}
Truth table100%3/3
A and B
A= $r eq "ARRAY"B= $self->{"array_datatypes"}
ABresult
0X0
100
111
2143 # array datatype: one bind value, like insert / update
2144 3 push @sqlq, "$label = ?";
2145 3 push @sqlv, $self->_bindtype($k, $v);
2146 ▶ } elsif ($r eq 'ARRAY' || $r eq 'REF' && ref $$v eq 'ARRAY') {
Condition50%3/6
$r eq "ARRAY" or $r eq "REF" and ref $$v eq "ARRAY"
l!l&&r!l&&!r
110
$r eq "REF" and ref $$v eq "ARRAY"
!ll&&!rl&&r
001
MC/DC0%0/3
$r eq "ARRAY" or $r eq "REF" and ref $$v eq "ARRAY"
$r eq "ARRAY" $r eq "REF" ref $$v eq "ARRAY"
Truth table50%2/4
A or B and C
A= $r eq "ARRAY"B= $r eq "REF"C= ref $$v eq "ARRAY"
ABCresult
1XX1
0111
00X0
0100
2147 # literal SQL with bind
2148 2 ▶ my ($sql, @bind) = $r eq 'REF' ? @$$v : @$v;
Branch: 1 branch
BranchTrueFalseTotal
$r eq 'REF' ? : 1 1 2
2149 2 $self->_assert_bindval_matches_bindtype(@bind);
2150 2 push @sqlq, "$label = $sql";
2151 2 push @sqlv, @bind;
2152 } elsif ($r eq 'SCALAR') {
2153 # literal SQL without bind
2154 0 push @sqlq, "$label = $$v";
2155 } else {
2156 0 push @sqlq, "$label = ?";
2157 0 push @sqlv, $self->_bindtype($k, $v);
2158 }
2159 }
2160 5 push @sql, $self->_sqlcase('set'), join ', ', @sqlq;
2161 } elsif ($ref eq 'ARRAY') {
2162 # unlike insert(), assume these are ONLY the column names, i.e. for SQL
2163 3 for my $v (@$_) {
2164 4 my $r = ref $v;
2165 4 ▶ if ($r eq 'ARRAY' && $self->{array_datatypes}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($r eq 'ARRAY' and $self->{'array_datatypes'}) { } 1 3 4
elsif ($r eq 'ARRAY' or $r eq 'REF' and ref $$v eq 'ARRAY') { } 2 1 3
elsif ($r eq 'SCALAR') { } 0 1 1
Condition100%3/3
$r eq "ARRAY" and $self->{"array_datatypes"}
!ll&&!rl&&r
211
MC/DC100%2/2
$r eq "ARRAY" and $self->{"array_datatypes"}
$r eq "ARRAY" $self->{"array_datatypes"}
Truth table100%3/3
A and B
A= $r eq "ARRAY"B= $self->{"array_datatypes"}
ABresult
0X0
100
111
2166 # array datatype: one bind value, like insert
2167 1 push @sqlq, '?';
2168 1 push @sqlv, $v;
2169 ▶ } elsif ($r eq 'ARRAY' || $r eq 'REF' && ref $$v eq 'ARRAY') {
Condition83%5/6
$r eq "ARRAY" or $r eq "REF" and ref $$v eq "ARRAY"
l!l&&r!l&&!r
111
$r eq "REF" and ref $$v eq "ARRAY"
!ll&&!rl&&r
101
MC/DC66%2/3
$r eq "ARRAY" or $r eq "REF" and ref $$v eq "ARRAY"
$r eq "ARRAY" $r eq "REF" ref $$v eq "ARRAY"
Truth table75%3/4
A or B and C
A= $r eq "ARRAY"B= $r eq "REF"C= ref $$v eq "ARRAY"
ABCresult
1XX1
0111
00X0
0100
2170 # literal SQL with bind
2171 2 ▶ my ($sql, @bind) = $r eq 'REF' ? @$$v : @$v;
Branch: 1 branch
BranchTrueFalseTotal
$r eq 'REF' ? : 1 1 2
2172 2 $self->_assert_bindval_matches_bindtype(@bind);
2173 2 push @sqlq, $sql;
2174 2 push @sqlv, @bind;
2175 } elsif ($r eq 'SCALAR') { # literal SQL without bind
2176 # embedded literal SQL
2177 0 push @sqlq, $$v;
2178 } else {
2179 1 push @sqlq, '?';
2180 1 push @sqlv, $v;
2181 }
2182 }
2183 3 push @sql, '(' . join(', ', @sqlq) . ')';
2184 } elsif ($ref eq 'SCALAR') {
2185 # literal SQL
2186 0 push @sql, $$_;
2187 } else {
2188 # strings get case twiddled
2189 8 push @sql, $self->_sqlcase($_);
2190 }
2191 }
2192  
2193 8 my $sql = join ' ', @sql;
2194  
2195 # this is pretty tricky
2196 # if ask for an array, return ($stmt, @bind)
2197 # otherwise, s/?/shift @sqlv/ to put it inline
2198 8 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 8 0 8
2199 8 return ($sql, @sqlv);
2200 } else {
2201 # single global pass: replace each original placeholder once, so a
2202 # bind value that itself contains a '?' does not swallow later binds
2203 0 $sql =~ s/\?/my $d = shift(@sqlv);
2204 0 ▶ ref $d ? $d->[1] : $d/ge;
Branch: 1 branch
BranchTrueFalseTotal
ref $d ? : 0 0 0
2205 0 return $sql;
2206 }
2207 }
2208  
2209  
2210 828 ▶sub DESTROY { 1 }
Subroutine DESTROY: called CC=1 SCAR=0.0
2211  
2212 1 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=2 SCAR=7.0
2213 # This allows us to check for a local, then _form, attr
2214 1 my $self = shift;
2215 1 my($name) = $AUTOLOAD =~ /.*::(.+)/;
2216 1 ▶ $self->puke("AUTOLOAD invoked for method name ${name} and allow_autoload option not set") unless $self->{allow_autoload};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"allow_autoload"} 0 1 1
2217 1 return $self->generate($name, @_);
2218 }
2219  
2220 20 1;
2221  
2222  
2223  
2224 __END__
« SQL/Abstract/Plugin/BangOverrides.pm ↑ Summary DBIx/Class/Storage/Debug/PrettyPrint.pm »