lib/DBIx/Struct.pm

filter: Statementstmt 43.9% 1071 / 2437 Branchbran 26.9% 316 / 1172 Conditioncond 36.3% 127 / 349 MC/DCmcdc 14.6% 31 / 212 Subroutinesub 53.3% 161 / 302 Podpod 20.6% 6 / 29 totaltotal 38.0% 1712 / 4501 SCAR 119.7
CC
817
Cov
38%
setup_row
569.9
_build_complex_query
460.1
update
378.5
CRAP 157969.2
↑ Summary blib/lib/DBIx/Struct.pm »
1 package DBIx::Struct::JSON::Array;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 sub TIEARRAY {
6 0 ▶ bless [$_[1], $_[2], $_[3]], $_[0];
Subroutine TIEARRAY: not called CC=1 SCAR=6.9
7 }
8  
9 sub FETCHSIZE {
10 0 ▶ scalar @{$_[0][0]};
Subroutine FETCHSIZE: not called CC=1 SCAR=6.9
11 }
12  
13 sub STORESIZE {
14 0 ▶ $_[0][1]{$_[0][2]} = undef;
Subroutine STORESIZE: not called CC=1 SCAR=6.9
15 0 $#{$_[0][0]} = $_[1] - 1;
16 }
17  
18 sub STORE {
19 0 ▶ $_[0][1]{$_[0][2]} = undef;
Subroutine STORE: not called CC=1 SCAR=6.9
20 0 $_[0][0][$_[1]] = $_[2];
21 }
22 0 ▶sub FETCH {$_[0][0][$_[1]]}
Subroutine FETCH: not called CC=1 SCAR=6.9
23  
24 sub CLEAR {
25 0 ▶ $_[0][1]{$_[0][2]} = undef;
Subroutine CLEAR: not called CC=1 SCAR=6.9
26 0 @{$_[0][0]} = ();
27 }
28  
29 sub POP {
30 0 ▶ $_[0][1]{$_[0][2]} = undef;
Subroutine POP: not called CC=1 SCAR=6.9
31 0 pop(@{$_[0][0]});
32 }
33  
34 sub PUSH {
35 0 ▶ my $o = shift;
Subroutine PUSH: not called CC=1 SCAR=6.9
36 0 $o->[1]{$o->[2]} = undef;
37 0 push(@{$o->[0]}, @_);
38 }
39  
40 sub SHIFT {
41 0 ▶ $_[0][1]{$_[0][2]} = undef;
Subroutine SHIFT: not called CC=1 SCAR=6.9
42 0 shift(@{$_[0][0]});
43 }
44  
45 sub UNSHIFT {
46 0 ▶ my $o = shift;
Subroutine UNSHIFT: not called CC=1 SCAR=6.9
47 0 $o->[1]{$o->[2]} = undef;
48 0 unshift(@$o, @_);
49 }
50 0 ▶sub EXISTS {exists $_[0][0]->[$_[1]]}
Subroutine EXISTS: not called CC=1 SCAR=6.9
51 0 ▶sub DELETE {delete $_[0][0]->[$_[1]]}
Subroutine DELETE: not called CC=1 SCAR=6.9
52  
53 sub SPLICE {
54 0 ▶ my $ob = shift;
Subroutine SPLICE: not called CC=4 SCAR=30.0
55 0 my $sz = $ob->FETCHSIZE;
56 0 ▶ my $off = @_ ? shift : 0;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
57 0 ▶ $off += $sz if $off < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $off < 0 0 0 0
58 0 ▶ my $len = @_ ? shift : $sz - $off;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
59 0 $ob->[1]{$ob->[2]} = undef;
60 0 return splice(@{$ob->[0]}, $off, $len, @_);
61 }
62  
63 package DBIx::Struct::JSON::Hash;
64 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 sub TIEHASH {
68 0 ▶ bless [$_[1], $_[2], $_[3]], $_[0];
Subroutine TIEHASH: not called CC=1 SCAR=6.9
69 }
70  
71 sub STORE {
72 0 ▶ $_[0][1]{$_[0][2]} = undef;
Subroutine STORE: not called CC=1 SCAR=6.9
73 0 $_[0][0]->{$_[1]} = $_[2];
74 }
75  
76 sub FETCH {
77 0 ▶ $_[0][0]->{$_[1]};
Subroutine FETCH: not called CC=1 SCAR=6.9
78 }
79  
80 sub FIRSTKEY {
81 0 ▶ my $a = scalar keys %{$_[0][0]};
Subroutine FIRSTKEY: not called CC=1 SCAR=6.9
82 0 each %{$_[0][0]};
83 }
84  
85 sub NEXTKEY {
86 0 ▶ each %{$_[0][0]};
Subroutine NEXTKEY: not called CC=1 SCAR=6.9
87 }
88  
89 sub EXISTS {
90 0 ▶ exists $_[0][0]->{$_[1]};
Subroutine EXISTS: not called CC=1 SCAR=6.9
91 }
92  
93 sub DELETE {
94 0 ▶ $_[0][1]{$_[0][2]} = undef;
Subroutine DELETE: not called CC=1 SCAR=6.9
95 0 delete $_[0][0]->{$_[1]};
96 }
97  
98 sub CLEAR {
99 0 ▶ $_[0][1]{$_[0][2]} = undef;
Subroutine CLEAR: not called CC=1 SCAR=6.9
100 0 %{$_[0][0]} = ();
101 }
102  
103 sub SCALAR {
104 0 ▶ scalar %{$_[0][0]};
Subroutine SCALAR: not called CC=1 SCAR=6.9
105 }
106  
107 package DBIx::Struct::JSON;
108  
109 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
110 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
111 3 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
112  
113 sub factory {
114 0 ▶ my ($class, $value_ref, $update_hash, $hash_key) = @_;
Subroutine factory: not called CC=7 SCAR=40.3
115 0 my $self;
116 0 ▶ if (not ref $$value_ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $$value_ref) 0 0 0
117 0 ▶ my $jv = from_json($$value_ref) if $$value_ref;
Branch: 1 branch
BranchTrueFalseTotal
if $$value_ref 0 0 0
118 0 ▶ $$value_ref = $jv if $jv;
Branch: 1 branch
BranchTrueFalseTotal
if $jv 0 0 0
119 }
120 0 ▶ if (not defined $$value_ref) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $$value_ref) { } 0 0 0
elsif ('HASH' eq ref $$value_ref) { } 0 0 0
elsif ('ARRAY' eq ref $$value_ref) { } 0 0 0
121 0 $self = [undef, undef];
122 } elsif ('HASH' eq ref $$value_ref) {
123 0 my %h;
124 0 tie %h, 'DBIx::Struct::JSON::Hash', $$value_ref, $update_hash, $hash_key;
125 0 $self = [\%h, $$value_ref];
126 } elsif ('ARRAY' eq ref $$value_ref) {
127 0 my @a;
128 0 tie @a, 'DBIx::Struct::JSON::Array', $$value_ref, $update_hash, $hash_key;
129 0 $self = [\@a, $$value_ref];
130 }
131 0 $$value_ref = bless $self, $class;
132 }
133  
134 sub revert {
135 0 ▶ $_[0] = defined($_[0][1]) ? to_json $_[0][1] : undef;
Subroutine revert: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0][1] ? : 0 0 0
136 }
137  
138 sub data {
139 0 ▶ $_[0][1];
Subroutine data: not called CC=1 SCAR=6.9
140 }
141  
142 sub accessor {
143 0 ▶ $_[0][0];
Subroutine accessor: not called CC=1 SCAR=6.9
144 }
145  
146 package DBIx::Struct::Connector;
147 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
148 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
149 3 ▶use base 'DBIx::Connector';
Subroutine BEGIN: called CC=1 SCAR=0.0
150  
151 3 our $db_reconnect_timeout = 30;
152  
153 sub _connect {
154 0 ▶ my ($self, @args) = @_;
Subroutine _connect: not called CC=5 SCAR=34.0
155 0 for my $try (1 .. $db_reconnect_timeout) {
156 0 my $dbh = eval {$self->SUPER::_connect(@args)};
157 0 ▶ return $dbh if $dbh;
Branch: 1 branch
BranchTrueFalseTotal
if $dbh 0 0 0
158 0 ▶ sleep 1 if $try != $db_reconnect_timeout;
Branch: 1 branch
BranchTrueFalseTotal
if $try != $DBIx::Struct::Connector::db_reconnect_timeout 0 0 0
159 }
160 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
161 0 die "DB connect error";
162 }
163  
164 package DBIx::Struct::Error::String;
165 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
166 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
167 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
168  
169 sub error_message (+%) {
170 0 ▶ my $msg = $_[0];
Subroutine error_message: not called CC=1 SCAR=6.9
171 0 delete $msg->{result};
172 0 my $message = delete $msg->{message};
173 0 croak join "; ", $message, map {"$_: $msg->{$_}"} keys %$msg;
174 }
175  
176 package DBIx::Struct::Error::Hash;
177 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
178 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
179  
180 sub error_message (+%) {
181 0 ▶ die $_[0];
Subroutine error_message: not called CC=1 SCAR=6.9
182 }
183  
184 package DBIx::Struct;
185 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
186 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
187 3 ▶use SQL::Abstract;
Subroutine BEGIN: called CC=1 SCAR=0.0
188 3 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
189 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
190 3 ▶use Scalar::Util 'refaddr';
Subroutine BEGIN: called CC=1 SCAR=0.0
191 3 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
192 3 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
193  
194 3 our $VERSION = '0.48';
195  
196 3 our @EXPORT = qw{
197 one_row
198 all_rows
199 for_rows
200 new_row
201 };
202  
203 3 our @EXPORT_OK = qw{
204 connector
205 hash_ref_slice
206 };
207  
208 sub ccmap ($) {
209 51 ▶ my $name = $_[0];
Subroutine ccmap: called CC=1 SCAR=0.0
Pod undocumented
210 51 $name =~ s/([[:upper:]])/_\l$1/g;
211 51 $name =~ s/^_//;
212 51 return $name;
213 }
214  
215 3 our $camel_case_map = \&ccmap;
216 3 our $conn;
217 3 our $update_on_destroy = 1;
218 3 our $connector_module = 'DBIx::Struct::Connector';
219 3 our $connector_constructor = 'new';
220 3 our $connector_pool;
221 3 our $connector_pool_method = 'get_connector';
222 3 our $connector_args = [];
223 3 our $connector_driver;
224 3 our $user_schema_namespace;
225 3 our $table_classes_namespace = 'DBC';
226 3 our $query_classes_namespace = 'DBQ';
227 3 our $error_message_class = 'DBIx::Struct::Error::String';
228 3 our %driver_pk_insert;
229  
230 sub error_message (+%) {
231 0 ▶ goto &DBIx::Struct::Error::String::error_message;
Subroutine error_message: not called CC=1 SCAR=6.9
Pod undocumented
232 }
233  
234 %driver_pk_insert = (
235 _returning => sub {
236 6 ▶ my ($table, $pk_row_data, $pk_returninig) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
237 6 my $ret;
238 6 ▶ if ($pk_row_data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pk_row_data) { } 4 2 6
239 4 $ret = <<INS;
240 ($pk_row_data) =
241 \$_->selectrow_array(\$insert . " $pk_returninig", undef, \@bind)
242 INS
243 } else {
244 2 $ret = <<INS;
245 \$_->do(\$insert, undef, \@bind)
246 INS
247 }
248 6 $ret .= <<INS
249 or DBIx::Struct::error_message {
250 result => 'SQLERR',
251 message => 'error '.\$_->errstr.' inserting into table $table'
252 };
253 INS
254 },
255 _last_id_undef => sub {
256 0 ▶ my ($table, $pk_row_data) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
257 0 my $ret;
258 0 $ret = <<INS;
259 \$_->do(\$insert, undef, \@bind)
260 or DBIx::Struct::error_message {
261 result => 'SQLERR',
262 message => 'error '.\$_->errstr.' inserting into table $table'
263 };
264 INS
265 0 ▶ if ($pk_row_data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pk_row_data) 0 0 0
266 0 $ret .= <<INS;
267 $pk_row_data = \$_->last_insert_id(undef, undef, undef, undef);
268 INS
269 }
270 },
271 _last_id_empty => sub {
272 0 ▶ my ($table, $pk_row_data) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
273 0 my $ret;
274 0 $ret = <<INS;
275 \$_->do(\$insert, undef, \@bind)
276 or DBIx::Struct::error_message {
277 result => 'SQLERR',
278 message => 'error '.\$_->errstr.' inserting into table $table'
279 };
280 INS
281 0 ▶ if ($pk_row_data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pk_row_data) 0 0 0
282 0 $ret .= <<INS;
283 $pk_row_data = \$_->last_insert_id("", "", "", "");
284 INS
285 }
286 }
287 3 );
288  
289 3 $driver_pk_insert{Pg} = $driver_pk_insert{_returning};
290 3 $driver_pk_insert{mysql} = $driver_pk_insert{_last_id_undef};
291 3 $driver_pk_insert{SQLite} = $driver_pk_insert{_last_id_empty};
292  
293 sub hash_ref_slice($@) {
294 0 ▶ my ($hashref, @slice) = @_;
Subroutine hash_ref_slice: not called CC=2 SCAR=17.9
Pod documented
295 0 ▶ error_message {
Branch: 1 branch
BranchTrueFalseTotal
if "HASH" ne ref $hashref 0 0 0
296 message => "first parameter is not hash reference",
297 result => 'INTERR',
298 }
299 if 'HASH' ne ref $hashref;
300 0 map {$_ => $hashref->{$_}} @slice;
301 }
302  
303 3 my @already_exported_to;
304  
305 sub connector {
306 51 ▶ $conn;
Subroutine connector: called CC=1 SCAR=0.0
Pod undocumented
307 }
308  
309 sub connector_from_pool {
310 0 ▶ $connector_pool->$connector_pool_method();
Subroutine connector_from_pool: not called CC=1 SCAR=6.9
Pod undocumented
311 }
312  
313 sub set_connector_pool {
314 0 ▶ $connector_pool = $_[0];
Subroutine set_connector_pool: not called CC=3 SCAR=15.4
Pod undocumented
315 0 ▶ if (\&connector != \&connector_from_pool) {
Branch: 1 branch
BranchTrueFalseTotal
if (\&DBIx::Struct::connector != \&DBIx::Struct::connector_from_pool) 0 0 0
316 3 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
317 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
318 0 *connector = \&connector_from_pool;
319 0 for my $aep (@already_exported_to) {
320 0 *{"$aep\::connector"} = \&connector;
321 }
322 }
323 }
324  
325 sub set_user_schema_namespace {
326 0 ▶ $user_schema_namespace = $_[0];
Subroutine set_user_schema_namespace: not called CC=1 SCAR=6.9
Pod undocumented
327 }
328  
329 sub set_connector_pool_method {
330 0 ▶ $connector_pool_method = $_[0];
Subroutine set_connector_pool_method: not called CC=1 SCAR=6.9
Pod undocumented
331 }
332  
333 sub set_connector_object {
334 0 ▶ *conn = \$_[0];
Subroutine set_connector_object: not called CC=1 SCAR=6.9
Pod undocumented
335 }
336  
337 sub set_camel_case_map {
338 0 ▶ error_message {
Subroutine set_camel_case_map: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if "CODE" ne ref $_[0] 0 0 0
339 message => "CamelCaseMap must be code reference",
340 result => 'SQLERR',
341 } if 'CODE' ne ref $_[0];
342 0 $camel_case_map = $_[0];
343 }
344  
345 sub check_package_scalar {
346 3 ▶ my ($package, $scalar) = @_;
Subroutine check_package_scalar: called CC=2 SCAR=7.2
Pod undocumented
347 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
348 3 my $pr = \%{$package . '::'};
349 3 my $er = $$pr{$scalar};
350 3 ▶ return unless $er;
Branch: 1 branch
BranchTrueFalseTotal
unless $er 3 0 3
351 0 defined *{$er}{'SCALAR'};
352 }
353  
354 sub import {
355 3 ▶ my ($class, @args) = @_;
Subroutine import: called CC=22 SCAR=47.3
356 3 my $defconn = 0;
357 3 my $_emc = 0;
358 3 my $_cp = 0;
359 3 my $_c = 0;
360 3 ▶ for (my $i = 0; $i < @args; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @args) 4 3 7
361 4 ▶ if ($args[$i] eq 'connector_module') {
Branch: 13 branches
BranchTrueFalseTotal
if ($args[$i] eq 'connector_module') { } 3 1 4
elsif ($args[$i] eq 'connector_constructor') { } 0 1 1
elsif ($args[$i] eq 'camel_case_map' and 'CODE' eq ref $args[$i]) { } 0 1 1
elsif ($args[$i] eq 'user_schema_namespace') { } 1 0 1
elsif ($args[$i] eq 'table_classes_namespace') { } 0 0 0
elsif ($args[$i] eq 'query_classes_namespace') { } 0 0 0
elsif ($args[$i] eq 'connect_timeout') { } 0 0 0
elsif ($args[$i] eq 'error_class') { } 0 0 0
elsif ($args[$i] eq 'connector_pool') { } 0 0 0
elsif ($args[$i] eq 'connector_pool_method') { } 0 0 0
elsif ($args[$i] eq 'connector_args') { } 0 0 0
elsif ($args[$i] eq 'connector') { } 0 0 0
elsif ($args[$i] eq 'connector_object') { } 0 0 0
362 3 (undef, $connector_module) = splice @args, $i, 2;
363 3 --$i;
364 3 ▶ if (not $defconn and check_package_scalar($connector_module, 'conn')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $defconn and check_package_scalar($DBIx::Struct::connector_module, "conn")) 0 3 3
Condition33%1/3
not $defconn and check_package_scalar($DBIx::Struct::connector_module, "conn")
!ll&&!rl&&r
030
MC/DC0%0/2
not $defconn and check_package_scalar($DBIx::Struct::connector_module, "conn")
not $defconn check_package_scalar($DBIx::Struct::connector_module, "conn")
Truth table33%1/3
not(A) and B
A= not $defconnB= check_package_scalar($DBIx::Struct::connector_module, "conn")
ABresult
0X0
100
111
365 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
366 0 set_connector_object(${$connector_module . '::conn'});
367 }
368 } elsif ($args[$i] eq 'connector_constructor') {
369 0 (undef, $connector_constructor) = splice @args, $i, 2;
370 0 --$i;
371 ▶ } elsif ($args[$i] eq 'camel_case_map' && 'CODE' eq ref $args[$i]) {
Condition33%1/3
$args[$i] eq "camel_case_map" and "CODE" eq ref $args[$i]
!ll&&!rl&&r
100
MC/DC0%0/2
$args[$i] eq "camel_case_map" and "CODE" eq ref $args[$i]
$args[$i] eq "camel_case_map" "CODE" eq ref $args[$i]
Truth table33%1/3
A and B
A= $args[$i] eq "camel_case_map"B= "CODE" eq ref $args[$i]
ABresult
0X0
100
111
372 0 (undef, $camel_case_map) = splice @args, $i, 2;
373 0 --$i;
374 } elsif ($args[$i] eq 'user_schema_namespace') {
375 1 (undef, $user_schema_namespace) = splice @args, $i, 2;
376 1 --$i;
377 } elsif ($args[$i] eq 'table_classes_namespace') {
378 0 (undef, $table_classes_namespace) = splice @args, $i, 2;
379 0 --$i;
380 } elsif ($args[$i] eq 'query_classes_namespace') {
381 0 (undef, $query_classes_namespace) = splice @args, $i, 2;
382 0 --$i;
383 } elsif ($args[$i] eq 'connect_timeout') {
384 0 (undef, $db_reconnect_timeout) = splice @args, $i, 2;
385 0 --$i;
386 } elsif ($args[$i] eq 'error_class') {
387 0 my (undef, $emc) = splice @args, $i, 2;
388 0 $error_message_class = $emc;
389 0 $_emc = 1;
390 0 --$i;
391 } elsif ($args[$i] eq 'connector_pool') {
392 0 (undef, $connector_pool) = splice @args, $i, 2;
393 0 $_cp = 1;
394 0 --$i;
395 } elsif ($args[$i] eq 'connector_pool_method') {
396 0 (undef, $connector_pool_method) = splice @args, $i, 2;
397 0 --$i;
398 } elsif ($args[$i] eq 'connector_args') {
399 0 (undef, $connector_args) = splice @args, $i, 2;
400 0 --$i;
401 } elsif ($args[$i] eq 'connector') {
402 0 $_c = 1;
403 } elsif ($args[$i] eq 'connector_object') {
404 0 $defconn = 1;
405 0 set_connector_object($args[$i + 1]);
406 0 splice @args, $i, 2;
407 0 --$i;
408 }
409 }
410 3 ▶ if ($_emc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_emc) 0 3 3
411 3 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
412 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
413 0 *error_message = \&{$error_message_class . "::error_message"};
414 }
415 3 ▶ if ($_cp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_cp) 0 3 3
416 3 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
417 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
418 0 *connector = \&connector_from_pool;
419 0 for my $aep (@already_exported_to) {
420 0 *{"$aep\::connector"} = \&connector;
421 }
422 }
423 3 my $callpkg = caller;
424 3 ▶ push @already_exported_to, $callpkg if $_c;
Branch: 1 branch
BranchTrueFalseTotal
if $_c 0 3 3
425 3 my %imps = map {$_ => undef} @args, @EXPORT;
426 3 $class->export_to_level(1, $class, keys %imps);
427 }
428  
429 sub _not_yet_connected {
430 2 ▶ if (!$connector_pool && !$conn) {
Subroutine _not_yet_connected: called CC=12 SCAR=34.0
Branch: 1 branch
BranchTrueFalseTotal
unless ($DBIx::Struct::connector_pool or $DBIx::Struct::conn) 2 0 2
Condition33%1/3
$DBIx::Struct::connector_pool or $DBIx::Struct::conn
l!l&&r!l&&!r
002
MC/DC0%0/2
$DBIx::Struct::connector_pool or $DBIx::Struct::conn
$DBIx::Struct::connector_pool $DBIx::Struct::conn
Truth table33%1/3
A or B
A= $DBIx::Struct::connector_poolB= $DBIx::Struct::conn
ABresult
1X1
011
000
431 2 my ($dsn, $user, $password) = @_;
432 2 ▶ if ($dsn && $dsn !~ /^dbi:/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dsn and not $dsn =~ /^dbi:/iu) 0 2 2
Condition33%1/3
$dsn and not $dsn =~ /^dbi:/iu
!ll&&!rl&&r
200
MC/DC0%0/2
$dsn and not $dsn =~ /^dbi:/iu
$dsn not $dsn =~ /^dbi:/iu
Truth table33%1/3
A and not(B)
A= $dsnB= not $dsn =~ /^dbi:/iu
ABresult
0X0
100
111
433 0 $dsn = "dbi:Pg:dbname=$dsn";
434 }
435 2 my $connect_attrs = {
436 AutoCommit => 1,
437 PrintError => 0,
438 AutoInactiveDestroy => 1,
439 RaiseError => 0,
440 };
441 2 ▶ if ($dsn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dsn) 0 2 2
442 0 my ($driver) = $dsn =~ /^dbi:(\w*?)(?:\((.*?)\))?:/i;
443 0 ▶ if ($driver) {
Branch: 1 branch
BranchTrueFalseTotal
if ($driver) 0 0 0
444 0 ▶ if ($driver eq 'Pg') {
Branch: 3 branches
BranchTrueFalseTotal
if ($driver eq 'Pg') { } 0 0 0
elsif ($driver eq 'mysql') { } 0 0 0
elsif ($driver eq 'SQLite') { } 0 0 0
445 0 $connect_attrs->{pg_enable_utf8} = 1;
446 } elsif ($driver eq 'mysql') {
447 0 $connect_attrs->{mysql_enable_utf8} = 1;
448 } elsif ($driver eq 'SQLite') {
449 0 $connect_attrs->{sqlite_unicode} = 1;
450 }
451 }
452 }
453 2 ▶ if (!@$connector_args) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$DBIx::Struct::connector_args) 2 0 2
454 2 @$connector_args = ($dsn, $user, $password, $connect_attrs);
455 }
456 2 ▶ $conn = $connector_module->$connector_constructor(@$connector_args)
Branch: 1 branch
BranchTrueFalseTotal
$DBIx::Struct::conn = $DBIx::Struct::connector_module->$DBIx::Struct::connector_constructor(@$DBIx::Struct::connector_args) or &error_message({"message", "DB connect error", "result", "SQLERR"}) 0 2 2
457 or error_message {
458 message => "DB connect error",
459 result => 'SQLERR',
460 };
461 2 $conn->mode('fixup');
462 }
463 2 '' =~ /()/;
464 2 $connector_driver = connector->driver->{driver};
465 3 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
466 2 *connect = \&connector;
467 2 populate();
468 2 connector;
469 }
470  
471 sub connect {
472 2 ▶ goto &_not_yet_connected;
Subroutine connect: called CC=1 SCAR=0.0
Pod documented
473 }
474  
475 {
476 3 my $md5 = Digest::MD5->new;
477  
478 sub make_name {
479 35 ▶ my ($table) = @_;
Subroutine make_name: called CC=2 SCAR=6.9
Pod undocumented
480 35 my $simple_table = (index($table, " ") == -1);
481 35 my $ncn;
482 35 ▶ if ($simple_table) {
Branch: 1 branch
BranchTrueFalseTotal
if ($simple_table) { } 30 5 35
483 30 $ncn = $table_classes_namespace . "::" . join('', map {ucfirst($_)} split(/[^a-zA-Z0-9]/, $table));
484 } else {
485 5 $md5->add($table);
486 5 $ncn = $query_classes_namespace . "::" . "G" . $md5->hexdigest;
487 5 $md5->reset;
488 }
489 35 $ncn;
490 }
491 }
492  
493 3 sub populate {
494 2 ▶ my @tables;
Subroutine populate: called CC=6 SCAR=18.8
Pod undocumented
495 DBIx::Struct::connect->run(
496 sub {
497 2 ▶ my $sth = $_->table_info('', '%', '%', "TABLE");
Subroutine __ANON__: called CC=3 SCAR=11.2
498 2 ▶ return if not $sth;
Branch: 1 branch
BranchTrueFalseTotal
unless $sth 0 2 2
499 2 my $tables = $sth->fetchall_arrayref;
500 @tables = map {
501 6 (my $t = $_->[2]) =~ s/"//g;
502 6 $t;
503 } grep {
504 2 ▶ $_->[3] eq 'TABLE' and $_->[2] !~ /^sql_/
Branch: 1 branch
BranchTrueFalseTotal
$_->[3] eq "TABLE" and not $_->[2] =~ /^sql_/u 6 0 6
505 } @$tables;
506 }
507 2 );
508 2 for (@tables) {
509 6 my $ncn = setup_row($_);
510 6 ▶ if ($user_schema_namespace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DBIx::Struct::user_schema_namespace) 3 3 6
511 3 (my $uncn = $ncn) =~ s/^.*:://;
512 3 ▶ eval "use ${user_schema_namespace}::${uncn}";
Subroutine BEGIN: called CC=1 SCAR=1.2
513 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
514 3 eval {
515 3 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{"$DBIx::Struct::user_schema_namespace::${uncn}::";} and not do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{"ISA"} && ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)) 0 3 3
Condition66%2/3
keys %{"$DBIx::Struct::user_schema_namespace::${uncn}::";} and not do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{"ISA"} && ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)
!ll&&!rl&&r
210
MC/DC50%1/2
keys %{"$DBIx::Struct::user_schema_namespace::${uncn}::";} and not do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{"ISA"} && ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)
keys %{"$DBIx::Struct::user_schema_namespace::${uncn}::";} not do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{"ISA"} && ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)
Truth table66%2/3
A and not(B)
A= keys %{"$DBIx::Struct::user_schema_namespace::${uncn}::";}B= not do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{"ISA"} && ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)
ABresult
0X0
100
111
516 3 ▶ keys %{"${user_schema_namespace}::${uncn}::"}
Condition33%1/3
do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{'ISA'} && ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)
!ll&&!rl&&r
001
MC/DC0%0/2
do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{'ISA'} && ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)
do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{'ISA'} ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)
Truth table33%1/3
A && B
A= do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{'ISA'}B= ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)
ABresult
0X0
100
111
517 1 and ( not ${"${user_schema_namespace}::${uncn}::"}{ISA}
518 or not "${user_schema_namespace}::${uncn}"->isa($ncn))
519 )
520 {
521 0 unshift @{"${user_schema_namespace}::${uncn}::ISA"}, $ncn;
522 }
523 };
524 }
525 }
526 }
527  
528 #<<<
529 my @uneq = (
530 qr/LessThanEqual$/, '<=',
531 qr/LessThan$/, '<',
532 qr/GreaterThanEqual$/, '>=',
533 qr/GreaterThan$/, '>',
534 1 ▶ qr/IsNull$/, sub {"'$_[0]' => {'=', undef}"},
Subroutine __ANON__: called CC=1 SCAR=0.0
535 0 ▶ qr/IsNotNull$/, sub {"'$_[0]' => {'!=', undef}"},
Subroutine __ANON__: not called CC=1 SCAR=6.9
536 qr/IsNot$/, '!=',
537 0 ▶ qr/NotNull$/, sub {"'$_[0]' => {'!=', undef}"},
Subroutine __ANON__: not called CC=1 SCAR=6.9
538 qr/NotEquals$/, '!=',
539 qr/NotIn$/, '-not_in',
540 qr/NotLike$/, '-not_like',
541 qr/IsEqualTo$/, '=',
542 0 ▶ qr/IsTrue$/, sub {"-bool => '$_[0]'"},
Subroutine __ANON__: not called CC=1 SCAR=6.9
543 0 ▶ qr/IsFalse$/, sub {"-not_bool => '$_[0]'"},
Subroutine __ANON__: not called CC=1 SCAR=6.9
544 qr/Equals$/, '=',
545 0 ▶ qr/True$/, sub {"-bool => '$_[0]'"},
Subroutine __ANON__: not called CC=1 SCAR=6.9
546 0 ▶ qr/False$/, sub {"-not_bool => '$_[0]'"},
Subroutine __ANON__: not called CC=1 SCAR=6.9
547 3 qr/Like$/, '-like',
548 qr/Is$/, '=',
549 qr/Not$/, '!=',
550 qr/In$/, '-in',
551 );
552 #>>>
553  
554 sub _parse_find_by {
555 20 ▶ my ($table, $find) = @_;
Subroutine _parse_find_by: called CC=25 SCAR=32.2
556 20 ▶ $find =~ s/^find(?<what>.*?)By(?![[:lower:]])// || $find =~ s/^find(?<what>.*)// or die "bad pattern: $find";
Branch: 1 branch
BranchTrueFalseTotal
$find =~ s/^find(?<what>.*?)By(?![[:lower:]])//u or $find =~ s/^find(?<what>.*)//u or die "bad pattern: $find" 0 20 20
Condition66%2/3
$find =~ s/^find(?<what>.*?)By(?![[:lower:]])//u or $find =~ s/^find(?<what>.*)//u
l!l&&r!l&&!r
1820
MC/DC0%0/2
$find =~ s/^find(?<what>.*?)By(?![[:lower:]])//u or $find =~ s/^find(?<what>.*)//u
$find =~ s/^find(?<what>.*?)By(?![[:lower:]])//u $find =~ s/^find(?<what>.*)//u
Truth table66%2/3
A or B
A= $find =~ s/^find(?<what>.*?)By(?![[:lower:]])//uB= $find =~ s/^find(?<what>.*)//u
ABresult
1X1
011
000
557 20 ▶ my $what = $+{what} || 'All';
Condition100%2/2
$+{'what'} || 'All'
l!l
173
MC/DC100%1/1
$+{'what'} || 'All'
$+{'what'}
Truth table100%2/2
A
A= $+{'what'}
Aresult
11
00
558 20 $what =~ s/(?<distinct>Distinct)(?![[:lower:]])//;
559 20 ▶ my $distinct = $+{distinct} // 0;
Condition100%2/2
$+{"distinct"} // 0
l!l
614
MC/DC100%1/1
$+{"distinct"} // 0
$+{"distinct"}
Truth table100%2/2
A
A= $+{"distinct"}
Aresult
11
00
560 20 $what =~ s/((?<type>(All|One|First))(?<limit>\d+)?)(?![[:lower:]])//;
561 20 ▶ my $type = $+{type} // 'All';
Condition100%2/2
$+{"type"} // "All"
l!l
182
MC/DC100%1/1
$+{"type"} // "All"
$+{"type"}
Truth table100%2/2
A
A= $+{"type"}
Aresult
11
00
562 20 my $limit = $+{limit};
563 20 $what =~ s/(?<column>\w+)//;
564 20 ▶ my $column = $camel_case_map->($+{column} // '');
Condition100%2/2
$+{"column"} // ""
l!l
713
MC/DC100%1/1
$+{"column"} // ""
$+{"column"}
Truth table100%2/2
A
A= $+{"column"}
Aresult
11
00
565 20 ▶ $find =~ s/OrderBy(?<order>.*?)(?<asc>Asc|Desc)(?=[[:upper:]]|$)// || $find =~ s/OrderBy(?<order>.*?)$//;
Branch: 1 branch
BranchTrueFalseTotal
$find =~ s/OrderBy(?<order>.*?)(?<asc>Asc|Desc)(?=[[:upper:]]|$)//u or $find =~ s/OrderBy(?<order>.*?)$//u 16 4 20
566 20 my $order = $+{order};
567 20 ▶ my $asc = $+{asc} || 'Asc';
Condition100%2/2
$+{'asc'} || 'Asc'
l!l
416
MC/DC100%1/1
$+{'asc'} || 'Asc'
$+{'asc'}
Truth table100%2/2
A
A= $+{'asc'}
Aresult
11
00
568 20 my $where = $find;
569  
570 20 ▶ if ($type eq 'First' && !$limit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "First" and not $limit) 2 18 20
Condition100%3/3
$type eq "First" and not $limit
!ll&&!rl&&r
1172
MC/DC100%2/2
$type eq "First" and not $limit
$type eq "First" not $limit
Truth table100%3/3
A and not(B)
A= $type eq "First"B= not $limit
ABresult
0X0
100
111
571 2 $limit = 1;
572 }
573 20 ▶ if ($limit && $limit == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and $limit == 1) 3 17 20
Condition100%3/3
$limit and $limit == 1
!ll&&!rl&&r
1163
MC/DC100%2/2
$limit and $limit == 1
$limit $limit == 1
Truth table100%3/3
A and B
A= $limitB= $limit == 1
ABresult
0X0
100
111
574 3 $type = 'One';
575 }
576 20 my $pi = 1;
577 my $pp = sub {
578 26 ▶ my ($param) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.1
579 26 my $found;
580 26 ▶ for (my $i = 0; $i < @uneq; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @uneq) 475 22 497
581 475 ▶ if ($param =~ s/$uneq[$i]//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param =~ s/$uneq[$i]//u) 4 471 475
582 4 $found = $i + 1;
583 4 last;
584 }
585 }
586 26 $param = $camel_case_map->($param);
587 26 my $ret;
588 26 ▶ if ($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) { } 4 22 26
589 4 ▶ if ('CODE' eq ref $uneq[$found]) {
Branch: 1 branch
BranchTrueFalseTotal
if ('CODE' eq ref $uneq[$found]) { } 1 3 4
590 1 $ret = $uneq[$found]->($param);
591 } else {
592 3 $ret = "'$param' => { '$uneq[$found]' => \$_[$pi]}";
593 3 ++$pi;
594 }
595 } else {
596 22 $ret = "'$param' => \$_[$pi]";
597 22 ++$pi;
598 }
599 26 $ret;
600 20 };
601 #<<<
602 my $conds = join(
603 ", ",
604 map {
605 20 /And(?![[:lower:]])/
606 16 ▶ ? '-and => [' . join(", ", map {$pp->($_)} split /And(?![[:lower:]])/x, $_) . ']'
Branch: 1 branch
BranchTrueFalseTotal
/And(?![[:lower:]])/u ? : 9 7 16
607 : $pp->($_);
608 } split /Or(?![[:lower:]])/, $where
609 );
610 #>>>
611 20 ▶ my $obj = $type eq 'One' ? 'DBIx::Struct::one_row' : 'DBIx::Struct::all_rows';
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'One' ? : 5 15 20
612 20 ▶ my $flags = $column ? ", -column => '$column'" : '';
Branch: 1 branch
BranchTrueFalseTotal
$column ? : 7 13 20
613 20 ▶ $flags = $distinct ? $flags ? ", -distinct => '$column'" : ", '-distinct'" : $flags;
Branch: 2 branches
BranchTrueFalseTotal
$distinct ? : 6 14 20
$flags ? : 6 0 6
614 20 ▶ $order =
Branch: 2 branches
BranchTrueFalseTotal
$order ? : 5 15 20
$asc eq 'Asc' ? : 4 1 5
615 $order
616 ? $asc eq 'Asc'
617 ? ", -order_by => '" . $camel_case_map->($order) . "'"
618 : ", -order_by => {-desc => '" . $camel_case_map->($order) . "'}"
619 : '';
620 20 ▶ $where = $conds ? ", -where => [$conds]" : '';
Branch: 1 branch
BranchTrueFalseTotal
$conds ? : 16 4 20
621 20 ▶ $limit = $limit && $limit > 1 && $type ne 'One' ? ", -limit => $limit" : '';
Branch: 1 branch
BranchTrueFalseTotal
$limit && $limit > 1 && $type ne 'One' ? : 6 14 20
Condition83%5/6
$limit and $limit > 1 and $type ne "One"
!ll&&!rl&&r
1406
$limit and $limit > 1
!ll&&!rl&&r
1136
MC/DC66%2/3
$limit and $limit > 1 and $type ne "One"
$limit $limit > 1 $type ne "One"
Truth table75%3/4
A and B and C
A= $limitB= $limit > 1C= $type ne "One"
ABCresult
0XX0
10X0
1100
1111
622 20 my $tspec = "'$table'" . $flags;
623 20 ▶ $tspec = "[$tspec]" if $column;
Branch: 1 branch
BranchTrueFalseTotal
if $column 7 13 20
624 20 $tspec .= $where . $order . $limit;
625 20 return "sub { $obj($tspec) }";
626 }
627  
628 sub _row_data () {0}
629 sub _row_updates () {1}
630  
631 sub make_object_new {
632 10 ▶ my ($table, $required, $pk_row_data, $pk_returninig) = @_;
Subroutine make_object_new: called CC=3 SCAR=11.0
Pod undocumented
633 10 my $new = <<NEW;
634 sub new {
635 my \$class = \$_[0];
636 my \$self = [ [] ];
637 bless \$self, \$class;
638 if(CORE::defined(\$_[1]) && CORE::ref(\$_[1]) eq 'ARRAY') {
639 10 \$self->[@{[_row_data]}] = \$_[1];
640 }
641 NEW
642 10 ▶ if (not ref $table) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $table) 6 4 10
643 6 $new .= <<NEW;
644 else {
645 my \%insert;
646 for(my \$i = 1; \$i < \@_; \$i += 2) {
647 if (CORE::exists \$fields{\$_[\$i]}) {
648 my \$f = \$_[\$i];
649 6 \$self->[@{[_row_data]}]->[\$fields{\$_[\$i]}] = \$_[\$i + 1];
650 \$insert{\$f} = \$_[\$i + 1];
651 } else {
652 DBIx::Struct::error_message {
653 result => 'SQLERR',
654 message => "unknown column \$_[\$i] inserting into table $table"
655 }
656 }
657 }
658 my (\@insert, \@values, \@bind);
659 \@insert =
660 CORE::map {
661 if(CORE::ref(\$insert{\$_}) eq 'ARRAY' and CORE::ref(\$insert{\$_}[0]) eq 'SCALAR') {
662 CORE::push \@bind, \@{\$insert{\$_}}[1..\$#{\$insert{\$_}}];
663 CORE::push \@values, \${\$insert{\$_}[0]};
664 DBIx::Struct::connect->dbh->quote_identifier(\$_);
665 } elsif(CORE::ref(\$insert{\$_}) eq 'REF' and CORE::ref(\${\$insert{\$_}}) eq 'ARRAY') {
666 if(CORE::defined \${\$insert{\$_}}->[0]) {
667 CORE::push \@bind, \@{\${\$insert{\$_}}}[1..\$#{\${\$insert{\$_}}}];
668 CORE::push \@values, \${\$insert{\$_}}->[0];
669 DBIx::Struct::connect->dbh->quote_identifier(\$_);
670 } else {
671 CORE::push \@values, "null";
672 DBIx::Struct::connect->dbh->quote_identifier(\$_)
673 }
674 } elsif(CORE::ref(\$insert{\$_}) eq 'SCALAR') {
675 CORE::push \@values, \${\$insert{\$_}};
676 DBIx::Struct::connect->dbh->quote_identifier(\$_);
677 } elsif(CORE::exists (\$json_fields{\$_})
678 && (CORE::ref(\$insert{\$_}) eq 'ARRAY' || CORE::ref(\$insert{\$_}) eq 'HASH')) {
679 CORE::push \@bind, JSON::to_json(\$insert{\$_});
680 CORE::push \@values, "?";
681 DBIx::Struct::connect->dbh->quote_identifier(\$_);
682 } else {
683 CORE::push \@bind, \$insert{\$_};
684 CORE::push \@values, "?";
685 DBIx::Struct::connect->dbh->quote_identifier(\$_);
686 }
687 } CORE::keys \%insert;
688 my \$insert;
689 if(\%insert){
690 \$insert = "insert into $table (" . CORE::join( ", ", \@insert) . ") values ("
691 . CORE::join( ", ", \@values) . ")";
692 } else {
693 \$insert = "insert into $table values (default)";
694 }
695 NEW
696 6 ▶ if ($required) {
Branch: 1 branch
BranchTrueFalseTotal
if ($required) 0 6 6
697 0 $new .= <<NEW;
698 for my \$r ($required) {
699 DBIx::Struct::error_message {
700 result => 'SQLERR',
701 message => "required field \$r is absent for table $table"
702 } if not CORE::exists \$insert{\$r};
703 }
704 NEW
705 }
706 6 $new .= <<NEW;
707 DBIx::Struct::connect->run(
708 sub {
709 NEW
710 6 $new .= $driver_pk_insert{$connector_driver}->($table, $pk_row_data, $pk_returninig);
711 6 $new .= <<NEW;
712 });
713 }
714 NEW
715 }
716 10 $new .= <<NEW;
717 \$self;
718 }
719 NEW
720 10 $new;
721 }
722  
723 sub make_object_filter_timestamp {
724 10 ▶ my ($timestamps) = @_;
Subroutine make_object_filter_timestamp: called CC=1 SCAR=0.0
Pod undocumented
725 10 my $filter_timestamp = <<FTS;
726 sub filter_timestamp {
727 my \$self = \$_[0];
728 if(\@_ == 1) {
729 for my \$f ($timestamps) {
730 10 if(\$self->[@{[_row_data]}][\$fields{\$f}]) {
731 10 \$self->[@{[_row_data]}][\$fields{\$f}] =~ s/\\.\\d+(\$|\\+|\\-)/\$1/;
732 10 \$self->[@{[_row_data]}][\$fields{\$f}] =~ s/(\\+|\\-)(\\d{2})\$/\$1\${2}00/;
733 }
734 }
735 } else {
736 for my \$f (\@_[1..\$#_]) {
737 10 if(\$self->[@{[_row_data]}][\$fields{\$f}]) {
738 10 \$self->[@{[_row_data]}][\$fields{\$f}] =~ s/\\.\\d+(\$|\\+|\\-)/\$1/;
739 10 \$self->[@{[_row_data]}][\$fields{\$f}] =~ s/(\\+|\\-)(\\d{2})\$/\$1\${2}00/;
740 }
741 }
742 }
743 '' =~ /()/;
744 \$self;
745 }
746 FTS
747 10 $filter_timestamp;
748 }
749  
750 sub make_object_set {
751 10 ▶ my $table = $_[0];
Subroutine make_object_set: called CC=1 SCAR=0.0
Pod undocumented
752 10 my $set = <<SET;
753 sub set {
754 my \$self = \$_[0];
755 my \@unknown_columns;
756 if(CORE::defined(\$_[1])) {
757 if(CORE::ref(\$_[1]) eq 'ARRAY') {
758 10 \$self->[@{[_row_data]}] = \$_[1];
759 10 \$self->[@{[_row_updates]}] = {};
760 } elsif(CORE::ref(\$_[1]) eq 'HASH') {
761 for my \$f (CORE::keys \%{\$_[1]}) {
762 if (CORE::exists \$fields{\$f}) {
763 \$self->\$f(\$_[1]->{\$f});
764 } else {
765 CORE::push \@unknown_columns, \$f;
766 }
767 }
768 } elsif(not CORE::ref(\$_[1])) {
769 for(my \$i = 1; \$i < \@_; \$i += 2) {
770 if (CORE::exists \$fields{\$_[\$i]}) {
771 my \$f = \$_[\$i];
772 \$self->\$f(\$_[\$i + 1]);
773 } else {
774 CORE::push \@unknown_columns, \$_[\$i];
775 }
776 }
777 }
778 }
779 DBIx::Struct::error_message {
780 result => 'SQLERR',
781 message => 'unknown columns '.CORE::join(", ", \@unknown_columns).' for $table->data'
782 } if \@unknown_columns;
783 \$self;
784 }
785 SET
786 10 $set;
787 }
788  
789 sub make_object_data {
790 10 ▶ my $table = $_[0];
Subroutine make_object_data: called CC=1 SCAR=0.0
Pod undocumented
791 10 my $data = <<DATA;
792 sub data {
793 my \$self = \$_[0];
794 my \@ret_keys;
795 my \$ret;
796 if(CORE::defined(\$_[1])) {
797 if(CORE::ref(\$_[1]) eq 'ARRAY') {
798 if(!\@{\$_[1]}) {
799 10 \$ret = \$self->[@{[_row_data]}];
800 } else {
801 10 \$ret = [CORE::map {\$self->[@{[_row_data]}]->[\$fields{\$_}] } \@{\$_[1]}];
802 }
803 } else {
804 for my \$k (\@_[1..\$#_]) {
805 CORE::push \@ret_keys, \$k if CORE::exists \$fields{\$k};
806 }
807 }
808 } else {
809 \@ret_keys = keys \%fields;
810 }
811 my \@unknown_columns = CORE::grep {not CORE::exists \$fields{\$_}} \@ret_keys;
812 DBIx::Struct::error_message {
813 result => 'SQLERR',
814 message => 'unknown columns '.CORE::join(", ", \@unknown_columns).' for $table->data'
815 } if \@unknown_columns;
816 \$ret = {
817 CORE::map {\$_ => \$self->\$_} \@ret_keys
818 } if not CORE::defined \$ret;
819 \$ret;
820 }
821 DATA
822 10 $data;
823 }
824  
825 sub make_object_update {
826 10 ▶ my ($table, $pk_where, $pk_row_data) = @_;
Subroutine make_object_update: called CC=2 SCAR=6.9
Pod undocumented
827 10 my $update;
828 10 ▶ if (not ref $table) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $table) { } 6 4 10
829  
830 # means this is just one simple table
831 6 $update = <<UPD;
832 sub update {
833 my \$self = \$_[0];
834 if(\@_ > 1 && CORE::ref(\$_[1]) eq 'HASH') {
835 my (\$set, \$where, \@bind, \@bind_where);
836 {
837 no strict 'vars';
838 local *set_hash = \$_[1];
839 my \@unknown_columns = CORE::grep {not CORE::exists \$fields{\$_}} CORE::keys %set_hash;
840 DBIx::Struct::error_message {
841 result => 'SQLERR',
842 message => 'unknown columns '.CORE::join(", ", \@unknown_columns).' updating table $table'
843 } if \@unknown_columns;
844 \$set =
845 CORE::join ", ",
846 CORE::map {
847 if(CORE::ref(\$set_hash{\$_}) eq 'ARRAY' and CORE::ref(\$set_hash{\$_}[0]) eq 'SCALAR') {
848 CORE::push \@bind, \@{\$set_hash{\$_}}[1..\$#{\$set_hash{\$_}}];
849 DBIx::Struct::connect->dbh->quote_identifier(\$_) . " = " . \${\$set_hash{\$_}[0]};
850 } elsif(CORE::ref(\$set_hash{\$_}) eq 'REF' and CORE::ref(\${\$set_hash{\$_}}) eq 'ARRAY') {
851 if(CORE::defined \${\$set_hash{\$_}}->[0]) {
852 CORE::push \@bind, \@{\${\$set_hash{\$_}}}[1..\$#{\${\$set_hash{\$_}}}];
853 DBIx::Struct::connect->dbh->quote_identifier(\$_) . " = " . \${\$set_hash{\$_}}->[0];
854 } else {
855 DBIx::Struct::connect->dbh->quote_identifier(\$_) . " = null"
856 }
857 } elsif(CORE::ref(\$set_hash{\$_}) eq 'SCALAR') {
858 DBIx::Struct::connect->dbh->quote_identifier(\$_) . " = " . \${\$set_hash{\$_}};
859 } elsif(CORE::exists(\$json_fields{\$_})
860 && (CORE::ref(\$set_hash{\$_}) eq 'ARRAY' || CORE::ref(\$set_hash{\$_}) eq 'HASH')) {
861 CORE::push \@bind, JSON::to_json(\$set_hash{\$_});
862 DBIx::Struct::connect->dbh->quote_identifier(\$_) . " = ?"
863 } else {
864 CORE::push \@bind, \$set_hash{\$_};
865 DBIx::Struct::connect->dbh->quote_identifier(\$_) . " = ?"
866 }
867 } CORE::keys \%set_hash;
868 }
869 if(\@_ > 2) {
870 my \$cond = \$_[2];
871 if(not CORE::ref(\$cond)) {
872 \$cond = {(selectKeys)[0] => \$_[2]};
873 }
874 (\$where, \@bind_where) = SQL::Abstract->new->where(\$cond);
875 }
876 return DBIx::Struct::connect->run(sub {
877 \$_->do(qq{update $table set \$set \$where}, undef, \@bind, \@bind_where)
878 or DBIx::Struct::error_message {
879 result => 'SQLERR',
880 message => 'error '.\$_->errstr.' updating table $table'
881 }
882 });
883 6 } elsif (CORE::ref(\$self) && \@\$self > 1 && \%{\$self->[@{[_row_updates]}]}) {
884 my (\$set, \@bind);
885 {
886 no strict 'vars';
887 \$set =
888 CORE::join ", ",
889 CORE::map {
890 6 local *column_value = \\\$self->[@{[_row_data]}][\$fields{\$_}];
891 if(CORE::ref(\$column_value) eq 'ARRAY' and CORE::ref(\$column_value->[0]) eq 'SCALAR') {
892 CORE::push \@bind, \@{\$column_value}[1..\$#\$column_value];
893 DBIx::Struct::connect->dbh->quote_identifier(\$_) . " = " . \${\$column_value->[0]};
894 } elsif(CORE::ref(\$column_value) eq 'REF' and CORE::ref(\${\$column_value}) eq 'ARRAY') {
895 if(CORE::defined \${\$column_value}->[0]) {
896 CORE::push \@bind, \@{\${\$column_value}}[1..\$#{\${\$column_value}}];
897 DBIx::Struct::connect->dbh->quote_identifier(\$_) . " = " . \${\$column_value}->[0];
898 } else {
899 DBIx::Struct::connect->dbh->quote_identifier(\$_) . " = null"
900 }
901 } elsif(CORE::ref(\$column_value) && CORE::ref(\$column_value) =~ /^DBIx::Struct::JSON/) {
902 \$column_value->revert;
903 CORE::push \@bind, \$column_value;
904 DBIx::Struct::connect->dbh->quote_identifier(\$_) . " = ?"
905 } elsif(CORE::ref(\$column_value) eq 'SCALAR') {
906 DBIx::Struct::connect->dbh->quote_identifier(\$_) . " = " . \$\$column_value;
907 } else {
908 CORE::push \@bind, \$column_value;
909 DBIx::Struct::connect->dbh->quote_identifier(\$_) . " = ?"
910 }
911 6 } CORE::keys \%{\$self->[@{[_row_updates]}]};
912 }
913 my \$update_query = qq{update $table set \$set where $pk_where};
914 DBIx::Struct::connect->run(
915 sub {
916 \$_->do(\$update_query, undef, \@bind, $pk_row_data)
917 or DBIx::Struct::error_message {
918 result => 'SQLERR',
919 message => 'error '.\$_->errstr.' updating table $table',
920 query => \$update_query,
921 bind => \\\@bind,
922 }
923 }
924 );
925 6 \$#\$self = @{[_row_data]};
926 }
927 \$self;
928 }
929 UPD
930 } else {
931 4 $update = <<UPD;
932 sub update {}
933 UPD
934 }
935 10 $update;
936 }
937  
938 sub make_object_delete {
939 10 ▶ my ($table, $pk_where, $pk_row_data) = @_;
Subroutine make_object_delete: called CC=2 SCAR=6.9
Pod undocumented
940 10 my $delete;
941 10 ▶ if (not ref $table) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $table) { } 6 4 10
942 6 $delete = <<DEL;
943 sub delete {
944 my \$self = \$_[0];
945 if(Scalar::Util::blessed \$self) {
946 DBIx::Struct::connect->run(
947 sub {
948 \$_->do(qq{delete from $table where $pk_where}, undef, $pk_row_data)
949 or DBIx::Struct::error_message {
950 result => 'SQLERR',
951 message => 'error '.\$_->errstr.' updating table $table'
952 }
953 });
954 return \$self;
955 }
956 my \$where = '';
957 my \@bind;
958 my \$cond = \$_[1] if \@_ > 1;
959 if(not CORE::ref(\$cond)) {
960 \$cond = {};
961 my \@keys = selectKeys();
962 for(my \$i = 1; \$i < \@_; ++\$i) {
963 DBIx::Struct::error_message {
964 result => 'SQLERR',
965 message => "Too many keys to delete for $table"
966 } if not CORE::defined \$keys[\$i-1];
967 \$cond->{\$keys[\$i-1]} = \$_[\$i];
968 }
969 }
970 my \@rpar = ();
971 if(\$cond) {
972 (\$where, \@bind) = SQL::Abstract->new->where(\$cond);
973 \@rpar = (undef, \@bind);
974 }
975 return DBIx::Struct::connect->run(sub {
976 \$_->do(qq{delete from $table \$where}, \@rpar)
977 or DBIx::Struct::error_message {
978 result => 'SQLERR',
979 message => 'error '.\$_->errstr.' updating table $table'
980 }
981 });
982 }
983 DEL
984 } else {
985 4 $delete = <<DEL
986 sub delete {}
987 DEL
988 }
989 10 $delete;
990 }
991  
992 sub make_object_autoload_find {
993 10 ▶ my ($table, $pk_where, $pk_row_data) = @_;
Subroutine make_object_autoload_find: called CC=2 SCAR=6.9
Pod undocumented
994 10 my $find = '';
995 10 ▶ if (not ref $table) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $table) 6 4 10
996 6 $find = <<AUTOLOAD;
997 sub AUTOLOAD {
998 my \$self = \$_[0];
999 ( my \$method = \$AUTOLOAD ) =~ s{.*::}{};
1000
1001 if(Scalar::Util::blessed \$self) {
1002 \$self = CORE::ref \$self;
1003 }
1004 DBIx::Struct::error_message {
1005 result => 'SQLERR',
1006 message => "Unknown method \$method for $table"
1007 } if !\$self || !"\$self"->can("tableName") || \$method !~ /^find/;
1008 my \$func = DBIx::Struct::_parse_find_by('$table', \$method);
1009 my \$ncn = DBIx::Struct::make_name('$table');
1010 {
1011 no strict 'refs';
1012 *{\$ncn."::".\$method} = eval \$func;
1013 DBIx::Struct::error_message {
1014 result => 'SQLERR',
1015 message => "Error creating method \$method for $table: \$\@"
1016 } if \$\@;
1017 }
1018 goto &{\$ncn."::".\$method};
1019 }
1020 AUTOLOAD
1021 }
1022 10 $find;
1023 }
1024  
1025 sub make_object_fetch {
1026 10 ▶ my ($table, $pk_where, $pk_row_data) = @_;
Subroutine make_object_fetch: called CC=2 SCAR=6.9
Pod undocumented
1027 10 my $fetch;
1028 10 ▶ if (not ref $table) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $table) { } 6 4 10
1029 6 $fetch = <<FETCH;
1030 sub fetch {
1031 my \$self = \$_[0];
1032 if(\@_ > 1) {
1033 my (\$where, \@bind);
1034 my \$cond = \$_[1];
1035 if(not CORE::ref(\$cond)) {
1036 \$cond = {(selectKeys)[0] => \$_[1]};
1037 }
1038 (\$where, \@bind) = SQL::Abstract->new->where(\$cond);
1039 DBIx::Struct::connect->run(sub {
1040 my \$rowref = \$_->selectrow_arrayref(qq{select * from $table \$where}, undef, \@bind)
1041 or DBIx::Struct::error_message {
1042 result => 'SQLERR',
1043 message => 'error '.\$_->errstr.' fetching table $table'
1044 };
1045 6 \$self->[@{[_row_data]}] = [\@\$rowref];
1046 });
1047 } else {
1048 DBIx::Struct::connect->run(
1049 sub {
1050 my \$rowref = \$_->selectrow_arrayref(qq{select * from $table where $pk_where}, undef, $pk_row_data)
1051 or DBIx::Struct::error_message {
1052 result => 'SQLERR',
1053 message => 'error '.\$_->errstr.' fetching table $table'
1054 };
1055 6 \$self->[@{[_row_data]}] = [\@\$rowref];
1056 });
1057 }
1058 \$self;
1059 }
1060 FETCH
1061 } else {
1062 4 $fetch = <<FETCH;
1063 sub fetch { \$_[0] }
1064 FETCH
1065 }
1066 10 $fetch;
1067 }
1068  
1069 sub _exists_row ($) {
1070 49 ▶ my $ncn = $_[0];
Subroutine _exists_row: called CC=2 SCAR=6.9
1071 3 ▶ no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
1072 49 ▶ if (grep {!/::$/} keys %{"${ncn}::"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not /::$/u;} keys %{"${ncn}::";}) 39 10 49
1073 39 return 1;
1074 }
1075 10 return;
1076 }
1077  
1078 sub _parse_interface ($) {
1079 0 ▶ my $interface = $_[0];
Subroutine _parse_interface: not called CC=16 SCAR=53.1
1080 0 my %ret;
1081 0 ▶ $interface = [$interface] if not ref $interface;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $interface 0 0 0
1082 0 ▶ if ('ARRAY' eq ref $interface) {
Branch: 2 branches
BranchTrueFalseTotal
if ('ARRAY' eq ref $interface) { } 0 0 0
elsif ('HASH' eq ref $interface) { } 0 0 0
1083 0 for my $i (@$interface) {
1084 0 my $dbc_name = make_name($i);
1085 0 ▶ error_message {
Branch: 1 branch
BranchTrueFalseTotal
unless &_exists_row($dbc_name) 0 0 0
1086 result => 'SQLERR',
1087 message => "Unknown base interface table $i",
1088 }
1089 unless _exists_row $dbc_name;
1090 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1091 0 my $href = \%{"${dbc_name}::fkfuncs"};
1092 0 ▶ if ($href && %$href) {
Branch: 1 branch
BranchTrueFalseTotal
if ($href and %$href) 0 0 0
Condition0%0/3
$href and %$href
!ll&&!rl&&r
000
MC/DC0%0/2
$href and %$href
$href %$href
Truth table0%0/3
A and B
A= $hrefB= %$href
ABresult
0X0
100
111
1093 0 my @i = keys %$href;
1094 0 @ret{@i} = @{$href}{@i};
1095 }
1096 }
1097 } elsif ('HASH' eq ref $interface) {
1098 0 for my $i (keys %$interface) {
1099 0 my $dbc_name = make_name($i);
1100 0 ▶ error_message {
Branch: 1 branch
BranchTrueFalseTotal
unless &_exists_row($dbc_name) 0 0 0
1101 result => 'SQLERR',
1102 message => "Unknown base interface table $i",
1103 }
1104 unless _exists_row $dbc_name;
1105 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1106 0 my $href = \%{"${dbc_name}::fkfuncs"};
1107 0 ▶ next if not $href or not %$href;
Branch: 1 branch
BranchTrueFalseTotal
unless $href and %$href 0 0 0
Condition0%0/3
$href and %$href
!ll&&!rl&&r
000
MC/DC0%0/2
$href and %$href
$href %$href
Truth table0%0/3
A and B
A= $hrefB= %$href
ABresult
0X0
100
111
1108 0 my $fl = $interface->{$i};
1109 0 ▶ $fl = [$fl] if not ref $fl;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $fl 0 0 0
1110 0 ▶ if ('ARRAY' eq ref $fl) {
Branch: 1 branch
BranchTrueFalseTotal
if ('ARRAY' eq ref $fl) { } 0 0 0
1111  
1112 0 for my $m (@$fl) {
1113 0 ▶ $ret{$m} = $href->{$m} if exists $href->{$m};
Branch: 1 branch
BranchTrueFalseTotal
if exists $href->{$m} 0 0 0
1114 }
1115 } else {
1116 0 error_message {
1117 result => 'SQLERR',
1118 message => "Usupported interface structure",
1119 };
1120 }
1121 }
1122 } else {
1123 0 error_message {
1124 result => 'SQLERR',
1125 message => "Unknown interface structure: " . ref($interface),
1126 };
1127 }
1128 0 \%ret;
1129 }
1130  
1131 sub make_object_to_json {
1132 10 ▶ my ($table, $field_types, $fields) = @_;
Subroutine make_object_to_json: called CC=5 SCAR=16.8
Pod undocumented
1133 10 my @to_types = map {[
1134 $_,
1135 20 ▶ qq|!defined(\$self->[@{[_row_data]}][$fields->{$_}])? undef: |
Branch: 1 branch
BranchTrueFalseTotal
$field_types->{$_} eq 'number' ? : 16 4 20
1136 . (
1137 16 ▶ $field_types->{$_} eq 'number' ? "0+\$self->[@{[_row_data]}][$fields->{$_}]"
Branch: 1 branch
BranchTrueFalseTotal
$field_types->{$_} eq 'boolean' ? : 0 4 4
1138 0 ▶ : $field_types->{$_} eq 'boolean' ? "\$self->[@{[_row_data]}][$fields->{$_}]? \\1: \\0"
Branch: 1 branch
BranchTrueFalseTotal
$field_types->{$_} eq 'json' ? : 0 4 4
1139 20 : $field_types->{$_} eq 'json'
1140 0 ? "CORE::ref(\$self->[@{[_row_data]}]->[$fields->{$_}])? \$self->[@{[_row_data]}][$fields->{$_}]->data"
1141 0 . ": JSON::from_json(\$self->[@{[_row_data]}][$fields->{$_}])"
1142 4 : "\"\$self->[@{[_row_data]}][$fields->{$_}]\""
1143 )
1144 ]
1145 } keys %$field_types;
1146 10 my $field_to_types = join ",\n\t\t\t\t ", map {qq|"$_->[0]" => $_->[1]|} @to_types;
1147 10 my $sub_to_types = '';
1148 10 for my $tt (@to_types) {
1149 20 my $k = $tt->[0];
1150 20 $k =~ s/[^\w\d]/_/g;
1151 20 $sub_to_types .= <<JSTT
1152 sub _to_json_$k { my \$self = \$_[0]; $tt->[1] }
1153 JSTT
1154 }
1155 10 my $to_json = <<TOJSON;
1156 sub TO_JSON {
1157 my \$self = shift;
1158 my \$ret;
1159 my \@columns = CORE::grep { not ref } \@_;
1160 my \@refs = CORE::grep { 'HASH' eq ref } \@_;
1161 if(\@columns) {
1162 \$ret = +{
1163 map {
1164 DBIx::Struct::error_message {
1165 result => 'SQLERR',
1166 message => "unknown column \$_ in table $table"
1167 } if not CORE::exists \$fields{\$_};
1168 my \$k = \$_;
1169 \$k =~ s/[^\\w\\d]/_/g;
1170 my \$m = "_to_json_\$k";
1171 \$_ => \$self->\$m
1172 } \@columns
1173 };
1174 } else {
1175 \$ret = +{
1176 $field_to_types
1177 };
1178 }
1179 if(\@refs) {
1180 \$ret = +{ %\$ret, map { %\$_ } \@refs };
1181 }
1182 return \$ret;
1183 }
1184 TOJSON
1185 10 return $sub_to_types . $to_json;
1186 }
1187  
1188 sub _field_type_from_name {
1189 20 ▶ my $type_name = $_[0];
Subroutine _field_type_from_name: called CC=12 SCAR=32.0
1190 20 ▶ return 'string' if not defined $type_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type_name 0 20 20
1191 20 ▶ if ( $type_name =~ /int(\d+)?$/i
Branch: 6 branches
BranchTrueFalseTotal
if ($type_name =~ /int(\d+)?$/iu or $type_name =~ /integer/iu or $type_name =~ /bit$/u or $type_name =~ /float|double|real|decimal|numeric/iu) { } 16 4 20
elsif ($type_name =~ /json/iu) { } 0 4 4
elsif ($type_name =~ /bool/iu) { } 0 4 4
elsif ($type_name =~ /date/iu and $type_name =~ /time/iu) { } 0 4 4
elsif ($type_name =~ /date/iu) { } 0 4 4
elsif ($type_name =~ /time/iu) { } 0 4 4
Condition66%6/9
$type_name =~ /int(\d+)?$/iu or $type_name =~ /integer/iu or $type_name =~ /bit$/u or $type_name =~ /float|double|real|decimal|numeric/iu
l!l&&r!l&&!r
1604
$type_name =~ /int(\d+)?$/iu or $type_name =~ /integer/iu or $type_name =~ /bit$/u
l!l&&r!l&&!r
1604
$type_name =~ /int(\d+)?$/iu or $type_name =~ /integer/iu
l!l&&r!l&&!r
0164
MC/DC25%1/4
$type_name =~ /int(\d+)?$/iu or $type_name =~ /integer/iu or $type_name =~ /bit$/u or $type_name =~ /float|double|real|decimal|numeric/iu
$type_name =~ /int(\d+)?$/iu $type_name =~ /integer/iu $type_name =~ /bit$/u $type_name =~ /float|double|real|decimal|numeric/iu
Truth table40%2/5
A or B or C or D
A= $type_name =~ /int(\d+)?$/iuB= $type_name =~ /integer/iuC= $type_name =~ /bit$/uD= $type_name =~ /float|double|real|decimal|numeric/iu
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1192 || $type_name =~ /integer/i
1193 || $type_name =~ /bit$/
1194 || $type_name =~ /float|double|real|decimal|numeric/i)
1195 {
1196 16 return 'number';
1197 } elsif ($type_name =~ /json/i) {
1198 0 return 'json';
1199 } elsif ($type_name =~ /bool/i) {
1200 0 return 'boolean';
1201 ▶ } elsif ($type_name =~ /date/i && $type_name =~ /time/i) {
Condition33%1/3
$type_name =~ /date/iu and $type_name =~ /time/iu
!ll&&!rl&&r
400
MC/DC0%0/2
$type_name =~ /date/iu and $type_name =~ /time/iu
$type_name =~ /date/iu $type_name =~ /time/iu
Truth table33%1/3
A and B
A= $type_name =~ /date/iuB= $type_name =~ /time/iu
ABresult
0X0
100
111
1202 0 return 'datetime';
1203 } elsif ($type_name =~ /date/i) {
1204 0 return 'date';
1205 } elsif ($type_name =~ /time/i) {
1206 0 return 'time';
1207 } else {
1208 4 return 'string';
1209 }
1210 }
1211  
1212 sub _schema_name {
1213 23 ▶ my $ncn = $_[0];
Subroutine _schema_name: called CC=4 SCAR=13.9
1214 23 ▶ if ($user_schema_namespace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DBIx::Struct::user_schema_namespace) 5 18 23
1215 5 (my $uncn = $ncn) =~ s/^.*:://;
1216 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1217 5 eval {
1218 5 ▶ if (${"${user_schema_namespace}::${uncn}::"}{ISA}
Branch: 1 branch
BranchTrueFalseTotal
if (do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{"ISA"} and ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)) 2 3 5
Condition66%2/3
do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{"ISA"} and ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)
!ll&&!rl&&r
302
MC/DC50%1/2
do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{"ISA"} and ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)
do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{"ISA"} ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)
Truth table66%2/3
A and B
A= do { "$DBIx::Struct::user_schema_namespace::${uncn}::" }->{"ISA"}B= ("$DBIx::Struct::user_schema_namespace::$uncn")->isa($ncn)
ABresult
0X0
100
111
1219 && "${user_schema_namespace}::${uncn}"->isa($ncn))
1220 {
1221 2 $ncn = "${user_schema_namespace}::${uncn}";
1222 }
1223 };
1224 }
1225 23 $ncn;
1226 }
1227  
1228 sub setup_row {
1229 49 ▶ my ($table, $ncn, $interface) = @_;
Subroutine setup_row: called CC=37 SCAR=63.5
Pod undocumented
1230 error_message {
1231 result => 'SQLERR',
1232 message => "Unsupported driver $connector_driver",
1233 }
1234 49 ▶ unless exists $driver_pk_insert{$connector_driver};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $DBIx::Struct::driver_pk_insert{$DBIx::Struct::connector_driver} 0 49 49
1235 49 ▶ $ncn ||= make_name($table);
Condition66%2/3
$ncn ||= make_name($table)
l!l&&r!l&&!r
4360
MC/DC0%0/2
$ncn ||= make_name($table)
$ncn make_name($table)
Truth table66%2/3
A ||= B
A= $ncnB= make_name($table)
ABresult
1X1
011
000
1236 49 ▶ return $ncn if _exists_row $ncn ;
Branch: 1 branch
BranchTrueFalseTotal
if &_exists_row($ncn) 39 10 49
1237 10 my %fields;
1238 my @fields;
1239 10 my @timestamp_fields;
1240 10 my @required;
1241 10 my @pkeys;
1242 10 my @fkeys;
1243 10 my @refkeys;
1244 10 my %json_fields;
1245 10 my $connector = DBIx::Struct::connect;
1246 10 my %field_types;
1247  
1248 10 ▶ if (not ref $table) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $table) { } 6 4 10
1249 # means this is just one simple table
1250 $connector->run(
1251 sub {
1252 6 ▶ my $ssth = $_->prepare('select * from ' . $_->quote_identifier($table) . ' where 0 = 1');
Subroutine __ANON__: called CC=33 SCAR=48.8
1253 6 ▶ error_message {
Branch: 1 branch
BranchTrueFalseTotal
unless $ssth 0 6 6
1254 result => 'SQLERR',
1255 message => "Unknown table $table",
1256 }
1257 if not $ssth;
1258 6 ▶ $ssth->execute
Branch: 1 branch
BranchTrueFalseTotal
$ssth->execute or &error_message({"result", "SQLERR", "message", "Probably unknown table ${table}: " . $_->errstr}) 0 6 6
1259 or error_message {
1260 result => 'SQLERR',
1261 message => "Probably unknown table $table: " . $_->errstr,
1262  
1263 };
1264 6 my $cih = $_->column_info(undef, undef, $table, undef);
1265 6 ▶ error_message {
Branch: 1 branch
BranchTrueFalseTotal
unless $cih 0 6 6
1266 result => 'SQLERR',
1267 message => "Unknown table $table",
1268 }
1269 if not $cih;
1270 6 my $i = 0;
1271 6 ▶ while (my $chr = $cih->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $chr = $cih->fetchrow_hashref) 12 6 18
1272 12 $chr->{COLUMN_NAME} =~ s/"//g;
1273 12 $chr->{COLUMN_NAME} = lc $chr->{COLUMN_NAME};
1274 12 push @fields, $chr->{COLUMN_NAME};
1275 12 ▶ if ($chr->{TYPE_NAME} =~ /^time/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chr->{"TYPE_NAME"} =~ /^time/iu) 0 12 12
1276 0 push @timestamp_fields, $chr->{COLUMN_NAME};
1277 }
1278 12 ▶ if ($chr->{TYPE_NAME} =~ /^json/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chr->{"TYPE_NAME"} =~ /^json/iu) 0 12 12
1279 0 $json_fields{$chr->{COLUMN_NAME}} = undef;
1280 }
1281 12 ▶ $chr->{COLUMN_DEF} //= $chr->{mysql_is_auto_increment};
Condition66%2/3
$chr->{"COLUMN_DEF"} //= $chr->{"mysql_is_auto_increment"}
l!l&&r!l&&!r
408
MC/DC50%1/2
$chr->{"COLUMN_DEF"} //= $chr->{"mysql_is_auto_increment"}
$chr->{"COLUMN_DEF"} $chr->{"mysql_is_auto_increment"}
Truth table66%2/3
A //= B
A= $chr->{"COLUMN_DEF"}B= $chr->{"mysql_is_auto_increment"}
ABresult
1X1
011
000
1282 12 ▶ if ($chr->{NULLABLE} == 0 && !defined($chr->{COLUMN_DEF})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chr->{"NULLABLE"} == 0 and not defined $chr->{"COLUMN_DEF"}) 0 12 12
Condition66%2/3
$chr->{"NULLABLE"} == 0 and not defined $chr->{"COLUMN_DEF"}
!ll&&!rl&&r
840
MC/DC0%0/2
$chr->{"NULLABLE"} == 0 and not defined $chr->{"COLUMN_DEF"}
$chr->{"NULLABLE"} == 0 not defined $chr->{"COLUMN_DEF"}
Truth table66%2/3
A and not(B)
A= $chr->{"NULLABLE"} == 0B= not defined $chr->{"COLUMN_DEF"}
ABresult
0X0
100
111
1283 0 push @required, $chr->{COLUMN_NAME};
1284 }
1285 12 $fields{$chr->{COLUMN_NAME}} = $i++;
1286 12 $field_types{$chr->{COLUMN_NAME}} = _field_type_from_name($chr->{TYPE_NAME});
1287 }
1288 6 @pkeys = map {lc} $_->primary_key(undef, undef, $table);
1289 6 ▶ if (!@pkeys && @required) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @pkeys and @required) 0 6 6
Condition66%2/3
not @pkeys and @required
!ll&&!rl&&r
420
MC/DC0%0/2
not @pkeys and @required
not @pkeys @required
Truth table66%2/3
not(A) and B
A= not @pkeysB= @required
ABresult
0X0
100
111
1290 0 my $ukh = $_->statistics_info(undef, undef, $table, 1, 1);
1291 0 my %req = map {$_ => undef} @required;
1292 0 my %pkeys;
1293 0 ▶ while (my $ukr = $ukh->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ukr = $ukh->fetchrow_hashref) 0 0 0
1294 0 ▶ if (not exists $req{$ukr->{COLUMN_NAME}} or defined $ukr->{FILTER_CONDITION}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $req{$ukr->{'COLUMN_NAME'}} or defined $ukr->{'FILTER_CONDITION'}) { } 0 0 0
Condition0%0/3
not exists $req{$ukr->{"COLUMN_NAME"}} or defined $ukr->{"FILTER_CONDITION"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $req{$ukr->{"COLUMN_NAME"}} or defined $ukr->{"FILTER_CONDITION"}
not exists $req{$ukr->{"COLUMN_NAME"}} defined $ukr->{"FILTER_CONDITION"}
Truth table0%0/3
not(A) or B
A= not exists $req{$ukr->{"COLUMN_NAME"}}B= defined $ukr->{"FILTER_CONDITION"}
ABresult
1X1
011
000
1295 0 $pkeys{lc $ukr->{INDEX_NAME}}{drop} = 1;
1296 } else {
1297 0 $pkeys{lc $ukr->{INDEX_NAME}}{fields}{lc $ukr->{COLUMN_NAME}} = undef;
1298 }
1299 }
1300 0 my @d = grep {exists $pkeys{$_}{drop}} keys %pkeys;
1301 0 delete $pkeys{$_} for @d;
1302 0 ▶ if (%pkeys) {
Branch: 1 branch
BranchTrueFalseTotal
if (%pkeys) 0 0 0
1303 0 my @spk = sort {scalar(keys %{$pkeys{$a}{fields}}) <=> scalar(keys %{$pkeys{$b}{fields}})}
1304 keys %pkeys;
1305 0 @pkeys = keys %{$pkeys{$spk[0]}{fields}};
1306 }
1307 }
1308 6 my $sth = $_->foreign_key_info(undef, undef, undef, undef, undef, $table);
1309 6 ▶ if ($sth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth) 6 0 6
1310 @fkeys =
1311 4 ▶ grep {($_->{PKTABLE_NAME} || $_->{UK_TABLE_NAME}) && $_->{FK_COLUMN_NAME} !~ /[^a-z_0-9]/}
Branch: 1 branch
BranchTrueFalseTotal
$_->{"PKTABLE_NAME"} || $_->{"UK_TABLE_NAME"} and not $_->{"FK_COLUMN_NAME"} =~ /[^a-z_0-9]/u 4 0 4
Condition33%1/3
$_->{"PKTABLE_NAME"} or $_->{"UK_TABLE_NAME"}
l!l&&r!l&&!r
400
MC/DC0%0/2
$_->{"PKTABLE_NAME"} or $_->{"UK_TABLE_NAME"}
$_->{"PKTABLE_NAME"} $_->{"UK_TABLE_NAME"}
Truth table33%1/3
A or B
A= $_->{"PKTABLE_NAME"}B= $_->{"UK_TABLE_NAME"}
ABresult
1X1
011
000
1312 map {
1313 $_->{FK_COLUMN_NAME} = $_->{FKCOLUMN_NAME}
1314 4 ▶ if $_->{FKCOLUMN_NAME};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"FKCOLUMN_NAME"} 0 4 4
1315 4 ▶ $_->{FK_TABLE_NAME} = $_->{FKTABLE_NAME} if $_->{FKTABLE_NAME};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"FKTABLE_NAME"} 0 4 4
1316 4 $_->{FK_TABLE_NAME} = lc $_->{FK_TABLE_NAME};
1317 4 $_->{FK_COLUMN_NAME} = lc $_->{FK_COLUMN_NAME};
1318 4 ▶ $_->{PKTABLE_NAME} ||= $_->{UK_TABLE_NAME};
Condition33%1/3
$_->{"PKTABLE_NAME"} ||= $_->{"UK_TABLE_NAME"}
l!l&&r!l&&!r
040
MC/DC0%0/2
$_->{"PKTABLE_NAME"} ||= $_->{"UK_TABLE_NAME"}
$_->{"PKTABLE_NAME"} $_->{"UK_TABLE_NAME"}
Truth table33%1/3
A ||= B
A= $_->{"PKTABLE_NAME"}B= $_->{"UK_TABLE_NAME"}
ABresult
1X1
011
000
1319 4 ▶ $_->{PKCOLUMN_NAME} ||= $_->{UK_COLUMN_NAME};
Condition33%1/3
$_->{"PKCOLUMN_NAME"} ||= $_->{"UK_COLUMN_NAME"}
l!l&&r!l&&!r
040
MC/DC0%0/2
$_->{"PKCOLUMN_NAME"} ||= $_->{"UK_COLUMN_NAME"}
$_->{"PKCOLUMN_NAME"} $_->{"UK_COLUMN_NAME"}
Truth table33%1/3
A ||= B
A= $_->{"PKCOLUMN_NAME"}B= $_->{"UK_COLUMN_NAME"}
ABresult
1X1
011
000
1320 4 ▶ $_->{PKTABLE_NAME} = lc $_->{PKTABLE_NAME} if $_->{PKTABLE_NAME};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"PKTABLE_NAME"} 4 0 4
1321 4 ▶ $_->{PKCOLUMN_NAME} = lc $_->{PKCOLUMN_NAME} if $_->{PKCOLUMN_NAME};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"PKCOLUMN_NAME"} 4 0 4
1322 4 $_
1323 6 } @{$sth->fetchall_arrayref({})};
1324 }
1325 6 $sth = $_->foreign_key_info(undef, undef, $table, undef, undef, undef);
1326 6 ▶ if ($sth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth) 6 0 6
1327 @refkeys =
1328 4 ▶ grep {($_->{PKTABLE_NAME} || $_->{UK_TABLE_NAME}) && $_->{FK_COLUMN_NAME} !~ /[^a-z_0-9]/}
Branch: 1 branch
BranchTrueFalseTotal
$_->{"PKTABLE_NAME"} || $_->{"UK_TABLE_NAME"} and not $_->{"FK_COLUMN_NAME"} =~ /[^a-z_0-9]/u 4 0 4
Condition33%1/3
$_->{"PKTABLE_NAME"} or $_->{"UK_TABLE_NAME"}
l!l&&r!l&&!r
400
MC/DC0%0/2
$_->{"PKTABLE_NAME"} or $_->{"UK_TABLE_NAME"}
$_->{"PKTABLE_NAME"} $_->{"UK_TABLE_NAME"}
Truth table33%1/3
A or B
A= $_->{"PKTABLE_NAME"}B= $_->{"UK_TABLE_NAME"}
ABresult
1X1
011
000
1329 map {
1330 $_->{FK_COLUMN_NAME} = $_->{FKCOLUMN_NAME}
1331 4 ▶ if $_->{FKCOLUMN_NAME};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"FKCOLUMN_NAME"} 0 4 4
1332 4 ▶ $_->{FK_TABLE_NAME} = $_->{FKTABLE_NAME} if $_->{FKTABLE_NAME};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"FKTABLE_NAME"} 0 4 4
1333 4 $_->{FK_TABLE_NAME} = lc $_->{FK_TABLE_NAME};
1334 4 $_->{FK_COLUMN_NAME} = lc $_->{FK_COLUMN_NAME};
1335 4 ▶ $_->{PKTABLE_NAME} = lc($_->{PKTABLE_NAME} || $_->{UK_TABLE_NAME});
Condition33%1/3
$_->{'PKTABLE_NAME'} || $_->{'UK_TABLE_NAME'}
l!l&&r!l&&!r
040
MC/DC0%0/2
$_->{'PKTABLE_NAME'} || $_->{'UK_TABLE_NAME'}
$_->{'PKTABLE_NAME'} $_->{'UK_TABLE_NAME'}
Truth table33%1/3
A || B
A= $_->{'PKTABLE_NAME'}B= $_->{'UK_TABLE_NAME'}
ABresult
1X1
011
000
1336 4 ▶ $_->{PKCOLUMN_NAME} = lc($_->{PKCOLUMN_NAME} || $_->{UK_COLUMN_NAME});
Condition33%1/3
$_->{'PKCOLUMN_NAME'} || $_->{'UK_COLUMN_NAME'}
l!l&&r!l&&!r
040
MC/DC0%0/2
$_->{'PKCOLUMN_NAME'} || $_->{'UK_COLUMN_NAME'}
$_->{'PKCOLUMN_NAME'} $_->{'UK_COLUMN_NAME'}
Truth table33%1/3
A || B
A= $_->{'PKCOLUMN_NAME'}B= $_->{'UK_COLUMN_NAME'}
ABresult
1X1
011
000
1337 4 $_
1338 6 } @{$sth->fetchall_arrayref({})};
1339 }
1340 }
1341 6 );
1342 } else {
1343  
1344 # means this is a query
1345 4 my %tnh = %{$table->{NAME_lc_hash}};
1346 4 for my $k (keys %tnh) {
1347 8 my $fk = $k;
1348 8 $fk =~ s/[^\w ].*$//;
1349 8 $fields{$fk} = $tnh{$k};
1350 }
1351 $connector->run(
1352 sub {
1353 4 ▶ for (my $cn = 0; $cn < @{$table->{NAME}}; ++$cn) {
Subroutine __ANON__: called CC=6 SCAR=19.4
Branch: 1 branch
BranchTrueFalseTotal
if ($cn < @{$table->{"NAME"};}) 8 4 12
1354 8 my $ti = $_->type_info($table->{TYPE}->[$cn]);
1355 8 my $field = lc $table->{NAME}->[$cn];
1356 8 $field =~ s/[^\w ].*$//;
1357 8 $field_types{$field} = _field_type_from_name($ti->{TYPE_NAME});
1358 push @timestamp_fields, $field
1359 8 ▶ if $ti->{TYPE_NAME} && $ti->{TYPE_NAME} =~ /^time/;
Branch: 1 branch
BranchTrueFalseTotal
if $ti->{"TYPE_NAME"} and $ti->{"TYPE_NAME"} =~ /^time/u 0 8 8
Condition33%1/3
$ti->{"TYPE_NAME"} and $ti->{"TYPE_NAME"} =~ /^time/u
!ll&&!rl&&r
080
MC/DC0%0/2
$ti->{"TYPE_NAME"} and $ti->{"TYPE_NAME"} =~ /^time/u
$ti->{"TYPE_NAME"} $ti->{"TYPE_NAME"} =~ /^time/u
Truth table33%1/3
A and B
A= $ti->{"TYPE_NAME"}B= $ti->{"TYPE_NAME"} =~ /^time/u
ABresult
0X0
100
111
1360 $json_fields{$field} = undef
1361 8 ▶ if $ti->{TYPE_NAME} && $ti->{TYPE_NAME} =~ /^json/;
Branch: 1 branch
BranchTrueFalseTotal
if $ti->{"TYPE_NAME"} and $ti->{"TYPE_NAME"} =~ /^json/u 0 8 8
Condition33%1/3
$ti->{"TYPE_NAME"} and $ti->{"TYPE_NAME"} =~ /^json/u
!ll&&!rl&&r
080
MC/DC0%0/2
$ti->{"TYPE_NAME"} and $ti->{"TYPE_NAME"} =~ /^json/u
$ti->{"TYPE_NAME"} $ti->{"TYPE_NAME"} =~ /^json/u
Truth table33%1/3
A and B
A= $ti->{"TYPE_NAME"}B= $ti->{"TYPE_NAME"} =~ /^json/u
ABresult
0X0
100
111
1362 }
1363 }
1364 4 );
1365 }
1366 10 my $field_types = join ", ", map {qq|"$_" => '$field_types{$_}'|} keys %field_types;
1367 10 my $fields = join ", ", map {qq|"$_" => $fields{$_}|} keys %fields;
1368 10 my $json_fields = join ", ", map {qq|"$_" => undef|} keys %json_fields;
1369 10 my $required = '';
1370 10 ▶ if (@required) {
Branch: 1 branch
BranchTrueFalseTotal
if (@required) 0 10 10
1371 0 $required = join(", ", map {qq|"$_"|} @required);
1372 }
1373 10 my $timestamps = '';
1374 10 ▶ if (@timestamp_fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (@timestamp_fields) { } 0 10 10
1375 0 $timestamps = join(", ", map {qq|"$_"|} @timestamp_fields);
1376 } else {
1377 10 $timestamps = "()";
1378 }
1379 10 my %keywords = (
1380 new => undef,
1381 set => undef,
1382 data => undef,
1383 delete => undef,
1384 fetch => undef,
1385 update => undef,
1386 DESTROY => undef,
1387 filter_timestamp => undef,
1388 );
1389 10 my $pk_row_data = '';
1390 10 my $pk_returninig = '';
1391 10 my $pk_where = '';
1392 10 my $select_keys = '';
1393 10 my %pk_fields;
1394 10 ▶ if (@pkeys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pkeys) { } 4 6 10
1395 4 @pk_fields{@pkeys} = undef;
1396 4 $pk_row_data = join(", ", map {qq|\$self->[@{[_row_data]}]->[$fields{"$_"}]|} @pkeys);
1397 4 $pk_returninig = 'returning ' . join(", ", @pkeys);
1398 4 $pk_where = join(" and ", map {"$_ = ?"} @pkeys);
1399 4 my $sk_list = join(", ", map {qq|"$_"|} @pkeys);
1400 4 $select_keys = <<SK;
1401 sub selectKeys () {
1402 ($sk_list)
1403 }
1404 SK
1405 } else {
1406 6 ▶ if (@fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fields) { } 2 4 6
1407 2 my $sk_list = join(", ", map {qq|"$_"|} @fields);
1408 2 $select_keys = <<SK;
1409 sub selectKeys () {
1410 ($sk_list)
1411 }
1412 SK
1413 } else {
1414 4 $select_keys = <<SK;
1415 sub selectKeys () { () }
1416 SK
1417 }
1418 }
1419 10 my $foreign_tables = '';
1420 10 my %foreign_tables;
1421 my %fkfuncs;
1422 10 for my $fk (@fkeys) {
1423 4 ▶ (my $pt = $fk->{PKTABLE_NAME} || $fk->{UK_TABLE_NAME}) =~ s/"//g;
Condition33%1/3
$fk->{'PKTABLE_NAME'} || $fk->{'UK_TABLE_NAME'}
l!l&&r!l&&!r
400
MC/DC0%0/2
$fk->{'PKTABLE_NAME'} || $fk->{'UK_TABLE_NAME'}
$fk->{'PKTABLE_NAME'} $fk->{'UK_TABLE_NAME'}
Truth table33%1/3
A || B
A= $fk->{'PKTABLE_NAME'}B= $fk->{'UK_TABLE_NAME'}
ABresult
1X1
011
000
1424 4 ▶ (my $pk = $fk->{PKCOLUMN_NAME} || $fk->{UK_COLUMN_NAME}) =~ s/"//g;
Condition33%1/3
$fk->{'PKCOLUMN_NAME'} || $fk->{'UK_COLUMN_NAME'}
l!l&&r!l&&!r
400
MC/DC0%0/2
$fk->{'PKCOLUMN_NAME'} || $fk->{'UK_COLUMN_NAME'}
$fk->{'PKCOLUMN_NAME'} $fk->{'UK_COLUMN_NAME'}
Truth table33%1/3
A || B
A= $fk->{'PKCOLUMN_NAME'}B= $fk->{'UK_COLUMN_NAME'}
ABresult
1X1
011
000
1425 4 my $fn = $pt;
1426 4 $fn =~ tr/_/-/;
1427 4 $fn =~ s/\b(\w)/\u$1/g;
1428 4 $fn =~ tr/-//d;
1429 4 $fk->{FK_COLUMN_NAME} =~ s/"//g;
1430 4 my $fn_suffix = $fk->{FK_COLUMN_NAME};
1431 4 ▶ $fn_suffix =~ s/^${pk}_*//i or $fn_suffix =~ s/_$pk(?=[^a-z]|$)//i or $fn_suffix =~ s/$pk(?=[^a-z]|$)//i;
Branch: 1 branch
BranchTrueFalseTotal
$fn_suffix =~ s/^${pk}_*//iu or $fn_suffix =~ s/_$pk(?=[^a-z]|$)//iu or $fn_suffix =~ s/$pk(?=[^a-z]|$)//iu 0 4 4
Condition33%1/3
$fn_suffix =~ s/^${pk}_*//iu or $fn_suffix =~ s/_$pk(?=[^a-z]|$)//iu
l!l&&r!l&&!r
400
MC/DC0%0/2
$fn_suffix =~ s/^${pk}_*//iu or $fn_suffix =~ s/_$pk(?=[^a-z]|$)//iu
$fn_suffix =~ s/^${pk}_*//iu $fn_suffix =~ s/_$pk(?=[^a-z]|$)//iu
Truth table33%1/3
A or B
A= $fn_suffix =~ s/^${pk}_*//iuB= $fn_suffix =~ s/_$pk(?=[^a-z]|$)//iu
ABresult
1X1
011
000
1432 4 $fn_suffix =~ tr/_/-/;
1433 4 $fn_suffix =~ s/\b(\w)/\u$1/g;
1434 4 $fn_suffix =~ tr/-//d;
1435 4 $fn_suffix =~ s/$fn//;
1436 4 $fn .= $fn_suffix;
1437 4 $fkfuncs{$fn} = undef;
1438 4 $foreign_tables .= <<FKT;
1439 sub $fn {
1440 if(CORE::defined(\$_[0]->$fk->{FK_COLUMN_NAME})) {
1441 return DBIx::Struct::one_row("$pt", {$pk => \$_[0]->$fk->{FK_COLUMN_NAME}});
1442 } else {
1443 return
1444 }
1445 }
1446 FKT
1447 4 $foreign_tables{$pt} = [$fk->{FK_COLUMN_NAME} => $pk];
1448 }
1449 10 for my $ft (keys %foreign_tables) {
1450 4 my $ucft = ucfirst $ft;
1451 4 $fkfuncs{"foreignKey$ucft"} = undef;
1452 4 $foreign_tables .= <<FKT;
1453 sub foreignKey$ucft () {("$foreign_tables{$ft}[0]" => "$foreign_tables{$ft}[1]")}
1454 FKT
1455 }
1456 10 my $references_tables = '';
1457 10 for my $rk (@refkeys) {
1458 4 $rk->{FK_TABLE_NAME} =~ s/"//g;
1459 4 my $ft = $rk->{FK_TABLE_NAME};
1460 4 (my $fk = $rk->{FK_COLUMN_NAME}) =~ s/"//g;
1461 4 ▶ (my $pt = $rk->{PKTABLE_NAME} || $rk->{UK_TABLE_NAME}) =~ s/"//g;
Condition33%1/3
$rk->{'PKTABLE_NAME'} || $rk->{'UK_TABLE_NAME'}
l!l&&r!l&&!r
400
MC/DC0%0/2
$rk->{'PKTABLE_NAME'} || $rk->{'UK_TABLE_NAME'}
$rk->{'PKTABLE_NAME'} $rk->{'UK_TABLE_NAME'}
Truth table33%1/3
A || B
A= $rk->{'PKTABLE_NAME'}B= $rk->{'UK_TABLE_NAME'}
ABresult
1X1
011
000
1462 4 ▶ (my $pk = $rk->{PKCOLUMN_NAME} || $rk->{UK_COLUMN_NAME}) =~ s/"//g;
Condition33%1/3
$rk->{'PKCOLUMN_NAME'} || $rk->{'UK_COLUMN_NAME'}
l!l&&r!l&&!r
400
MC/DC0%0/2
$rk->{'PKCOLUMN_NAME'} || $rk->{'UK_COLUMN_NAME'}
$rk->{'PKCOLUMN_NAME'} $rk->{'UK_COLUMN_NAME'}
Truth table33%1/3
A || B
A= $rk->{'PKCOLUMN_NAME'}B= $rk->{'UK_COLUMN_NAME'}
ABresult
1X1
011
000
1463 4 ▶ if ($pk ne $fk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pk ne $fk) 4 0 4
1464 4 my $fn = $fk;
1465 4 ▶ $fn =~ s/^${pk}_*//i or $fn =~ s/_$pk(?=[^a-z]|$)//i or $fn =~ s/$pk(?=[^a-z]|$)//i;
Branch: 1 branch
BranchTrueFalseTotal
$fn =~ s/^${pk}_*//iu or $fn =~ s/_$pk(?=[^a-z]|$)//iu or $fn =~ s/$pk(?=[^a-z]|$)//iu 0 4 4
Condition33%1/3
$fn =~ s/^${pk}_*//iu or $fn =~ s/_$pk(?=[^a-z]|$)//iu
l!l&&r!l&&!r
400
MC/DC0%0/2
$fn =~ s/^${pk}_*//iu or $fn =~ s/_$pk(?=[^a-z]|$)//iu
$fn =~ s/^${pk}_*//iu $fn =~ s/_$pk(?=[^a-z]|$)//iu
Truth table33%1/3
A or B
A= $fn =~ s/^${pk}_*//iuB= $fn =~ s/_$pk(?=[^a-z]|$)//iu
ABresult
1X1
011
000
1466 4 $fn =~ s/$pt//i;
1467 4 ▶ $ft .= "_$fn" if $fn;
Branch: 1 branch
BranchTrueFalseTotal
if $fn 0 4 4
1468 }
1469 4 $ft =~ tr/_/-/;
1470 4 $ft =~ s/\b(\w)/\u$1/g;
1471 4 $ft =~ tr/-//d;
1472 4 $fkfuncs{"ref${ft}s"} = undef;
1473 4 $fkfuncs{"ref${ft}"} = undef;
1474 4 $references_tables .= <<RT;
1475 sub ref${ft}s {
1476 my (\$self, \@cond) = \@_;
1477 my \%cond;
1478 if(\@cond) {
1479 if(not CORE::ref \$cond[0]) {
1480 \%cond = \@cond;
1481 } else {
1482 \%cond = \%{\$cond[0]};
1483 }
1484 }
1485 \$cond{$fk} = \$self->$pk;
1486 return DBIx::Struct::all_rows("$rk->{FK_TABLE_NAME}", \\\%cond);
1487 }
1488 sub ref${ft} {
1489 my (\$self, \@cond) = \@_;
1490 my \%cond;
1491 if(\@cond) {
1492 if(not CORE::ref \$cond[0]) {
1493 \%cond = \@cond;
1494 } else {
1495 \%cond = \%{\$cond[0]};
1496 }
1497 }
1498 \$cond{$fk} = \$self->$pk;
1499 return DBIx::Struct::one_row("$rk->{FK_TABLE_NAME}", \\\%cond);
1500 }
1501 RT
1502 }
1503 10 my $accessors = <<ACC;
1504 sub markUpdated {
1505 10 \$_[0]->[@{[_row_updates]}]{\$_[1]} = undef if CORE::exists \$fields{\$_[1]};
1506 \$_[0];
1507 }
1508 ACC
1509 10 for my $k (keys %fields) {
1510 20 ▶ next if exists $keywords{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $keywords{$k} 0 20 20
1511 20 ▶ next if $k =~ /^\d/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^\d/u 0 20 20
1512 20 $k =~ s/[^\w\d]/_/g;
1513 20 ▶ if (!exists $json_fields{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $json_fields{$k}) { } 20 0 20
1514 20 ▶ if (!exists($pk_fields{$k}) && (not ref $table)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $pk_fields{$k} || ref $table) { } 8 12 20
Condition100%3/3
exists $pk_fields{$k} || ref $table
l!l&&r!l&&!r
488
MC/DC100%2/2
exists $pk_fields{$k} || ref $table
exists $pk_fields{$k} ref $table
Truth table100%3/3
A || B
A= exists $pk_fields{$k}B= ref $table
ABresult
1X1
011
000
1515 8 $accessors .= <<ACC;
1516 sub _$k {
1517 if(\@_ > 1) {
1518 8 \$_[0]->[@{[_row_data]}]->[$fields{$k}] = \$_[1];
1519 }
1520 8 \$_[0]->[@{[_row_data]}]->[$fields{$k}];
1521 }
1522 sub $k {
1523 if(\@_ > 1) {
1524 8 \$_[0]->[@{[_row_data]}]->[$fields{$k}] = \$_[1];
1525 8 \$_[0]->[@{[_row_updates]}]{"$k"} = undef;
1526 }
1527 8 \$_[0]->[@{[_row_data]}]->[$fields{$k}];
1528 }
1529 ACC
1530 } else {
1531 12 $accessors .= <<ACC;
1532 sub $k {
1533 12 \$_[0]->[@{[_row_data]}]->[$fields{$k}];
1534 }
1535 ACC
1536 }
1537 } else {
1538 0 ▶ if (!exists($pk_fields{$k}) && (not ref $table)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $pk_fields{$k} || ref $table) { } 0 0 0
Condition0%0/3
exists $pk_fields{$k} || ref $table
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $pk_fields{$k} || ref $table
exists $pk_fields{$k} ref $table
Truth table0%0/3
A || B
A= exists $pk_fields{$k}B= ref $table
ABresult
1X1
011
000
1539 0 $accessors .= <<ACC;
1540 sub _$k {
1541 if(\@_ > 1) {
1542 if(not CORE::ref \$_[1]) {
1543 0 \$_[0]->[@{[_row_data]}]->[$fields{$k}] = \$_[1];
1544 } else {
1545 0 \$_[0]->[@{[_row_data]}]->[$fields{$k}] = JSON::to_json(\$_[1]);
1546 }
1547 }
1548 0 if(not CORE::ref \$_[0]->[@{[_row_data]}]->[$fields{$k}]) {
1549 0 \$_[0]->[@{[_row_updates]}] = {} if not \$_[0]->[@{[_row_updates]}];
1550 0 \$_[0]->[@{[_row_data]}]->[$fields{$k}] =
1551 0 DBIx::Struct::JSON->factory(\\\$_[0]->[@{[_row_data]}]->[$fields{$k}], \$_[0]->[@{[_row_updates]}], "$k");
1552 }
1553 0 \$_[0]->[@{[_row_data]}]->[$fields{$k}]->accessor;
1554 }
1555 sub $k {
1556 if(\@_ > 1) {
1557 if(not CORE::ref \$_[1]) {
1558 0 \$_[0]->[@{[_row_data]}]->[$fields{$k}] = \$_[1];
1559 } else {
1560 0 \$_[0]->[@{[_row_data]}]->[$fields{$k}] = JSON::to_json(\$_[1]);
1561 }
1562 0 \$_[0]->[@{[_row_updates]}]{"$k"} = undef;
1563 }
1564 0 if(not CORE::ref \$_[0]->[@{[_row_data]}]->[$fields{$k}]) {
1565 0 \$_[0]->[@{[_row_updates]}] = {} if not \$_[0]->[@{[_row_updates]}];
1566 0 \$_[0]->[@{[_row_data]}]->[$fields{$k}] =
1567 0 DBIx::Struct::JSON->factory(\\\$_[0]->[@{[_row_data]}]->[$fields{$k}], \$_[0]->[@{[_row_updates]}], "$k");
1568 }
1569 0 \$_[0]->[@{[_row_data]}]->[$fields{$k}]->accessor;
1570 }
1571 ACC
1572 } else {
1573 0 $accessors .= <<ACC;
1574 sub $k {
1575 0 if(\$_[0]->[@{[_row_data]}]->[$fields{$k}] and not CORE::ref \$_[0]->[@{[_row_data]}]->[$fields{$k}]) {
1576 0 \$_[0]->[@{[_row_data]}]->[$fields{$k}] = JSON::from_json(\$_[0]->[@{[_row_data]}]->[$fields{$k}]);
1577 }
1578 0 \$_[0]->[@{[_row_data]}]->[$fields{$k}];
1579 }
1580 ACC
1581 }
1582 }
1583 }
1584 10 my $package_header = <<PHD;
1585 package ${ncn};
1586 use strict;
1587 use warnings;
1588 use Carp;
1589 use SQL::Abstract;
1590 use JSON;
1591 use Scalar::Util 'blessed';
1592 use vars qw(\$AUTOLOAD);
1593 our \%field_types = ($field_types);
1594 our \%fields = ($fields);
1595 our \%json_fields = ($json_fields);
1596 PHD
1597 10 ▶ if (not ref $table) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $table) { } 6 4 10
1598 6 ▶ if (%fkfuncs) {
Branch: 1 branch
BranchTrueFalseTotal
if (%fkfuncs) { } 6 0 6
1599 6 my $fkfuncs = join ",", map {qq{"$_" => \\&${ncn}::$_}} keys %fkfuncs;
1600 6 $package_header .= <<PHD;
1601 our \%fkfuncs = ($fkfuncs);
1602 PHD
1603 } else {
1604 0 $package_header .= <<PHD;
1605 our \%fkfuncs = ();
1606 PHD
1607 }
1608 6 $package_header .= <<PHD;
1609 sub tableName () {"$table"}
1610 PHD
1611 } else {
1612 4 $package_header .= <<PHD;
1613 sub tableName () {"\\\$query\\\$$ncn"}
1614 PHD
1615 }
1616 10 my $new = make_object_new($table, $required, $pk_row_data, $pk_returninig);
1617 10 my $filter_timestamp = make_object_filter_timestamp($timestamps);
1618 10 my $set = make_object_set($table);
1619 10 my $data = make_object_data($table);
1620 10 my $update = make_object_update($table, $pk_where, $pk_row_data);
1621 10 my $delete = make_object_delete($table, $pk_where, $pk_row_data);
1622 10 my $fetch = make_object_fetch($table, $pk_where, $pk_row_data);
1623 10 my $autoload = make_object_autoload_find($table, $pk_where, $pk_row_data);
1624 10 my $to_json = make_object_to_json($table, \%field_types, \%fields);
1625 10 my $destroy;
1626  
1627 10 ▶ if (not ref $table) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $table) { } 6 4 10
1628 6 $destroy = <<DESTROY;
1629 sub DESTROY {
1630 no warnings 'once';
1631 \$_[0]->update if \$DBIx::Struct::update_on_destroy;
1632 }
1633 DESTROY
1634 } else {
1635 4 $destroy = '';
1636 }
1637 10 my $eval_code = join "", $package_header, $select_keys, $new,
1638 $set, $data, $fetch, $autoload, $to_json, $filter_timestamp,
1639 $update, $delete, $destroy, $accessors, $foreign_tables, $references_tables;
1640  
1641 # print $eval_code;
1642 2 ▶ eval $eval_code;
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine BEGIN: called CC=1 SCAR=4.2
Subroutine AUTOLOAD: not called CC=6 SCAR=32.1
Subroutine AUTOLOAD: not called CC=6 SCAR=32.1
Subroutine AUTOLOAD: not called CC=6 SCAR=32.1
Subroutine DESTROY: called CC=2 SCAR=14.1
Subroutine DESTROY: called CC=2 SCAR=14.1
Subroutine DESTROY: called CC=2 SCAR=14.1
Subroutine List: not called CC=2 SCAR=14.1
Subroutine Prim: called CC=2 SCAR=14.1
Subroutine TO_JSON: not called CC=6 SCAR=32.1
Subroutine TO_JSON: not called CC=6 SCAR=32.1
Subroutine TO_JSON: not called CC=6 SCAR=32.1
Subroutine TO_JSON: not called CC=6 SCAR=32.1
Subroutine TO_JSON: not called CC=6 SCAR=32.1
Subroutine TO_JSON: not called CC=6 SCAR=32.1
Subroutine TO_JSON: not called CC=6 SCAR=32.1
Subroutine __ANON__: not called CC=2 SCAR=14.1
Subroutine _id_list: not called CC=2 SCAR=14.1
Subroutine _id_prim: not called CC=2 SCAR=14.1
Subroutine _payload: not called CC=2 SCAR=14.1
Subroutine _ref: not called CC=2 SCAR=14.1
Subroutine _to_json_id: not called CC=2 SCAR=14.1
Subroutine _to_json_id: not called CC=2 SCAR=14.1
Subroutine _to_json_id: not called CC=2 SCAR=14.1
Subroutine _to_json_id: not called CC=2 SCAR=14.1
Subroutine _to_json_id: not called CC=2 SCAR=14.1
Subroutine _to_json_id: not called CC=2 SCAR=14.1
Subroutine _to_json_id_list: not called CC=2 SCAR=14.1
Subroutine _to_json_id_prim: not called CC=2 SCAR=14.1
Subroutine _to_json_payload: not called CC=2 SCAR=14.1
Subroutine _to_json_ref: not called CC=2 SCAR=14.1
Subroutine _to_json_ref: not called CC=2 SCAR=14.1
Subroutine _to_json_ref: not called CC=2 SCAR=14.1
Subroutine _to_json_ref: not called CC=2 SCAR=14.1
Subroutine _to_json_ref: not called CC=2 SCAR=14.1
Subroutine data: not called CC=8 SCAR=37.2
Subroutine data: not called CC=8 SCAR=37.2
Subroutine data: not called CC=8 SCAR=37.2
Subroutine data: not called CC=8 SCAR=37.2
Subroutine data: not called CC=8 SCAR=37.2
Subroutine data: not called CC=8 SCAR=37.2
Subroutine data: not called CC=8 SCAR=37.2
Subroutine delete: not called CC=7 SCAR=34.8
Subroutine delete: not called CC=7 SCAR=34.8
Subroutine delete: not called CC=7 SCAR=34.8
Subroutine delete: not called CC=7 SCAR=34.8
Subroutine delete: not called CC=7 SCAR=34.8
Subroutine delete: not called CC=7 SCAR=34.8
Subroutine delete: called CC=7 SCAR=34.8
Subroutine fetch: not called CC=3 SCAR=20.4
Subroutine fetch: not called CC=3 SCAR=20.4
Subroutine fetch: not called CC=3 SCAR=20.4
Subroutine fetch: not called CC=3 SCAR=20.4
Subroutine fetch: not called CC=3 SCAR=20.4
Subroutine fetch: not called CC=3 SCAR=20.4
Subroutine fetch: not called CC=3 SCAR=20.4
Subroutine filter_timestamp: not called CC=6 SCAR=32.1
Subroutine filter_timestamp: not called CC=6 SCAR=32.1
Subroutine filter_timestamp: not called CC=6 SCAR=32.1
Subroutine filter_timestamp: not called CC=6 SCAR=32.1
Subroutine filter_timestamp: not called CC=6 SCAR=32.1
Subroutine filter_timestamp: not called CC=6 SCAR=32.1
Subroutine filter_timestamp: not called CC=6 SCAR=32.1
Subroutine foreignKeyList: called CC=1 SCAR=4.2
Subroutine foreignKeyPrim: not called CC=1 SCAR=4.2
Subroutine id: called CC=1 SCAR=4.2
Subroutine id: called CC=1 SCAR=4.2
Subroutine id: not called CC=1 SCAR=4.2
Subroutine id: not called CC=1 SCAR=4.2
Subroutine id: not called CC=1 SCAR=4.2
Subroutine id: not called CC=1 SCAR=4.2
Subroutine id_list: not called CC=2 SCAR=14.1
Subroutine id_prim: called CC=2 SCAR=14.1
Subroutine markUpdated: not called CC=2 SCAR=14.1
Subroutine markUpdated: not called CC=2 SCAR=14.1
Subroutine markUpdated: not called CC=2 SCAR=14.1
Subroutine markUpdated: not called CC=2 SCAR=14.1
Subroutine markUpdated: not called CC=2 SCAR=14.1
Subroutine markUpdated: not called CC=2 SCAR=14.1
Subroutine markUpdated: not called CC=2 SCAR=14.1
Subroutine new: called CC=3 SCAR=20.4
Subroutine new: called CC=3 SCAR=20.4
Subroutine new: called CC=3 SCAR=20.4
Subroutine new: called CC=3 SCAR=20.4
Subroutine new: called CC=3 SCAR=20.4
Subroutine new: called CC=3 SCAR=20.4
Subroutine new: called CC=3 SCAR=20.4
Subroutine payload: called CC=2 SCAR=14.1
Subroutine ref: not called CC=1 SCAR=4.2
Subroutine ref: not called CC=1 SCAR=4.2
Subroutine ref: not called CC=1 SCAR=4.2
Subroutine ref: called CC=1 SCAR=4.2
Subroutine ref: not called CC=1 SCAR=4.2
Subroutine refPlAssoc: not called CC=3 SCAR=20.4
Subroutine refPlAssoc: called CC=3 SCAR=20.4
Subroutine refPlAssocs: not called CC=3 SCAR=20.4
Subroutine refPlAssocs: not called CC=3 SCAR=20.4
Subroutine selectKeys: not called CC=1 SCAR=4.2
Subroutine selectKeys: not called CC=1 SCAR=4.2
Subroutine selectKeys: not called CC=1 SCAR=4.2
Subroutine selectKeys: not called CC=1 SCAR=4.2
Subroutine selectKeys: not called CC=1 SCAR=4.2
Subroutine set: not called CC=10 SCAR=41.3
Subroutine set: not called CC=10 SCAR=41.3
Subroutine set: not called CC=10 SCAR=41.3
Subroutine set: not called CC=10 SCAR=41.3
Subroutine set: not called CC=10 SCAR=41.3
Subroutine set: not called CC=10 SCAR=41.3
Subroutine set: not called CC=10 SCAR=41.3
Subroutine update: called CC=1 SCAR=4.2
Subroutine update: called CC=1 SCAR=4.2
Subroutine update: called CC=1 SCAR=4.2
Subroutine update: called CC=1 SCAR=4.2
Subroutine update: called CC=1 SCAR=4.2
Subroutine update: not called CC=1 SCAR=4.2
Subroutine update: not called CC=1 SCAR=4.2
Branch: 326 branches
BranchTrueFalseTotal
if (builtin::blessed($self)) 0 0 0
unless $self and "$self"->can("tableName") and $method =~ /^find/u 0 0 0
if $@ 0 0 0
if (builtin::blessed($self)) 0 0 0
unless $self and "$self"->can("tableName") and $method =~ /^find/u 0 0 0
if $@ 0 0 0
if (builtin::blessed($self)) 0 0 0
unless $self and "$self"->can("tableName") and $method =~ /^find/u 0 0 0
if $@ 0 0 0
if $DBIx::Struct::update_on_destroy 5 0 5
if $DBIx::Struct::update_on_destroy 7 0 7
if $DBIx::Struct::update_on_destroy 5 0 5
if (defined $_[0]->id_list) { } 0 0 0
if (defined $_[0]->id_prim) { } 3 0 3
if (@columns) { } 0 0 0
unless exists $DBQ::G464b0f2c2fd3af9c8371c384bec897fb::fields{$_} 0 0 0
!defined($self->[0][0]) ? : 0 0 0
!defined($self->[0][1]) ? : 0 0 0
if (@refs) 0 0 0
if (@columns) { } 0 0 0
unless exists $DBQ::Gf38728c81f08225a5fb3e311a29988ae::fields{$_} 0 0 0
!defined($self->[0][1]) ? : 0 0 0
!defined($self->[0][0]) ? : 0 0 0
if (@refs) 0 0 0
if (@columns) { } 0 0 0
unless exists $DBC::List::fields{$_} 0 0 0
!defined($self->[0][1]) ? : 0 0 0
!defined($self->[0][0]) ? : 0 0 0
if (@refs) 0 0 0
if (@columns) { } 0 0 0
unless exists $DBQ::Gf9f056b2ce12853cb16e3c6a6b82cc10::fields{$_} 0 0 0
!defined($self->[0][0]) ? : 0 0 0
!defined($self->[0][1]) ? : 0 0 0
if (@refs) 0 0 0
if (@columns) { } 0 0 0
unless exists $DBC::Prim::fields{$_} 0 0 0
!defined($self->[0][0]) ? : 0 0 0
!defined($self->[0][1]) ? : 0 0 0
if (@refs) 0 0 0
if (@columns) { } 0 0 0
unless exists $DBQ::Ge98b53a1a872757fa223c9817aea8bc7::fields{$_} 0 0 0
!defined($self->[0][1]) ? : 0 0 0
!defined($self->[0][0]) ? : 0 0 0
if (@refs) 0 0 0
if (@columns) { } 0 0 0
unless exists $DBC::PlAssoc::fields{$_} 0 0 0
!defined($self->[0][1]) ? : 0 0 0
!defined($self->[0][0]) ? : 0 0 0
if (@refs) 0 0 0
my $rowref = $_->selectrow_arrayref("select * from pl_assoc where ", undef) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' fetching table pl_assoc'}) 0 0 0
$_->do($insert, undef, @bind) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' inserting into table pl_assoc'}) 0 0 0
my $rowref = $_->selectrow_arrayref("select * from list where id = ?", undef, $self->[0][0]) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' fetching table list'}) 0 0 0
$_->do("delete from pl_assoc where ", undef) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' updating table pl_assoc'}) 0 0 0
($self->[0][0]) = $_->selectrow_array($insert . ' returning id', undef, @bind) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' inserting into table list'}) 0 3 3
$_->do($update_query, undef, @bind, $self->[0][0]) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' updating table list', "query", $update_query, "bind", \@bind}) 0 3 3
($self->[0][0]) = $_->selectrow_array($insert . ' returning id', undef, @bind) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' inserting into table prim'}) 0 0 0
$_->do($update_query, undef, @bind, $self->[0][0]) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' updating table prim', "query", $update_query, "bind", \@bind}) 0 0 0
$_->do("delete from prim $where", @rpar) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' updating table prim'}) 0 0 0
$_->do($update_query, undef, @bind) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' updating table pl_assoc', "query", $update_query, "bind", \@bind}) 0 0 0
my $rowref = $_->selectrow_arrayref("select * from list $where", undef, @bind) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' fetching table list'}) 0 0 0
$_->do("delete from pl_assoc $where", @rpar) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' updating table pl_assoc'}) 0 0 0
$_->do("update prim set $set $where", undef, @bind, @bind_where) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' updating table prim'}) 0 0 0
$_->do("update pl_assoc set $set $where", undef, @bind, @bind_where) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' updating table pl_assoc'}) 0 0 0
$_->do("update list set $set $where", undef, @bind, @bind_where) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' updating table list'}) 0 1 1
$_->do("delete from list where id = ?", undef, $self->[0][0]) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' updating table list'}) 0 0 0
my $rowref = $_->selectrow_arrayref("select * from prim $where", undef, @bind) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' fetching table prim'}) 0 0 0
my $rowref = $_->selectrow_arrayref("select * from pl_assoc $where", undef, @bind) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' fetching table pl_assoc'}) 0 0 0
$_->do("delete from prim where id = ?", undef, $self->[0][0]) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' updating table prim'}) 0 0 0
my $rowref = $_->selectrow_arrayref("select * from prim where id = ?", undef, $self->[0][0]) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' fetching table prim'}) 0 0 0
$_->do("delete from list $where", @rpar) or &DBIx::Struct::error_message({"result", "SQLERR", "message", 'error ' . $_->errstr . ' updating table list'}) 0 1 1
if (@_ > 1) 0 0 0
if (@_ > 1) 0 0 0
if (@_ > 1) 0 0 0
if (@_ > 1) 0 0 0
!defined($self->[0][0]) ? : 0 0 0
!defined($self->[0][0]) ? : 0 0 0
!defined($self->[0][0]) ? : 0 0 0
!defined($self->[0][0]) ? : 0 0 0
!defined($self->[0][0]) ? : 0 0 0
!defined($self->[0][0]) ? : 0 0 0
!defined($self->[0][1]) ? : 0 0 0
!defined($self->[0][0]) ? : 0 0 0
!defined($self->[0][1]) ? : 0 0 0
!defined($self->[0][1]) ? : 0 0 0
!defined($self->[0][1]) ? : 0 0 0
!defined($self->[0][1]) ? : 0 0 0
!defined($self->[0][1]) ? : 0 0 0
!defined($self->[0][1]) ? : 0 0 0
if (defined $_[1]) { } 0 0 0
if (CORE::ref $_[1] eq 'ARRAY') { } 0 0 0
if (not @{$_[1];}) { } 0 0 0
if exists $DBQ::G464b0f2c2fd3af9c8371c384bec897fb::fields{$k} 0 0 0
if @unknown_columns 0 0 0
unless defined $ret 0 0 0
if (defined $_[1]) { } 0 0 0
if (ref $_[1] eq 'ARRAY') { } 0 0 0
if (not @{$_[1];}) { } 0 0 0
if exists $DBC::Prim::fields{$k} 0 0 0
if @unknown_columns 0 0 0
unless defined $ret 0 0 0
if (defined $_[1]) { } 0 0 0
if (CORE::ref $_[1] eq 'ARRAY') { } 0 0 0
if (not @{$_[1];}) { } 0 0 0
if exists $DBQ::Gf38728c81f08225a5fb3e311a29988ae::fields{$k} 0 0 0
if @unknown_columns 0 0 0
unless defined $ret 0 0 0
if (defined $_[1]) { } 0 0 0
if (CORE::ref $_[1] eq 'ARRAY') { } 0 0 0
if (not @{$_[1];}) { } 0 0 0
if exists $DBQ::Ge98b53a1a872757fa223c9817aea8bc7::fields{$k} 0 0 0
if @unknown_columns 0 0 0
unless defined $ret 0 0 0
if (defined $_[1]) { } 0 0 0
if (ref $_[1] eq 'ARRAY') { } 0 0 0
if (not @{$_[1];}) { } 0 0 0
if exists $DBC::PlAssoc::fields{$k} 0 0 0
if @unknown_columns 0 0 0
unless defined $ret 0 0 0
if (defined $_[1]) { } 0 0 0
if (CORE::ref $_[1] eq 'ARRAY') { } 0 0 0
if (not @{$_[1];}) { } 0 0 0
if exists $DBC::List::fields{$k} 0 0 0
if @unknown_columns 0 0 0
unless defined $ret 0 0 0
if (defined $_[1]) { } 0 0 0
if (CORE::ref $_[1] eq 'ARRAY') { } 0 0 0
if (not @{$_[1];}) { } 0 0 0
if exists $DBQ::Gf9f056b2ce12853cb16e3c6a6b82cc10::fields{$k} 0 0 0
if @unknown_columns 0 0 0
unless defined $ret 0 0 0
if (builtin::blessed($self)) 0 0 0
if @_ > 1 0 0 0
unless (ref $cond) 0 0 0
if ($i < @_) 0 0 0
unless defined $keys[$i - 1] 0 0 0
if ($cond) 0 0 0
if (builtin::blessed($self)) 0 0 0
if @_ > 1 0 0 0
unless (ref $cond) 0 0 0
if ($i < @_) 0 0 0
unless defined $keys[$i - 1] 0 0 0
if ($cond) 0 0 0
if (builtin::blessed($self)) 0 1 1
if @_ > 1 1 0 1
unless (CORE::ref $cond) 0 1 1
if ($i < @_) 0 0 0
unless defined $keys[$i - 1] 0 0 0
if ($cond) 1 0 1
if (@_ > 1) { } 0 0 0
unless (ref $cond) 0 0 0
if (@_ > 1) { } 0 0 0
unless (CORE::ref $cond) 0 0 0
if (@_ > 1) { } 0 0 0
unless (ref $cond) 0 0 0
if (@_ == 1) { } 0 0 0
if ($self->[0][$DBQ::Gf9f056b2ce12853cb16e3c6a6b82cc10::fields{$f}]) 0 0 0
if ($self->[0][$DBQ::Gf9f056b2ce12853cb16e3c6a6b82cc10::fields{$f}]) 0 0 0
if (@_ == 1) { } 0 0 0
if ($self->[0][$DBQ::Gf38728c81f08225a5fb3e311a29988ae::fields{$f}]) 0 0 0
if ($self->[0][$DBQ::Gf38728c81f08225a5fb3e311a29988ae::fields{$f}]) 0 0 0
if (@_ == 1) { } 0 0 0
if ($self->[0][$DBC::Prim::fields{$f}]) 0 0 0
if ($self->[0][$DBC::Prim::fields{$f}]) 0 0 0
if (@_ == 1) { } 0 0 0
if ($self->[0][$DBQ::G464b0f2c2fd3af9c8371c384bec897fb::fields{$f}]) 0 0 0
if ($self->[0][$DBQ::G464b0f2c2fd3af9c8371c384bec897fb::fields{$f}]) 0 0 0
if (@_ == 1) { } 0 0 0
if ($self->[0][$DBQ::Ge98b53a1a872757fa223c9817aea8bc7::fields{$f}]) 0 0 0
if ($self->[0][$DBQ::Ge98b53a1a872757fa223c9817aea8bc7::fields{$f}]) 0 0 0
if (@_ == 1) { } 0 0 0
if ($self->[0][$DBC::PlAssoc::fields{$f}]) 0 0 0
if ($self->[0][$DBC::PlAssoc::fields{$f}]) 0 0 0
if (@_ == 1) { } 0 0 0
if ($self->[0][$DBC::List::fields{$f}]) 0 0 0
if ($self->[0][$DBC::List::fields{$f}]) 0 0 0
if (@_ > 1) 0 0 0
if (@_ > 1) 0 6 6
if exists $DBQ::Gf9f056b2ce12853cb16e3c6a6b82cc10::fields{$_[1]} 0 0 0
if exists $DBC::PlAssoc::fields{$_[1]} 0 0 0
if exists $DBC::Prim::fields{$_[1]} 0 0 0
if exists $DBC::List::fields{$_[1]} 0 0 0
if exists $DBQ::G464b0f2c2fd3af9c8371c384bec897fb::fields{$_[1]} 0 0 0
if exists $DBQ::Ge98b53a1a872757fa223c9817aea8bc7::fields{$_[1]} 0 0 0
if exists $DBQ::Gf38728c81f08225a5fb3e311a29988ae::fields{$_[1]} 0 0 0
if (defined $_[1] and ref $_[1] eq 'ARRAY') { } 4 0 4
if ($i < @_) 0 0 0
if (exists $DBC::PlAssoc::fields{$_[$i]}) { } 0 0 0
if (ref $insert{$_} eq 'ARRAY' and ref $insert{$_}[0] eq 'SCALAR') { } 0 0 0
elsif (ref $insert{$_} eq 'REF' and ref ${$insert{$_};} eq 'ARRAY') { } 0 0 0
elsif (ref $insert{$_} eq 'SCALAR') { } 0 0 0
elsif (exists $DBC::PlAssoc::json_fields{$_} and ref $insert{$_} eq 'ARRAY' || ref $insert{$_} eq 'HASH') { } 0 0 0
if (defined ${$insert{$_};}->[0]) { } 0 0 0
if (%insert) { } 0 0 0
if (defined $_[1] and CORE::ref $_[1] eq "ARRAY") 2 0 2
if (defined $_[1] and CORE::ref $_[1] eq "ARRAY") 3 0 3
if (defined $_[1] and ref $_[1] eq 'ARRAY') { } 3 0 3
if ($i < @_) 0 0 0
if (exists $DBC::Prim::fields{$_[$i]}) { } 0 0 0
if (ref $insert{$_} eq 'ARRAY' and ref $insert{$_}[0] eq 'SCALAR') { } 0 0 0
elsif (ref $insert{$_} eq 'REF' and ref ${$insert{$_};} eq 'ARRAY') { } 0 0 0
elsif (ref $insert{$_} eq 'SCALAR') { } 0 0 0
elsif (exists $DBC::Prim::json_fields{$_} and ref $insert{$_} eq 'ARRAY' || ref $insert{$_} eq 'HASH') { } 0 0 0
if (defined ${$insert{$_};}->[0]) { } 0 0 0
if (%insert) { } 0 0 0
if (defined $_[1] and CORE::ref $_[1] eq 'ARRAY') { } 3 3 6
if ($i < @_) 3 3 6
if (exists $DBC::List::fields{$_[$i]}) { } 3 0 3
if (CORE::ref $insert{$_} eq 'ARRAY' and CORE::ref $insert{$_}[0] eq 'SCALAR') { } 1 2 3
elsif (CORE::ref $insert{$_} eq 'REF' and CORE::ref ${$insert{$_};} eq 'ARRAY') { } 0 2 2
elsif (CORE::ref $insert{$_} eq 'SCALAR') { } 1 1 2
elsif (exists $DBC::List::json_fields{$_} and CORE::ref $insert{$_} eq 'ARRAY' || CORE::ref $insert{$_} eq 'HASH') { } 0 1 1
if (defined ${$insert{$_};}->[0]) { } 0 0 0
if (%insert) { } 3 0 3
if (defined $_[1] and CORE::ref $_[1] eq "ARRAY") 1 0 1
if (defined $_[1] and CORE::ref $_[1] eq "ARRAY") 1 0 1
if (@_ > 1) 0 1 1
if (@_ > 1) 3 1 4
if (@cond) 0 0 0
if (not ref $cond[0]) { } 0 0 0
if (@cond) 0 5 5
if (not CORE::ref $cond[0]) { } 0 0 0
if (@cond) 0 0 0
if (not CORE::ref $cond[0]) { } 0 0 0
if (@cond) 0 0 0
if (not ref $cond[0]) { } 0 0 0
if (defined $_[1]) 0 0 0
if (CORE::ref $_[1] eq 'ARRAY') { } 0 0 0
elsif (CORE::ref $_[1] eq 'HASH') { } 0 0 0
elsif (not CORE::ref $_[1]) { } 0 0 0
if (exists $DBQ::Ge98b53a1a872757fa223c9817aea8bc7::fields{$f}) { } 0 0 0
if ($i < @_) 0 0 0
if (exists $DBQ::Ge98b53a1a872757fa223c9817aea8bc7::fields{$_[$i]}) { } 0 0 0
if @unknown_columns 0 0 0
if (defined $_[1]) 0 0 0
if (ref $_[1] eq 'ARRAY') { } 0 0 0
elsif (ref $_[1] eq 'HASH') { } 0 0 0
elsif (not ref $_[1]) { } 0 0 0
if (exists $DBC::PlAssoc::fields{$f}) { } 0 0 0
if ($i < @_) 0 0 0
if (exists $DBC::PlAssoc::fields{$_[$i]}) { } 0 0 0
if @unknown_columns 0 0 0
if (defined $_[1]) 0 0 0
if (CORE::ref $_[1] eq 'ARRAY') { } 0 0 0
elsif (CORE::ref $_[1] eq 'HASH') { } 0 0 0
elsif (not CORE::ref $_[1]) { } 0 0 0
if (exists $DBQ::Gf38728c81f08225a5fb3e311a29988ae::fields{$f}) { } 0 0 0
if ($i < @_) 0 0 0
if (exists $DBQ::Gf38728c81f08225a5fb3e311a29988ae::fields{$_[$i]}) { } 0 0 0
if @unknown_columns 0 0 0
if (defined $_[1]) 0 0 0
if (CORE::ref $_[1] eq 'ARRAY') { } 0 0 0
elsif (CORE::ref $_[1] eq 'HASH') { } 0 0 0
elsif (not CORE::ref $_[1]) { } 0 0 0
if (exists $DBQ::Gf9f056b2ce12853cb16e3c6a6b82cc10::fields{$f}) { } 0 0 0
if ($i < @_) 0 0 0
if (exists $DBQ::Gf9f056b2ce12853cb16e3c6a6b82cc10::fields{$_[$i]}) { } 0 0 0
if @unknown_columns 0 0 0
if (defined $_[1]) 0 0 0
if (ref $_[1] eq 'ARRAY') { } 0 0 0
elsif (ref $_[1] eq 'HASH') { } 0 0 0
elsif (not ref $_[1]) { } 0 0 0
if (exists $DBC::Prim::fields{$f}) { } 0 0 0
if ($i < @_) 0 0 0
if (exists $DBC::Prim::fields{$_[$i]}) { } 0 0 0
if @unknown_columns 0 0 0
if (defined $_[1]) 0 0 0
if (CORE::ref $_[1] eq 'ARRAY') { } 0 0 0
elsif (CORE::ref $_[1] eq 'HASH') { } 0 0 0
elsif (not CORE::ref $_[1]) { } 0 0 0
if (exists $DBQ::G464b0f2c2fd3af9c8371c384bec897fb::fields{$f}) { } 0 0 0
if ($i < @_) 0 0 0
if (exists $DBQ::G464b0f2c2fd3af9c8371c384bec897fb::fields{$_[$i]}) { } 0 0 0
if @unknown_columns 0 0 0
if (defined $_[1]) 0 0 0
if (CORE::ref $_[1] eq 'ARRAY') { } 0 0 0
elsif (CORE::ref $_[1] eq 'HASH') { } 0 0 0
elsif (not CORE::ref $_[1]) { } 0 0 0
if (exists $DBC::List::fields{$f}) { } 0 0 0
if ($i < @_) 0 0 0
if (exists $DBC::List::fields{$_[$i]}) { } 0 0 0
if @unknown_columns 0 0 0
if (@_ > 1 and ref $_[1] eq 'HASH') { } 0 7 7
elsif (ref $self and @$self > 1 and %{$self->[1];}) { } 0 14 14
if @unknown_columns 0 0 0
if (ref $set_hash{$_} eq 'ARRAY' and ref $set_hash{$_}[0] eq 'SCALAR') { } 0 0 0
elsif (ref $set_hash{$_} eq 'REF' and ref ${$set_hash{$_};} eq 'ARRAY') { } 0 0 0
elsif (ref $set_hash{$_} eq 'SCALAR') { } 0 0 0
elsif (exists $json_fields{$_} and ref $set_hash{$_} eq 'ARRAY' || ref $set_hash{$_} eq 'HASH') { } 0 0 0
if (defined ${$set_hash{$_};}->[0]) { } 0 0 0
if (@_ > 2) 0 0 0
unless (ref $cond) 0 0 0
if (ref $column_value eq 'ARRAY' and ref $column_value->[0] eq 'SCALAR') { } 0 0 0
elsif (ref $column_value eq 'REF' and ref ${$column_value;} eq 'ARRAY') { } 0 0 0
elsif (ref $column_value and ref($column_value) =~ /^DBIx::Struct::JSON/u) { } 0 0 0
elsif (ref $column_value eq 'SCALAR') { } 0 0 0
if (defined ${$column_value;}->[0]) { } 0 0 0
if (@_ > 1 and ref $_[1] eq 'HASH') { } 0 4 4
elsif (ref $self and @$self > 1 and %{$self->[1];}) { } 0 8 8
if @unknown_columns 0 0 0
if (ref $set_hash{$_} eq 'ARRAY' and ref $set_hash{$_}[0] eq 'SCALAR') { } 0 0 0
elsif (ref $set_hash{$_} eq 'REF' and ref ${$set_hash{$_};} eq 'ARRAY') { } 0 0 0
elsif (ref $set_hash{$_} eq 'SCALAR') { } 0 0 0
elsif (exists $json_fields{$_} and ref $set_hash{$_} eq 'ARRAY' || ref $set_hash{$_} eq 'HASH') { } 0 0 0
if (defined ${$set_hash{$_};}->[0]) { } 0 0 0
if (@_ > 2) 0 0 0
unless (ref $cond) 0 0 0
if (ref $column_value eq 'ARRAY' and ref $column_value->[0] eq 'SCALAR') { } 0 0 0
elsif (ref $column_value eq 'REF' and ref ${$column_value;} eq 'ARRAY') { } 0 0 0
elsif (ref $column_value and ref($column_value) =~ /^DBIx::Struct::JSON/u) { } 0 0 0
elsif (ref $column_value eq 'SCALAR') { } 0 0 0
if (defined ${$column_value;}->[0]) { } 0 0 0
if (@_ > 1 and CORE::ref $_[1] eq 'HASH') { } 1 9 10
elsif (CORE::ref $self and @$self > 1 and %{$self->[1];}) { } 3 12 15
if @unknown_columns 0 1 1
if (CORE::ref $set_hash{$_} eq 'ARRAY' and CORE::ref $set_hash{$_}[0] eq 'SCALAR') { } 0 1 1
elsif (CORE::ref $set_hash{$_} eq 'REF' and CORE::ref ${$set_hash{$_};} eq 'ARRAY') { } 0 1 1
elsif (CORE::ref $set_hash{$_} eq 'SCALAR') { } 0 1 1
elsif (exists $json_fields{$_} and CORE::ref $set_hash{$_} eq 'ARRAY' || CORE::ref $set_hash{$_} eq 'HASH') { } 0 1 1
if (defined ${$set_hash{$_};}->[0]) { } 0 0 0
if (@_ > 2) 1 0 1
unless (CORE::ref $cond) 0 1 1
if (CORE::ref $column_value eq 'ARRAY' and CORE::ref $column_value->[0] eq 'SCALAR') { } 1 2 3
elsif (CORE::ref $column_value eq 'REF' and CORE::ref ${$column_value;} eq 'ARRAY') { } 0 2 2
elsif (CORE::ref $column_value and CORE::ref($column_value) =~ /^DBIx::Struct::JSON/u) { } 0 2 2
elsif (CORE::ref $column_value eq 'SCALAR') { } 1 1 2
if (defined ${$column_value;}->[0]) { } 0 0 0
Condition19%32/165
$self and "$self"->can("tableName") and $method =~ /^find/u
!ll&&!rl&&r
000
$self and "$self"->can("tableName")
!ll&&!rl&&r
000
$self and "$self"->can("tableName") and $method =~ /^find/u
!ll&&!rl&&r
000
$self and "$self"->can("tableName")
!ll&&!rl&&r
000
$self and "$self"->can("tableName") and $method =~ /^find/u
!ll&&!rl&&r
000
$self and "$self"->can("tableName")
!ll&&!rl&&r
000
defined $_[1] and ref $_[1] eq "ARRAY"
!ll&&!rl&&r
004
ref $insert{$_} eq "ARRAY" and ref $insert{$_}[0] eq "SCALAR"
!ll&&!rl&&r
000
ref $insert{$_} eq "REF" and ref ${$insert{$_};} eq "ARRAY"
!ll&&!rl&&r
000
exists $DBC::PlAssoc::json_fields{$_} and ref $insert{$_} eq "ARRAY" || ref $insert{$_} eq "HASH"
!ll&&!rl&&r
000
ref $insert{$_} eq "ARRAY" or ref $insert{$_} eq "HASH"
l!l&&r!l&&!r
000
defined $_[1] and CORE::ref $_[1] eq "ARRAY"
!ll&&!rl&&r
002
defined $_[1] and CORE::ref $_[1] eq "ARRAY"
!ll&&!rl&&r
003
defined $_[1] and ref $_[1] eq "ARRAY"
!ll&&!rl&&r
003
ref $insert{$_} eq "ARRAY" and ref $insert{$_}[0] eq "SCALAR"
!ll&&!rl&&r
000
ref $insert{$_} eq "REF" and ref ${$insert{$_};} eq "ARRAY"
!ll&&!rl&&r
000
exists $DBC::Prim::json_fields{$_} and ref $insert{$_} eq "ARRAY" || ref $insert{$_} eq "HASH"
!ll&&!rl&&r
000
ref $insert{$_} eq "ARRAY" or ref $insert{$_} eq "HASH"
l!l&&r!l&&!r
000
defined $_[1] and CORE::ref $_[1] eq "ARRAY"
!ll&&!rl&&r
033
CORE::ref $insert{$_} eq "ARRAY" and CORE::ref $insert{$_}[0] eq "SCALAR"
!ll&&!rl&&r
201
CORE::ref $insert{$_} eq "REF" and CORE::ref ${$insert{$_};} eq "ARRAY"
!ll&&!rl&&r
200
exists $DBC::List::json_fields{$_} and CORE::ref $insert{$_} eq "ARRAY" || CORE::ref $insert{$_} eq "HASH"
!ll&&!rl&&r
100
CORE::ref $insert{$_} eq "ARRAY" or CORE::ref $insert{$_} eq "HASH"
l!l&&r!l&&!r
000
defined $_[1] and CORE::ref $_[1] eq "ARRAY"
!ll&&!rl&&r
001
defined $_[1] and CORE::ref $_[1] eq "ARRAY"
!ll&&!rl&&r
001
@_ > 1 and ref $_[1] eq "HASH"
!ll&&!rl&&r
700
ref $set_hash{$_} eq "ARRAY" and ref $set_hash{$_}[0] eq "SCALAR"
!ll&&!rl&&r
000
ref $set_hash{$_} eq "REF" and ref ${$set_hash{$_};} eq "ARRAY"
!ll&&!rl&&r
000
exists $json_fields{$_} and ref $set_hash{$_} eq "ARRAY" || ref $set_hash{$_} eq "HASH"
!ll&&!rl&&r
000
ref $set_hash{$_} eq "ARRAY" or ref $set_hash{$_} eq "HASH"
l!l&&r!l&&!r
000
ref $self and @$self > 1 and %{$self->[1];}
!ll&&!rl&&r
700
ref $self and @$self > 1
!ll&&!rl&&r
070
ref $column_value eq "ARRAY" and ref $column_value->[0] eq "SCALAR"
!ll&&!rl&&r
000
ref $column_value eq "REF" and ref ${$column_value;} eq "ARRAY"
!ll&&!rl&&r
000
ref $column_value and ref($column_value) =~ /^DBIx::Struct::JSON/u
!ll&&!rl&&r
000
@_ > 1 and ref $_[1] eq "HASH"
!ll&&!rl&&r
400
ref $set_hash{$_} eq "ARRAY" and ref $set_hash{$_}[0] eq "SCALAR"
!ll&&!rl&&r
000
ref $set_hash{$_} eq "REF" and ref ${$set_hash{$_};} eq "ARRAY"
!ll&&!rl&&r
000
exists $json_fields{$_} and ref $set_hash{$_} eq "ARRAY" || ref $set_hash{$_} eq "HASH"
!ll&&!rl&&r
000
ref $set_hash{$_} eq "ARRAY" or ref $set_hash{$_} eq "HASH"
l!l&&r!l&&!r
000
ref $self and @$self > 1 and %{$self->[1];}
!ll&&!rl&&r
400
ref $self and @$self > 1
!ll&&!rl&&r
040
ref $column_value eq "ARRAY" and ref $column_value->[0] eq "SCALAR"
!ll&&!rl&&r
000
ref $column_value eq "REF" and ref ${$column_value;} eq "ARRAY"
!ll&&!rl&&r
000
ref $column_value and ref($column_value) =~ /^DBIx::Struct::JSON/u
!ll&&!rl&&r
000
@_ > 1 and CORE::ref $_[1] eq "HASH"
!ll&&!rl&&r
901
CORE::ref $set_hash{$_} eq "ARRAY" and CORE::ref $set_hash{$_}[0] eq "SCALAR"
!ll&&!rl&&r
100
CORE::ref $set_hash{$_} eq "REF" and CORE::ref ${$set_hash{$_};} eq "ARRAY"
!ll&&!rl&&r
100
exists $json_fields{$_} and CORE::ref $set_hash{$_} eq "ARRAY" || CORE::ref $set_hash{$_} eq "HASH"
!ll&&!rl&&r
100
CORE::ref $set_hash{$_} eq "ARRAY" or CORE::ref $set_hash{$_} eq "HASH"
l!l&&r!l&&!r
000
CORE::ref $self and @$self > 1 and %{$self->[1];}
!ll&&!rl&&r
603
CORE::ref $self and @$self > 1
!ll&&!rl&&r
063
CORE::ref $column_value eq "ARRAY" and CORE::ref $column_value->[0] eq "SCALAR"
!ll&&!rl&&r
201
CORE::ref $column_value eq "REF" and CORE::ref ${$column_value;} eq "ARRAY"
!ll&&!rl&&r
200
CORE::ref $column_value and CORE::ref($column_value) =~ /^DBIx::Struct::JSON/u
!ll&&!rl&&r
110
MC/DC0%0/3
$self and "$self"->can("tableName") and $method =~ /^find/u
$self "$self"->can("tableName") $method =~ /^find/u
MC/DC0%0/3
$self and "$self"->can("tableName") and $method =~ /^find/u
$self "$self"->can("tableName") $method =~ /^find/u
MC/DC0%0/3
$self and "$self"->can("tableName") and $method =~ /^find/u
$self "$self"->can("tableName") $method =~ /^find/u
MC/DC0%0/2
defined $_[1] and ref $_[1] eq "ARRAY"
defined $_[1] ref $_[1] eq "ARRAY"
MC/DC0%0/2
ref $insert{$_} eq "ARRAY" and ref $insert{$_}[0] eq "SCALAR"
ref $insert{$_} eq "ARRAY" ref $insert{$_}[0] eq "SCALAR"
MC/DC0%0/2
ref $insert{$_} eq "REF" and ref ${$insert{$_};} eq "ARRAY"
ref $insert{$_} eq "REF" ref ${$insert{$_};} eq "ARRAY"
MC/DC0%0/3
exists $DBC::PlAssoc::json_fields{$_} and ref $insert{$_} eq "ARRAY" || ref $insert{$_} eq "HASH"
exists $DBC::PlAssoc::json_fields{$_} ref $insert{$_} eq "ARRAY" ref $insert{$_} eq "HASH"
MC/DC0%0/2
defined $_[1] and CORE::ref $_[1] eq "ARRAY"
defined $_[1] CORE::ref $_[1] eq "ARRAY"
MC/DC0%0/2
defined $_[1] and CORE::ref $_[1] eq "ARRAY"
defined $_[1] CORE::ref $_[1] eq "ARRAY"
MC/DC0%0/2
defined $_[1] and ref $_[1] eq "ARRAY"
defined $_[1] ref $_[1] eq "ARRAY"
MC/DC0%0/2
ref $insert{$_} eq "ARRAY" and ref $insert{$_}[0] eq "SCALAR"
ref $insert{$_} eq "ARRAY" ref $insert{$_}[0] eq "SCALAR"
MC/DC0%0/2
ref $insert{$_} eq "REF" and ref ${$insert{$_};} eq "ARRAY"
ref $insert{$_} eq "REF" ref ${$insert{$_};} eq "ARRAY"
MC/DC0%0/3
exists $DBC::Prim::json_fields{$_} and ref $insert{$_} eq "ARRAY" || ref $insert{$_} eq "HASH"
exists $DBC::Prim::json_fields{$_} ref $insert{$_} eq "ARRAY" ref $insert{$_} eq "HASH"
MC/DC50%1/2
defined $_[1] and CORE::ref $_[1] eq "ARRAY"
defined $_[1] CORE::ref $_[1] eq "ARRAY"
MC/DC50%1/2
CORE::ref $insert{$_} eq "ARRAY" and CORE::ref $insert{$_}[0] eq "SCALAR"
CORE::ref $insert{$_} eq "ARRAY" CORE::ref $insert{$_}[0] eq "SCALAR"
MC/DC0%0/2
CORE::ref $insert{$_} eq "REF" and CORE::ref ${$insert{$_};} eq "ARRAY"
CORE::ref $insert{$_} eq "REF" CORE::ref ${$insert{$_};} eq "ARRAY"
MC/DC0%0/3
exists $DBC::List::json_fields{$_} and CORE::ref $insert{$_} eq "ARRAY" || CORE::ref $insert{$_} eq "HASH"
exists $DBC::List::json_fields{$_} CORE::ref $insert{$_} eq "ARRAY" CORE::ref $insert{$_} eq "HASH"
MC/DC0%0/2
defined $_[1] and CORE::ref $_[1] eq "ARRAY"
defined $_[1] CORE::ref $_[1] eq "ARRAY"
MC/DC0%0/2
defined $_[1] and CORE::ref $_[1] eq "ARRAY"
defined $_[1] CORE::ref $_[1] eq "ARRAY"
MC/DC0%0/2
@_ > 1 and ref $_[1] eq "HASH"
@_ > 1 ref $_[1] eq "HASH"
MC/DC0%0/2
ref $set_hash{$_} eq "ARRAY" and ref $set_hash{$_}[0] eq "SCALAR"
ref $set_hash{$_} eq "ARRAY" ref $set_hash{$_}[0] eq "SCALAR"
MC/DC0%0/2
ref $set_hash{$_} eq "REF" and ref ${$set_hash{$_};} eq "ARRAY"
ref $set_hash{$_} eq "REF" ref ${$set_hash{$_};} eq "ARRAY"
MC/DC0%0/3
exists $json_fields{$_} and ref $set_hash{$_} eq "ARRAY" || ref $set_hash{$_} eq "HASH"
exists $json_fields{$_} ref $set_hash{$_} eq "ARRAY" ref $set_hash{$_} eq "HASH"
MC/DC0%0/3
ref $self and @$self > 1 and %{$self->[1];}
ref $self @$self > 1 %{$self->[1];}
MC/DC0%0/2
ref $column_value eq "ARRAY" and ref $column_value->[0] eq "SCALAR"
ref $column_value eq "ARRAY" ref $column_value->[0] eq "SCALAR"
MC/DC0%0/2
ref $column_value eq "REF" and ref ${$column_value;} eq "ARRAY"
ref $column_value eq "REF" ref ${$column_value;} eq "ARRAY"
MC/DC0%0/2
ref $column_value and ref($column_value) =~ /^DBIx::Struct::JSON/u
ref $column_value ref($column_value) =~ /^DBIx::Struct::JSON/u
MC/DC0%0/2
@_ > 1 and ref $_[1] eq "HASH"
@_ > 1 ref $_[1] eq "HASH"
MC/DC0%0/2
ref $set_hash{$_} eq "ARRAY" and ref $set_hash{$_}[0] eq "SCALAR"
ref $set_hash{$_} eq "ARRAY" ref $set_hash{$_}[0] eq "SCALAR"
MC/DC0%0/2
ref $set_hash{$_} eq "REF" and ref ${$set_hash{$_};} eq "ARRAY"
ref $set_hash{$_} eq "REF" ref ${$set_hash{$_};} eq "ARRAY"
MC/DC0%0/3
exists $json_fields{$_} and ref $set_hash{$_} eq "ARRAY" || ref $set_hash{$_} eq "HASH"
exists $json_fields{$_} ref $set_hash{$_} eq "ARRAY" ref $set_hash{$_} eq "HASH"
MC/DC0%0/3
ref $self and @$self > 1 and %{$self->[1];}
ref $self @$self > 1 %{$self->[1];}
MC/DC0%0/2
ref $column_value eq "ARRAY" and ref $column_value->[0] eq "SCALAR"
ref $column_value eq "ARRAY" ref $column_value->[0] eq "SCALAR"
MC/DC0%0/2
ref $column_value eq "REF" and ref ${$column_value;} eq "ARRAY"
ref $column_value eq "REF" ref ${$column_value;} eq "ARRAY"
MC/DC0%0/2
ref $column_value and ref($column_value) =~ /^DBIx::Struct::JSON/u
ref $column_value ref($column_value) =~ /^DBIx::Struct::JSON/u
MC/DC50%1/2
@_ > 1 and CORE::ref $_[1] eq "HASH"
@_ > 1 CORE::ref $_[1] eq "HASH"
MC/DC0%0/2
CORE::ref $set_hash{$_} eq "ARRAY" and CORE::ref $set_hash{$_}[0] eq "SCALAR"
CORE::ref $set_hash{$_} eq "ARRAY" CORE::ref $set_hash{$_}[0] eq "SCALAR"
MC/DC0%0/2
CORE::ref $set_hash{$_} eq "REF" and CORE::ref ${$set_hash{$_};} eq "ARRAY"
CORE::ref $set_hash{$_} eq "REF" CORE::ref ${$set_hash{$_};} eq "ARRAY"
MC/DC0%0/3
exists $json_fields{$_} and CORE::ref $set_hash{$_} eq "ARRAY" || CORE::ref $set_hash{$_} eq "HASH"
exists $json_fields{$_} CORE::ref $set_hash{$_} eq "ARRAY" CORE::ref $set_hash{$_} eq "HASH"
MC/DC33%1/3
CORE::ref $self and @$self > 1 and %{$self->[1];}
CORE::ref $self @$self > 1 %{$self->[1];}
MC/DC50%1/2
CORE::ref $column_value eq "ARRAY" and CORE::ref $column_value->[0] eq "SCALAR"
CORE::ref $column_value eq "ARRAY" CORE::ref $column_value->[0] eq "SCALAR"
MC/DC0%0/2
CORE::ref $column_value eq "REF" and CORE::ref ${$column_value;} eq "ARRAY"
CORE::ref $column_value eq "REF" CORE::ref ${$column_value;} eq "ARRAY"
MC/DC0%0/2
CORE::ref $column_value and CORE::ref($column_value) =~ /^DBIx::Struct::JSON/u
CORE::ref $column_value CORE::ref($column_value) =~ /^DBIx::Struct::JSON/u
Truth table0%0/4
A and B and C
A= $selfB= "$self"->can("tableName")C= $method =~ /^find/u
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= $selfB= "$self"->can("tableName")C= $method =~ /^find/u
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= $selfB= "$self"->can("tableName")C= $method =~ /^find/u
ABCresult
0XX0
10X0
1100
1111
Truth table33%1/3
A and B
A= defined $_[1]B= ref $_[1] eq "ARRAY"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $insert{$_} eq "ARRAY"B= ref $insert{$_}[0] eq "SCALAR"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $insert{$_} eq "REF"B= ref ${$insert{$_};} eq "ARRAY"
ABresult
0X0
100
111
Truth table0%0/4
A and B or C
A= exists $DBC::PlAssoc::json_fields{$_}B= ref $insert{$_} eq "ARRAY"C= ref $insert{$_} eq "HASH"
ABCresult
0XX0
1000
11X1
1011
Truth table33%1/3
A and B
A= defined $_[1]B= CORE::ref $_[1] eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $_[1]B= CORE::ref $_[1] eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $_[1]B= ref $_[1] eq "ARRAY"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $insert{$_} eq "ARRAY"B= ref $insert{$_}[0] eq "SCALAR"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $insert{$_} eq "REF"B= ref ${$insert{$_};} eq "ARRAY"
ABresult
0X0
100
111
Truth table0%0/4
A and B or C
A= exists $DBC::Prim::json_fields{$_}B= ref $insert{$_} eq "ARRAY"C= ref $insert{$_} eq "HASH"
ABCresult
0XX0
1000
11X1
1011
Truth table66%2/3
A and B
A= defined $_[1]B= CORE::ref $_[1] eq "ARRAY"
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= CORE::ref $insert{$_} eq "ARRAY"B= CORE::ref $insert{$_}[0] eq "SCALAR"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= CORE::ref $insert{$_} eq "REF"B= CORE::ref ${$insert{$_};} eq "ARRAY"
ABresult
0X0
100
111
Truth table25%1/4
A and B or C
A= exists $DBC::List::json_fields{$_}B= CORE::ref $insert{$_} eq "ARRAY"C= CORE::ref $insert{$_} eq "HASH"
ABCresult
0XX0
1000
11X1
1011
Truth table33%1/3
A and B
A= defined $_[1]B= CORE::ref $_[1] eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $_[1]B= CORE::ref $_[1] eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= @_ > 1B= ref $_[1] eq "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $set_hash{$_} eq "ARRAY"B= ref $set_hash{$_}[0] eq "SCALAR"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $set_hash{$_} eq "REF"B= ref ${$set_hash{$_};} eq "ARRAY"
ABresult
0X0
100
111
Truth table0%0/4
A and B or C
A= exists $json_fields{$_}B= ref $set_hash{$_} eq "ARRAY"C= ref $set_hash{$_} eq "HASH"
ABCresult
0XX0
1000
11X1
1011
Truth table25%1/4
A and B and C
A= ref $selfB= @$self > 1C= %{$self->[1];}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A and B
A= ref $column_value eq "ARRAY"B= ref $column_value->[0] eq "SCALAR"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $column_value eq "REF"B= ref ${$column_value;} eq "ARRAY"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $column_valueB= ref($column_value) =~ /^DBIx::Struct::JSON/u
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= @_ > 1B= ref $_[1] eq "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $set_hash{$_} eq "ARRAY"B= ref $set_hash{$_}[0] eq "SCALAR"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $set_hash{$_} eq "REF"B= ref ${$set_hash{$_};} eq "ARRAY"
ABresult
0X0
100
111
Truth table0%0/4
A and B or C
A= exists $json_fields{$_}B= ref $set_hash{$_} eq "ARRAY"C= ref $set_hash{$_} eq "HASH"
ABCresult
0XX0
1000
11X1
1011
Truth table25%1/4
A and B and C
A= ref $selfB= @$self > 1C= %{$self->[1];}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A and B
A= ref $column_value eq "ARRAY"B= ref $column_value->[0] eq "SCALAR"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $column_value eq "REF"B= ref ${$column_value;} eq "ARRAY"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $column_valueB= ref($column_value) =~ /^DBIx::Struct::JSON/u
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= @_ > 1B= CORE::ref $_[1] eq "HASH"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= CORE::ref $set_hash{$_} eq "ARRAY"B= CORE::ref $set_hash{$_}[0] eq "SCALAR"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= CORE::ref $set_hash{$_} eq "REF"B= CORE::ref ${$set_hash{$_};} eq "ARRAY"
ABresult
0X0
100
111
Truth table25%1/4
A and B or C
A= exists $json_fields{$_}B= CORE::ref $set_hash{$_} eq "ARRAY"C= CORE::ref $set_hash{$_} eq "HASH"
ABCresult
0XX0
1000
11X1
1011
Truth table50%2/4
A and B and C
A= CORE::ref $selfB= @$self > 1C= %{$self->[1];}
ABCresult
0XX0
10X0
1100
1111
Truth table66%2/3
A and B
A= CORE::ref $column_value eq "ARRAY"B= CORE::ref $column_value->[0] eq "SCALAR"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= CORE::ref $column_value eq "REF"B= CORE::ref ${$column_value;} eq "ARRAY"
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= CORE::ref $column_valueB= CORE::ref($column_value) =~ /^DBIx::Struct::JSON/u
ABresult
0X0
100
111
1643 10 ▶ error_message {
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 10 10
1644 result => 'SQLERR',
1645 message => "Unknown error: $@",
1646 } if $@;
1647 10 ▶ if ($interface) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interface) 0 10 10
1648 0 my $ifuncs = _parse_interface $interface;
1649 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1650 0 for my $f (keys %$ifuncs) {
1651 0 *{"${ncn}::$f"} = $ifuncs->{$f};
1652 }
1653 }
1654 10 '' =~ /()/;
1655 10 return $ncn;
1656 }
1657  
1658 3 my %cache_complex_query;
1659 3 my $json_canonical = JSON->new->canonical->convert_blessed;
1660  
1661 sub _cached_complex_query {
1662 4 ▶ my $key = $json_canonical->encode(\@_);
Subroutine _cached_complex_query: called CC=3 SCAR=12.3
1663 4 my ($ret, $is_one_column);
1664 4 ▶ if (exists $cache_complex_query{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cache_complex_query{$key}) { } 0 4 4
1665 0 ($ret, $is_one_column) = @{$cache_complex_query{$key}};
1666 } else {
1667 4 ($ret, $is_one_column) = _build_complex_query(@_);
1668 4 $cache_complex_query{$key} = [($ret, $is_one_column)];
1669 }
1670 4 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 4 0 4
1671 4 return ($ret, $is_one_column);
1672 } else {
1673 0 return $ret;
1674 }
1675 }
1676  
1677 sub _table_name() {0}
1678 sub _table_alias() {1}
1679 sub _table_join() {2}
1680 sub _table_join_on() {3}
1681  
1682 3 my $sql_abstract = SQL::Abstract->new;
1683 3 my $tblnum;
1684  
1685 sub _build_complex_query {
1686 4 ▶ my ($table, $query_bind, $where) = @_;
Subroutine _build_complex_query: called CC=73 SCAR=61.3
1687 4 ▶ return $table if not ref $table;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $table 0 4 4
1688 4 my @from;
1689 my @columns;
1690 4 ▶ my @linked_list = (
Branch: 1 branch
BranchTrueFalseTotal
ref $table eq 'ARRAY' ? : 4 0 4
1691 ref($table) eq 'ARRAY'
1692 ? @$table
1693 : error_message {
1694 result => 'SQLERR',
1695 message => "Unsupported type of query: " . ref($table)
1696 }
1697 );
1698 4 my ($conditions, $groupby, $having, $limit, $offset, $orderby);
1699 4 my $one_column = 0;
1700 4 my $distinct = 0;
1701 4 my $count = 0;
1702 4 my $all = 0;
1703  
1704 4 ▶ for (my $i = 0; $i < @linked_list; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @linked_list) 11 4 15
1705 11 my $le = $linked_list[$i];
1706 11 ▶ if ('ARRAY' eq ref $le) {
Branch: 1 branch
BranchTrueFalseTotal
if ("ARRAY" eq ref $le) 0 11 11
1707 0 my $subfrom = _build_complex_query($le, $query_bind);
1708 0 my $ta = "t$tblnum";
1709 0 ++$tblnum;
1710 0 push @from, ["($subfrom)", $ta];
1711 0 next;
1712 }
1713 11 ▶ if (substr($le, 0, 1) ne '-') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($le, 0, 1) ne '-') { } 5 6 11
1714 5 my ($tn, $ta) = split ' ', $le;
1715 5 ▶ $ta = $tn if not $ta;
Branch: 1 branch
BranchTrueFalseTotal
unless $ta 5 0 5
1716 5 my $ncn = make_name($tn);
1717 5 $ncn = _schema_name($ncn);
1718 5 ▶ error_message {
Branch: 1 branch
BranchTrueFalseTotal
unless setup_row($tn, $ncn) 0 5 5
1719 result => 'SQLERR',
1720 message => "Unknown table $tn"
1721 }
1722 unless setup_row($tn, $ncn);
1723 5 push @from, [$tn, $ta];
1724 } else {
1725 6 my $cmd = substr($le, 1);
1726 6 ▶ if ($cmd eq 'left') {
Branch: 13 branches
BranchTrueFalseTotal
if ($cmd eq 'left') { } 0 6 6
elsif ($cmd eq 'right') { } 0 6 6
elsif ($cmd eq 'join') { } 1 5 6
elsif ($cmd eq 'on') { } 0 5 5
elsif ($cmd eq 'using') { } 0 5 5
elsif ($cmd eq 'as') { } 0 5 5
elsif ($cmd eq 'where') { } 0 5 5
elsif ($cmd eq 'group_by') { } 0 5 5
elsif ($cmd eq 'order_by') { } 0 5 5
elsif ($cmd eq 'having') { } 0 5 5
elsif ($cmd eq 'limit') { } 0 5 5
elsif ($cmd eq 'offset') { } 0 5 5
elsif ($cmd eq 'columns' or $cmd eq 'column' or $cmd eq 'distinct' or $cmd eq 'count' or $cmd eq 'all') { } 5 0 5
1727 0 $from[-1][_table_join] = 'left join';
1728 } elsif ($cmd eq 'right') {
1729 0 $from[-1][_table_join] = 'right join';
1730 } elsif ($cmd eq 'join') {
1731 1 $from[-1][_table_join] = 'join';
1732 } elsif ($cmd eq 'on') {
1733 0 $from[-1][_table_join_on] = ["on", $linked_list[++$i]];
1734 } elsif ($cmd eq 'using') {
1735 0 $from[-1][_table_join_on] = ["using", $linked_list[++$i]];
1736 } elsif ($cmd eq 'as') {
1737 0 $from[-1][_table_alias] = $linked_list[++$i];
1738 } elsif ($cmd eq 'where') {
1739 0 $conditions = $linked_list[++$i];
1740 } elsif ($cmd eq 'group_by') {
1741 0 $groupby = $linked_list[++$i];
1742 } elsif ($cmd eq 'order_by') {
1743 0 $orderby = $linked_list[++$i];
1744 } elsif ($cmd eq 'having') {
1745 0 $having = $linked_list[++$i];
1746 } elsif ($cmd eq 'limit') {
1747 0 $limit = 0 + $linked_list[++$i];
1748 } elsif ($cmd eq 'offset') {
1749 0 $offset = 0 + $linked_list[++$i];
1750 ▶ } elsif ($cmd eq 'columns'
Condition66%8/12
$cmd eq "columns" or $cmd eq "column" or $cmd eq "distinct" or $cmd eq "count" or $cmd eq "all"
l!l&&r!l&&!r
500
$cmd eq "columns" or $cmd eq "column" or $cmd eq "distinct" or $cmd eq "count"
l!l&&r!l&&!r
320
$cmd eq "columns" or $cmd eq "column" or $cmd eq "distinct"
l!l&&r!l&&!r
212
$cmd eq "columns" or $cmd eq "column"
l!l&&r!l&&!r
203
MC/DC0%0/5
$cmd eq "columns" or $cmd eq "column" or $cmd eq "distinct" or $cmd eq "count" or $cmd eq "all"
$cmd eq "columns" $cmd eq "column" $cmd eq "distinct" $cmd eq "count" $cmd eq "all"
Truth table50%3/6
A or B or C or D or E
A= $cmd eq "columns"B= $cmd eq "column"C= $cmd eq "distinct"D= $cmd eq "count"E= $cmd eq "all"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1751 || $cmd eq 'column'
1752 || $cmd eq 'distinct'
1753 || $cmd eq 'count'
1754 || $cmd eq 'all')
1755 {
1756 5 ▶ if ($cmd eq 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "all") 0 5 5
1757 0 $all = 1;
1758 }
1759 5 ▶ if ($cmd eq 'distinct') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "distinct") 1 4 5
1760 1 $distinct = 1;
1761 }
1762 5 ▶ if ($cmd eq 'count') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "count") 2 3 5
1763 2 $count = 1;
1764 }
1765 5 ▶ if ($i + 1 < @linked_list && substr($linked_list[$i + 1], 0, 1) ne '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($i + 1 < @linked_list and substr($linked_list[$i + 1], 0, 1) ne "-") 4 1 5
Condition66%2/3
$i + 1 < @linked_list and substr($linked_list[$i + 1], 0, 1) ne "-"
!ll&&!rl&&r
014
MC/DC50%1/2
$i + 1 < @linked_list and substr($linked_list[$i + 1], 0, 1) ne "-"
$i + 1 < @linked_list substr($linked_list[$i + 1], 0, 1) ne "-"
Truth table66%2/3
A and B
A= $i + 1 < @linked_listB= substr($linked_list[$i + 1], 0, 1) ne "-"
ABresult
0X0
100
111
1766 4 my $cols = $linked_list[++$i];
1767 4 ▶ if ($cols && $cols !~ /^\d|^true$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cols and not $cols =~ /^\d|^true$/u) { } 2 2 4
elsif ($cols =~ /^\d+$/u and $cols == 0 or $cols eq '') { } 0 2 2
Condition66%2/3
$cols and not $cols =~ /^\d|^true$/u
!ll&&!rl&&r
022
MC/DC50%1/2
$cols and not $cols =~ /^\d|^true$/u
$cols not $cols =~ /^\d|^true$/u
Truth table66%2/3
A and not(B)
A= $colsB= not $cols =~ /^\d|^true$/u
ABresult
0X0
100
111
1768 2 ▶ if ('ARRAY' eq ref($cols)) {
Branch: 1 branch
BranchTrueFalseTotal
if ('ARRAY' eq ref $cols) { } 0 2 2
1769 0 push @columns, @$cols;
1770 } else {
1771 2 push @columns, $cols;
1772 }
1773 ▶ } elsif (($cols =~ /^\d+$/ && $cols == 0) || $cols eq '') {
Condition33%2/6
$cols =~ /^\d+$/u and $cols == 0 or $cols eq ""
l!l&&r!l&&!r
002
$cols =~ /^\d+$/u and $cols == 0
!ll&&!rl&&r
020
MC/DC0%0/3
$cols =~ /^\d+$/u and $cols == 0 or $cols eq ""
$cols =~ /^\d+$/u $cols == 0 $cols eq ""
Truth table20%1/5
A and B or C
A= $cols =~ /^\d+$/uB= $cols == 0C= $cols eq ""
ABCresult
11X1
0X11
1011
0X00
1000
1774 0 ▶ $distinct = 0 if $cmd eq 'distinct';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "distinct" 0 0 0
1775 }
1776 }
1777 5 ▶ if ($cmd eq 'column') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq 'column') { } 0 5 5
1778 0 ++$one_column;
1779 } else {
1780 5 $one_column += 2;
1781 }
1782  
1783 } else {
1784 0 error_message {
1785 result => 'SQLERR',
1786 message => "Unknown directive $le"
1787 };
1788 }
1789 }
1790 }
1791 4 ▶ error_message {
Branch: 1 branch
BranchTrueFalseTotal
unless @from 0 4 4
1792 result => 'SQLERR',
1793 message => "No table to build query on"
1794 } if !@from;
1795 4 ▶ for (my $idx = 1; $idx < @from; ++$idx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < @from) 1 4 5
1796 1 ▶ next if $from[$idx][_table_join_on] or not $from[$idx - 1][_table_join];
Branch: 1 branch
BranchTrueFalseTotal
if $from[$idx][3] or not $from[$idx - 1][2] 0 1 1
Condition33%1/3
$from[$idx][3] or not $from[$idx - 1][2]
l!l&&r!l&&!r
001
MC/DC0%0/2
$from[$idx][3] or not $from[$idx - 1][2]
$from[$idx][3] not $from[$idx - 1][2]
Truth table33%1/3
A or not(B)
A= $from[$idx][3]B= not $from[$idx - 1][2]
ABresult
1X1
011
000
1797 1 ▶ next if substr($from[$idx][_table_name], 0, 1) eq "(";
Branch: 1 branch
BranchTrueFalseTotal
if substr($from[$idx][0], 0, 1) eq "(" 0 1 1
1798 1 my $cta = $from[$idx][_table_alias];
1799 1 my $cto = make_name($from[$idx][_table_name]);
1800 1 my $ucct = ucfirst $from[$idx][_table_name];
1801 1 my @join;
1802 1 ▶ for (my $i = $idx - 1; $i >= 0; --$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 1 1 2
1803 1 ▶ next if not $from[$i][_table_join];
Branch: 1 branch
BranchTrueFalseTotal
unless $from[$i][2] 0 1 1
1804 1 my $ptn = $from[$i][_table_name];
1805 1 ▶ next if substr($ptn, 0, 1) eq "(";
Branch: 1 branch
BranchTrueFalseTotal
if substr($ptn, 0, 1) eq "(" 0 1 1
1806 1 my $ucfptn = ucfirst $ptn;
1807 1 ▶ if ($cto->can("foreignKey$ucfptn")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cto->can("foreignKey$ucfptn")) { } 1 0 1
1808 1 my $fkfn = "foreignKey$ucfptn";
1809 1 my ($ctf, $ptk) = $cto->$fkfn;
1810 1 push @join, "$cta.$ctf = " . $from[$i][_table_alias] . ".$ptk";
1811 } else {
1812 0 my $ptno = make_name($ptn);
1813 0 ▶ if ($ptno->can("foreignKey$ucct")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ptno->can("foreignKey$ucct")) 0 0 0
1814 0 my $fkfn = "foreignKey$ucct";
1815 0 my ($ptf, $ctk) = $ptno->$fkfn;
1816 0 push @join, "$cta.$ctk = " . $from[$i][_table_alias] . ".$ptf";
1817 }
1818 }
1819 }
1820 1 $from[$idx][_table_join_on] = ["on", join(" and ", @join)];
1821 }
1822 4 my $from = '';
1823 4 ▶ @columns = ('*') if not @columns;
Branch: 1 branch
BranchTrueFalseTotal
unless @columns 2 2 4
1824 4 ▶ @columns = map {('SCALAR' eq ref) ? DBIx::Struct::connect->dbh->quote_identifier($$_) : $_} @columns;
Branch: 1 branch
BranchTrueFalseTotal
'SCALAR' eq ref $_ ? : 0 4 4
1825 4 my $joined = 0;
1826 4 ▶ for (my $idx = 0; $idx < @from; ++$idx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < @from) 5 4 9
1827 5 ▶ if (not $joined) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($joined) 4 1 5
1828 4 $from .= " " . $from[$idx][_table_name];
1829 4 ▶ $from .= " " . $from[$idx][_table_alias] if $from[$idx][_table_alias] ne $from[$idx][_table_name];
Branch: 1 branch
BranchTrueFalseTotal
if $from[$idx][1] ne $from[$idx][0] 0 4 4
1830 }
1831 5 ▶ if ($from[$idx][_table_join]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from[$idx][2]) { } 1 4 5
1832 1 my $nt = $from[$idx + 1];
1833 1 $from .= " " . $from[$idx][_table_join];
1834 1 $from .= " " . $nt->[_table_name];
1835 1 ▶ $from .= " " . $nt->[_table_alias] if $nt->[_table_alias] ne $nt->[_table_name];
Branch: 1 branch
BranchTrueFalseTotal
if $nt->[1] ne $nt->[0] 0 1 1
1836 1 my $using_on = $nt->[_table_join_on][0];
1837 1 ▶ if ($using_on eq 'on' and ref $nt->[_table_join_on][1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($using_on eq 'on' and ref $nt->[3][1]) { } 0 1 1
Condition33%1/3
$using_on eq "on" and ref $nt->[3][1]
!ll&&!rl&&r
010
MC/DC0%0/2
$using_on eq "on" and ref $nt->[3][1]
$using_on eq "on" ref $nt->[3][1]
Truth table33%1/3
A and B
A= $using_on eq "on"B= ref $nt->[3][1]
ABresult
0X0
100
111
1838 0 my ($on_where, @on_bind) = $sql_abstract->where($nt->[_table_join_on][1]);
1839 0 $on_where =~ s/WHERE //;
1840 0 push @$query_bind, @on_bind;
1841 0 $from .= " $using_on(" . $on_where . ")";
1842 } else {
1843 1 $from .= " $using_on(" . $nt->[_table_join_on][1] . ")";
1844 }
1845 1 $joined = 1;
1846 } else {
1847 4 ▶ $from .= "," if $idx != $#from;
Branch: 1 branch
BranchTrueFalseTotal
if $idx != $#from 0 4 4
1848 4 $joined = 0;
1849 }
1850 }
1851 4 my $what = join(", ", @columns);
1852 4 ▶ if ($count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count) { } 2 2 4
1853 2 $one_column = 1;
1854 2 ▶ if ($distinct) {
Branch: 2 branches
BranchTrueFalseTotal
if ($distinct) { } 1 1 2
elsif ($all) { } 0 1 1
1855 1 ▶ $what = $from[0][_table_alias] . ".*" if $what eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "*" 1 0 1
1856 1 $what = "count(distinct $what)";
1857 } elsif ($all) {
1858 0 ▶ $what = $from[0][_table_alias] . ".*" if $what eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "*" 0 0 0
1859 0 $what = "count(all $what)";
1860 } else {
1861 1 $what = "count(*)";
1862 }
1863 } else {
1864 2 ▶ if ($distinct) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distinct) 0 2 2
1865 0 $what = "distinct $what";
1866 }
1867 }
1868 4 my $ret = "select $what from" . $from;
1869 4 ▶ if (not defined $where) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $where) 0 4 4
1870 0 my $sql_grp = _parse_groupby($groupby);
1871 0 my $having_bind = [];
1872 0 ▶ if ($sql_grp && defined $having) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sql_grp and defined $having) 0 0 0
Condition0%0/3
$sql_grp and defined $having
!ll&&!rl&&r
000
MC/DC0%0/2
$sql_grp and defined $having
$sql_grp defined $having
Truth table0%0/3
A and B
A= $sql_grpB= defined $having
ABresult
0X0
100
111
1873 0 my $sql_having;
1874 0 ($sql_having, $having_bind) = _parse_having($having);
1875 0 $sql_grp .= " $sql_having";
1876 }
1877 0 ▶ if ($conditions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conditions) { } 0 0 0
1878 0 my @where_bind;
1879 0 ($where, @where_bind) = $sql_abstract->where($conditions);
1880 0 push @$query_bind, @where_bind;
1881 } else {
1882 0 $where = '';
1883 }
1884 0 ▶ if (defined $sql_grp) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sql_grp) 0 0 0
1885 0 $where .= " $sql_grp";
1886 0 push @$query_bind, @$having_bind;
1887 }
1888 0 ▶ $where .= " limit $limit" if defined $limit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $limit 0 0 0
1889 0 ▶ $where .= " offset $offset" if $offset;
Branch: 1 branch
BranchTrueFalseTotal
if $offset 0 0 0
1890 }
1891 4 ▶ $ret .= " $where" if $where;
Branch: 1 branch
BranchTrueFalseTotal
if $where 0 4 4
1892 4 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 4 0 4
1893 4 return ($ret, $one_column == 1);
1894 } else {
1895 0 return $ret;
1896 }
1897 }
1898  
1899 sub _parse_groupby {
1900 20 ▶ my $groupby = $_[0];
Subroutine _parse_groupby: called CC=5 SCAR=16.4
1901 20 my $sql_grp;
1902 20 ▶ if (defined $groupby) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $groupby) 2 18 20
1903 2 $sql_grp = "GROUP BY ";
1904 my @groupby =
1905 2 ▶ map {/^\d+$/ ? $_ : /^[a-z][\w ]*$/i ? "\"$_\"" : "$_"} (ref($groupby) ? @$groupby : ($groupby));
Branch: 3 branches
BranchTrueFalseTotal
/^\d+$/u ? : 0 2 2
/^[a-z][\w ]*$/iu ? : 2 0 2
ref $groupby ? : 0 2 2
1906 2 $sql_grp .= join(", ", @groupby);
1907 }
1908 20 $sql_grp;
1909 }
1910  
1911 sub _parse_having {
1912 2 ▶ my $having = $_[0];
Subroutine _parse_having: called CC=2 SCAR=7.0
1913 2 my $sql_having;
1914 my @having_bind;
1915 2 ▶ if (defined $having) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $having) 2 0 2
1916 2 ($sql_having, @having_bind) = $sql_abstract->where($having);
1917 2 $sql_having =~ s/\bWHERE\b/HAVING/;
1918 }
1919 2 ($sql_having, \@having_bind);
1920 }
1921  
1922 sub execute {
1923 20 ▶ my ($groupby, $having, $up_conditions, $up_order, $up_limit, $up_offset, $up_interface, $sql, $dry_run);
Subroutine execute: called CC=39 SCAR=46.2
Pod undocumented
1924 20 my $distinct = '';
1925 20 ▶ for (my $i = 2; $i < @_; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_) 18 20 38
1926 18 ▶ next unless defined $_[$i] and not ref $_[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[$i] and not ref $_[$i] 10 8 18
Condition66%2/3
defined $_[$i] and not ref $_[$i]
!ll&&!rl&&r
0108
MC/DC50%1/2
defined $_[$i] and not ref $_[$i]
defined $_[$i] not ref $_[$i]
Truth table66%2/3
A and not(B)
A= defined $_[$i]B= not ref $_[$i]
ABresult
0X0
100
111
1927 8 ▶ if ($_[$i] eq '-group_by') {
Branch: 11 branches
BranchTrueFalseTotal
if ($_[$i] eq '-group_by') { } 2 6 8
elsif ($_[$i] eq '-distinct') { } 0 6 6
elsif ($_[$i] eq '-having') { } 2 4 6
elsif ($_[$i] eq '-order_by') { } 0 4 4
elsif ($_[$i] eq '-where') { } 0 4 4
elsif ($_[$i] eq '-limit') { } 0 4 4
elsif ($_[$i] eq '-interface') { } 0 4 4
elsif ($_[$i] eq '-offset') { } 0 4 4
elsif ($_[$i] eq '-sql') { } 0 4 4
elsif ($_[$i] eq '-dry_run') { } 0 4 4
elsif (substr($_[$i], 0, 1) eq '-') { } 0 4 4
1928 2 (undef, $groupby) = splice @_, $i, 2;
1929 2 --$i;
1930 } elsif ($_[$i] eq '-distinct') {
1931 0 $distinct = ' distinct';
1932 0 splice @_, $i, 1;
1933 0 --$i;
1934 } elsif ($_[$i] eq '-having') {
1935 2 (undef, $having) = splice @_, $i, 2;
1936 2 --$i;
1937 } elsif ($_[$i] eq '-order_by') {
1938 0 (undef, $up_order) = splice @_, $i, 2;
1939 0 --$i;
1940 } elsif ($_[$i] eq '-where') {
1941 0 (undef, $up_conditions) = splice @_, $i, 2;
1942 0 --$i;
1943 } elsif ($_[$i] eq '-limit') {
1944 0 (undef, $up_limit) = splice @_, $i, 2;
1945 0 --$i;
1946 } elsif ($_[$i] eq '-interface') {
1947 0 (undef, $up_interface) = splice @_, $i, 2;
1948 0 --$i;
1949 } elsif ($_[$i] eq '-offset') {
1950 0 (undef, $up_offset) = splice @_, $i, 2;
1951 0 --$i;
1952 } elsif ($_[$i] eq '-sql') {
1953 0 (undef, $sql) = splice @_, $i, 2;
1954 0 --$i;
1955 } elsif ($_[$i] eq '-dry_run') {
1956 0 (undef, $dry_run) = splice @_, $i, 2;
1957 0 --$i;
1958 } elsif (substr($_[$i], 0, 1) eq '-') {
1959 0 error_message {
1960 result => 'SQLERR',
1961 message => "Unknown directive $_[$i]"
1962 };
1963 }
1964 }
1965 20 $tblnum = 1;
1966 20 my $sql_grp = _parse_groupby($groupby);
1967 20 my $having_bind = [];
1968 20 ▶ if ($sql_grp && defined $having) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sql_grp and defined $having) 2 18 20
Condition66%2/3
$sql_grp and defined $having
!ll&&!rl&&r
1802
MC/DC50%1/2
$sql_grp and defined $having
$sql_grp defined $having
Truth table66%2/3
A and B
A= $sql_grpB= defined $having
ABresult
0X0
100
111
1969 2 my $sql_having;
1970 2 ($sql_having, $having_bind) = _parse_having($having);
1971 2 $sql_grp .= " $sql_having";
1972 }
1973 20 my ($code, $table, $conditions, $order, $limit, $offset) = @_;
1974 20 my $have_conditions = @_ > 2;
1975 20 ▶ $conditions //= $up_conditions;
Condition66%2/3
$conditions //= $up_conditions
l!l&&r!l&&!r
1406
MC/DC50%1/2
$conditions //= $up_conditions
$conditions $up_conditions
Truth table66%2/3
A //= B
A= $conditionsB= $up_conditions
ABresult
1X1
011
000
1976 20 ▶ $order //= $up_order;
Condition33%1/3
$order //= $up_order
l!l&&r!l&&!r
0020
MC/DC0%0/2
$order //= $up_order
$order $up_order
Truth table33%1/3
A //= B
A= $orderB= $up_order
ABresult
1X1
011
000
1977 20 ▶ $limit //= $up_limit;
Condition33%1/3
$limit //= $up_limit
l!l&&r!l&&!r
0020
MC/DC0%0/2
$limit //= $up_limit
$limit $up_limit
Truth table33%1/3
A //= B
A= $limitB= $up_limit
ABresult
1X1
011
000
1978 20 ▶ $offset //= $up_offset;
Condition33%1/3
$offset //= $up_offset
l!l&&r!l&&!r
0020
MC/DC0%0/2
$offset //= $up_offset
$offset $up_offset
Truth table33%1/3
A //= B
A= $offsetB= $up_offset
ABresult
1X1
011
000
1979 20 my $where;
1980 20 my $need_where = 0;
1981 20 my @where_bind;
1982 20 ▶ my $simple_table = (not ref $table and index($table, " ") == -1);
Condition100%3/3
!ref($table) && index($table, ' ') == -1
!ll&&!rl&&r
4115
MC/DC100%2/2
!ref($table) && index($table, ' ') == -1
!ref($table) index($table, ' ') == -1
Truth table100%3/3
not(A) && B
A= !ref($table)B= index($table, ' ') == -1
ABresult
0X0
100
111
1983 20 my $ncn;
1984  
1985 20 ▶ if ($simple_table) {
Branch: 1 branch
BranchTrueFalseTotal
if ($simple_table) { } 15 5 20
1986 15 $ncn = make_name($table);
1987 15 $ncn = _schema_name($ncn);
1988 15 setup_row($table, $ncn);
1989 15 ▶ if ($have_conditions and not ref $conditions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_conditions and not ref $conditions) { } 4 11 15
Condition100%3/3
$have_conditions and not ref $conditions
!ll&&!rl&&r
1104
MC/DC100%2/2
$have_conditions and not ref $conditions
$have_conditions not ref $conditions
Truth table100%3/3
A and not(B)
A= $have_conditionsB= not ref $conditions
ABresult
0X0
100
111
1990 4 ▶ my $id = ($ncn->selectKeys())[0]
Branch: 1 branch
BranchTrueFalseTotal
my $id = ($ncn->selectKeys)[0] or &error_message({"result", "SQLERR", "message", "unknown primary key", "query", "select * from $table"}) 0 4 4
1991 or error_message {
1992 result => 'SQLERR',
1993 message => "unknown primary key",
1994 query => "select * from $table",
1995 };
1996 4 ▶ if (defined $conditions) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $conditions) { } 4 0 4
1997 4 $where = "where $id = ?";
1998 4 @where_bind = ($conditions);
1999 } else {
2000 0 $where = "where $id is null";
2001 }
2002 } else {
2003 11 $need_where = 1;
2004 }
2005 } else {
2006 5 $need_where = 1;
2007 }
2008 20 ▶ if ($need_where) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_where) 16 4 20
2009 16 ($where, @where_bind) = $sql_abstract->where($conditions);
2010 }
2011 20 ▶ if (defined $sql_grp) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sql_grp) 2 18 20
2012 2 $where .= " $sql_grp";
2013 2 push @where_bind, @$having_bind;
2014 }
2015 20 ▶ if ($order) {
Branch: 1 branch
BranchTrueFalseTotal
if ($order) 0 20 20
2016 0 my ($order_sql, @order_bind) = $sql_abstract->where(undef, $order);
2017 0 $where .= " $order_sql";
2018 0 push @where_bind, @order_bind;
2019 }
2020 20 ▶ if (defined($limit)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $limit) 0 20 20
2021 0 $limit += 0;
2022 0 $where .= " limit $limit";
2023 }
2024 20 ▶ if (defined($offset)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset) 0 20 20
2025 0 $offset += 0;
2026 0 ▶ $where .= " offset $offset" if $offset;
Branch: 1 branch
BranchTrueFalseTotal
if $offset 0 0 0
2027 }
2028 20 my $query;
2029 my @query_bind;
2030 20 my $one_column = 0;
2031 20 ▶ if ($simple_table) {
Branch: 1 branch
BranchTrueFalseTotal
if ($simple_table) { } 15 5 20
2032 15 $query = qq{select$distinct * from $table $where};
2033 } else {
2034 5 ▶ if (not ref $table) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $table) { } 1 4 5
2035 1 $query = "$table $where";
2036 } else {
2037 4 ($query, $one_column) = _cached_complex_query($table, \@query_bind, $where);
2038 }
2039 5 $ncn = make_name($query);
2040 }
2041 20 ▶ if ($sql) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sql) 0 20 20
2042 0 ▶ if ('CODE' eq ref $sql) {
Branch: 2 branches
BranchTrueFalseTotal
if ('CODE' eq ref $sql) { } 0 0 0
elsif ('SCALAR' eq ref $sql) { } 0 0 0
2043 0 $sql->($query, \@where_bind);
2044 } elsif ('SCALAR' eq ref $sql) {
2045 0 $$sql = $query;
2046 }
2047 }
2048 20 ▶ return if $dry_run;
Branch: 1 branch
BranchTrueFalseTotal
if $dry_run 0 20 20
2049 20 '' =~ /()/;
2050 20 my $sth;
2051 return DBIx::Struct::connect->run(
2052 sub {
2053 20 ▶ $sth = $_->prepare($query)
Subroutine __ANON__: called CC=3 SCAR=11.4
Branch: 1 branch
BranchTrueFalseTotal
$sth = $_->prepare($query) or &error_message({"result", "SQLERR", "message", $_->errstr, "query", $query}) 0 20 20
2054 or error_message {
2055 result => 'SQLERR',
2056 message => $_->errstr,
2057 query => $query,
2058 };
2059 20 ▶ $sth->execute(@query_bind, @where_bind)
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@query_bind, @where_bind) or &error_message({"result", "SQLERR", "message", $_->errstr, "query", $query, "where_bind", Dumper(\@where_bind), "query_bind", Dumper(\@query_bind), "conditions", Dumper($conditions)}) 0 20 20
2060 or error_message {
2061 result => 'SQLERR',
2062 message => $_->errstr,
2063 query => $query,
2064 where_bind => Dumper(\@where_bind),
2065 query_bind => Dumper(\@query_bind),
2066 conditions => Dumper($conditions),
2067 };
2068 20 setup_row($sth, $ncn, $up_interface);
2069 20 return $code->($sth, $ncn, $one_column);
2070 }
2071 20 );
2072 }
2073  
2074 sub one_row {
2075 return execute(
2076 sub {
2077 20 ▶ my ($sth, $ncn, $one_column) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
2078 20 my $data = $sth->fetchrow_arrayref;
2079 20 $sth->finish;
2080 20 ▶ return if not $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 1 19 20
2081 19 ▶ if ($one_column) {
Branch: 1 branch
BranchTrueFalseTotal
if ($one_column) 2 17 19
2082 #<<<
2083 # json type is not working yet here
2084 # no strict 'refs';
2085 # my @f = %{$ncn . "::field_types"};
2086 # if ($f[1] eq 'json') {
2087 # return (defined($data->[0]) ? from_json($data->[0]) : undef);
2088 # } else {
2089 2 return $data->[0];
2090 #>>> }
2091 }
2092 17 return $ncn->new([@$data]);
2093 },
2094 @_
2095 20 ▶ );
Subroutine one_row: called CC=1 SCAR=0.0
Pod documented
2096 }
2097  
2098 sub all_rows {
2099 0 ▶ my $mapfunc;
Subroutine all_rows: not called CC=3 SCAR=24.8
Pod documented
2100 0 ▶ for (my $i = 0; $i < @_; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_) 0 0 0
2101 0 ▶ if (ref($_[$i]) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[$i] eq "CODE") 0 0 0
2102 0 $mapfunc = splice @_, $i, 1;
2103 0 last;
2104 }
2105 }
2106 return execute(
2107 sub {
2108 0 ▶ my ($sth, $ncn, $one_column) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
2109 0 my @rows;
2110 my $row;
2111 0 ▶ if ($mapfunc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mapfunc) { } 0 0 0
2112 0 ▶ while ($row = $sth->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row = $sth->fetch) 0 0 0
2113 0 local $_ = $ncn->new([@$row]);
2114 0 push @rows, $mapfunc->();
2115 }
2116 } else {
2117 0 ▶ if ($one_column) {
Branch: 1 branch
BranchTrueFalseTotal
if ($one_column) { } 0 0 0
2118 #<<<
2119 # json type is not working yet here
2120 # no strict 'refs';
2121 # my @f = %{$ncn . "::field_types"};
2122 # if ($f[1] eq 'json') {
2123 # push @rows, (defined($row->[0]) ? from_json($row->[0]) : undef) while ($row = $sth->fetch);
2124 # } else {
2125 0 ▶ push @rows, $row->[0] while ($row = $sth->fetch);
Branch: 1 branch
BranchTrueFalseTotal
$row = $sth->fetch and do { push @rows, $row->[0] } 0 0 0
2126 # }
2127 #>>>
2128 } else {
2129 0 ▶ push @rows, $ncn->new([@$row]) while ($row = $sth->fetch);
Branch: 1 branch
BranchTrueFalseTotal
$row = $sth->fetch and do { push @rows, $ncn->new([@$row]) } 0 0 0
2130 }
2131 }
2132 0 return \@rows;
2133 },
2134 @_
2135 0 );
2136 }
2137  
2138 sub for_rows {
2139 0 ▶ my $itemfunc;
Subroutine for_rows: not called CC=4 SCAR=30.0
Pod documented
2140 0 ▶ for (my $i = 0; $i < @_; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_) 0 0 0
2141 0 ▶ if (ref($_[$i]) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[$i] eq "CODE") 0 0 0
2142 0 $itemfunc = splice @_, $i, 1;
2143 0 last;
2144 }
2145 }
2146 0 ▶ error_message {
Branch: 1 branch
BranchTrueFalseTotal
unless $itemfunc 0 0 0
2147 result => 'SQLERR',
2148 message => "Item function is required",
2149 query => "(not parsed)",
2150 where_bind => "(not parsed)",
2151 query_bind => "(not parsed)",
2152 conditions => "(not parsed)",
2153 }
2154 if not $itemfunc;
2155 return execute(
2156 sub {
2157 0 ▶ my ($sth, $ncn) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
2158 0 my $rows = 0;
2159 0 my $row;
2160 0 my $dbh = $_;
2161 0 ▶ local $dbh->{mysql_use_result} = 1 if $connector_driver eq 'mysql';
Branch: 1 branch
BranchTrueFalseTotal
if $DBIx::Struct::connector_driver eq "mysql" 0 0 0
2162 0 local $_;
2163 0 ▶ while ($row = $sth->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row = $sth->fetch) 0 0 0
2164 0 ++$rows;
2165 0 $_ = $ncn->new([@$row]);
2166 0 ▶ last if not $itemfunc->();
Branch: 1 branch
BranchTrueFalseTotal
unless &$itemfunc() 0 0 0
2167 }
2168 0 return $rows;
2169 },
2170 @_
2171 0 );
2172 }
2173  
2174 sub new_row {
2175 3 ▶ my ($table, @data) = @_;
Subroutine new_row: called CC=2 SCAR=7.0
Pod documented
2176 3 my $simple_table = (index($table, " ") == -1);
2177 3 ▶ error_message {
Branch: 1 branch
BranchTrueFalseTotal
unless $simple_table 0 3 3
2178 result => 'SQLERR',
2179 message => "insert row can't work for queries"
2180 }
2181 unless $simple_table;
2182 3 my $ncn = make_name($table);
2183 3 $ncn = _schema_name($ncn);
2184 3 $ncn = setup_row($table, $ncn);
2185 3 return $ncn->new(@data);
2186 }
2187  
2188 3 1;
↑ Summary blib/lib/DBIx/Struct.pm »