| 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 || {}
MC/DC0%0/1
$rh_args || {}
$rh_args
Truth table50%1/2
A
A= $rh_args
| |||||||||||||||||||||||||||||||||||||||
| 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 ||= {}
MC/DC0%0/1
$cond ||= {}
$cond
Truth table50%1/2
A
A= $cond
| |||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||
| 36 | 19 | ▶ | if (ref($cond) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 37 | 19 | ▶ | my %h_new_where = (%{$self->{where} || {}}, %{$cond}); | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'where'} || {}
MC/DC100%1/1
$self->{'where'} || {}
$self->{'where'}
Truth table100%2/2
A
A= $self->{'where'}
| |||||||||||||||||||||||||||||||||||||||
| 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"} ||= []
MC/DC0%0/1
$self->{"joins"} ||= []
$self->{"joins"}
Truth table50%1/2
A
A= $self->{"joins"}
| |||||||||||||||||||||||||||||||||||||||
| 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"} ||= []
MC/DC0%0/1
$self->{"joins"} ||= []
$self->{"joins"}
Truth table0%0/2
A
A= $self->{"joins"}
| |||||||||||||||||||||||||||||||||||||||
| 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"} ||= []
MC/DC0%0/1
$self->{"joins"} ||= []
$self->{"joins"}
Truth table0%0/2
A
A= $self->{"joins"}
| |||||||||||||||||||||||||||||||||||||||
| 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"} ||= []
MC/DC0%0/1
$self->{"joins"} ||= []
$self->{"joins"}
Truth table0%0/2
A
A= $self->{"joins"}
| |||||||||||||||||||||||||||||||||||||||
| 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"} ||= []
MC/DC0%0/1
$self->{"joins"} ||= []
$self->{"joins"}
Truth table0%0/2
A
A= $self->{"joins"}
| |||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
scalar @order_by == 1 and ref $order_by[0] eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 137 | 12 | ▶ | if (ref($columns) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$columns and ref $columns ne "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 167 | 4 | ▶ | if (ref($columns) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$columns and ref $columns ne "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | if (ref($columns) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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()"}
$count[0]{"COUNT(*)"} // $count[0]{"count()"}
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()"}
| |||||||||||||||||||||||||||||||||||||||
| 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 ||= {}
MC/DC0%0/1
$rh_insert ||= {}
$rh_insert
Truth table50%1/2
A
A= $rh_insert
| |||||||||||||||||||||||||||||||||||||||
| 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"})
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"})
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||
| 252 | 27 | ▶ | if ($auto_pk) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 253 | 27 | my @row; | |||||||||||||||||||||||||||||||||||||
| 254 | 27 | ▶ | if ($sth->can('last_insert_id')) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
not ref $_ and /\./
MC/DC50%1/2
not ref $_ and /\./
not ref $_
/\./
Truth table66%2/3
not(A) and B
A= not ref $_B= /\./
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||
| 339 | 40 | my @from = ($from_table); | |||||||||||||||||||||||||||||||||||||
| 340 | 40 | ▶ | if ($self->{joins}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my $log = "DBIW: $label() | $sql | " . CORE::join(" -- ", @bind) . "\n"; | |||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | if ($ENV{DEBUG_DBIW_FILE}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 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
$self->{"inflate_class"} or "DBIx::Wizard::DB"->inflate_class($self->{"db"})
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
| |||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$inflate_class and not $_loaded_classes{$inflate_class}
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}
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | if (defined $rh_row->{$col}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | if ($inflate_class eq 'Time::Moment') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 425 | 0 | (my $iso = $rh_row->{$col}) =~ s/ /T/; | |||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | $iso .= 'Z' unless $iso =~ /[Z+-]/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||