Wizard/ResultSet.pm

filter: Statementstmt 69.9% 156 / 223 Branchbran 57.4% 54 / 94 Conditioncond 45.8% 22 / 48 MC/DCmcdc 18.5% 5 / 27 Subroutinesub 75.6% 31 / 41 Podpod 0.0% 0 / 27 totaltotal 58.2% 268 / 460 CC 69 SCAR 26.7
CC
69
Cov
64%
_inflate_time_objects
110.0
_build_select
11.0
insert
9.7
CRAP 14.5
« Wizard/DB/Table.pm ↑ Summary Wizard/DB.pm »
1 package DBIx::Wizard::ResultSet;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use DBIx::Wizard::DB;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use DBIx::Wizard::DB::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use DBIx::Wizard::Cursor;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use SQL::Wizard;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 my $sw = SQL::Wizard->new;
11  
12 0 ▶sub _sw { return $sw }
Subroutine _sw: not called CC=1 SCAR=6.9
13  
14 76 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
15 76 my ($class, $rh_args) = @_;
16 76 ▶ return bless($rh_args || {}, $class);
Condition50%1/2
$rh_args || {}
l!l
760
MC/DC0%0/1
$rh_args || {}
$rh_args
Truth table50%1/2
A
A= $rh_args
Aresult
11
00
17 }
18  
19 18 ▶sub _clone {
Subroutine _clone: called CC=1 SCAR=0.0
20 18 my ($self) = @_;
21 18 return bless { %$self }, ref($self);
22 }
23  
24 ## Query building methods (all return $self for chaining)
25  
26 3 ▶sub as {
Subroutine as: called CC=1 SCAR=0.0
Pod undocumented
27 3 my ($self, $alias) = @_;
28 3 $self->{alias} = $alias;
29 3 return $self;
30 }
31  
32 19 ▶sub where {
Subroutine where: called CC=5 SCAR=17.3
Pod undocumented
33 19 my ($self, $cond) = @_;
34 19 ▶ $cond ||= {};
Condition50%1/2
$cond ||= {}
l!l
190
MC/DC0%0/1
$cond ||= {}
$cond
Truth table50%1/2
A
A= $cond
Aresult
11
00
35  
36 19 ▶ if (ref($cond) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $cond eq 'HASH') { } 19 0 19
elsif (ref $cond eq 'ARRAY') { } 0 0 0
37 19 ▶ my %h_new_where = (%{$self->{where} || {}}, %{$cond});
Condition100%2/2
$self->{'where'} || {}
l!l
118
MC/DC100%1/1
$self->{'where'} || {}
$self->{'where'}
Truth table100%2/2
A
A= $self->{'where'}
Aresult
11
00
38 19 $self->{where} = \%h_new_where;
39 } elsif (ref($cond) eq 'ARRAY') {
40 0 $self->{where} = $cond;
41 }
42  
43 19 return $self;
44 }
45  
46 2 ▶sub join {
Subroutine join: called CC=2 SCAR=7.0
Pod undocumented
47 2 my ($self, $table, $on) = @_;
48 2 ▶ $self->{joins} ||= [];
Condition50%1/2
$self->{"joins"} ||= []
l!l
02
MC/DC0%0/1
$self->{"joins"} ||= []
$self->{"joins"}
Truth table50%1/2
A
A= $self->{"joins"}
Aresult
11
00
49 2 push @{$self->{joins}}, $sw->join($table, $on);
50 2 return $self;
51 }
52  
53 0 ▶sub left_join {
Subroutine left_join: not called CC=2 SCAR=17.9
Pod undocumented
54 0 my ($self, $table, $on) = @_;
55 0 ▶ $self->{joins} ||= [];
Condition0%0/2
$self->{"joins"} ||= []
l!l
00
MC/DC0%0/1
$self->{"joins"} ||= []
$self->{"joins"}
Truth table0%0/2
A
A= $self->{"joins"}
Aresult
11
00
56 0 push @{$self->{joins}}, $sw->left_join($table, $on);
57 0 return $self;
58 }
59  
60 0 ▶sub right_join {
Subroutine right_join: not called CC=2 SCAR=17.9
Pod undocumented
61 0 my ($self, $table, $on) = @_;
62 0 ▶ $self->{joins} ||= [];
Condition0%0/2
$self->{"joins"} ||= []
l!l
00
MC/DC0%0/1
$self->{"joins"} ||= []
$self->{"joins"}
Truth table0%0/2
A
A= $self->{"joins"}
Aresult
11
00
63 0 push @{$self->{joins}}, $sw->right_join($table, $on);
64 0 return $self;
65 }
66  
67 0 ▶sub full_join {
Subroutine full_join: not called CC=2 SCAR=17.9
Pod undocumented
68 0 my ($self, $table, $on) = @_;
69 0 ▶ $self->{joins} ||= [];
Condition0%0/2
$self->{"joins"} ||= []
l!l
00
MC/DC0%0/1
$self->{"joins"} ||= []
$self->{"joins"}
Truth table0%0/2
A
A= $self->{"joins"}
Aresult
11
00
70 0 push @{$self->{joins}}, $sw->full_join($table, $on);
71 0 return $self;
72 }
73  
74 0 ▶sub cross_join {
Subroutine cross_join: not called CC=2 SCAR=17.9
Pod undocumented
75 0 my ($self, $table) = @_;
76 0 ▶ $self->{joins} ||= [];
Condition0%0/2
$self->{"joins"} ||= []
l!l
00
MC/DC0%0/1
$self->{"joins"} ||= []
$self->{"joins"}
Truth table0%0/2
A
A= $self->{"joins"}
Aresult
11
00
77 0 push @{$self->{joins}}, $sw->cross_join($table);
78 0 return $self;
79 }
80  
81 12 ▶sub order_by {
Subroutine order_by: called CC=3 SCAR=12.7
Pod undocumented
82 12 my ($self, @order_by) = @_;
83  
84 12 ▶ if (scalar(@order_by) == 1 && ref($order_by[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @order_by == 1 and ref $order_by[0] eq 'ARRAY') { } 0 12 12
Condition33%1/3
scalar @order_by == 1 and ref $order_by[0] eq "ARRAY"
!ll&&!rl&&r
0120
MC/DC0%0/2
scalar @order_by == 1 and ref $order_by[0] eq "ARRAY"
scalar @order_by == 1 ref $order_by[0] eq "ARRAY"
Truth table33%1/3
A and B
A= scalar @order_by == 1B= ref $order_by[0] eq "ARRAY"
ABresult
0X0
100
111
85 0 $self->{order_by} = $order_by[0];
86 } else {
87 12 $self->{order_by} = \@order_by;
88 }
89  
90 12 return $self;
91 }
92  
93 0 ▶sub group_by {
Subroutine group_by: not called CC=1 SCAR=6.9
Pod undocumented
94 0 my ($self, @group_by) = @_;
95 0 $self->{group_by} = \@group_by;
96 0 return $self;
97 }
98  
99 0 ▶sub having {
Subroutine having: not called CC=1 SCAR=6.9
Pod undocumented
100 0 my ($self, $having) = @_;
101 0 $self->{having} = $having;
102 0 return $self;
103 }
104  
105 3 ▶sub limit {
Subroutine limit: called CC=2 SCAR=7.0
Pod undocumented
106 3 my ($self, $limit) = @_;
107 3 ▶ croak "DBIW: limit failed: invalid input $limit" if $limit !~ m/^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $limit =~ /^\d+$/ 0 3 3
108 3 $self->{limit} = $limit;
109 3 return $self;
110 }
111  
112 1 ▶sub offset {
Subroutine offset: called CC=2 SCAR=7.0
Pod undocumented
113 1 my ($self, $offset) = @_;
114 1 ▶ croak "DBIW: offset failed: invalid input $offset" if $offset !~ m/^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $offset =~ /^\d+$/ 0 1 1
115 1 $self->{offset} = $offset;
116 1 return $self;
117 }
118  
119 38 ▶sub inflate {
Subroutine inflate: called CC=1 SCAR=0.0
Pod undocumented
120 38 my ($self, $inflate) = @_;
121 38 $self->{inflate} = $inflate;
122 38 return $self;
123 }
124  
125 2 ▶sub inflate_class {
Subroutine inflate_class: called CC=1 SCAR=0.0
Pod undocumented
126 2 my ($self, $class) = @_;
127 2 $self->{inflate_class} = $class;
128 2 return $self;
129 }
130  
131 ## Data retrieval
132  
133 17 ▶sub all {
Subroutine all: called CC=5 SCAR=16.1
Pod undocumented
134 17 my ($self, $columns) = @_;
135  
136 17 ▶ if ($columns) {
Branch: 1 branch
BranchTrueFalseTotal
if ($columns) 12 5 17
137 12 ▶ if (ref($columns) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $columns eq 'ARRAY') { } 4 8 12
138 4 $self->{columns} = [_alias_dotted(@$columns)];
139 } else {
140 8 $self->{columns} = [_alias_dotted($columns)];
141 }
142 }
143  
144 17 my @all = $self->_select();
145  
146 17 ▶ if ($columns && ref($columns) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($columns and ref $columns ne 'ARRAY') { } 8 9 17
Condition100%3/3
$columns and ref $columns ne "ARRAY"
!ll&&!rl&&r
548
MC/DC100%2/2
$columns and ref $columns ne "ARRAY"
$columns ref $columns ne "ARRAY"
Truth table100%3/3
A and B
A= $columnsB= ref $columns ne "ARRAY"
ABresult
0X0
100
111
147 8 return map { $_->{$columns} } @all;
148 } else {
149 9 return @all;
150 }
151 }
152  
153 3 ▶sub distinct {
Subroutine distinct: called CC=2 SCAR=6.9
Pod undocumented
154 3 my ($self, $columns) = @_;
155 3 ▶ croak "distinct() requires a column name or arrayref of columns" unless $columns;
Branch: 1 branch
BranchTrueFalseTotal
unless $columns 1 2 3
156 2 $self->{distinct} = 1;
157 2 return $self->all($columns);
158 }
159  
160 6 ▶sub one {
Subroutine one: called CC=5 SCAR=16.3
Pod undocumented
161 6 my ($self, $columns) = @_;
162 6 my $clone = $self->_clone;
163  
164 6 $clone->{limit} = 1;
165  
166 6 ▶ if ($columns) {
Branch: 1 branch
BranchTrueFalseTotal
if ($columns) 4 2 6
167 4 ▶ if (ref($columns) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $columns eq 'ARRAY') { } 0 4 4
168 0 $clone->{columns} = [_alias_dotted(@$columns)];
169 } else {
170 4 $clone->{columns} = [_alias_dotted($columns)];
171 }
172 }
173  
174 6 my @one = $clone->_select();
175  
176 6 ▶ if ($columns && ref($columns) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($columns and ref $columns ne 'ARRAY') { } 4 2 6
Condition66%2/3
$columns and ref $columns ne "ARRAY"
!ll&&!rl&&r
204
MC/DC50%1/2
$columns and ref $columns ne "ARRAY"
$columns ref $columns ne "ARRAY"
Truth table66%2/3
A and B
A= $columnsB= ref $columns ne "ARRAY"
ABresult
0X0
100
111
177 4 return $one[0]->{$columns};
178 } else {
179 2 return $one[0];
180 }
181 }
182  
183 4 ▶sub cursor {
Subroutine cursor: called CC=4 SCAR=14.1
Pod undocumented
184 4 my ($self, $columns) = @_;
185  
186 4 ▶ if ($columns) {
Branch: 1 branch
BranchTrueFalseTotal
if ($columns) 1 3 4
187 1 ▶ if (ref($columns) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $columns eq 'ARRAY') { } 1 0 1
188 1 $self->{columns} = $columns;
189 } else {
190 0 $self->{columns} = [$columns];
191 }
192 }
193  
194 4 my ($sql, @bind) = $self->_build_select()->to_sql();
195 4 _debug_log('cursor', $sql, @bind);
196  
197 4 my $dbh = DBIx::Wizard::DB->dbh($self->{db});
198 4 my $sth = $dbh->prepare($sql);
199 4 ▶ $sth->execute(@bind) || croak "DBIW: query failed: $DBI::errstr";
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind) or croak("DBIW: query failed: $DBI::errstr") 4 0 4
200  
201 4 return DBIx::Wizard::Cursor->new({
202 rs => $self,
203 sth => $sth,
204 });
205 }
206  
207 12 ▶sub count {
Subroutine count: called CC=3 SCAR=12.7
Pod undocumented
208 12 my $clone = shift->_clone;
209  
210 12 $clone->{columns} = [$sw->func('COUNT', '*')];
211 12 my @count = $clone->_select();
212  
213 ## NOTE: fallback is for ClickHouse
214 12 ▶ return $count[0]->{'COUNT(*)'} // $count[0]->{'count()'} // $count[0]->{'COUNT()'};
Condition33%2/6
($count[0]{"COUNT(*)"} // $count[0]{"count()"}) // $count[0]{"COUNT()"}
l!l&&r!l&&!r
1200
$count[0]{"COUNT(*)"} // $count[0]{"count()"}
l!l&&r!l&&!r
1200
MC/DC0%0/3
($count[0]{"COUNT(*)"} // $count[0]{"count()"}) // $count[0]{"COUNT()"}
$count[0]{"COUNT(*)"} $count[0]{"count()"} $count[0]{"COUNT()"}
Truth table25%1/4
A // B // C
A= $count[0]{"COUNT(*)"}B= $count[0]{"count()"}C= $count[0]{"COUNT()"}
ABCresult
1XX1
01X1
0011
0000
215 }
216  
217 2 ▶sub exists {
Subroutine exists: called CC=1 SCAR=0.0
Pod undocumented
218 2 my $self = shift;
219 2 return $self->count > 0;
220 }
221  
222 0 ▶sub sum {
Subroutine sum: not called CC=1 SCAR=6.9
Pod undocumented
223 0 my ($self, $column) = @_;
224 0 my $clone = $self->_clone;
225  
226 0 $column =~ s/[^\w\.]+//gs;
227 0 $clone->{columns} = [$sw->func('SUM', $column)];
228 0 my @sum = $clone->_select();
229  
230 0 return $sum[0]->{"SUM($column)"} + 0;
231 }
232  
233 ## Data modification
234  
235 27 ▶sub insert {
Subroutine insert: called CC=7 SCAR=22.7
Pod undocumented
236 27 my ($self, $rh_insert, $auto_pk) = @_;
237 27 ▶ $rh_insert ||= {};
Condition50%1/2
$rh_insert ||= {}
l!l
270
MC/DC0%0/1
$rh_insert ||= {}
$rh_insert
Truth table50%1/2
A
A= $rh_insert
Aresult
11
00
238  
239 27 my $dbh = DBIx::Wizard::DB->dbh($self->{db});
240 27 ▶ $auto_pk ||= DBIx::Wizard::DB::Table->auto_pk($self->{db}, $self->{table});
Condition33%1/3
$auto_pk ||= "DBIx::Wizard::DB::Table"->auto_pk($self->{"db"}, $self->{"table"})
l!l&&r!l&&!r
0270
MC/DC0%0/2
$auto_pk ||= "DBIx::Wizard::DB::Table"->auto_pk($self->{"db"}, $self->{"table"})
$auto_pk "DBIx::Wizard::DB::Table"->auto_pk($self->{"db"}, $self->{"table"})
Truth table33%1/3
A ||= B
A= $auto_pkB= "DBIx::Wizard::DB::Table"->auto_pk($self->{"db"}, $self->{"table"})
ABresult
1X1
011
000
241  
242 my ($sql, @bind) = $sw->insert(
243 -into => $self->{table},
244 27 -values => $rh_insert,
245 )->to_sql;
246  
247 27 _debug_log('insert', $sql, @bind);
248  
249 27 my $sth = $dbh->prepare($sql);
250 27 ▶ $sth->execute(@bind) || croak "DBIW: insert failed: $DBI::errstr";
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind) or croak("DBIW: insert failed: $DBI::errstr") 27 0 27
251  
252 27 ▶ if ($auto_pk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auto_pk) 27 0 27
253 27 my @row;
254 27 ▶ if ($sth->can('last_insert_id')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sth->can('last_insert_id')) { } 27 0 27
elsif ($dbh->can('last_insert_id')) { } 0 0 0
255 27 @row = $sth->last_insert_id();
256 } elsif ($dbh->can('last_insert_id')) {
257 0 @row = $dbh->last_insert_id(undef, $self->{db}, $self->{table}, $auto_pk);
258 } else {
259 0 @row = $dbh->selectrow_array('SELECT LAST_INSERT_ID()');
260 }
261 27 return $row[0];
262 }
263  
264 0 return;
265 }
266  
267 3 ▶sub update {
Subroutine update: called CC=4 SCAR=14.3
Pod undocumented
268 3 my ($self, $rh_update) = @_;
269  
270 my ($sql, @bind) = $sw->update(
271 -table => $self->{table},
272 -set => $rh_update,
273 ($self->{where}) ? (-where => $self->{where}) : (),
274 3 ▶ (defined $self->{limit}) ? (-limit => $self->{limit}) : (),
Branch: 2 branches
BranchTrueFalseTotal
$self->{'where'} ? : 3 0 3
defined $self->{'limit'} ? : 0 3 3
275 )->to_sql;
276  
277 3 _debug_log('update', $sql, @bind);
278  
279 3 my $dbh = DBIx::Wizard::DB->dbh($self->{db});
280 3 my $sth = $dbh->prepare($sql);
281 3 ▶ $sth->execute(@bind) || croak "DBIW: update failed: $DBI::errstr";
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind) or croak("DBIW: update failed: $DBI::errstr") 3 0 3
282  
283 3 return $sth->rows;
284 }
285  
286 1 ▶sub delete {
Subroutine delete: called CC=3 SCAR=11.2
Pod undocumented
287 1 my $self = shift;
288  
289 my ($sql, @bind) = $sw->delete(
290 -from => $self->{table},
291 1 ▶ ($self->{where}) ? (-where => $self->{where}) : (),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'where'} ? : 1 0 1
292 )->to_sql;
293  
294 1 _debug_log('delete', $sql, @bind);
295  
296 1 my $dbh = DBIx::Wizard::DB->dbh($self->{db});
297 1 my $sth = $dbh->prepare($sql);
298 1 ▶ $sth->execute(@bind) || croak "DBIW: delete failed: $DBI::errstr";
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind) or croak("DBIW: delete failed: $DBI::errstr") 1 0 1
299 }
300  
301 1 ▶sub truncate {
Subroutine truncate: called CC=3 SCAR=11.3
Pod undocumented
302 1 my $self = shift;
303  
304 1 my $dbh = DBIx::Wizard::DB->dbh($self->{db});
305 1 my $driver = $dbh->{Driver}->{Name};
306  
307 # SQLite doesn't support TRUNCATE TABLE
308 1 my ($sql, @bind);
309 1 ▶ if ($driver eq 'SQLite') {
Branch: 1 branch
BranchTrueFalseTotal
if ($driver eq 'SQLite') { } 1 0 1
310 1 ($sql, @bind) = $sw->delete(-from => $self->{table})->to_sql;
311 } else {
312 0 ($sql, @bind) = $sw->truncate(-table => $self->{table})->to_sql;
313 }
314  
315 1 _debug_log('truncate', $sql, @bind);
316  
317 1 my $sth = $dbh->prepare($sql);
318 1 ▶ $sth->execute(@bind) || croak "DBIW: truncate failed: $DBI::errstr";
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind) or croak("DBIW: truncate failed: $DBI::errstr") 1 0 1
319 }
320  
321 0 ▶sub dbh {
Subroutine dbh: not called CC=1 SCAR=6.9
Pod undocumented
322 0 my $self = shift;
323 0 return DBIx::Wizard::DB->dbh($self->{db});
324 }
325  
326 ## Internal
327  
328 16 ▶sub _alias_dotted {
Subroutine _alias_dotted: called CC=3 SCAR=11.1
329 16 ▶ return map { !ref($_) && /\./ ? $sw->col($_)->as($_) : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
!ref($_) && /\./ ? : 4 15 19
Condition66%2/3
not ref $_ and /\./
!ll&&!rl&&r
0154
MC/DC50%1/2
not ref $_ and /\./
not ref $_ /\./
Truth table66%2/3
not(A) and B
A= not ref $_B= /\./
ABresult
0X0
100
111
330 }
331  
332 40 ▶sub _build_select {
Subroutine _build_select: called CC=11 SCAR=24.0
333 40 my $self = shift;
334  
335 my $from_table = $self->{alias}
336 ? "$self->{table}|$self->{alias}"
337 40 ▶ : $self->{table};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'alias'} ? : 3 37 40
338  
339 40 my @from = ($from_table);
340 40 ▶ if ($self->{joins}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"joins"}) 2 38 40
341 2 push @from, @{$self->{joins}};
342 }
343  
344 return $sw->select(
345 -from => \@from,
346 ($self->{distinct}) ? (-distinct => 1) : (),
347 ($self->{columns}) ? (-columns => $self->{columns}) : (),
348 ($self->{where}) ? (-where => $self->{where}) : (),
349 ($self->{group_by}) ? (-group_by => $self->{group_by}) : (),
350 ($self->{having}) ? (-having => $self->{having}) : (),
351 ($self->{order_by}) ? (-order_by => $self->{order_by}) : (),
352 (defined $self->{limit}) ? (-limit => $self->{limit}) : (),
353 40 ▶ (defined $self->{offset}) ? (-offset => $self->{offset}) : (),
Branch: 8 branches
BranchTrueFalseTotal
$self->{'distinct'} ? : 2 38 40
$self->{'columns'} ? : 29 11 40
$self->{'where'} ? : 15 25 40
$self->{'group_by'} ? : 0 40 40
$self->{'having'} ? : 0 40 40
$self->{'order_by'} ? : 13 27 40
defined $self->{'limit'} ? : 9 31 40
defined $self->{'offset'} ? : 1 39 40
354 );
355 }
356  
357 35 ▶sub _select {
Subroutine _select: called CC=3 SCAR=11.5
358 35 my $self = shift;
359  
360 35 my ($sql, @bind) = $self->_build_select()->to_sql();
361  
362 35 _debug_log('_select', $sql, @bind);
363  
364 35 my $dbh = DBIx::Wizard::DB->dbh($self->{db});
365 35 my $sth = $dbh->prepare($sql);
366 35 ▶ $sth->execute(@bind) || confess "DBIW: query failed: $DBI::errstr\n" .
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind) or confess("DBIW: query failed: $DBI::errstr\n" . "SQL: $sql\n" . 'BIND: ' . CORE::join(" -- ", @bind) . "\n") 35 0 35
367 "SQL: $sql\n" .
368 "BIND: " . CORE::join(" -- ", @bind) . "\n";
369  
370 35 my $ra_rows = $sth->fetchall_arrayref({});
371  
372 35 ▶ if ($self->{inflate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"inflate"}) 0 35 35
373 0 my $ic = $self->_resolve_inflate_class;
374 0 _inflate_time_objects($ra_rows, $self->{db}, $self->{table}, $ic);
375 }
376  
377 35 return @$ra_rows;
378 }
379  
380 71 ▶sub _debug_log {
Subroutine _debug_log: called CC=3 SCAR=19.2
381 71 my ($label, $sql, @bind) = @_;
382  
383 71 ▶ return unless $ENV{DEBUG_DBIW};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"DEBUG_DBIW"} 71 0 71
384  
385 0 my $log = "DBIW: $label() | $sql | " . CORE::join(" -- ", @bind) . "\n";
386  
387 0 ▶ if ($ENV{DEBUG_DBIW_FILE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'DEBUG_DBIW_FILE'}) { } 0 0 0
388 0 open my $fh, '>>', $ENV{DEBUG_DBIW_FILE};
389 0 print $fh $log;
390 0 close $fh;
391 } else {
392 0 print $log;
393 }
394 }
395  
396 4 ▶sub _resolve_inflate_class {
Subroutine _resolve_inflate_class: called CC=3 SCAR=11.0
397 4 my $self = shift;
398  
399 # ResultSet > DB declare > package default
400 return $self->{inflate_class}
401 || DBIx::Wizard::DB->inflate_class($self->{db})
402 4 ▶ || DBIx::Wizard->default_inflate_class;
Condition83%5/6
$self->{'inflate_class'} || 'DBIx::Wizard::DB'->inflate_class($self->{'db'}) || 'DBIx::Wizard'->default_inflate_class
l!l&&r!l&&!r
310
$self->{"inflate_class"} or "DBIx::Wizard::DB"->inflate_class($self->{"db"})
l!l&&r!l&&!r
211
MC/DC0%0/3
$self->{'inflate_class'} || 'DBIx::Wizard::DB'->inflate_class($self->{'db'}) || 'DBIx::Wizard'->default_inflate_class
$self->{"inflate_class"} "DBIx::Wizard::DB"->inflate_class($self->{"db"}) 'DBIx::Wizard'->default_inflate_class
Truth table75%3/4
A or B || C
A= $self->{"inflate_class"}B= "DBIx::Wizard::DB"->inflate_class($self->{"db"})C= 'DBIx::Wizard'->default_inflate_class
ABCresult
1XX1
01X1
0011
0000
403 }
404  
405 11 my %_loaded_classes;
406  
407 0 ▶sub _inflate_time_objects {
Subroutine _inflate_time_objects: not called CC=10 SCAR=47.0
408 0 my ($ra_rows, $db, $table, $inflate_class) = @_;
409  
410 # Lazy-load the inflate class
411 0 ▶ if ($inflate_class && !$_loaded_classes{$inflate_class}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inflate_class and not $_loaded_classes{$inflate_class}) 0 0 0
Condition0%0/3
$inflate_class and not $_loaded_classes{$inflate_class}
!ll&&!rl&&r
000
MC/DC0%0/2
$inflate_class and not $_loaded_classes{$inflate_class}
$inflate_class not $_loaded_classes{$inflate_class}
Truth table0%0/3
A and not(B)
A= $inflate_classB= not $_loaded_classes{$inflate_class}
ABresult
0X0
100
111
412 0 (my $file = $inflate_class) =~ s|::|/|g;
413 0 require "$file.pm";
414 0 $_loaded_classes{$inflate_class} = 1;
415 }
416  
417 0 my $rh_time_columns = DBIx::Wizard::DB::Table->time_columns_href($db, $table);
418  
419 0 ▶ if (%$rh_time_columns) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$rh_time_columns) 0 0 0
420 0 for my $rh_row (@$ra_rows) {
421 0 for my $col (keys %$rh_row) {
422 0 ▶ if ($rh_time_columns->{$col}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rh_time_columns->{$col}) 0 0 0
423 0 ▶ if (defined $rh_row->{$col}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rh_row->{$col}) 0 0 0
424 0 ▶ if ($inflate_class eq 'Time::Moment') {
Branch: 1 branch
BranchTrueFalseTotal
if ($inflate_class eq 'Time::Moment') { } 0 0 0
425 0 (my $iso = $rh_row->{$col}) =~ s/ /T/;
426 0 ▶ $iso .= 'Z' unless $iso =~ /[Z+-]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $iso =~ /[Z+-]/ 0 0 0
427 0 $rh_row->{$col} = Time::Moment->from_string($iso);
428 } else {
429 0 $rh_row->{$col} = $inflate_class->new($rh_row->{$col});
430 }
431 }
432 }
433 }
434 }
435 }
436 }
437  
438 11 1;
« Wizard/DB/Table.pm ↑ Summary Wizard/DB.pm »