| 1 | package ActiveRecord::Simple::Find; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use vars qw/$AUTOLOAD/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use parent 'ActiveRecord::Simple'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use ActiveRecord::Simple::Utils qw/load_module/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | our $MAXIMUM_LIMIT = 100_000_000_000; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 86 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=18 SCAR=29.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 86 | my ($self_class, $class, @param) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | #my $self = $class->new(); | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 86 | my $self = bless { class => $class } => $self_class; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 86 | ▶ | my $table_name = ($self->{class}->can('_get_table_name')) ? $self->{class}->_get_table_name : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 86 | ▶ | my $pkey = ($self->{class}->can('_get_primary_key')) ? $self->{class}->_get_primary_key : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 86 | ▶ | croak 'can not get table_name for class ' . $self->{class} unless $table_name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | #croak 'can not get primary_key for class ' . $self->{class} unless $pkey; | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 86 | ▶ | $self->{prep_select_fields} //= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"prep_select_fields"} //= []
MC/DC0%0/1
$self->{"prep_select_fields"} //= []
$self->{"prep_select_fields"}
Truth table50%1/2
A
A= $self->{"prep_select_fields"}
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 86 | ▶ | $self->{prep_select_from} //= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"prep_select_from"} //= []
MC/DC0%0/1
$self->{"prep_select_from"} //= []
$self->{"prep_select_from"}
Truth table50%1/2
A
A= $self->{"prep_select_from"}
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 86 | ▶ | $self->{prep_select_where} //= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"prep_select_where"} //= []
MC/DC0%0/1
$self->{"prep_select_where"} //= []
$self->{"prep_select_where"}
Truth table50%1/2
A
A= $self->{"prep_select_where"}
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 86 | my ($fields, $from, $where); | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 86 | ▶ | if (!ref $param[0] && scalar @param == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition100%3/3
not ref $param[0] and scalar @param == 1
MC/DC100%2/2
not ref $param[0] and scalar @param == 1
not ref $param[0]
scalar @param == 1
Truth table100%3/3
not(A) and B
A= not ref $param[0]B= scalar @param == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 22 | $fields = qq/"$table_name".*/; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 22 | $from = qq/"$table_name"/; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 22 | $where = qq/"$table_name"."$pkey" = ?/; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | $self->{BIND} = \@param | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 22 | } | |||||||||||||||||||||||||||||||||||||||||
| 43 | ▶ | elsif (!ref $param[0] && scalar @param == 0) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not ref $param[0] and scalar @param == 0
MC/DC100%2/2
not ref $param[0] and scalar @param == 0
not ref $param[0]
scalar @param == 0
Truth table100%3/3
not(A) and B
A= not ref $param[0]B= scalar @param == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 33 | $fields = qq/"$table_name".*/; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 33 | $from = qq/"$table_name"/; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 33 | $self->{BIND} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | ▶ | elsif (ref $param[0] && ref $param[0] eq 'HASH') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
ref $param[0] and ref $param[0] eq "HASH"
MC/DC100%2/2
ref $param[0] and ref $param[0] eq "HASH"
ref $param[0]
ref $param[0] eq "HASH"
Truth table100%3/3
A and B
A= ref $param[0]B= ref $param[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | # find many by params | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 23 | my ($bind, $condition_pairs) = $self->_parse_hash($param[0]); | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 23 | my $where_str = join q/ AND /, @$condition_pairs; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 23 | $fields = qq/"$table_name".*/; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 23 | $from = qq/"$table_name"/; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 23 | $where = $where_str; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 23 | $self->{BIND} = $bind; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ▶ | elsif (ref $param[0] && ref $param[0] eq 'ARRAY') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $param[0] and ref $param[0] eq "ARRAY"
MC/DC50%1/2
ref $param[0] and ref $param[0] eq "ARRAY"
ref $param[0]
ref $param[0] eq "ARRAY"
Truth table66%2/3
A and B
A= ref $param[0]B= ref $param[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | # find many by primary keys | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | my $whereinstr = join ', ', @{ $param[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | $fields = qq/"$table_name".*/; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | $from = qq/"$table_name"/; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | $where = qq/"$table_name"."$pkey" IN ($whereinstr)/; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | $self->{BIND} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # find many by condition | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 6 | my $wherestr = shift @param; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 6 | $fields = qq/"$table_name".*/; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | $from = qq/"$table_name"/; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | $where = $wherestr; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 6 | $self->{BIND} = \@param; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 86 | ▶ | push @{ $self->{prep_select_fields} }, $fields if $fields; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 86 | ▶ | push @{ $self->{prep_select_from} }, $from if $from; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 86 | ▶ | push @{ $self->{prep_select_where} }, $where if $where; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 86 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 8 | ▶ | sub count { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
count: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 8 | my $inv = shift; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 8 | ▶ | my $self = ref $inv ? $inv : $inv->new(@_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 8 | $self->{prep_select_fields} = [ 'COUNT(*)' ]; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | ▶ | if (@{ $self->{prep_group_by} || [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{'prep_group_by'} || []
MC/DC100%1/1
$self->{'prep_group_by'} || []
$self->{'prep_group_by'}
Truth table100%2/2
A
A= $self->{'prep_group_by'}
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | my $table_name = $self->{class}->_get_table_name; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | push @{ $self->{prep_select_fields} }, map qq/"$table_name".$_/, @{ $self->{prep_group_by} }; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | my @group_by = @{ $self->{prep_group_by} }; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | s/"//g foreach @group_by; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | my @results; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | foreach my $item ($self->fetch) { | |||||||||||||||||||||||||||||||||||||||||
| 100 | 7 | push my @line, (count => $item->{'COUNT(*)'}), map { $_ => $item->{$_} } @group_by; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 7 | push @results, { @line }; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | return @results; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | return $self->fetch->{'COUNT(*)'}; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | ▶ | sub first { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | my ($self, $limit) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 6 | ▶ | $limit //= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$limit //= 1
MC/DC100%1/1
$limit //= 1
$limit
Truth table100%2/2
A
A= $limit
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 6 | ▶ | $self->{class}->can('_get_primary_key') or croak 'Can\'t use "first" without primary key'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 6 | my $primary_key = $self->{class}->_get_primary_key; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | return $self->order_by($primary_key)->limit($limit)->fetch; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | ▶ | sub last { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | my ($self, $limit) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 3 | ▶ | $self->{class}->can('_get_primary_key') or croak 'Can\'t use "first" without primary key'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | my $primary_key = $self->{class}->_get_primary_key; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | ▶ | $limit //= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$limit //= 1
MC/DC0%0/1
$limit //= 1
$limit
Truth table50%1/2
A
A= $limit
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | return $self->order_by($primary_key)->desc->limit($limit)->fetch; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 7 | ▶ | sub only { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
only: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 7 | my ($self, @fields) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 7 | ▶ | scalar @fields > 0 or croak 'Not defined fields for method "only"'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 7 | ▶ | ref $self or croak 'Create an object abstraction before using the modifiers. Use methods like `find`, `first`, `last` at the beginning'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 7 | ▶ | if ($self->{class}->can('_get_primary_key')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 7 | my $pk = $self->{class}->_get_primary_key; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 7 | ▶ | push @fields, $pk if ! grep { $_ eq $pk } @fields; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 7 | my $table_name = $self->{class}->_get_table_name; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 7 | ▶ | my $mixins = $self->{class}->can('_get_mixins') ? $self->{class}->_get_mixins : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | my @filtered_prep_select_fields = | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 7 | grep { $_ ne qq/"$table_name".*/ } @{ $self->{prep_select_fields} }; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 7 | for my $fld (@fields) { | |||||||||||||||||||||||||||||||||||||||||
| 148 | 10 | ▶ | if ($mixins && grep { $_ eq $fld } keys %$mixins) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mixins and grep {$_ eq $fld;} keys %$mixins
MC/DC100%2/2
$mixins and grep {$_ eq $fld;} keys %$mixins
$mixins
grep {$_ eq $fld;} keys %$mixins
Truth table100%3/3
A and B
A= $mixinsB= grep {$_ eq $fld;} keys %$mixins
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | my $mixin = $mixins->{$fld}->($self->{class}); | |||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | $mixin .= qq/ AS $fld/ unless $mixin =~ /as\s+\w+$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | push @filtered_prep_select_fields, $mixin; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 9 | push @filtered_prep_select_fields, qq/"$table_name"."$fld"/; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 7 | $self->{prep_select_fields} = \@filtered_prep_select_fields; | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | # alias to only: | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | sub fields { shift->only(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 20 | ▶ | sub order_by { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
order_by: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 20 | my ($self, @param) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | #return if not defined $self->{SQL}; ### TODO: die | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 20 | ▶ | $self->{prep_order_by} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"prep_order_by"} ||= []
MC/DC100%1/1
$self->{"prep_order_by"} ||= []
$self->{"prep_order_by"}
Truth table100%2/2
A
A= $self->{"prep_order_by"}
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 20 | push @{$self->{prep_order_by}}, map qq/"$_"/, @param; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 20 | delete $self->{prep_asc_desc}; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 20 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 7 | ▶ | sub desc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 7 | return shift->_order_by_direction('DESC'); | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 2 | ▶ | sub asc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
asc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | return shift->_order_by_direction('ASC'); | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | ▶ | sub group_by { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
group_by: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | my ($self, @param) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 3 | ▶ | $self->{prep_group_by} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"prep_group_by"} ||= []
MC/DC0%0/1
$self->{"prep_group_by"} ||= []
$self->{"prep_group_by"}
Truth table50%1/2
A
A= $self->{"prep_group_by"}
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | push @{$self->{prep_group_by}}, map qq/"$_"/, @param; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 12 | ▶ | sub limit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
limit: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 12 | my ($self, $limit) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | #return if not defined $self->{SQL}; | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 12 | ▶ | return $self if exists $self->{prep_limit}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 12 | $self->{prep_limit} = $limit; ### TODO: move $limit to $self->{BIND} | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 12 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 3 | ▶ | sub offset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
offset: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 3 | my ($self, $offset) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | #return if not defined $self->{SQL}; | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 3 | ▶ | return $self if exists $self->{prep_offset}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 3 | $self->{prep_offset} = $offset; ### TODO: move $offset to $self->{BIND} | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 78 | ▶ | sub fetch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch: called CC=10 SCAR=23.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 78 | my ($self, $param) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 78 | my ($read_only, $limit); | |||||||||||||||||||||||||||||||||||||||||
| 219 | 78 | ▶ | if (ref $param eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $limit = $param->{limit}; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $read_only = $param->{read_only}; | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 78 | $limit = $param; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 78 | ▶ | return $self->_get_slice($limit) if $self->{_objects}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 78 | $self->_finish_sql_stmt(); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 78 | $self->_quote_sql_stmt(); | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 78 | my $class = $self->{class}; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 78 | ▶ | my $sth = $self->dbh->prepare($self->{SQL}) or croak $self->dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 78 | ▶ | $sth->execute(@{ $self->{BIND} }) or croak $self->dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 78 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 29 | my @objects; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 29 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 29 | ▶ | while (my $object_data = $sth->fetchrow_hashref()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 80 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 80 | my $obj = $class->new($object_data); | |||||||||||||||||||||||||||||||||||||||||
| 242 | 80 | $self->_finish_object_representation($obj, $object_data, $read_only); | |||||||||||||||||||||||||||||||||||||||||
| 243 | 80 | push @objects, $obj; | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 80 | ▶ | last if $limit && $i == $limit; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$limit and $i == $limit
MC/DC0%0/2
$limit and $i == $limit
$limit
$i == $limit
Truth table33%1/3
A and B
A= $limitB= $i == $limit
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 29 | delete $self->{has_joined_table}; | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 29 | return @objects; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 49 | ▶ | my $object_data = $sth->fetchrow_hashref() or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 49 | my $obj = $class->new($object_data); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 49 | $self->_finish_object_representation($obj, $object_data, $read_only); | |||||||||||||||||||||||||||||||||||||||||
| 255 | 49 | delete $self->{has_joined_table}; | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 49 | return $obj; | |||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | ▶ | sub upload { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upload: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | my ($self, $param) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | my $o = $self->fetch($param); | |||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | $_[0] = $o; | |||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 7 | ▶ | sub next { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 7 | my ($self, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 7 | ▶ | $n ||= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$n ||= 1
MC/DC100%1/1
$n ||= 1
$n
Truth table100%2/2
A
A= $n
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 7 | $self->{prep_limit} = $n; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 7 | ▶ | $self->{prep_offset} = 0 unless defined $self->{prep_offset}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 7 | my @result = $self->fetch; | |||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 7 | $self->{prep_offset} += $n; | |||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 7 | ▶ | return wantarray ? @result : $result[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub with { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
with: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my ($self, @rels) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | return $self if exists $self->{prep_left_joins}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | return $self unless @rels; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | $self->{class}->can('_get_relations') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | or die "Class doesn't have any relations"; | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | my $table_name = $self->{class}->_get_table_name; | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $self->{prep_left_joins} = []; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $self->{with} = \@rels; | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | RELATION: | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | for my $rel_name (@rels) { | |||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | my $relation = $self->{class}->_get_relations->{$rel_name} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | or next RELATION; | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | next RELATION unless grep { $_ eq $relation->{type} } qw/one only/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $rel_table_name = $relation->{class}->_get_table_name; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my $rel_columns = $relation->{class}->_get_columns; | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | REL_COLUMN: | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | for (@$rel_columns) { | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | next REL_COLUMN if ref $_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | push @{ $self->{prep_select_fields} }, qq/"$rel_table_name"."$_" AS "JOINED_$rel_name\_$_"/; | |||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if ($relation->{type} eq 'one') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | my $join_sql = qq/LEFT JOIN "$rel_table_name" ON /; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $join_sql .= qq/"$rel_table_name"."$relation->{params}{pk}"/; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $join_sql .= qq/ = "$table_name"."$relation->{params}{fk}"/; | |||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | push @{ $self->{prep_left_joins} }, $join_sql; | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | sub left_join { shift->with(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
left_join: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | sub to_sql { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_sql: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $self->_finish_sql_stmt(); | |||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $self->_quote_sql_stmt(); | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | return wantarray ? ($self->{SQL}, $self->{BIND}) : $self->{SQL}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 7 | ▶ | sub exists { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 7 | $self->{prep_select_fields} = ['1']; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 7 | $self->_finish_sql_stmt; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 7 | $self->_quote_sql_stmt; | |||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 7 | my $sth = $self->dbh->prepare($self->{SQL}); | |||||||||||||||||||||||||||||||||||||||||
| 344 | 7 | $sth->execute(@{ $self->{BIND} }); | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 7 | return $sth->fetchrow_arrayref(); | |||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | ### Private | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 14 | ▶ | sub _find_many_to_many { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_many_to_many: called CC=8 SCAR=28.7
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 14 | my ($self_class, $class, $param) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 14 | ▶ | return unless $self_class->dbh && $class && $param; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self_class->dbh and $class and $param
$self_class->dbh and $class
MC/DC0%0/3
$self_class->dbh and $class and $param
$self_class->dbh
$class
$param
Truth table25%1/4
A and B and C
A= $self_class->dbhB= $classC= $param
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 14 | my $mc_fkey; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 14 | my $class_opts = {}; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 14 | my $root_class_opts = {}; | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 14 | ▶ | if ($param->{m_class}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | #eval { load $param->{m_class} }; | ||||||||||||||||||||||||||||||||||||||||||
| 363 | #if (!is_loaded $param->{m_class}) { | ||||||||||||||||||||||||||||||||||||||||||
| 364 | # load $param->{m_class}; | ||||||||||||||||||||||||||||||||||||||||||
| 365 | # mark_as_loaded | ||||||||||||||||||||||||||||||||||||||||||
| 366 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | load_module $param->{m_class}; | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | for my $opts ( values %{ $param->{m_class}->_get_relations } ) { | |||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | if ($opts->{class} eq $param->{root_class}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $root_class_opts = $opts; | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | elsif ($opts->{class} eq $class) { | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | $class_opts = $opts; | |||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my $self = $self_class->new($class, @{ $param->{where_statement} }); | |||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my $connected_table_name = $class->_get_table_name; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $self->{prep_select_from} = [ $param->{m_class}->_get_table_name ]; | |||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | push @{ $self->{prep_left_joins} }, | |||||||||||||||||||||||||||||||||||||||||
| 385 | 'JOIN ' . $connected_table_name . ' ON ' . $connected_table_name . '.' . $class->_get_primary_key . ' = ' | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | . $param->{m_class}->_get_table_name . '.' . $class_opts->{params}{fk}; | |||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | push @{ $self->{prep_select_where} }, | |||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | $root_class_opts->{params}{fk} . ' = ' . $param->{self}->{ $param->{root_class}->_get_primary_key }; | |||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 14 | my $self = $self_class->new($class, @{ $param->{where_statement} }); | |||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 14 | my $connected_table_name = $class->_get_table_name; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 14 | $self->{prep_select_from} = [ $param->{via_table} ]; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 14 | my $fk = ActiveRecord::Simple::Utils::class_to_table_name($class); | |||||||||||||||||||||||||||||||||||||||||
| 399 | 14 | $fk .= '_id'; | |||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 14 | push @{ $self->{prep_left_joins} }, | |||||||||||||||||||||||||||||||||||||||||
| 402 | 'JOIN ' . $connected_table_name . ' ON ' . $connected_table_name . '.' . $class->_get_primary_key . ' = ' | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 14 | . $param->{via_table} . '.' . $fk; | |||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 14 | my $fk2 = ActiveRecord::Simple::Utils::class_to_table_name($param->{root_class}) . '_id'; | |||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 14 | push @{ $self->{prep_select_where} }, | |||||||||||||||||||||||||||||||||||||||||
| 408 | 14 | $fk2 . ' = ' . $param->{self}->{ $param->{root_class}->_get_primary_key }; | |||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 14 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | sub _get_slice { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_slice: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my ($self, $time) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | return unless $self->{_objects} | ||||||||||||||||||||||||||||||||||||||||||
| 419 | && ref $self->{_objects} eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | && scalar @{ $self->{_objects} } > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->{"_objects"} and ref $self->{"_objects"} eq "ARRAY" and scalar @{$self->{"_objects"};} > 0
$self->{"_objects"} and ref $self->{"_objects"} eq "ARRAY"
MC/DC0%0/3
$self->{"_objects"} and ref $self->{"_objects"} eq "ARRAY" and scalar @{$self->{"_objects"};} > 0
$self->{"_objects"}
ref $self->{"_objects"} eq "ARRAY"
scalar @{$self->{"_objects"};} > 0
Truth table0%0/4
A and B and C
A= $self->{"_objects"}B= ref $self->{"_objects"} eq "ARRAY"C= scalar @{$self->{"_objects"};} > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | $time ||= scalar @{ $self->{_objects} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$time ||= scalar @{$self->{"_objects"};}
MC/DC0%0/1
$time ||= scalar @{$self->{"_objects"};}
$time
Truth table0%0/2
A
A= $time
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | return splice @{ $self->{_objects} }, 0, $time; | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | return shift @{ $self->{_objects} }; | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 85 | ▶ | sub _quote_sql_stmt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quote_sql_stmt: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 85 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 85 | ▶ | return unless $self->{SQL} && $self->dbh; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"SQL"} and $self->dbh
MC/DC0%0/2
$self->{"SQL"} and $self->dbh
$self->{"SQL"}
$self->dbh
Truth table33%1/3
A and B
A= $self->{"SQL"}B= $self->dbh
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 85 | my $driver_name = $self->dbh->{Driver}{Name}; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 85 | ▶ | $driver_name //= 'Pg'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$driver_name //= "Pg"
MC/DC0%0/1
$driver_name //= "Pg"
$driver_name
Truth table50%1/2
A
A= $driver_name
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | 85 | my $quotes_map = { | |||||||||||||||||||||||||||||||||||||||||
| 439 | Pg => q/"/, | ||||||||||||||||||||||||||||||||||||||||||
| 440 | mysql => q/`/, | ||||||||||||||||||||||||||||||||||||||||||
| 441 | SQLite => q/`/, | ||||||||||||||||||||||||||||||||||||||||||
| 442 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 85 | my $quote = $quotes_map->{$driver_name}; | |||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 85 | $self->{SQL} =~ s/"/$quote/g; | |||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 85 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 129 | ▶ | sub _finish_object_representation { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish_object_representation: called CC=7 SCAR=29.1
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 129 | my ($self, $obj, $object_data, $read_only) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 129 | ▶ | if ($self->{has_joined_table}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | RELATION: | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 27 | for my $rel_name (@{ $self->{with} }) { | |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | my $relation = $self->{class}->_get_relations->{$rel_name} or next RELATION; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | my %pairs = map { $_, $object_data->{$_} } grep { $_ =~ /^JOINED\_$rel_name\_/ } keys %$object_data; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | next RELATION unless %pairs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | for my $key (keys %pairs) { | |||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | my $val = delete $pairs{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | $key =~ s/^JOINED\_$rel_name\_//; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | $pairs{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $obj->{"relation_instance_$rel_name"} = $relation->{class}->new(\%pairs); | |||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $obj->_delete_keys(qr/^JOINED\_$rel_name/); | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 129 | ▶ | $obj->{read_only} = 1 if defined $read_only; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | 129 | $obj->{isin_database} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 129 | return $obj; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | 85 | ▶ | sub _finish_sql_stmt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish_sql_stmt: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | 85 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 85 | ▶ | ref $self->{prep_select_fields} or croak 'Invalid prepare SQL statement'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 85 | ▶ | ref $self->{prep_select_from} or croak 'Invalid prepare SQL statement'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 85 | my $table_name = $self->{class}->_get_table_name; | |||||||||||||||||||||||||||||||||||||||||
| 485 | 85 | ▶ | my @add = grep { $_ !~~ $self->{prep_select_fields} } map qq/"$table_name".$_/, @{ $self->{prep_group_by}||[] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'prep_group_by'} || []
MC/DC100%1/1
$self->{'prep_group_by'} || []
$self->{'prep_group_by'}
Truth table100%2/2
A
A= $self->{'prep_group_by'}
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 85 | push @{ $self->{prep_select_fields} }, @add; | |||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | 85 | $self->{SQL} = "SELECT " . (join q/, /, @{ $self->{prep_select_fields} }) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 489 | 85 | $self->{SQL} .= "FROM " . (join q/, /, @{ $self->{prep_select_from} }) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 85 | ▶ | if (defined $self->{prep_left_joins}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 14 | $self->{SQL} .= "$_\n" for @{ $self->{prep_left_joins} }; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 14 | $self->{has_joined_table} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 85 | ▶ | if (@{ $self->{prep_select_where}||[] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{'prep_select_where'} || []
MC/DC0%0/1
$self->{'prep_select_where'} || []
$self->{'prep_select_where'}
Truth table50%1/2
A
A= $self->{'prep_select_where'}
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 58 | $self->{SQL} .= "WHERE\n"; | |||||||||||||||||||||||||||||||||||||||||
| 498 | 58 | $self->{SQL} .= join " AND ", @{ $self->{prep_select_where} }; | |||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | 85 | ▶ | if (@{ $self->{prep_group_by}||[] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{'prep_group_by'} || []
MC/DC100%1/1
$self->{'prep_group_by'} || []
$self->{'prep_group_by'}
Truth table100%2/2
A
A= $self->{'prep_group_by'}
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 3 | $self->{SQL} .= ' GROUP BY '; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 3 | $self->{SQL} .= join q/, /, @{ $self->{prep_group_by} }; | |||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 85 | ▶ | if (@{ $self->{prep_order_by}||[] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{'prep_order_by'} || []
MC/DC100%1/1
$self->{'prep_order_by'} || []
$self->{'prep_order_by'}
Truth table100%2/2
A
A= $self->{'prep_order_by'}
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | 21 | $self->{SQL} .= ' ORDER BY '; | |||||||||||||||||||||||||||||||||||||||||
| 508 | 21 | $self->{SQL} .= join q/, /, @{ $self->{prep_order_by} }; | |||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | 85 | ▶ | $self->{SQL} .= ' LIMIT ' . ($self->{prep_limit} // $MAXIMUM_LIMIT); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"prep_limit"} // $ActiveRecord::Simple::Find::MAXIMUM_LIMIT
MC/DC0%0/2
$self->{"prep_limit"} // $ActiveRecord::Simple::Find::MAXIMUM_LIMIT
$self->{"prep_limit"}
$ActiveRecord::Simple::Find::MAXIMUM_LIMIT
Truth table66%2/3
A // B
A= $self->{"prep_limit"}B= $ActiveRecord::Simple::Find::MAXIMUM_LIMIT
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | 85 | ▶ | $self->{SQL} .= ' OFFSET '. ($self->{prep_offset} // 0); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"prep_offset"} // 0
MC/DC100%1/1
$self->{"prep_offset"} // 0
$self->{"prep_offset"}
Truth table100%2/2
A
A= $self->{"prep_offset"}
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | 85 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | 23 | ▶ | sub _parse_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_hash: called CC=13 SCAR=34.7
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 23 | my ($self, $param_hash) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 519 | 23 | my $class = $self->{class}; | |||||||||||||||||||||||||||||||||||||||||
| 520 | 23 | ▶ | my $table_name = ($self->{class}->can('_get_table_name')) ? $self->{class}->_get_table_name : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 23 | my ($bind, $condition_pairs) = ([],[]); | |||||||||||||||||||||||||||||||||||||||||
| 522 | 23 | for my $param_name (keys %{ $param_hash }) { | |||||||||||||||||||||||||||||||||||||||||
| 523 | 23 | ▶ | if (ref $param_hash->{$param_name} eq 'ARRAY' and !ref $param_hash->{$param_name}[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
ref $param_hash->{$param_name} eq "ARRAY" and not ref $param_hash->{$param_name}[0]
MC/DC0%0/2
ref $param_hash->{$param_name} eq "ARRAY" and not ref $param_hash->{$param_name}[0]
ref $param_hash->{$param_name} eq "ARRAY"
not ref $param_hash->{$param_name}[0]
Truth table33%1/3
A and not(B)
A= ref $param_hash->{$param_name} eq "ARRAY"B= not ref $param_hash->{$param_name}[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | my $instr = join q/, /, map { '?' } @{ $param_hash->{$param_name} }; | |||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | push @$condition_pairs, qq/"$table_name"."$param_name" IN ($instr)/; | |||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | push @$bind, @{ $param_hash->{$param_name} }; | |||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | elsif (ref $param_hash->{$param_name}) { | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 2 | ▶ | next if !$class->can('_get_relations'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | 2 | ▶ | my $relation = $class->_get_relations->{$param_name} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | 2 | ▶ | next if $relation->{type} ne 'one'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | 2 | my $fk = $relation->{params}{fk}; | |||||||||||||||||||||||||||||||||||||||||
| 534 | 2 | my $pk = $relation->{params}{pk}; | |||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 2 | ▶ | if (ref $param_hash->{$param_name} eq __PACKAGE__) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | my $object = $param_hash->{$param_name}; | |||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | my $tmp_table = qq/tmp_table_/ . sprintf("%x", $object); | |||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | my $request_table = $object->{class}->_get_table_name; | |||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | $object->{prep_select_fields} = [qq/"$request_table"."$pk"/]; | |||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | $object->_finish_sql_stmt; | |||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | push @$condition_pairs, qq/"$table_name"."$fk" IN (SELECT "$tmp_table"."$pk" from ($object->{SQL}) as $tmp_table)/; | |||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | push @$bind, @{ $object->{BIND} } if ref $object->{BIND} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||
| 548 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 549 | 2 | my $object = $param_hash->{$param_name}; | |||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | 2 | ▶ | if (ref $object eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | push @$bind, map $_->$pk, @$object; | |||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | push @$condition_pairs, qq/"$table_name"."$fk" IN (@{[ join ', ', map "?", @$object ]})/; | |||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||
| 555 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 556 | 2 | push @$condition_pairs, qq/"$table_name"."$fk" = ?/; | |||||||||||||||||||||||||||||||||||||||||
| 557 | 2 | push @$bind, $object->$pk; | |||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||
| 561 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 21 | ▶ | if (defined $param_hash->{$param_name}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | 21 | push @$condition_pairs, qq/"$table_name"."$param_name" = ?/; | |||||||||||||||||||||||||||||||||||||||||
| 564 | 21 | push @$bind, $param_hash->{$param_name}; | |||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 567 | # is NULL | ||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | push @$condition_pairs, qq/"$table_name"."$param_name" IS NULL/; | |||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 23 | return ($bind, $condition_pairs); | |||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||
| 575 | 9 | ▶ | sub _order_by_direction { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_order_by_direction: called CC=5 SCAR=17.1
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | 9 | my ($self, $direction) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | # There are no fields for order yet | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 9 | ▶ | return unless ref $self->{prep_order_by} eq 'ARRAY' and scalar @{ $self->{prep_order_by} } > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $self->{"prep_order_by"} eq "ARRAY" and scalar @{$self->{"prep_order_by"};} > 0
MC/DC0%0/2
ref $self->{"prep_order_by"} eq "ARRAY" and scalar @{$self->{"prep_order_by"};} > 0
ref $self->{"prep_order_by"} eq "ARRAY"
scalar @{$self->{"prep_order_by"};} > 0
Truth table33%1/3
A and B
A= ref $self->{"prep_order_by"} eq "ARRAY"B= scalar @{$self->{"prep_order_by"};} > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | # asc/desc is called before: ->asc->desc | ||||||||||||||||||||||||||||||||||||||||||
| 582 | 9 | ▶ | return if defined $self->{prep_asc_desc}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | # $direction should be ASC/DESC | ||||||||||||||||||||||||||||||||||||||||||
| 585 | 9 | ▶ | return unless $direction =~ /^(ASC|DESC)$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | # Add $direction to the latest field | ||||||||||||||||||||||||||||||||||||||||||
| 588 | 9 | @{$self->{prep_order_by}}[-1] .= " $direction"; | |||||||||||||||||||||||||||||||||||||||||
| 589 | 9 | $self->{prep_asc_desc} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | 9 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | ▶ | sub DESTROY { } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | my $call = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | my $class = ref $self; | |||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | $call =~ s/.*:://; | |||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | my $error = "Can't call method `$call` on class $class.\nPerhaps you have forgotten to fetch your object?"; | |||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | croak $error; | |||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | __END__; | ||||||||||||||||||||||||||||||||||||||||||