blib/lib/DBIO/ResultSource.pm

filter: Statementstmt 86.7% 515 / 594 Branchbran 70.4% 248 / 352 Conditioncond 55.9% 183 / 327 MC/DCmcdc 30.1% 53 / 176 Subroutinesub 89.1% 66 / 74 Podpod 97.3% 36 / 37 totaltotal 70.5% 1101 / 1560 CC 335 SCAR 53.2
CC
335
Cov
74%
_resolve_relationship_condition
821.3
_minimal_valueset_satisfying_constraint
33.0
add_index_declaration
24.9
CRAP 204.7
↑ Summary blib/lib/DBIO/Test/Util/LeakTracer.pm »
1 package DBIO::ResultSource;
2 # ABSTRACT: Metadata object describing a table, view, or query source
3  
4 379 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 379 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 379 our $VERSION = '0.900007';
8  
9 379 ▶use base qw/DBIO::ResultSource::RowParser DBIO::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 379 ▶use DBIO::ResultSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 379 ▶use DBIO::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 379 ▶use DBIO::Util 'UNRESOLVABLE_CONDITION';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 379 ▶use DBIO::Util qw(is_literal_value);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 379 ▶use Devel::GlobalDestruction;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 379 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 379 ▶use Scalar::Util qw/blessed weaken isweak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 379 ▶use Storable ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 379 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 379 __PACKAGE__->mk_group_accessors(simple => qw/
24 source_name name source_info
25 _ordered_columns _columns _primaries _unique_constraints
26 _relationships resultset_attributes
27 column_info_from_storage
28 /);
29  
30 379 __PACKAGE__->mk_group_accessors(component_class => qw/
31 resultset_class
32 result_class
33 /);
34  
35 379 __PACKAGE__->mk_classdata( sqlt_deploy_callback => 'default_sqlt_deploy_hook' );
36  
37  
38 208662 ▶sub new {
Subroutine new: called CC=11 SCAR=24.0
Pod documented
39 208662 my ($class, $attrs) = @_;
40 208662 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 195650 13012 208662
41  
42 208662 ▶ my $new = bless { %{$attrs || {}} }, $class;
Condition50%1/2
$attrs || {}
l!l
2086620
MC/DC0%0/1
$attrs || {}
$attrs
Truth table50%1/2
A
A= $attrs
Aresult
11
00
43 208662 ▶ $new->{resultset_class} ||= 'DBIO::ResultSet';
Condition100%2/2
$new->{"resultset_class"} ||= "DBIO::ResultSet"
l!l
2071811481
MC/DC100%1/1
$new->{"resultset_class"} ||= "DBIO::ResultSet"
$new->{"resultset_class"}
Truth table100%2/2
A
A= $new->{"resultset_class"}
Aresult
11
00
44 208662 ▶ $new->{resultset_attributes} = { %{$new->{resultset_attributes} || {}} };
Condition100%2/2
$new->{'resultset_attributes'} || {}
l!l
2071811481
MC/DC100%1/1
$new->{'resultset_attributes'} || {}
$new->{'resultset_attributes'}
Truth table100%2/2
A
A= $new->{'resultset_attributes'}
Aresult
11
00
45 208662 ▶ $new->{_ordered_columns} = [ @{$new->{_ordered_columns}||[]}];
Condition100%2/2
$new->{'_ordered_columns'} || []
l!l
2071811481
MC/DC100%1/1
$new->{'_ordered_columns'} || []
$new->{'_ordered_columns'}
Truth table100%2/2
A
A= $new->{'_ordered_columns'}
Aresult
11
00
46 208662 ▶ $new->{_columns} = { %{$new->{_columns}||{}} };
Condition100%2/2
$new->{'_columns'} || {}
l!l
2071811481
MC/DC100%1/1
$new->{'_columns'} || {}
$new->{'_columns'}
Truth table100%2/2
A
A= $new->{'_columns'}
Aresult
11
00
47 208662 ▶ $new->{_relationships} = { %{$new->{_relationships}||{}} };
Condition100%2/2
$new->{'_relationships'} || {}
l!l
2071811481
MC/DC100%1/1
$new->{'_relationships'} || {}
$new->{'_relationships'}
Truth table100%2/2
A
A= $new->{'_relationships'}
Aresult
11
00
48 208662 ▶ $new->{_index_declarations} = [ @{$new->{_index_declarations}||[]} ];
Condition100%2/2
$new->{'_index_declarations'} || []
l!l
2071811481
MC/DC100%1/1
$new->{'_index_declarations'} || []
$new->{'_index_declarations'}
Truth table100%2/2
A
A= $new->{'_index_declarations'}
Aresult
11
00
49 208662 ▶ $new->{name} ||= "!!NAME NOT SET!!";
Condition100%2/2
$new->{"name"} ||= "!!NAME NOT SET!!"
l!l
208562100
MC/DC100%1/1
$new->{"name"} ||= "!!NAME NOT SET!!"
$new->{"name"}
Truth table100%2/2
A
A= $new->{"name"}
Aresult
11
00
50 208662 ▶ $new->{_columns_info_loaded} ||= 0;
Condition50%1/2
$new->{"_columns_info_loaded"} ||= 0
l!l
0208662
MC/DC0%0/1
$new->{"_columns_info_loaded"} ||= 0
$new->{"_columns_info_loaded"}
Truth table50%1/2
A
A= $new->{"_columns_info_loaded"}
Aresult
11
00
51 208662 return $new;
52 }
53  
54  
55  
56 12576 ▶sub add_columns {
Subroutine add_columns: called CC=6 SCAR=17.9
Pod documented
57 12576 my ($self, @cols) = @_;
58 12576 ▶ $self->_ordered_columns(\@cols) unless $self->_ordered_columns;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_ordered_columns 0 12576 12576
59  
60 12576 my @added;
61 12576 my $columns = $self->_columns;
62 12576 ▶ while (my $col = shift @cols) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $col = shift @cols) 37758 12576 50334
63 37758 my $column_info = {};
64 37758 ▶ if ($col =~ s/^\+//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col =~ s/^\+//) 512 37246 37758
65 512 $column_info = $self->column_info($col);
66 }
67  
68 # If next entry is { ... } use that for the column info, if not
69 # use an empty hashref
70 37758 ▶ if (ref $cols[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cols[0]) 37758 0 37758
71 37758 my $new_info = shift(@cols);
72 37758 %$column_info = (%$column_info, %$new_info);
73 }
74 37758 ▶ push(@added, $col) unless exists $columns->{$col};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $columns->{$col} 37242 516 37758
75 37758 $columns->{$col} = $column_info;
76 }
77 12576 push @{ $self->_ordered_columns }, @added;
78 12576 return $self;
79 }
80  
81  
82 1 ▶sub add_column { shift->add_columns(@_); } # DO NOT CHANGE THIS TO GLOB
Subroutine add_column: called CC=1 SCAR=0.0
Pod documented
83  
84  
85 62962 ▶sub has_column {
Subroutine has_column: called CC=1 SCAR=0.0
Pod documented
86 62962 my ($self, $column) = @_;
87 62962 return exists $self->_columns->{$column};
88 }
89  
90  
91 64129 ▶sub column_info {
Subroutine column_info: called CC=6 SCAR=28.1
Pod documented
92 64129 my ($self, $column) = @_;
93 $self->throw_exception("No such column $column")
94 64129 ▶ unless exists $self->_columns->{$column};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->_columns->{$column} 0 64129 64129
95  
96 64129 ▶ if ( ! $self->_columns->{$column}{data_type}
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_columns->{$column}{"data_type"} || $self->{"_columns_info_loaded"} and $self->column_info_from_storage and my $stor = &try(sub { $self->storage; } )) 0 64129 64129
Condition55%5/9
not $self->_columns->{$column}{"data_type"} || $self->{"_columns_info_loaded"} and $self->column_info_from_storage and my $stor = &try(sub { $self->storage; } )
!ll&&!rl&&r
6412900
not $self->_columns->{$column}{"data_type"} || $self->{"_columns_info_loaded"} and $self->column_info_from_storage
!ll&&!rl&&r
64064650
$self->_columns->{$column}{'data_type'} || $self->{'_columns_info_loaded'}
l!l&&r!l&&!r
64064065
MC/DC0%0/4
not $self->_columns->{$column}{"data_type"} || $self->{"_columns_info_loaded"} and $self->column_info_from_storage and my $stor = &try(sub { $self->storage; } )
$self->_columns->{$column}{'data_type'} $self->{'_columns_info_loaded'} $self->column_info_from_storage my $stor = &try(sub { $self->storage; } )
Truth table40%2/5
not(A || B) and C and D
A= $self->_columns->{$column}{'data_type'}B= $self->{'_columns_info_loaded'}C= $self->column_info_from_storageD= my $stor = &try(sub { $self->storage; } )
ABCDresult
1XXX0
01XX0
000X0
00100
00111
97 and ! $self->{_columns_info_loaded}
98 and $self->column_info_from_storage
99 0 ▶ and my $stor = try { $self->storage } )
Subroutine __ANON__: not called CC=1 SCAR=6.9
100 {
101 0 $self->{_columns_info_loaded}++;
102  
103 # try for the case of storage without table
104 0 ▶ try {
Subroutine __ANON__: not called CC=4 SCAR=30.0
105 0 my $info = $stor->columns_info_for( $self->from );
106 my $lc_info = { map
107 0 { (lc $_) => $info->{$_} }
108 ( keys %$info )
109 };
110  
111 0 foreach my $col ( keys %{$self->_columns} ) {
112 $self->_columns->{$col} = {
113 0 %{ $self->_columns->{$col} },
114 0 ▶ %{ $info->{$col} || $lc_info->{lc $col} || {} }
Condition0%0/5
$info->{$col} || $$lc_info{lc $col} || {}
l!l
00
$info->{$col} or $$lc_info{lc $col}
l!l&&r!l&&!r
000
MC/DC0%0/2
$info->{$col} || $$lc_info{lc $col} || {}
$info->{$col} $$lc_info{lc $col}
Truth table0%0/3
A or B
A= $info->{$col}B= $$lc_info{lc $col}
ABresult
1X1
011
000
115 };
116 }
117 0 };
118 }
119  
120 64129 return $self->_columns->{$column};
121 }
122  
123  
124 16222 ▶sub columns {
Subroutine columns: called CC=3 SCAR=11.0
Pod documented
125 16222 my $self = shift;
126 16222 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 16221 16222
127 "columns() is a read-only accessor, did you mean add_columns()?"
128 ) if @_;
129 16221 ▶ return @{$self->{_ordered_columns}||[]};
Condition50%1/2
$self->{'_ordered_columns'} || []
l!l
162210
MC/DC0%0/1
$self->{'_ordered_columns'} || []
$self->{'_ordered_columns'}
Truth table50%1/2
A
A= $self->{'_ordered_columns'}
Aresult
11
00
130 }
131  
132  
133 30673 ▶sub columns_info {
Subroutine columns_info: called CC=10 SCAR=30.1
Pod documented
134 30673 my ($self, $columns) = @_;
135  
136 30673 my $colinfo = $self->_columns;
137  
138 30673 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not $_->{"data_type"};} values %$colinfo and not $self->{"_columns_info_loaded"} and $self->column_info_from_storage and my $stor = &try(sub { $self->storage; } )) 0 30673 30673
Condition55%5/9
grep {not $_->{"data_type"};} values %$colinfo and not $self->{"_columns_info_loaded"} and $self->column_info_from_storage and my $stor = &try(sub { $self->storage; } )
!ll&&!rl&&r
3067300
grep {not $_->{"data_type"};} values %$colinfo and not $self->{"_columns_info_loaded"} and $self->column_info_from_storage
!ll&&!rl&&r
30646270
grep {not $_->{"data_type"};} values %$colinfo and not $self->{"_columns_info_loaded"}
!ll&&!rl&&r
30646027
MC/DC0%0/4
grep {not $_->{"data_type"};} values %$colinfo and not $self->{"_columns_info_loaded"} and $self->column_info_from_storage and my $stor = &try(sub { $self->storage; } )
grep {not $_->{"data_type"};} values %$colinfo not $self->{"_columns_info_loaded"} $self->column_info_from_storage my $stor = &try(sub { $self->storage; } )
Truth table40%2/5
A and not(B) and C and D
A= grep {not $_->{"data_type"};} values %$colinfoB= not $self->{"_columns_info_loaded"}C= $self->column_info_from_storageD= my $stor = &try(sub { $self->storage; } )
ABCDresult
0XXX0
10XX0
110X0
11100
11111
139 111631 grep { ! $_->{data_type} } values %$colinfo
140 and
141 ! $self->{_columns_info_loaded}
142 and
143 $self->column_info_from_storage
144 and
145 0 ▶ my $stor = try { $self->storage }
Subroutine __ANON__: not called CC=1 SCAR=6.9
146 ) {
147 0 $self->{_columns_info_loaded}++;
148  
149 # try for the case of storage without table
150 0 ▶ try {
Subroutine __ANON__: not called CC=4 SCAR=30.0
151 0 my $info = $stor->columns_info_for( $self->from );
152 my $lc_info = { map
153 0 { (lc $_) => $info->{$_} }
154 ( keys %$info )
155 };
156  
157 0 foreach my $col ( keys %$colinfo ) {
158 $colinfo->{$col} = {
159 0 %{ $colinfo->{$col} },
160 0 ▶ %{ $info->{$col} || $lc_info->{lc $col} || {} }
Condition0%0/5
$info->{$col} || $$lc_info{lc $col} || {}
l!l
00
$info->{$col} or $$lc_info{lc $col}
l!l&&r!l&&!r
000
MC/DC0%0/2
$info->{$col} || $$lc_info{lc $col} || {}
$info->{$col} $$lc_info{lc $col}
Truth table0%0/3
A or B
A= $info->{$col}B= $$lc_info{lc $col}
ABresult
1X1
011
000
161 };
162 }
163 0 };
164 }
165  
166 30673 my %ret;
167  
168 30673 ▶ if ($columns) {
Branch: 1 branch
BranchTrueFalseTotal
if ($columns) { } 11638 19035 30673
169 11638 for (@$columns) {
170 15518 ▶ if (my $inf = $colinfo->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $inf = $colinfo->{$_}) { } 15514 4 15518
171 15514 $ret{$_} = $inf;
172 }
173 else {
174 4 ▶ $self->throw_exception( sprintf (
Condition60%3/5
$self->source_name || $self->name || 'Unknown source...?'
l!l
40
$self->source_name or $self->name
l!l&&r!l&&!r
310
MC/DC0%0/2
$self->source_name || $self->name || 'Unknown source...?'
$self->source_name $self->name
Truth table66%2/3
A or B
A= $self->source_nameB= $self->name
ABresult
1X1
011
000
175 "No such column '%s' on source '%s'",
176 $_,
177 $self->source_name || $self->name || 'Unknown source...?',
178 ));
179 }
180 }
181 }
182 else {
183 19035 %ret = %$colinfo;
184 }
185  
186 30669 return \%ret;
187 }
188  
189  
190 1 ▶sub remove_columns {
Subroutine remove_columns: called CC=3 SCAR=11.0
Pod documented
191 1 my ($self, @to_remove) = @_;
192  
193 1 ▶ my $columns = $self->_columns
Branch: 1 branch
BranchTrueFalseTotal
my $columns = $self->_columns or return 1 0 1
194 or return;
195  
196 1 my %to_remove;
197 1 for (@to_remove) {
198 1 delete $columns->{$_};
199 1 ++$to_remove{$_};
200 }
201  
202 1 $self->_ordered_columns([ grep { not $to_remove{$_} } @{$self->_ordered_columns} ]);
203 }
204  
205  
206 0 ▶sub remove_column { shift->remove_columns(@_); } # DO NOT CHANGE THIS TO GLOB
Subroutine remove_column: not called CC=1 SCAR=6.9
Pod documented
207  
208  
209 11359 ▶sub set_primary_key {
Subroutine set_primary_key: called CC=5 SCAR=16.7
Pod documented
210 11359 my ($self, @cols) = @_;
211  
212 11359 my $colinfo = $self->columns_info(\@cols);
213 11358 for my $col (@cols) {
214 carp_unique(sprintf (
215 "Primary key of source '%s' includes the column '%s' which has its "
216 . "'is_nullable' attribute set to true. This is a mistake and will cause "
217 . 'various Result-object operations to fail',
218 $self->source_name || $self->name || 'Unknown source...?',
219 $col,
220 15219 ▶ )) if $colinfo->{$col}{is_nullable};
Branch: 1 branch
BranchTrueFalseTotal
if $colinfo->{$col}{"is_nullable"} 1 15218 15219
Condition40%2/5
$self->source_name || $self->name || 'Unknown source...?'
l!l
10
$self->source_name or $self->name
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->source_name || $self->name || 'Unknown source...?'
$self->source_name $self->name
Truth table33%1/3
A or B
A= $self->source_nameB= $self->name
ABresult
1X1
011
000
221 }
222  
223 11358 $self->_primaries(\@cols);
224  
225 11358 $self->add_unique_constraint(primary => \@cols);
226 }
227  
228  
229 19426 ▶sub primary_columns {
Subroutine primary_columns: called CC=2 SCAR=6.9
Pod documented
230 19426 ▶ return @{shift->_primaries||[]};
Condition100%2/2
(shift())->_primaries || []
l!l
1939729
MC/DC100%1/1
(shift())->_primaries || []
(shift())->_primaries
Truth table100%2/2
A
A= (shift())->_primaries
Aresult
11
00
231 }
232  
233 # a helper method that will automatically die with a descriptive message if
234 # no pk is defined on the source in question. For internal use to save
235 # on if @pks... boilerplate
236 15262 ▶sub _pri_cols_or_die {
Subroutine _pri_cols_or_die: called CC=5 SCAR=25.9
237 15262 my $self = shift;
238 15262 ▶ my @pcols = $self->primary_columns
Branch: 1 branch
BranchTrueFalseTotal
my(@pcols) = $self->primary_columns or $self->throw_exception(sprintf("Operation requires a primary key to be declared on '%s' via set_primary_key", $self->source_name || $self->result_class || $self->name || "Unknown source...?")) 15262 0 15262
Condition0%0/8
$self->source_name || $self->result_class || $self->name || 'Unknown source...?'
l!l
00
$self->source_name or $self->result_class or $self->name
l!l&&r!l&&!r
000
$self->source_name or $self->result_class
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->source_name || $self->result_class || $self->name || 'Unknown source...?'
$self->source_name $self->result_class $self->name
Truth table0%0/4
A or B or C
A= $self->source_nameB= $self->result_classC= $self->name
ABCresult
1XX1
01X1
0011
0000
239 or $self->throw_exception (sprintf(
240 "Operation requires a primary key to be declared on '%s' via set_primary_key",
241 # source_name is set only after schema-registration
242 $self->source_name || $self->result_class || $self->name || 'Unknown source...?',
243 ));
244 15262 return @pcols;
245 }
246  
247 # same as above but mandating single-column PK (used by relationship condition
248 # inference)
249 14495 ▶sub _single_pri_col_or_die {
Subroutine _single_pri_col_or_die: called CC=5 SCAR=24.5
250 14495 my $self = shift;
251 14495 my ($pri, @too_many) = $self->_pri_cols_or_die;
252  
253 14495 ▶ $self->throw_exception( sprintf(
Branch: 1 branch
BranchTrueFalseTotal
if @too_many 0 14495 14495
Condition0%0/8
$self->source_name || $self->result_class || $self->name || 'Unknown source...?'
l!l
00
$self->source_name or $self->result_class or $self->name
l!l&&r!l&&!r
000
$self->source_name or $self->result_class
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->source_name || $self->result_class || $self->name || 'Unknown source...?'
$self->source_name $self->result_class $self->name
Truth table0%0/4
A or B or C
A= $self->source_nameB= $self->result_classC= $self->name
ABCresult
1XX1
01X1
0011
0000
254 "Operation requires a single-column primary key declared on '%s'",
255 $self->source_name || $self->result_class || $self->name || 'Unknown source...?',
256 )) if @too_many;
257 14495 return $pri;
258 }
259  
260  
261  
262 256 ▶sub sequence {
Subroutine sequence: called CC=3 SCAR=11.1
Pod documented
263 256 my ($self,$seq) = @_;
264  
265 256 ▶ my @pks = $self->primary_columns
Branch: 1 branch
BranchTrueFalseTotal
my(@pks) = $self->primary_columns or return 256 0 256
266 or return;
267  
268 $_->{sequence} = $seq
269 256 for values %{ $self->columns_info (\@pks) };
270 }
271  
272  
273  
274 16122 ▶sub add_unique_constraint {
Subroutine add_unique_constraint: called CC=7 SCAR=21.8
Pod documented
275 16122 my $self = shift;
276  
277 16122 ▶ if (@_ > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2) 0 16122 16122
278 0 $self->throw_exception(
279 'add_unique_constraint() does not accept multiple constraints, use '
280 . 'add_unique_constraints() instead'
281 );
282 }
283  
284 16122 my $cols = pop @_;
285 16122 ▶ if (ref $cols ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cols ne "ARRAY") 0 16122 16122
286 0 ▶ $self->throw_exception (
Condition0%0/2
$cols || 'NOTHING'
l!l
00
MC/DC0%0/1
$cols || 'NOTHING'
$cols
Truth table0%0/2
A
A= $cols
Aresult
11
00
287 'Expecting an arrayref of constraint columns, got ' . ($cols||'NOTHING')
288 );
289 }
290  
291 16122 my $name = shift @_;
292  
293 16122 ▶ $name ||= $self->name_unique_constraint($cols);
Condition66%2/3
$name ||= $self->name_unique_constraint($cols)
l!l&&r!l&&!r
1345426680
MC/DC0%0/2
$name ||= $self->name_unique_constraint($cols)
$name $self->name_unique_constraint($cols)
Truth table66%2/3
A ||= B
A= $nameB= $self->name_unique_constraint($cols)
ABresult
1X1
011
000
294  
295 16122 foreach my $col (@$cols) {
296 23329 ▶ $self->throw_exception("No such column $col on table " . $self->name)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_column($col) 0 23329 23329
297 unless $self->has_column($col);
298 }
299  
300 16122 my %unique_constraints = $self->unique_constraints;
301 16122 $unique_constraints{$name} = $cols;
302 16122 $self->_unique_constraints(\%unique_constraints);
303 }
304  
305  
306 514 ▶sub add_unique_constraints {
Subroutine add_unique_constraints: called CC=5 SCAR=16.1
Pod documented
307 514 my $self = shift;
308 514 my @constraints = @_;
309  
310 514 ▶ if ( !(@constraints % 2) && grep { ref $_ ne 'ARRAY' } @constraints ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @constraints % 2 and grep {ref $_ ne 'ARRAY';} @constraints) { } 257 257 514
Condition66%2/3
not @constraints % 2 and grep {ref $_ ne "ARRAY";} @constraints
!ll&&!rl&&r
0257257
MC/DC50%1/2
not @constraints % 2 and grep {ref $_ ne "ARRAY";} @constraints
not @constraints % 2 grep {ref $_ ne "ARRAY";} @constraints
Truth table66%2/3
not(A) and B
A= not @constraints % 2B= grep {ref $_ ne "ARRAY";} @constraints
ABresult
0X0
100
111
311 # with constraint name
312 257 ▶ while (my ($name, $constraint) = splice @constraints, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@constraints, 0, 2)) 514 257 771
313 514 $self->add_unique_constraint($name => $constraint);
314 }
315 }
316 else {
317 # no constraint name
318 257 foreach my $constraint (@constraints) {
319 514 $self->add_unique_constraint($constraint);
320 }
321 }
322 }
323  
324  
325 2669 ▶sub name_unique_constraint {
Subroutine name_unique_constraint: called CC=2 SCAR=6.9
Pod documented
326 2669 my ($self, $cols) = @_;
327  
328 2669 my $name = $self->name;
329 2669 ▶ $name = $$name if (ref $name eq 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $name eq "SCALAR" 257 2412 2669
330 2669 $name =~ s/ ^ [^\.]+ \. //x; # strip possible schema qualifier
331  
332 2669 return join '_', $name, @$cols;
333 }
334  
335  
336 23773 ▶sub unique_constraints {
Subroutine unique_constraints: called CC=2 SCAR=6.9
Pod documented
337 23773 ▶ return %{shift->_unique_constraints||{}};
Condition100%2/2
(shift())->_unique_constraints || {}
l!l
1215711616
MC/DC100%1/1
(shift())->_unique_constraints || {}
(shift())->_unique_constraints
Truth table100%2/2
A
A= (shift())->_unique_constraints
Aresult
11
00
338 }
339  
340  
341 72 ▶sub add_index_declaration {
Subroutine add_index_declaration: called CC=24 SCAR=32.2
Pod documented
342 72 my ($self, $decl) = @_;
343  
344 72 ▶ $self->throw_exception('add_index_declaration() expects a hashref')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $decl eq "HASH" 1 71 72
345 unless ref $decl eq 'HASH';
346  
347 71 my $name = $decl->{name};
348 71 ▶ $self->throw_exception('add_index_declaration(): the index needs a name')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name and not ref $name 2 69 71
Condition83%5/6
defined $name and length $name and not ref $name
!ll&&!rl&&r
2069
defined $name and length $name
!ll&&!rl&&r
1169
MC/DC66%2/3
defined $name and length $name and not ref $name
defined $name length $name not ref $name
Truth table75%3/4
A and B and not(C)
A= defined $nameB= length $nameC= not ref $name
ABCresult
0XX0
10X0
1100
1111
349 unless defined $name and length $name and !ref $name;
350  
351 69 my $cols = $decl->{columns};
352 69 ▶ $cols = [ $cols ] if defined $cols and !ref $cols and length $cols;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cols and not ref $cols and length $cols 15 54 69
Condition83%5/6
defined $cols and not ref $cols and length $cols
!ll&&!rl&&r
54015
defined $cols and not ref $cols
!ll&&!rl&&r
15315
MC/DC66%2/3
defined $cols and not ref $cols and length $cols
defined $cols not ref $cols length $cols
Truth table75%3/4
A and not(B) and C
A= defined $colsB= not ref $colsC= length $cols
ABCresult
0XX0
10X0
1100
1111
353 $self->throw_exception(
354 "add_index_declaration(): index '$name' needs columns, a column name or an arrayref of them"
355 ) unless ref $cols eq 'ARRAY'
356 and @$cols
357 69 ▶ and !grep { !defined $_ or ref $_ or !length $_ } @$cols;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cols eq "ARRAY" and @$cols and not grep({not defined $_ or ref $_ or not length $_;} @$cols) 3 66 69
Condition58%7/12
ref $cols eq "ARRAY" and @$cols and not grep({not defined $_ or ref $_ or not length $_;} @$cols)
!ll&&!rl&&r
3066
ref $cols eq "ARRAY" and @$cols
!ll&&!rl&&r
2166
!defined($_) || ref $_ || !length($_)
l!l&&r!l&&!r
0074
not defined $_ or ref $_
l!l&&r!l&&!r
0074
MC/DC66%2/3
ref $cols eq "ARRAY" and @$cols and not grep({not defined $_ or ref $_ or not length $_;} @$cols)
ref $cols eq "ARRAY" @$cols not grep({not defined $_ or ref $_ or not length $_;} @$cols)
MC/DC0%0/3
!defined($_) || ref $_ || !length($_)
not defined $_ ref $_ !length($_)
Truth table75%3/4
A and B and not(C)
A= ref $cols eq "ARRAY"B= @$colsC= not grep({not defined $_ or ref $_ or not length $_;} @$cols)
ABCresult
0XX0
10X0
1100
1111
Truth table25%1/4
not(A) or B || not(C)
A= not defined $_B= ref $_C= !length($_)
ABCresult
1XX1
01X1
0011
0000
358  
359 66 my $driver = $decl->{driver};
360 66 ▶ if (defined $driver) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $driver) 23 43 66
361 23 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $driver eq "HASH" 1 22 23
362 "add_index_declaration(): index '$name': driver must be a hashref, driver => { pg => { ... } }"
363 ) unless ref $driver eq 'HASH';
364 22 my %known = map { $_ => 1 } $self->index_declaration_drivers;
365 22 for my $drv (sort keys %$driver) {
366 $self->throw_exception(
367 "add_index_declaration(): index '$name': unknown driver block '$drv' "
368 . "(accepted: " . join(', ', map "'$_'", $self->index_declaration_drivers) . ")"
369 25 ▶ ) unless $known{$drv};
Branch: 1 branch
BranchTrueFalseTotal
unless $known{$drv} 1 24 25
370 $self->throw_exception(
371 "add_index_declaration(): index '$name': driver block '$drv' must be a hashref"
372 24 ▶ ) unless ref $driver->{$drv} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $driver->{$drv} eq "HASH" 1 23 24
373 }
374 }
375  
376 my $entry = Storable::dclone({
377 name => $name,
378 columns => $cols,
379 unique => (
380 ($decl->{unique} or ($decl->{type} // '') =~ /^unique$/i) ? 1 : 0
381 ),
382 type => $decl->{type},
383 options => $decl->{options},
384 63 ▶ driver => $driver || {},
Branch: 1 branch
BranchTrueFalseTotal
$decl->{'unique'} || ($decl->{'type'} // '') =~ /^unique$/i ? : 9 54 63
Condition85%6/7
$decl->{"unique"} or ($decl->{"type"} // "") =~ /^unique$/i
l!l&&r!l&&!r
0954
$decl->{"type"} // ""
l!l
954
$driver || {}
l!l
2043
MC/DC50%1/2
$decl->{"unique"} or ($decl->{"type"} // "") =~ /^unique$/i
$decl->{"unique"} $decl->{"type"}
MC/DC100%1/1
$driver || {}
$driver
Truth table66%2/3
A or B
A= $decl->{"unique"}B= $decl->{"type"}
ABresult
1X1
011
000
Truth table100%2/2
A
A= $driver
Aresult
11
00
385 });
386  
387 63 ▶ my $list = $self->{_index_declarations} ||= [];
Condition50%1/2
$self->{"_index_declarations"} ||= []
l!l
630
MC/DC0%0/1
$self->{"_index_declarations"} ||= []
$self->{"_index_declarations"}
Truth table50%1/2
A
A= $self->{"_index_declarations"}
Aresult
11
00
388 63 my ($pos) = grep { $list->[$_]{name} eq $name } 0 .. $#$list;
389 63 ▶ if (defined $pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) { } 1 62 63
390 1 $list->[$pos] = $entry;
391 }
392 else {
393 62 push @$list, $entry;
394 }
395  
396 63 return;
397 }
398  
399  
400 33 ▶sub index_declarations {
Subroutine index_declarations: called CC=2 SCAR=7.0
Pod documented
401 33 my $self = shift;
402 33 ▶ return map { Storable::dclone($_) } @{ $self->{_index_declarations} || [] };
Condition50%1/2
$self->{'_index_declarations'} || []
l!l
330
MC/DC0%0/1
$self->{'_index_declarations'} || []
$self->{'_index_declarations'}
Truth table50%1/2
A
A= $self->{'_index_declarations'}
Aresult
11
00
403 }
404  
405  
406 99 ▶sub index_declaration_drivers { qw(pg sqlite mysql oracle mssql sybase firebird clickhouse duckdb db2 informix) }
Subroutine index_declaration_drivers: called CC=1 SCAR=0.0
Pod documented
407  
408  
409 7 ▶sub index_declarations_for {
Subroutine index_declarations_for: called CC=13 SCAR=26.5
Pod documented
410 7 my ($self, $driver, $allowed) = @_;
411  
412 $self->throw_exception(
413 "index_declarations_for(): '" . ($driver // 'undef') . "' is not a driver "
414 . "name, expected one of "
415 . join(', ', map "'$_'", $self->index_declaration_drivers)
416 7 ▶ ) unless defined $driver and grep { $_ eq $driver } $self->index_declaration_drivers;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $driver and grep {$_ eq $driver;} $self->index_declaration_drivers 0 7 7
Condition20%1/5
defined $driver and grep {$_ eq $driver;} $self->index_declaration_drivers
!ll&&!rl&&r
007
$driver // "undef"
l!l
00
MC/DC0%0/2
defined $driver and grep {$_ eq $driver;} $self->index_declaration_drivers
defined $driver grep {$_ eq $driver;} $self->index_declaration_drivers
MC/DC0%0/1
$driver // "undef"
$driver
Truth table33%1/3
A and B
A= defined $driverB= grep {$_ eq $driver;} $self->index_declaration_drivers
ABresult
0X0
100
111
Truth table0%0/2
A
A= $driver
Aresult
11
00
417 7 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $allowed eq "ARRAY" 1 6 7
418 "index_declarations_for('$driver'): expects the allowed keys of the "
419 . "driver block as an arrayref"
420 ) unless ref $allowed eq 'ARRAY';
421  
422 6 my %allowed = map { $_ => 1 } @$allowed;
423 6 my $label = $self->source_name;
424 6 ▶ $label = $self->name unless defined $label;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $label 6 0 6
425 6 ▶ $label = 'source' if ref $label;
Branch: 1 branch
BranchTrueFalseTotal
if ref $label 0 6 6
426  
427 6 my @out;
428 6 for my $idx ($self->index_declarations) {
429 15 ▶ my $blocks = $idx->{driver} || {};
Condition50%1/2
$idx->{'driver'} || {}
l!l
150
MC/DC0%0/1
$idx->{'driver'} || {}
$idx->{'driver'}
Truth table50%1/2
A
A= $idx->{'driver'}
Aresult
11
00
430 15 my $own = $blocks->{$driver};
431  
432 15 ▶ if (!$own) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $own) { } 8 7 15
433 8 ▶ if (my @foreign = sort keys %$blocks) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@foreign) = sort(keys %$blocks)) 3 5 8
434 3 $self->throw_exception(
435 "$label: index '$idx->{name}' carries only the "
436 . join(', ', map "'$_'", @foreign)
437 . " block and none for '$driver'; declare $driver => { ... } "
438 . "for it, or $driver => {} for the plain index"
439 );
440 }
441 }
442 else {
443 7 for my $key (sort keys %$own) {
444 4 ▶ next if $allowed{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $allowed{$key} 3 1 4
445 1 $self->throw_exception(
446 "$label: index '$idx->{name}': unknown key '$key' in its "
447 . "'$driver' block (valid keys: "
448 . join(', ', map "'$_'", sort keys %allowed) . ")"
449 );
450 }
451 }
452 11 push @out, $idx;
453 }
454  
455 2 return @out;
456 }
457  
458  
459 1002 ▶sub unique_constraint_names {
Subroutine unique_constraint_names: called CC=1 SCAR=0.0
Pod documented
460 1002 my ($self) = @_;
461  
462 1002 my %unique_constraints = $self->unique_constraints;
463  
464 1002 return keys %unique_constraints;
465 }
466  
467  
468 5465 ▶sub unique_constraint_columns {
Subroutine unique_constraint_columns: called CC=2 SCAR=6.9
Pod documented
469 5465 my ($self, $constraint_name) = @_;
470  
471 5465 my %unique_constraints = $self->unique_constraints;
472  
473 $self->throw_exception(
474 "Unknown unique constraint $constraint_name on '" . $self->name . "'"
475 5465 ▶ ) unless exists $unique_constraints{$constraint_name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $unique_constraints{$constraint_name} 2 5463 5465
476  
477 5463 return @{ $unique_constraints{$constraint_name} };
478 }
479  
480  
481 0 ▶sub default_sqlt_deploy_hook {
Subroutine default_sqlt_deploy_hook: not called CC=3 SCAR=24.8
Pod documented
482 0 my $self = shift;
483  
484 0 my $class = $self->result_class;
485  
486 0 ▶ if ($class and $class->can('sqlt_deploy_hook')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class and $class->can("sqlt_deploy_hook")) 0 0 0
Condition0%0/3
$class and $class->can("sqlt_deploy_hook")
!ll&&!rl&&r
000
MC/DC0%0/2
$class and $class->can("sqlt_deploy_hook")
$class $class->can("sqlt_deploy_hook")
Truth table0%0/3
A and B
A= $classB= $class->can("sqlt_deploy_hook")
ABresult
0X0
100
111
487 0 $class->sqlt_deploy_hook(@_);
488 }
489 }
490  
491 0 ▶sub _invoke_sqlt_deploy_hook {
Subroutine _invoke_sqlt_deploy_hook: not called CC=2 SCAR=17.9
492 0 my $self = shift;
493 0 ▶ if ( my $hook = $self->sqlt_deploy_callback) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hook = $self->sqlt_deploy_callback) 0 0 0
494 0 $self->$hook(@_);
495 }
496 }
497  
498  
499  
500 6450 ▶sub resultset {
Subroutine resultset: called CC=2 SCAR=7.0
Pod documented
501 6450 my $self = shift;
502 6450 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 6450 6450
503 'resultset does not take any arguments. If you want another resultset, '.
504 'call it on the schema instead.'
505 ) if scalar @_;
506  
507 $self->resultset_class->new(
508 $self,
509 {
510 6450 ▶ try { %{$self->schema->default_resultset_attributes} },
Subroutine __ANON__: called CC=1 SCAR=0.0
511 6450 %{$self->{resultset_attributes}},
512 },
513 );
514 }
515  
516  
517 0 ▶sub from { die 'Virtual method!' }
Subroutine from: not called CC=1 SCAR=6.9
Pod documented
518  
519  
520 144075 ▶sub schema {
Subroutine schema: called CC=5 SCAR=16.1
Pod documented
521 144075 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) { } 105594 38481 144075
522 105594 $_[0]->{schema} = $_[1];
523 }
524 else {
525 38481 ▶ $_[0]->{schema} || do {
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"schema"} or do { my $name = $_[0]{"source_name"} || "_unnamed_"; my $err = 'Unable to perform storage-dependent operations with a detached result source ' . "(source '${name}' is not associated with a schema)."; $err .= ' You need to use $schema->thaw() or manually set $DBIO::ResultSource::thaw_schema while thawing.' if $_[0]{"_detached_thaw"}; "DBIO::Exception"->throw($err) } 38442 39 38481
526 39 ▶ my $name = $_[0]->{source_name} || '_unnamed_';
Condition100%2/2
$_[0]{'source_name'} || '_unnamed_'
l!l
1029
MC/DC100%1/1
$_[0]{'source_name'} || '_unnamed_'
$_[0]{'source_name'}
Truth table100%2/2
A
A= $_[0]{'source_name'}
Aresult
11
00
527 39 my $err = 'Unable to perform storage-dependent operations with a detached result source '
528 . "(source '$name' is not associated with a schema).";
529  
530 $err .= ' You need to use $schema->thaw() or manually set'
531 . ' $DBIO::ResultSource::thaw_schema while thawing.'
532 39 ▶ if $_[0]->{_detached_thaw};
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_detached_thaw"} 10 29 39
533  
534 39 DBIO::Exception->throw($err);
535 };
536 }
537 }
538  
539  
540 14431 ▶sub storage { shift->schema->storage; }
Subroutine storage: called CC=1 SCAR=0.0
Pod documented
541  
542  
543 22714 ▶sub add_relationship {
Subroutine add_relationship: called CC=9 SCAR=22.0
Pod documented
544 22714 my ($self, $rel, $f_source_name, $cond, $attrs) = @_;
545 22714 ▶ $self->throw_exception("Can't create relationship without join condition")
Branch: 1 branch
BranchTrueFalseTotal
unless $cond 0 22714 22714
546 unless $cond;
547 22714 ▶ $attrs ||= {};
Condition100%2/2
$attrs ||= {}
l!l
227131
MC/DC100%1/1
$attrs ||= {}
$attrs
Truth table100%2/2
A
A= $attrs
Aresult
11
00
548  
549 # Check foreign and self are right in cond
550 22714 ▶ if ( (ref $cond ||'') eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ((ref $cond || "") eq "HASH") 18874 3840 22714
Condition50%1/2
ref $cond || ''
l!l
227140
MC/DC0%0/1
ref $cond || ''
ref $cond
Truth table50%1/2
A
A= ref $cond
Aresult
11
00
551 $_ =~ /^foreign\./ or $self->throw_exception("Malformed relationship condition key '$_': must be prefixed with 'foreign.'")
552 18874 ▶ for keys %$cond;
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /^foreign\./ or $self->throw_exception("Malformed relationship condition key '${_}': must be prefixed with 'foreign.'") 21175 3 21178
553  
554 $_ =~ /^self\./ or $self->throw_exception("Malformed relationship condition value '$_': must be prefixed with 'self.'")
555 18871 ▶ for values %$cond;
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /^self\./ or $self->throw_exception("Malformed relationship condition value '${_}': must be prefixed with 'self.'") 21171 4 21175
556 }
557  
558 22707 my %rels = %{ $self->_relationships };
559 22707 $rels{$rel} = { class => $f_source_name,
560 source => $f_source_name,
561 cond => $cond,
562 attrs => $attrs };
563 22707 $self->_relationships(\%rels);
564  
565 # No definition-time resolution of the related source (ADR 0054). Only the
566 # local, self-contained checks above run here (join condition present;
567 # foreign./self. prefixing). The related source named by $f_source_name is
568 # deliberately NOT resolved at declaration time: relationships are declared
569 # while the schema is still being composed, when the far side is routinely
570 # not registered yet (forward and circular references are normal), and on a
571 # standalone prototype source there is neither a schema nor storage to
572 # resolve against. Resolution is lazy -- it happens on first use, when
573 # related_source/_resolve_join run against a fully-composed schema.
574 22707 return $self;
575 }
576  
577  
578 # Through an array, not `return sort ...`: sort in scalar context is
579 # undefined, and the count is what this returned there all along.
580 1292 ▶sub relationships {
Subroutine relationships: called CC=1 SCAR=0.0
Pod documented
581 1292 my @rel_names = sort keys %{shift->_relationships};
582 1292 return @rel_names;
583 }
584  
585  
586 46867 ▶sub relationship_info {
Subroutine relationship_info: called CC=1 SCAR=0.0
Pod documented
587 #my ($self, $rel) = @_;
588 46867 return shift->_relationships->{+shift};
589 }
590  
591  
592 6326 ▶sub has_relationship {
Subroutine has_relationship: called CC=1 SCAR=0.0
Pod documented
593 #my ($self, $rel) = @_;
594 6326 return exists shift->_relationships->{+shift};
595 }
596  
597  
598 152 ▶sub reverse_relationship_info {
Subroutine reverse_relationship_info: called CC=13 SCAR=25.7
Pod documented
599 152 my ($self, $rel) = @_;
600  
601 152 ▶ my $rel_info = $self->relationship_info($rel)
Branch: 1 branch
BranchTrueFalseTotal
my $rel_info = $self->relationship_info($rel) or $self->throw_exception("No such relationship '${rel}'") 152 0 152
602 or $self->throw_exception("No such relationship '$rel'");
603  
604 152 my $ret = {};
605  
606 152 ▶ return $ret unless ((ref $rel_info->{cond}) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rel_info->{"cond"} eq "HASH" 1 151 152
607  
608 151 my $stripped_cond = $self->__strip_relcond ($rel_info->{cond});
609  
610 151 my $registered_source_name = $self->source_name;
611  
612 # this may be a partial schema or something else equally esoteric
613 151 my $other_rsrc = $self->related_source($rel);
614  
615 # Get all the relationships for that source that related to this source
616 # whose foreign column set are our self columns on $rel and whose self
617 # columns are our foreign columns on $rel
618 151 foreach my $other_rel ($other_rsrc->relationships) {
619  
620 # only consider stuff that points back to us
621 # "us" here is tricky - if we are in a schema registration, we want
622 # to use the source_names, otherwise we will use the actual classes
623  
624 # the schema may be partial
625 1542 ▶ my $roundtrip_rsrc = try { $other_rsrc->related_source($other_rel) }
Subroutine __ANON__: called CC=1 SCAR=0.0
626 1542 ▶ or next;
Branch: 1 branch
BranchTrueFalseTotal
my $roundtrip_rsrc = &try(sub { $other_rsrc->related_source($other_rel); } ) or next 1542 0 1542
627  
628 1542 ▶ if ($registered_source_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($registered_source_name) { } 1528 14 1542
629 1528 ▶ next if $registered_source_name ne ($roundtrip_rsrc->source_name || '')
Branch: 1 branch
BranchTrueFalseTotal
if $registered_source_name ne ($roundtrip_rsrc->source_name || "") 977 551 1528
Condition50%1/2
$roundtrip_rsrc->source_name || ''
l!l
15280
MC/DC0%0/1
$roundtrip_rsrc->source_name || ''
$roundtrip_rsrc->source_name
Truth table50%1/2
A
A= $roundtrip_rsrc->source_name
Aresult
11
00
630 }
631 else {
632 14 ▶ next if $self->result_class ne $roundtrip_rsrc->result_class;
Branch: 1 branch
BranchTrueFalseTotal
if $self->result_class ne $roundtrip_rsrc->result_class 6 8 14
633 }
634  
635 559 my $other_rel_info = $other_rsrc->relationship_info($other_rel);
636  
637 # this can happen when we have a self-referential class
638 559 ▶ next if $other_rel_info eq $rel_info;
Branch: 1 branch
BranchTrueFalseTotal
if $other_rel_info eq $rel_info 4 555 559
639  
640 555 ▶ next unless ref $other_rel_info->{cond} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $other_rel_info->{"cond"} eq "HASH" 189 366 555
641 366 my $other_stripped_cond = $self->__strip_relcond($other_rel_info->{cond});
642  
643 366 ▶ $ret->{$other_rel} = $other_rel_info if (
Branch: 1 branch
BranchTrueFalseTotal
if $self->_compare_relationship_keys([keys %$stripped_cond], [values %$other_stripped_cond]) and $self->_compare_relationship_keys([values %$stripped_cond], [keys %$other_stripped_cond]) 277 89 366
Condition100%3/3
$self->_compare_relationship_keys([keys %$stripped_cond], [values %$other_stripped_cond]) and $self->_compare_relationship_keys([values %$stripped_cond], [keys %$other_stripped_cond])
!ll&&!rl&&r
863277
MC/DC100%2/2
$self->_compare_relationship_keys([keys %$stripped_cond], [values %$other_stripped_cond]) and $self->_compare_relationship_keys([values %$stripped_cond], [keys %$other_stripped_cond])
$self->_compare_relationship_keys([keys %$stripped_cond], [values %$other_stripped_cond]) $self->_compare_relationship_keys([values %$stripped_cond], [keys %$other_stripped_cond])
Truth table100%3/3
A and B
A= $self->_compare_relationship_keys([keys %$stripped_cond], [values %$other_stripped_cond])B= $self->_compare_relationship_keys([values %$stripped_cond], [keys %$other_stripped_cond])
ABresult
0X0
100
111
644 $self->_compare_relationship_keys (
645 [ keys %$stripped_cond ], [ values %$other_stripped_cond ]
646 )
647 and
648 $self->_compare_relationship_keys (
649 [ values %$stripped_cond ], [ keys %$other_stripped_cond ]
650 )
651 );
652 }
653  
654 151 return $ret;
655 }
656  
657 # all this does is removes the foreign/self prefix from a condition
658 517 ▶sub __strip_relcond {
Subroutine __strip_relcond: called CC=1 SCAR=0.0
659 +{
660 map
661 517 { map { /^ (?:foreign|self) \. (.+) $/x } ($_, $_[1]{$_}) }
662 517 keys %{$_[1]}
663 }
664 }
665  
666 # Returns true if both sets of keynames are the same, false otherwise.
667 646 ▶sub _compare_relationship_keys {
Subroutine _compare_relationship_keys: called CC=1 SCAR=0.0
668 # my ($self, $keys1, $keys2) = @_;
669 return
670 646 join ("\x00", sort @{$_[1]})
671 eq
672 646 join ("\x00", sort @{$_[2]})
673 ;
674 }
675  
676 # optionally takes either an arrayref of column names, or a hashref of already
677 # retrieved colinfos
678 # returns an arrayref of column names of the shortest unique constraint
679 # (matching some of the input if any), giving preference to the PK
680 403 ▶sub _identifying_column_set {
Subroutine _identifying_column_set: called CC=9 SCAR=22.3
681 403 my ($self, $cols) = @_;
682  
683 403 my %unique = $self->unique_constraints;
684 403 ▶ my $colinfos = ref $cols eq 'HASH' ? $cols : $self->columns_info($cols||());
Branch: 1 branch
BranchTrueFalseTotal
ref $cols eq 'HASH' ? : 107 296 403
Condition66%2/3
$cols || ()
l!l&&r!l&&!r
122840
MC/DC0%0/2
$cols || ()
$cols ()
Truth table66%2/3
A || B
A= $colsB= ()
ABresult
1X1
011
000
685  
686 # always prefer the PK first, and then shortest constraints first
687 USET:
688 403 for my $set (delete $unique{primary}, sort { @$a <=> @$b } (values %unique) ) {
689 465 ▶ next unless $set && @$set;
Branch: 1 branch
BranchTrueFalseTotal
unless $set and @$set 0 465 465
Condition33%1/3
$set and @$set
!ll&&!rl&&r
00465
MC/DC0%0/2
$set and @$set
$set @$set
Truth table33%1/3
A and B
A= $setB= @$set
ABresult
0X0
100
111
690  
691 465 for (@$set) {
692 501 ▶ next USET unless ($colinfos->{$_} && !$colinfos->{$_}{is_nullable} );
Branch: 1 branch
BranchTrueFalseTotal
unless $colinfos->{$_} and not $colinfos->{$_}{"is_nullable"} 83 418 501
Condition100%3/3
$colinfos->{$_} and not $colinfos->{$_}{"is_nullable"}
!ll&&!rl&&r
785418
MC/DC100%2/2
$colinfos->{$_} and not $colinfos->{$_}{"is_nullable"}
$colinfos->{$_} not $colinfos->{$_}{"is_nullable"}
Truth table100%3/3
A and not(B)
A= $colinfos->{$_}B= not $colinfos->{$_}{"is_nullable"}
ABresult
0X0
100
111
693 }
694  
695 # copy so we can mangle it at will
696 382 return [ @$set ];
697 }
698  
699 21 return undef;
700 }
701  
702 1997 ▶sub _minimal_valueset_satisfying_constraint {
Subroutine _minimal_valueset_satisfying_constraint: called CC=19 SCAR=35.0
703 1997 my $self = shift;
704 0 ▶ my $args = { ref $_[0] eq 'HASH' ? %{ $_[0] } : @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 1997 1997
705  
706 1997 ▶ $args->{columns_info} ||= $self->columns_info;
Condition66%2/3
$args->{"columns_info"} ||= $self->columns_info
l!l&&r!l&&!r
98510120
MC/DC0%0/2
$args->{"columns_info"} ||= $self->columns_info
$args->{"columns_info"} $self->columns_info
Truth table66%2/3
A ||= B
A= $args->{"columns_info"}B= $self->columns_info
ABresult
1X1
011
000
707  
708 my $vals = $self->storage->_extract_fixed_condition_columns(
709 $args->{values},
710 1997 ▶ ($args->{carp_on_nulls} ? 'consider_nulls' : undef ),
Branch: 1 branch
BranchTrueFalseTotal
$args->{'carp_on_nulls'} ? : 0 1997 1997
711 );
712  
713 1997 my $cols;
714 1997 for my $col ($self->unique_constraint_columns($args->{constraint_name}) ) {
715 2032 ▶ if( ! exists $vals->{$col} or ( $vals->{$col}||'' ) eq UNRESOLVABLE_CONDITION ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $vals->{$col} or ($vals->{$col} || '') eq \'1 = 0') { } 2 2030 2032
elsif (not defined $vals->{$col}) { } 0 2030 2030
Condition60%3/5
not exists $vals->{$col} or ($vals->{$col} || "") eq \"1 = 0"
l!l&&r!l&&!r
202030
$vals->{$col} || ''
l!l
20300
MC/DC0%0/2
not exists $vals->{$col} or ($vals->{$col} || "") eq \"1 = 0"
not exists $vals->{$col} $vals->{$col}
Truth table66%2/3
not(A) or B
A= not exists $vals->{$col}B= $vals->{$col}
ABresult
1X1
011
000
716 2 $cols->{missing}{$col} = undef;
717 }
718 elsif( ! defined $vals->{$col} ) {
719 0 ▶ $cols->{$args->{carp_on_nulls} ? 'undefined' : 'missing'}{$col} = undef;
Branch: 1 branch
BranchTrueFalseTotal
$args->{'carp_on_nulls'} ? : 0 0 0
720 }
721 else {
722 # we need to inject back the '=' as _extract_fixed_condition_columns
723 # will strip it from literals and values alike, resulting in an invalid
724 # condition in the end
725 2030 $cols->{present}{$col} = { '=' => $vals->{$col} };
726 }
727  
728 $cols->{fc}{$col} = 1 if (
729 ( ! $cols->{missing} or ! exists $cols->{missing}{$col} )
730 and
731 2032 ▶ keys %{ $args->{columns_info}{$col}{_filter_info} || {} }
Branch: 1 branch
BranchTrueFalseTotal
if not $cols->{"missing"} && exists $cols->{"missing"}{$col} and keys %{$args->{"columns_info"}{$col}{"_filter_info"} or {};} 0 2032 2032
Condition75%6/8
not $cols->{"missing"} && exists $cols->{"missing"}{$col} and keys %{$args->{"columns_info"}{$col}{"_filter_info"} or {};}
!ll&&!rl&&r
220300
$cols->{'missing'} && exists $cols->{'missing'}{$col}
!ll&&!rl&&r
202912
$args->{'columns_info'}{$col}{'_filter_info'} || {}
l!l
02030
MC/DC0%0/3
not $cols->{"missing"} && exists $cols->{"missing"}{$col} and keys %{$args->{"columns_info"}{$col}{"_filter_info"} or {};}
$cols->{'missing'} exists $cols->{'missing'}{$col} keys %{$args->{"columns_info"}{$col}{"_filter_info"} or {};}
MC/DC0%0/1
$args->{'columns_info'}{$col}{'_filter_info'} || {}
$args->{'columns_info'}{$col}{'_filter_info'}
Truth table60%3/5
not(A && B) and C
A= $cols->{'missing'}B= exists $cols->{'missing'}{$col}C= keys %{$args->{"columns_info"}{$col}{"_filter_info"} or {};}
ABCresult
11X0
0X00
1000
0X11
1011
Truth table50%1/2
A
A= $args->{'columns_info'}{$col}{'_filter_info'}
Aresult
11
00
732 );
733 }
734  
735 $self->throw_exception( sprintf ( "Unable to satisfy requested constraint '%s', missing values for column(s): %s",
736 $args->{constraint_name},
737 2 join (', ', map { "'$_'" } sort keys %{$cols->{missing}} ),
738 1997 ▶ ) ) if $cols->{missing};
Branch: 1 branch
BranchTrueFalseTotal
if $cols->{"missing"} 2 1995 1997
739  
740 $self->throw_exception( sprintf (
741 "Unable to satisfy requested constraint '%s', FilterColumn values not usable for column(s): %s",
742 $args->{constraint_name},
743 0 join (', ', map { "'$_'" } sort keys %{$cols->{fc}}),
744 1995 ▶ )) if $cols->{fc};
Branch: 1 branch
BranchTrueFalseTotal
if $cols->{"fc"} 0 1995 1995
745  
746 1995 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($cols->{"undefined"} and not $ENV{"DBIO_NULLABLE_KEY_NOWARN"}) 0 1995 1995
Condition33%1/3
$cols->{"undefined"} and not $ENV{"DBIO_NULLABLE_KEY_NOWARN"}
!ll&&!rl&&r
199500
MC/DC0%0/2
$cols->{"undefined"} and not $ENV{"DBIO_NULLABLE_KEY_NOWARN"}
$cols->{"undefined"} not $ENV{"DBIO_NULLABLE_KEY_NOWARN"}
Truth table33%1/3
A and not(B)
A= $cols->{"undefined"}B= not $ENV{"DBIO_NULLABLE_KEY_NOWARN"}
ABresult
0X0
100
111
747 $cols->{undefined}
748 and
749 !$ENV{DBIO_NULLABLE_KEY_NOWARN}
750 ) {
751 carp_unique ( sprintf (
752 "NULL/undef values supplied for requested unique constraint '%s' (NULL "
753 . 'values in column(s): %s). This is almost certainly not what you wanted, '
754 . 'though you can set DBIO_NULLABLE_KEY_NOWARN to disable this warning.',
755 $args->{constraint_name},
756 0 join (', ', map { "'$_'" } sort keys %{$cols->{undefined}}),
757 ));
758 }
759  
760 1995 ▶ return { map { %{ $cols->{$_}||{} } } qw(present undefined) };
Condition100%2/2
$cols->{$_} || {}
l!l
19951995
MC/DC100%1/1
$cols->{$_} || {}
$cols->{$_}
Truth table100%2/2
A
A= $cols->{$_}
Aresult
11
00
761 }
762  
763 # Returns the {from} structure used to express JOIN conditions
764 258 ▶sub _resolve_join {
Subroutine _resolve_join: called CC=18 SCAR=29.7
765 258 my ($self, $join, $alias, $seen, $jpath, $parent_force_left) = @_;
766  
767 # we need a supplied one, because we do in-place modifications, no returns
768 258 ▶ $self->throw_exception ('You must supply a seen hashref as the 3rd argument to _resolve_join')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $seen eq "HASH" 0 258 258
769 unless ref $seen eq 'HASH';
770  
771 258 ▶ $self->throw_exception ('You must supply a joinpath arrayref as the 4th argument to _resolve_join')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $jpath eq "ARRAY" 0 258 258
772 unless ref $jpath eq 'ARRAY';
773  
774 258 $jpath = [@$jpath]; # copy
775  
776 258 ▶ if (not defined $join or not length $join) {
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $join && length $join) { } 16 242 258
elsif (ref $join eq 'ARRAY') { } 65 177 242
elsif (ref $join eq 'HASH') { } 14 163 177
elsif (ref $join) { } 0 163 163
Condition66%2/3
defined $join && length $join
!ll&&!rl&&r
160242
MC/DC50%1/2
defined $join && length $join
defined $join length $join
Truth table66%2/3
A && B
A= defined $joinB= length $join
ABresult
0X0
100
111
777 16 return ();
778 }
779 elsif (ref $join eq 'ARRAY') {
780 return
781 map {
782 65 $self->_resolve_join($_, $alias, $seen, $jpath, $parent_force_left);
783 } @$join;
784 }
785 elsif (ref $join eq 'HASH') {
786  
787 14 my @ret;
788 14 for my $rel (keys %$join) {
789  
790 13 ▶ my $rel_info = $self->relationship_info($rel)
Branch: 1 branch
BranchTrueFalseTotal
my $rel_info = $self->relationship_info($rel) or $self->throw_exception("No such relationship '${rel}' on " . $self->source_name) 13 0 13
791 or $self->throw_exception("No such relationship '$rel' on " . $self->source_name);
792  
793 13 my $force_left = $parent_force_left;
794 13 ▶ $force_left ||= lc($rel_info->{attrs}{join_type}||'') eq 'left';
Condition100%5/5
$force_left ||= lc($rel_info->{"attrs"}{"join_type"} || "") eq "left"
l!l&&r!l&&!r
175
$rel_info->{'attrs'}{'join_type'} || ''
l!l
75
MC/DC100%2/2
$force_left ||= lc($rel_info->{"attrs"}{"join_type"} || "") eq "left"
$force_left $rel_info->{'attrs'}{'join_type'}
Truth table100%3/3
A ||= B
A= $force_leftB= $rel_info->{'attrs'}{'join_type'}
ABresult
1X1
011
000
795  
796 # the actual seen value will be incremented by the recursion
797 my $as = $self->storage->relname_to_table_alias(
798 13 ▶ $rel, ($seen->{$rel} && $seen->{$rel} + 1)
Condition66%2/3
$seen->{$rel} && $seen->{$rel} + 1
!ll&&!rl&&r
1003
MC/DC50%1/2
$seen->{$rel} && $seen->{$rel} + 1
$seen->{$rel} $seen->{$rel} + 1
Truth table66%2/3
A && B
A= $seen->{$rel}B= $seen->{$rel} + 1
ABresult
0X0
100
111
799 );
800  
801 push @ret, (
802 $self->_resolve_join($rel, $alias, $seen, [@$jpath], $force_left),
803 $self->related_source($rel)->_resolve_join(
804 13 $join->{$rel}, $as, $seen, [@$jpath, { $rel => $as }], $force_left
805 )
806 );
807 }
808 14 return @ret;
809  
810 }
811 elsif (ref $join) {
812 0 $self->throw_exception("No idea how to resolve join reftype ".ref $join);
813 }
814 else {
815 163 my $count = ++$seen->{$join};
816 163 ▶ my $as = $self->storage->relname_to_table_alias(
Condition66%2/3
$count > 1 && $count
!ll&&!rl&&r
15508
MC/DC50%1/2
$count > 1 && $count
$count > 1 $count
Truth table66%2/3
A && B
A= $count > 1B= $count
ABresult
0X0
100
111
817 $join, ($count > 1 && $count)
818 );
819  
820 163 ▶ my $rel_info = $self->relationship_info($join)
Branch: 1 branch
BranchTrueFalseTotal
my $rel_info = $self->relationship_info($join) or $self->throw_exception("No such relationship $join on " . $self->source_name) 163 0 163
821 or $self->throw_exception("No such relationship $join on " . $self->source_name);
822  
823 163 my $rel_src = $self->related_source($join);
824 return [ { $as => $rel_src->from,
825 -rsrc => $rel_src,
826 -join_type => $parent_force_left
827 ? 'left'
828 : $rel_info->{attrs}{join_type}
829 ,
830 -join_path => [@$jpath, { $join => $as } ],
831 -is_single => !!(
832 (! $rel_info->{attrs}{accessor})
833 or
834 326 ▶ grep { $rel_info->{attrs}{accessor} eq $_ } (qw/single filter/)
Condition100%2/2
$seen->{'-relation_chain_depth'} || 0
l!l
39124
MC/DC100%1/1
$seen->{'-relation_chain_depth'} || 0
$seen->{'-relation_chain_depth'}
Truth table100%2/2
A
A= $seen->{'-relation_chain_depth'}
Aresult
11
00
835 ),
836 -alias => $as,
837 -relation_chain_depth => ( $seen->{-relation_chain_depth} || 0 ) + 1,
838 },
839 163 ▶ scalar $self->_resolve_condition($rel_info->{cond}, $as, $alias, $join)
Branch: 1 branch
BranchTrueFalseTotal
$parent_force_left ? : 17 146 163
Condition66%2/3
!$rel_info->{'attrs'}{'accessor'} || grep({$rel_info->{'attrs'}{'accessor'} eq $_;} 'single', 'filter')
l!l&&r!l&&!r
07687
MC/DC50%1/2
!$rel_info->{'attrs'}{'accessor'} || grep({$rel_info->{'attrs'}{'accessor'} eq $_;} 'single', 'filter')
!$rel_info->{'attrs'}{'accessor'} grep({$rel_info->{'attrs'}{'accessor'} eq $_;} 'single', 'filter')
Truth table66%2/3
not(A) || B
A= !$rel_info->{'attrs'}{'accessor'}B= grep({$rel_info->{'attrs'}{'accessor'} eq $_;} 'single', 'filter')
ABresult
1X1
011
000
840 ];
841 }
842 }
843  
844 # Determines whether a relation is dependent on an object from this source
845 # having already been inserted. Takes the name of the relationship and a
846 # hashref of columns of the related object.
847 132 ▶sub _pk_depends_on {
Subroutine _pk_depends_on: called CC=7 SCAR=19.6
848 132 my ($self, $rel_name, $rel_data) = @_;
849  
850 132 my $relinfo = $self->relationship_info($rel_name);
851  
852 # don't assume things if the relationship direction is specified
853 return $relinfo->{attrs}{is_foreign_key_constraint}
854 132 ▶ if exists ($relinfo->{attrs}{is_foreign_key_constraint});
Branch: 1 branch
BranchTrueFalseTotal
if exists $relinfo->{"attrs"}{"is_foreign_key_constraint"} 86 46 132
855  
856 46 my $cond = $relinfo->{cond};
857 46 ▶ return 0 unless ref($cond) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cond eq "HASH" 0 46 46
858  
859 # map { foreign.foo => 'self.bar' } to { bar => 'foo' }
860 46 my $keyhash = { map { my $x = $_; $x =~ s/.*\.//; $x; } reverse %$cond };
861  
862 # assume anything that references our PK probably is dependent on us
863 # rather than vice versa, unless the far side is (a) defined or (b)
864 # auto-increment
865 46 my $rel_source = $self->related_source($rel_name);
866  
867 46 foreach my $p ($self->primary_columns) {
868 46 ▶ if (exists $keyhash->{$p}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $keyhash->{$p}) 46 0 46
869 46 ▶ unless (defined($rel_data->{$keyhash->{$p}})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$rel_data{$keyhash->{$p}} or $rel_source->column_info($keyhash->{$p})->{"is_auto_increment"}) 45 1 46
Condition66%2/3
defined $$rel_data{$keyhash->{$p}} or $rel_source->column_info($keyhash->{$p})->{"is_auto_increment"}
l!l&&r!l&&!r
1045
MC/DC50%1/2
defined $$rel_data{$keyhash->{$p}} or $rel_source->column_info($keyhash->{$p})->{"is_auto_increment"}
defined $$rel_data{$keyhash->{$p}} $rel_source->column_info($keyhash->{$p})->{"is_auto_increment"}
Truth table66%2/3
A or B
A= defined $$rel_data{$keyhash->{$p}}B= $rel_source->column_info($keyhash->{$p})->{"is_auto_increment"}
ABresult
1X1
011
000
870 || $rel_source->column_info($keyhash->{$p})
871 ->{is_auto_increment}) {
872 45 return 0;
873 }
874 }
875 }
876  
877 1 return 1;
878 }
879  
880 # True for a relationship that holds this row's foreign key (belongs_to): the
881 # related row exists before this one, so multi-create may look it up.
882 104 ▶sub _relationship_depends_on {
Subroutine _relationship_depends_on: called CC=3 SCAR=11.0
883 104 my ($self, $rel_name) = @_;
884  
885 104 my $relinfo = $self->relationship_info($rel_name);
886 104 ▶ return $relinfo && $relinfo->{attrs}{is_depends_on} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$relinfo && $relinfo->{'attrs'}{'is_depends_on'} ? : 86 18 104
Condition66%2/3
$relinfo and $relinfo->{"attrs"}{"is_depends_on"}
!ll&&!rl&&r
01886
MC/DC50%1/2
$relinfo and $relinfo->{"attrs"}{"is_depends_on"}
$relinfo $relinfo->{"attrs"}{"is_depends_on"}
Truth table66%2/3
A and B
A= $relinfoB= $relinfo->{"attrs"}{"is_depends_on"}
ABresult
0X0
100
111
887 }
888  
889 # The columns of this source a relationship with a hash condition sets on a
890 # row of this source, as the foreign key side of the condition names them.
891 # A condition of any other kind names none here: its columns are known only
892 # when it is resolved against a value.
893 46 ▶sub _relationship_self_columns {
Subroutine _relationship_self_columns: called CC=5 SCAR=18.1
894 46 my ($self, $rel_name) = @_;
895  
896 46 ▶ my $cond = ( $self->relationship_info($rel_name) || {} )->{cond};
Condition50%1/2
$self->relationship_info($rel_name) || {}
l!l
460
MC/DC0%0/1
$self->relationship_info($rel_name) || {}
$self->relationship_info($rel_name)
Truth table50%1/2
A
A= $self->relationship_info($rel_name)
Aresult
11
00
897 46 ▶ return () unless ref $cond eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cond eq "HASH" 0 46 46
898  
899 46 ▶ return map { ! ref $_ && $_ =~ /^self\.(.+)/ ? $1 : () } values %$cond;
Branch: 1 branch
BranchTrueFalseTotal
!ref($_) && $_ =~ /^self\.(.+)/ ? : 46 0 46
Condition33%1/3
not ref $_ and $_ =~ /^self\.(.+)/
!ll&&!rl&&r
0046
MC/DC0%0/2
not ref $_ and $_ =~ /^self\.(.+)/
not ref $_ $_ =~ /^self\.(.+)/
Truth table33%1/3
not(A) and B
A= not ref $_B= $_ =~ /^self\.(.+)/
ABresult
0X0
100
111
900 }
901  
902 # Mass assignment (ADR 0071): throws for the first column of the list that is
903 # marked is_guarded.
904 6745 ▶sub _assert_columns_not_guarded {
Subroutine _assert_columns_not_guarded: called CC=4 SCAR=13.9
905 6745 my ($self, @cols) = @_;
906  
907 6745 my $columns = $self->_columns;
908 6745 for my $col (@cols) {
909 $self->throw_exception(sprintf(
910 "Column '%s' of source '%s' is guarded (is_guarded) and takes no value "
911 . "from new_result, create, update(\\%%hash), update_or_create, populate or multi-create",
912 $col, $self->source_name,
913 6745 ▶ )) if $columns->{$col} and $columns->{$col}{is_guarded};
Branch: 1 branch
BranchTrueFalseTotal
if $columns->{$col} and $columns->{$col}{"is_guarded"} 23 6722 6745
Condition100%3/3
$columns->{$col} and $columns->{$col}{"is_guarded"}
!ll&&!rl&&r
4671823
MC/DC100%2/2
$columns->{$col} and $columns->{$col}{"is_guarded"}
$columns->{$col} $columns->{$col}{"is_guarded"}
Truth table100%3/3
A and B
A= $columns->{$col}B= $columns->{$col}{"is_guarded"}
ABresult
0X0
100
111
914 }
915  
916 6722 return;
917 }
918  
919 # Throws unless the relationship takes data in multi-create.
920 42 ▶sub _assert_relationship_not_guarded {
Subroutine _assert_relationship_not_guarded: called CC=3 SCAR=11.0
921 42 my ($self, $rel_name) = @_;
922  
923 42 my $relinfo = $self->relationship_info($rel_name);
924  
925 $self->throw_exception(sprintf(
926 "Relationship '%s' of source '%s' is guarded (is_guarded) and takes no data in multi-create",
927 $rel_name, $self->source_name,
928 42 ▶ )) if $relinfo and $relinfo->{attrs}{is_guarded};
Branch: 1 branch
BranchTrueFalseTotal
if $relinfo and $relinfo->{"attrs"}{"is_guarded"} 3 39 42
Condition66%2/3
$relinfo and $relinfo->{"attrs"}{"is_guarded"}
!ll&&!rl&&r
0393
MC/DC50%1/2
$relinfo and $relinfo->{"attrs"}{"is_guarded"}
$relinfo $relinfo->{"attrs"}{"is_guarded"}
Truth table66%2/3
A and B
A= $relinfoB= $relinfo->{"attrs"}{"is_guarded"}
ABresult
0X0
100
111
929  
930 39 return;
931 }
932  
933 # Mass assignment (ADR 0071): the values the caller assigns ({ column =>
934 # value }) agree with the equality conditions of the resultset ({ column =>
935 # value }, undef for IS NULL): the same value, NULL for NULL. A condition that
936 # is not a plain value (a literal) is not compared.
937 3010 ▶sub _assert_scope_agrees {
Subroutine _assert_scope_agrees: called CC=14 SCAR=26.5
938 3010 my ($self, $assigned, $scope) = @_;
939  
940 3010 for my $col (sort keys %$assigned) {
941 7453 ▶ next unless exists $scope->{$col};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $scope->{$col} 5933 1520 7453
942  
943 1520 my ($fixed, $got) = ($scope->{$col}, $assigned->{$col});
944 1520 ▶ next if ref $fixed;
Branch: 1 branch
BranchTrueFalseTotal
if ref $fixed 0 1520 1520
945  
946 1520 ▶ next if ! defined $fixed and ! defined $got;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fixed or defined $got 1 1519 1520
Condition100%3/3
defined $fixed or defined $got
l!l&&r!l&&!r
151721
MC/DC100%2/2
defined $fixed or defined $got
defined $fixed defined $got
Truth table100%3/3
A or B
A= defined $fixedB= defined $got
ABresult
1X1
011
000
947 1519 ▶ next if defined $fixed and defined $got and ! ref $got and $fixed eq $got;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fixed and defined $got and not ref $got and $fixed eq $got 1498 21 1519
Condition88%8/9
defined $fixed and defined $got and not ref $got and $fixed eq $got
!ll&&!rl&&r
4171498
defined $fixed and defined $got and not ref $got
!ll&&!rl&&r
401515
defined $fixed and defined $got
!ll&&!rl&&r
221515
MC/DC75%3/4
defined $fixed and defined $got and not ref $got and $fixed eq $got
defined $fixed defined $got not ref $got $fixed eq $got
Truth table80%4/5
A and B and not(C) and D
A= defined $fixedB= defined $gotC= not ref $gotD= $fixed eq $got
ABCDresult
0XXX0
10XX0
110X0
11100
11111
948  
949 # the text names the column and whether a value or NULL is meant, never
950 # a value: the values are the caller's and the condition's
951 21 ▶ $self->throw_exception(sprintf(
Branch: 4 branches
BranchTrueFalseTotal
!defined($fixed) ? : 2 19 21
!defined($got) ? : 2 19 21
ref $got ? : 0 19 19
defined $fixed ? : 17 2 19
952 "create on a scoped resultset: '%s' is fixed to %s by the condition, got %s",
953 $col,
954 ! defined $fixed ? 'NULL' : 'a value',
955 ! defined $got ? 'NULL'
956 : ref $got ? 'a ' . ref($got) . ' value'
957 : defined $fixed ? 'another value' : 'a value',
958 ));
959 }
960  
961 2989 return;
962 }
963  
964 2287 ▶sub _resolve_condition {
Subroutine _resolve_condition: called CC=15 SCAR=27.9
965 # carp_unique sprintf
966 # '_resolve_condition is a private method, and moreover is about to go '
967 # . 'away. Please contact the development team at %s if you believe you '
968 # . 'have a genuine use for this method, in order to discuss alternatives.',
969 # help_url,
970 # ;
971  
972 #######################
973 ### API Design? What's that...? (a backwards compatible shim, kill me now)
974  
975 2287 my ($self, $cond, @res_args, $rel_name);
976  
977 # we *SIMPLY DON'T KNOW YET* which arg is which, yay
978 2287 ($self, $cond, $res_args[0], $res_args[1], $rel_name) = @_;
979  
980 # assume that an undef is an object-like unset (set_from_related(undef))
981 2287 ▶ my @is_objlike = map { ! defined $_ or length ref $_ } (@res_args);
Condition66%2/3
!defined($_) || length ref $_
l!l&&r!l&&!r
021242450
MC/DC50%1/2
!defined($_) || length ref $_
!defined($_) length ref $_
Truth table66%2/3
not(A) || B
A= !defined($_)B= length ref $_
ABresult
1X1
011
000
982  
983 # turn objlike into proper objects for saner code further down
984 2287 for (0,1) {
985 4574 ▶ next unless $is_objlike[$_];
Branch: 1 branch
BranchTrueFalseTotal
unless $is_objlike[$_] 2450 2124 4574
986  
987 2124 ▶ if ( defined blessed $res_args[$_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined builtin::blessed($res_args[$_])) { } 2115 9 2124
988  
989 # but wait - there is more!!! WHAT THE FUCK?!?!?!?!
990 2115 ▶ if ($res_args[$_]->isa('DBIO::ResultSet')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res_args[$_]->isa("DBIO::ResultSet")) 0 2115 2115
991 0 carp('Passing a resultset for relationship resolution makes no sense - invoking __gremlins__');
992 0 $is_objlike[$_] = 0;
993 0 $res_args[$_] = '__gremlins__';
994 }
995 }
996 else {
997 9 ▶ $res_args[$_] ||= {};
Condition50%1/2
$res_args[$_] ||= {}
l!l
90
MC/DC0%0/1
$res_args[$_] ||= {}
$res_args[$_]
Truth table50%1/2
A
A= $res_args[$_]
Aresult
11
00
998  
999 # hate everywhere - have to pass in as a plain hash
1000 # pretending to be an object at least for now
1001 9 ▶ $self->throw_exception("Unsupported object-like structure encountered: $res_args[$_]")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $res_args[$_] eq "HASH" 0 9 9
1002 unless ref $res_args[$_] eq 'HASH';
1003 }
1004 }
1005  
1006 2287 ▶ my $args = {
Branch: 3 branches
BranchTrueFalseTotal
$is_objlike[1] ? : 2104 183 2287
$is_objlike[0] ? : 20 163 183
$rel_name ? : 2287 0 2287
1007 condition => $cond,
1008  
1009 # where-is-waldo block guesses relname, then further down we override it if available
1010 (
1011 $is_objlike[1] ? ( rel_name => $res_args[0], self_alias => $res_args[0], foreign_alias => 'me', self_result_object => $res_args[1] )
1012 : $is_objlike[0] ? ( rel_name => $res_args[1], self_alias => 'me', foreign_alias => $res_args[1], foreign_values => $res_args[0] )
1013 : ( rel_name => $res_args[0], self_alias => $res_args[1], foreign_alias => $res_args[0] )
1014 ),
1015  
1016 ( $rel_name ? ( rel_name => $rel_name ) : () ),
1017 };
1018 #######################
1019  
1020 # now it's fucking easy isn't it?!
1021 2287 my $rc = $self->_resolve_relationship_condition( $args );
1022  
1023 my @res = (
1024 ( $rc->{join_free_condition} || $rc->{condition} ),
1025 ! $rc->{join_free_condition},
1026 2287 ▶ );
Condition66%2/3
$rc->{'join_free_condition'} || $rc->{'condition'}
l!l&&r!l&&!r
21231640
MC/DC0%0/2
$rc->{'join_free_condition'} || $rc->{'condition'}
$rc->{'join_free_condition'} $rc->{'condition'}
Truth table66%2/3
A || B
A= $rc->{'join_free_condition'}B= $rc->{'condition'}
ABresult
1X1
011
000
1027  
1028 # _resolve_relationship_condition always returns qualified cols even in the
1029 # case of join_free_condition, but nothing downstream expects this
1030 2287 ▶ if ($rc->{join_free_condition} and ref $res[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc->{"join_free_condition"} and ref $res[0] eq "HASH") 2108 179 2287
Condition100%3/3
$rc->{"join_free_condition"} and ref $res[0] eq "HASH"
!ll&&!rl&&r
164152108
MC/DC100%2/2
$rc->{"join_free_condition"} and ref $res[0] eq "HASH"
$rc->{"join_free_condition"} ref $res[0] eq "HASH"
Truth table100%3/3
A and B
A= $rc->{"join_free_condition"}B= ref $res[0] eq "HASH"
ABresult
0X0
100
111
1031 $res[0] = { map
1032 2108 { ($_ =~ /\.(.+)/) => $res[0]{$_} }
1033 2108 keys %{$res[0]}
1034 };
1035 }
1036  
1037 # and more legacy
1038 2287 ▶ return wantarray ? @res : $res[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2118 169 2287
1039 }
1040  
1041 # Keep this indefinitely. There is evidence of both CPAN and
1042 # darkpan using it, and there isn't much harm in an extra var
1043 # anyway.
1044 379 our $UNRESOLVABLE_CONDITION = UNRESOLVABLE_CONDITION;
1045 # YES I KNOW THIS IS EVIL
1046 # it is there to save darkpan from themselves, since internally
1047 # we are moving to a constant
1048 379 Internals::SvREADONLY($UNRESOLVABLE_CONDITION => 1);
1049  
1050 # Resolves the passed condition to a concrete query fragment and extra
1051 # metadata
1052 #
1053 ## self-explanatory API, modeled on the custom cond coderef:
1054 # rel_name => (scalar)
1055 # foreign_alias => (scalar)
1056 # foreign_values => (either not supplied, or a hashref, or a foreign ResultObject (to be ->get_columns()ed), or plain undef )
1057 # self_alias => (scalar)
1058 # self_result_object => (either not supplied or a result object)
1059 # require_join_free_condition => (boolean, throws on failure to construct a JF-cond)
1060 # infer_values_based_on => (either not supplied or a hashref, implies require_join_free_condition)
1061 # condition => (sqla cond struct, optional, defeaults to from $self->rel_info(rel_name)->{cond})
1062 #
1063 ## returns a hash
1064 # condition => (a valid *likely fully qualified* sqla cond structure)
1065 # identity_map => (a hashref of foreign-to-self *unqualified* column equality names)
1066 # join_free_condition => (a valid *fully qualified* sqla cond structure, maybe unset)
1067 # inferred_values => (in case of an available join_free condition, this is a hashref of
1068 # *unqualified* column/value *EQUALITY* pairs, representing an amalgamation
1069 # of the JF-cond parse and infer_values_based_on
1070 # always either complete or unset)
1071 #
1072 5506 ▶sub _resolve_relationship_condition {
Subroutine _resolve_relationship_condition: called CC=97 SCAR=67.1
1073 5506 my $self = shift;
1074  
1075 5506 ▶ my $args = { ref $_[0] eq 'HASH' ? %{ $_[0] } : @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 2317 3189 5506
1076  
1077 5506 for ( qw( rel_name self_alias foreign_alias ) ) {
1078 $self->throw_exception("Mandatory argument '$_' to _resolve_relationship_condition() is not a plain string")
1079 16518 ▶ if !defined $args->{$_} or length ref $args->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $args->{$_} or length ref $args->{$_} 0 16518 16518
Condition33%1/3
not defined $args->{$_} or length ref $args->{$_}
l!l&&r!l&&!r
0016518
MC/DC0%0/2
not defined $args->{$_} or length ref $args->{$_}
not defined $args->{$_} length ref $args->{$_}
Truth table33%1/3
not(A) or B
A= not defined $args->{$_}B= length ref $args->{$_}
ABresult
1X1
011
000
1080 }
1081  
1082 $self->throw_exception("Arguments 'self_alias' and 'foreign_alias' may not be identical")
1083 5506 ▶ if $args->{self_alias} eq $args->{foreign_alias};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"self_alias"} eq $args->{"foreign_alias"} 0 5506 5506
1084  
1085 # TEMP
1086 5506 my $exception_rel_id = "relationship '$args->{rel_name}' on source '@{[ $self->source_name ]}'";
1087  
1088 my $rel_info = $self->relationship_info($args->{rel_name})
1089 # TEMP
1090 # or $self->throw_exception( "No such $exception_rel_id" );
1091 0 ▶ or carp_unique("Requesting resolution on non-existent relationship '$args->{rel_name}' on source '@{[ $self->source_name ]}': fix your code *soon*, as it will break with the next major version");
Branch: 1 branch
BranchTrueFalseTotal
my $rel_info = $self->relationship_info($args->{"rel_name"}) or carp_unique(qq[Requesting resolution on non-existent relationship '$args->{"rel_name"}' on source '@{[$self->source_name];}': fix your code *soon*, as it will break with the next major version]) 5506 0 5506
1092  
1093 # TEMP
1094 0 $exception_rel_id = "relationship '$rel_info->{_original_name}' on source '@{[ $self->source_name ]}'"
1095 5506 ▶ if $rel_info and exists $rel_info->{_original_name};
Branch: 1 branch
BranchTrueFalseTotal
if $rel_info and exists $rel_info->{"_original_name"} 0 5506 5506
Condition33%1/3
$rel_info and exists $rel_info->{"_original_name"}
!ll&&!rl&&r
055060
MC/DC0%0/2
$rel_info and exists $rel_info->{"_original_name"}
$rel_info exists $rel_info->{"_original_name"}
Truth table33%1/3
A and B
A= $rel_infoB= exists $rel_info->{"_original_name"}
ABresult
0X0
100
111
1096  
1097 $self->throw_exception("No practical way to resolve $exception_rel_id between two data structures")
1098 5506 ▶ if exists $args->{self_result_object} and exists $args->{foreign_values};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"self_result_object"} and exists $args->{"foreign_values"} 0 5506 5506
Condition66%2/3
exists $args->{"self_result_object"} and exists $args->{"foreign_values"}
!ll&&!rl&&r
38151250
MC/DC0%0/2
exists $args->{"self_result_object"} and exists $args->{"foreign_values"}
exists $args->{"self_result_object"} exists $args->{"foreign_values"}
Truth table66%2/3
A and B
A= exists $args->{"self_result_object"}B= exists $args->{"foreign_values"}
ABresult
0X0
100
111
1099  
1100 $self->throw_exception( "Argument to infer_values_based_on must be a hash" )
1101 5506 ▶ if exists $args->{infer_values_based_on} and ref $args->{infer_values_based_on} ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"infer_values_based_on"} and ref $args->{"infer_values_based_on"} ne "HASH" 0 5506 5506
Condition66%2/3
exists $args->{"infer_values_based_on"} and ref $args->{"infer_values_based_on"} ne "HASH"
!ll&&!rl&&r
234631600
MC/DC0%0/2
exists $args->{"infer_values_based_on"} and ref $args->{"infer_values_based_on"} ne "HASH"
exists $args->{"infer_values_based_on"} ref $args->{"infer_values_based_on"} ne "HASH"
Truth table66%2/3
A and B
A= exists $args->{"infer_values_based_on"}B= ref $args->{"infer_values_based_on"} ne "HASH"
ABresult
0X0
100
111
1102  
1103 5506 ▶ $args->{require_join_free_condition} ||= !!$args->{infer_values_based_on};
Condition66%2/3
$args->{"require_join_free_condition"} ||= !!$args->{"infer_values_based_on"}
l!l&&r!l&&!r
031602346
MC/DC50%1/2
$args->{"require_join_free_condition"} ||= !!$args->{"infer_values_based_on"}
$args->{"require_join_free_condition"} !!$args->{"infer_values_based_on"}
Truth table66%2/3
A ||= B
A= $args->{"require_join_free_condition"}B= !!$args->{"infer_values_based_on"}
ABresult
1X1
011
000
1104  
1105 5506 ▶ $args->{condition} ||= $rel_info->{cond};
Condition66%2/3
$args->{"condition"} ||= $rel_info->{"cond"}
l!l&&r!l&&!r
231731890
MC/DC0%0/2
$args->{"condition"} ||= $rel_info->{"cond"}
$args->{"condition"} $rel_info->{"cond"}
Truth table66%2/3
A ||= B
A= $args->{"condition"}B= $rel_info->{"cond"}
ABresult
1X1
011
000
1106  
1107 $self->throw_exception( "Argument 'self_result_object' must be an object inheriting from DBIO::Row" )
1108 if (
1109 exists $args->{self_result_object}
1110 and
1111 5506 ▶ ( ! defined blessed $args->{self_result_object} or ! $args->{self_result_object}->isa('DBIO::Row') )
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"self_result_object"} and not defined builtin::blessed($args->{"self_result_object"}) && $args->{"self_result_object"}->isa("DBIO::Row") 0 5506 5506
Condition50%3/6
exists $args->{"self_result_object"} and not defined builtin::blessed($args->{"self_result_object"}) && $args->{"self_result_object"}->isa("DBIO::Row")
!ll&&!rl&&r
38151250
defined builtin::blessed($args->{'self_result_object'}) && $args->{'self_result_object'}->isa('DBIO::Row')
!ll&&!rl&&r
005125
MC/DC0%0/3
exists $args->{"self_result_object"} and not defined builtin::blessed($args->{"self_result_object"}) && $args->{"self_result_object"}->isa("DBIO::Row")
exists $args->{"self_result_object"} defined builtin::blessed($args->{'self_result_object'}) $args->{'self_result_object'}->isa('DBIO::Row')
Truth table50%2/4
A and not(B && C)
A= exists $args->{"self_result_object"}B= defined builtin::blessed($args->{'self_result_object'})C= $args->{'self_result_object'}->isa('DBIO::Row')
ABCresult
0XX0
1110
10X1
1101
1112 )
1113 ;
1114  
1115 #TEMP
1116 5506 my $rel_rsrc;# = $self->related_source($args->{rel_name});
1117  
1118 5506 ▶ if (exists $args->{foreign_values}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"foreign_values"}) 213 5293 5506
1119 # TEMP
1120 213 ▶ $rel_rsrc ||= $self->related_source($args->{rel_name});
Condition33%1/3
$rel_rsrc ||= $self->related_source($args->{"rel_name"})
l!l&&r!l&&!r
02130
MC/DC0%0/2
$rel_rsrc ||= $self->related_source($args->{"rel_name"})
$rel_rsrc $self->related_source($args->{"rel_name"})
Truth table33%1/3
A ||= B
A= $rel_rsrcB= $self->related_source($args->{"rel_name"})
ABresult
1X1
011
000
1121  
1122 213 ▶ if (defined blessed $args->{foreign_values}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined builtin::blessed($args->{'foreign_values'})) { } 170 43 213
elsif (not defined $args->{'foreign_values'} or ref $args->{'foreign_values'} eq 'HASH') { } 43 0 43
1123  
1124 $self->throw_exception( "Objects supplied as 'foreign_values' ($args->{foreign_values}) must inherit from DBIO::Row" )
1125 170 ▶ unless $args->{foreign_values}->isa('DBIO::Row');
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"foreign_values"}->isa("DBIO::Row") 0 170 170
1126  
1127 carp_unique(
1128 "Objects supplied as 'foreign_values' ($args->{foreign_values}) "
1129 0 . "usually should inherit from the related ResultClass ('@{[ $rel_rsrc->result_class ]}'), "
1130 . "perhaps you've made a mistake invoking the condition resolver?"
1131 170 ▶ ) unless $args->{foreign_values}->isa($rel_rsrc->result_class);
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"foreign_values"}->isa($rel_rsrc->result_class) 0 170 170
1132  
1133 170 my $fvals = { $args->{foreign_values}->get_columns };
1134  
1135 # The very low level resolve_relationship_condition() deliberately contains
1136 # extra logic to ensure that it isn't passed garbage. Unfortunately we can
1137 # get into a situation where an object *has* extra columns on it, which
1138 # the interface of ->get_columns is obligated to return. In order not to
1139 # compromise the sanity checks within r_r_c, simply do a cleanup pass here.
1140 #
1141 # FIXME - perhaps this should warn, but that's a battle for another day
1142 #
1143 $args->{foreign_values} = { map {
1144 170 exists $fvals->{$_}
1145 586 ▶ ? ( $_ => $fvals->{$_} )
Branch: 1 branch
BranchTrueFalseTotal
exists $fvals->{$_} ? : 443 143 586
1146 : ()
1147 } $rel_rsrc->columns };
1148 }
1149 ▶ elsif (! defined $args->{foreign_values} or ref $args->{foreign_values} eq 'HASH') {
Condition66%2/3
not defined $args->{"foreign_values"} or ref $args->{"foreign_values"} eq "HASH"
l!l&&r!l&&!r
3400
MC/DC0%0/2
not defined $args->{"foreign_values"} or ref $args->{"foreign_values"} eq "HASH"
not defined $args->{"foreign_values"} ref $args->{"foreign_values"} eq "HASH"
Truth table66%2/3
not(A) or B
A= not defined $args->{"foreign_values"}B= ref $args->{"foreign_values"} eq "HASH"
ABresult
1X1
011
000
1150 43 my $ri = { map { $_ => 1 } $rel_rsrc->relationships };
1151 43 my $ci = $rel_rsrc->columns_info;
1152 ! exists $ci->{$_} and ! exists $ri->{$_} and $self->throw_exception(
1153 0 "Key '$_' supplied as 'foreign_values' is not a column on related source '@{[ $rel_rsrc->source_name ]}'"
1154 43 ▶ ) for keys %{ $args->{foreign_values} ||= {} };
Branch: 1 branch
BranchTrueFalseTotal
exists $ci->{$_} or exists $ri->{$_} or $self->throw_exception("Key '${_}' supplied as 'foreign_values' is not a column on related source '@{[$rel_rsrc->source_name];}'") 43 0 43
Condition60%3/5
$args->{"foreign_values"} ||= {}
l!l
403
exists $ci->{$_} or exists $ri->{$_}
l!l&&r!l&&!r
4300
MC/DC100%1/1
$args->{"foreign_values"} ||= {}
$args->{"foreign_values"}
MC/DC0%0/2
exists $ci->{$_} or exists $ri->{$_}
exists $ci->{$_} exists $ri->{$_}
Truth table100%2/2
A
A= $args->{"foreign_values"}
Aresult
11
00
Truth table33%1/3
A or B
A= exists $ci->{$_}B= exists $ri->{$_}
ABresult
1X1
011
000
1155 }
1156 else {
1157 0 $self->throw_exception(
1158 0 "Argument 'foreign_values' must be either an object inheriting from '@{[ $rel_rsrc->result_class ]}', "
1159 . "or a hash reference, or undef"
1160 );
1161 }
1162 }
1163  
1164 5506 my $ret;
1165  
1166 5506 ▶ if (ref $args->{condition} eq 'CODE') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $args->{'condition'} eq 'CODE') { } 1 5505 5506
elsif (ref $args->{'condition'} eq 'HASH') { } 5490 15 5505
elsif (ref $args->{'condition'} eq 'ARRAY') { } 15 0 15
1167  
1168 my $cref_args = {
1169 rel_name => $args->{rel_name},
1170 self_resultsource => $self,
1171 self_alias => $args->{self_alias},
1172 foreign_alias => $args->{foreign_alias},
1173 ( map
1174 1 ▶ { (exists $args->{$_}) ? ( $_ => $args->{$_} ) : () }
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{$_} ? : 1 1 2
1175 qw( self_result_object foreign_values )
1176 ),
1177 };
1178  
1179 # legacy - never remove these!!!
1180 1 $cref_args->{foreign_relname} = $cref_args->{rel_name};
1181  
1182 $cref_args->{self_rowobj} = $cref_args->{self_result_object}
1183 1 ▶ if exists $cref_args->{self_result_object};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cref_args->{"self_result_object"} 0 1 1
1184  
1185 1 ($ret->{condition}, $ret->{join_free_condition}, my @extra) = $args->{condition}->($cref_args);
1186  
1187 # sanity check
1188 1 ▶ $self->throw_exception("A custom condition coderef can return at most 2 conditions, but $exception_rel_id returned extra values: @extra")
Branch: 1 branch
BranchTrueFalseTotal
if @extra 0 1 1
1189 if @extra;
1190  
1191 1 ▶ if (my $jfc = $ret->{join_free_condition}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $jfc = $ret->{"join_free_condition"}) 0 1 1
1192  
1193 0 ▶ $self->throw_exception (
Branch: 1 branch
BranchTrueFalseTotal
unless ref $jfc eq "HASH" 0 0 0
1194 "The join-free condition returned for $exception_rel_id must be a hash reference"
1195 ) unless ref $jfc eq 'HASH';
1196  
1197 # TEMP
1198 0 ▶ $rel_rsrc ||= $self->related_source($args->{rel_name});
Condition0%0/3
$rel_rsrc ||= $self->related_source($args->{"rel_name"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$rel_rsrc ||= $self->related_source($args->{"rel_name"})
$rel_rsrc $self->related_source($args->{"rel_name"})
Truth table0%0/3
A ||= B
A= $rel_rsrcB= $self->related_source($args->{"rel_name"})
ABresult
1X1
011
000
1199  
1200 0 my ($joinfree_alias, $joinfree_source);
1201 0 ▶ if (defined $args->{self_result_object}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args->{'self_result_object'}) { } 0 0 0
elsif (defined $args->{'foreign_values'}) { } 0 0 0
1202 0 $joinfree_alias = $args->{foreign_alias};
1203 0 $joinfree_source = $rel_rsrc;
1204 }
1205 elsif (defined $args->{foreign_values}) {
1206 0 $joinfree_alias = $args->{self_alias};
1207 0 $joinfree_source = $self;
1208 }
1209  
1210 # FIXME sanity check until things stabilize, remove at some point
1211 $self->throw_exception (
1212 0 ▶ "A join-free condition returned for $exception_rel_id without a result object to chain from"
Branch: 1 branch
BranchTrueFalseTotal
unless $joinfree_alias 0 0 0
1213 ) unless $joinfree_alias;
1214  
1215 my $fq_col_list = { map
1216 0 { ( "$joinfree_alias.$_" => 1 ) }
1217 $joinfree_source->columns
1218 };
1219  
1220 exists $fq_col_list->{$_} or $self->throw_exception (
1221 "The join-free condition returned for $exception_rel_id may only "
1222 . 'contain keys that are fully qualified column names of the corresponding source '
1223 . "(it returned '$_')"
1224 0 ▶ ) for keys %$jfc;
Branch: 1 branch
BranchTrueFalseTotal
exists $fq_col_list->{$_} or $self->throw_exception("The join-free condition returned for $exception_rel_id may only " . 'contain keys that are fully qualified column names of the corresponding source ' . "(it returned '${_}')") 0 0 0
1225  
1226 (
1227 length ref $_
1228 and
1229 defined blessed($_)
1230 and
1231 $_->isa('DBIO::Row')
1232 and
1233 $self->throw_exception (
1234 "The join-free condition returned for $exception_rel_id may not "
1235 . 'contain result objects as values - perhaps instead of invoking '
1236 . '->$something you meant to return ->get_column($something)'
1237 )
1238 0 ▶ ) for values %$jfc;
Branch: 1 branch
BranchTrueFalseTotal
length ref $_ and defined builtin::blessed($_) and $_->isa("DBIO::Row") and $self->throw_exception("The join-free condition returned for $exception_rel_id may not " . 'contain result objects as values - perhaps instead of invoking ' . "->\$something you meant to return ->get_column(\$something)") 0 0 0
Condition0%0/6
length ref $_ and defined builtin::blessed($_) and $_->isa("DBIO::Row")
!ll&&!rl&&r
000
length ref $_ and defined builtin::blessed($_)
!ll&&!rl&&r
000
MC/DC0%0/3
length ref $_ and defined builtin::blessed($_) and $_->isa("DBIO::Row")
length ref $_ defined builtin::blessed($_) $_->isa("DBIO::Row")
Truth table0%0/4
A and B and C
A= length ref $_B= defined builtin::blessed($_)C= $_->isa("DBIO::Row")
ABCresult
0XX0
10X0
1100
1111
1239  
1240 }
1241 }
1242 elsif (ref $args->{condition} eq 'HASH') {
1243  
1244 # the condition is static - use parallel arrays
1245 # for a "pivot" depending on which side of the
1246 # rel did we get as an object
1247 5490 my (@f_cols, @l_cols);
1248 5490 for my $fc (keys %{$args->{condition}}) {
1249 5490 my $lc = $args->{condition}{$fc};
1250  
1251 # FIXME STRICTMODE should probably check these are valid columns
1252 5490 ▶ $fc =~ s/^foreign\.// ||
Branch: 1 branch
BranchTrueFalseTotal
$fc =~ s/^foreign\.// or $self->throw_exception("Invalid rel cond key '${fc}'") 5490 0 5490
1253 $self->throw_exception("Invalid rel cond key '$fc'");
1254  
1255 5490 ▶ $lc =~ s/^self\.// ||
Branch: 1 branch
BranchTrueFalseTotal
$lc =~ s/^self\.// or $self->throw_exception("Invalid rel cond val '${lc}'") 5490 0 5490
1256 $self->throw_exception("Invalid rel cond val '$lc'");
1257  
1258 5490 push @f_cols, $fc;
1259 5490 push @l_cols, $lc;
1260 }
1261  
1262 # construct the crosstable condition and the identity map
1263 5490 for (0..$#f_cols) {
1264 5490 $ret->{condition}{"$args->{foreign_alias}.$f_cols[$_]"} = { -ident => "$args->{self_alias}.$l_cols[$_]" };
1265 5490 $ret->{identity_map}{$l_cols[$_]} = $f_cols[$_];
1266 };
1267  
1268 5490 ▶ if ($args->{foreign_values}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args->{'foreign_values'}) { } 212 5278 5490
elsif (defined $args->{'self_result_object'}) { } 5110 168 5278
1269 $ret->{join_free_condition}{"$args->{self_alias}.$l_cols[$_]"} = $args->{foreign_values}{$f_cols[$_]}
1270 212 for 0..$#f_cols;
1271 }
1272 elsif (defined $args->{self_result_object}) {
1273  
1274 5110 for my $i (0..$#l_cols) {
1275 5110 ▶ if ( $args->{self_result_object}->has_column_loaded($l_cols[$i]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'self_result_object'}->has_column_loaded($l_cols[$i])) { } 5110 0 5110
1276 5110 $ret->{join_free_condition}{"$args->{foreign_alias}.$f_cols[$i]"} = $args->{self_result_object}->get_column($l_cols[$i]);
1277 }
1278 else {
1279 $self->throw_exception(sprintf
1280 "Unable to resolve relationship '%s' from object '%s': column '%s' not "
1281 . 'loaded from storage (or not passed to new() prior to insert()). You '
1282 . 'probably need to call ->discard_changes to get the server-side defaults '
1283 . 'from the database.',
1284 $args->{rel_name},
1285 $args->{self_result_object},
1286 $l_cols[$i],
1287 0 ▶ ) if $args->{self_result_object}->in_storage;
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"self_result_object"}->in_storage 0 0 0
1288  
1289 # FIXME - temporarly force-override
1290 0 delete $args->{require_join_free_condition};
1291 0 $ret->{join_free_condition} = UNRESOLVABLE_CONDITION;
1292 0 last;
1293 }
1294 }
1295 }
1296 }
1297 elsif (ref $args->{condition} eq 'ARRAY') {
1298 15 ▶ if (@{$args->{condition}} == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$args->{'condition'};} == 0) { } 0 15 15
elsif (@{$args->{'condition'};} == 1) { } 0 15 15
1299 0 $ret = {
1300 condition => UNRESOLVABLE_CONDITION,
1301 join_free_condition => UNRESOLVABLE_CONDITION,
1302 };
1303 }
1304 15 elsif (@{$args->{condition}} == 1) {
1305 $ret = $self->_resolve_relationship_condition({
1306 %$args,
1307 0 condition => $args->{condition}[0],
1308 });
1309 }
1310 else {
1311 # we are discarding inferred values here... likely incorrect...
1312 # then again - the entire thing is an OR, so we *can't* use them anyway
1313 15 for my $subcond ( map
1314 30 { $self->_resolve_relationship_condition({ %$args, condition => $_ }) }
1315 15 @{$args->{condition}}
1316 ) {
1317 $self->throw_exception('Either all or none of the OR-condition members must resolve to a join-free condition')
1318 30 ▶ if ( $ret and ( $ret->{join_free_condition} xor $subcond->{join_free_condition} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $ret and $ret->{"join_free_condition"} ^^ $subcond->{"join_free_condition"} 0 30 30
Condition42%3/7
$ret and $ret->{"join_free_condition"} ^^ $subcond->{"join_free_condition"}
!ll&&!rl&&r
15150
$ret->{"join_free_condition"} xor $subcond->{"join_free_condition"}
l&&rl&&!r!l&&r!l&&!r
15000
MC/DC0%0/3
$ret and $ret->{"join_free_condition"} ^^ $subcond->{"join_free_condition"}
$ret $ret->{"join_free_condition"} $subcond->{"join_free_condition"}
Truth table40%2/5
A and B xor C
A= $retB= $ret->{"join_free_condition"}C= $subcond->{"join_free_condition"}
ABCresult
0XX0
1110
1000
1101
1011
1319  
1320 30 ▶ $subcond->{$_} and push @{$ret->{$_}}, $subcond->{$_} for (qw(condition join_free_condition));
Branch: 1 branch
BranchTrueFalseTotal
$subcond->{$_} and push @{$$ret{$_};}, $subcond->{$_} 60 0 60
1321 }
1322 }
1323 }
1324 else {
1325 0 $self->throw_exception ("Can't handle condition $args->{condition} for $exception_rel_id yet :(");
1326 }
1327  
1328 $self->throw_exception(ucfirst "$exception_rel_id does not resolve to a join-free condition fragment") if (
1329 $args->{require_join_free_condition}
1330 and
1331 5506 ▶ ( ! $ret->{join_free_condition} or $ret->{join_free_condition} eq UNRESOLVABLE_CONDITION )
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"require_join_free_condition"} and !$ret->{"join_free_condition"} || $ret->{"join_free_condition"} eq \"1 = 0" 0 5506 5506
Condition50%3/6
$args->{"require_join_free_condition"} and !$ret->{"join_free_condition"} || $ret->{"join_free_condition"} eq \"1 = 0"
!ll&&!rl&&r
234631600
not $ret->{"join_free_condition"} or $ret->{"join_free_condition"} eq \"1 = 0"
l!l&&r!l&&!r
003160
MC/DC0%0/3
$args->{"require_join_free_condition"} and !$ret->{"join_free_condition"} || $ret->{"join_free_condition"} eq \"1 = 0"
$args->{"require_join_free_condition"} not $ret->{"join_free_condition"} $ret->{"join_free_condition"} eq \"1 = 0"
Truth table50%2/4
A and not(B) or C
A= $args->{"require_join_free_condition"}B= not $ret->{"join_free_condition"}C= $ret->{"join_free_condition"} eq \"1 = 0"
ABCresult
0XX0
1000
11X1
1011
1332 );
1333  
1334 5506 my $storage = $self->schema->storage;
1335  
1336 # we got something back - sanity check and infer values if we can
1337 5506 my @nonvalues;
1338 5506 ▶ if ( my $jfc = $ret->{join_free_condition} and $ret->{join_free_condition} ne UNRESOLVABLE_CONDITION ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $jfc = $ret->{"join_free_condition"} and $ret->{"join_free_condition"} ne \"1 = 0") 5337 169 5506
Condition66%2/3
my $jfc = $ret->{"join_free_condition"} and $ret->{"join_free_condition"} ne \"1 = 0"
!ll&&!rl&&r
16905337
MC/DC50%1/2
my $jfc = $ret->{"join_free_condition"} and $ret->{"join_free_condition"} ne \"1 = 0"
my $jfc = $ret->{"join_free_condition"} $ret->{"join_free_condition"} ne \"1 = 0"
Truth table66%2/3
A and B
A= my $jfc = $ret->{"join_free_condition"}B= $ret->{"join_free_condition"} ne \"1 = 0"
ABresult
0X0
100
111
1339  
1340 5337 my $jfc_eqs = $storage->_extract_fixed_condition_columns($jfc, 'consider_nulls');
1341  
1342 5337 ▶ if (keys %$jfc_eqs) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$jfc_eqs) 5322 15 5337
1343  
1344 5322 for (keys %$jfc) {
1345 # $jfc is fully qualified by definition
1346 5322 my ($col) = $_ =~ /\.(.+)/;
1347  
1348 5322 ▶ if (exists $jfc_eqs->{$_} and ($jfc_eqs->{$_}||'') ne UNRESOLVABLE_CONDITION) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $jfc_eqs->{$_} and ($jfc_eqs->{$_} || '') ne \'1 = 0') { } 5322 0 5322
elsif (not $args->{'infer_values_based_on'} && exists $args->{'infer_values_based_on'}{$col}) { } 0 0 0
Condition60%3/5
exists $jfc_eqs->{$_} and ($jfc_eqs->{$_} || "") ne \"1 = 0"
!ll&&!rl&&r
005322
$jfc_eqs->{$_} || ''
l!l
530022
MC/DC50%1/2
exists $jfc_eqs->{$_} and ($jfc_eqs->{$_} || "") ne \"1 = 0"
exists $jfc_eqs->{$_} $jfc_eqs->{$_}
Truth table66%2/3
A and B
A= exists $jfc_eqs->{$_}B= $jfc_eqs->{$_}
ABresult
0X0
100
111
1349 5322 $ret->{inferred_values}{$col} = $jfc_eqs->{$_};
1350 }
1351 ▶ elsif ( !$args->{infer_values_based_on} or ! exists $args->{infer_values_based_on}{$col} ) {
Condition0%0/3
$args->{'infer_values_based_on'} && exists $args->{'infer_values_based_on'}{$col}
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{'infer_values_based_on'} && exists $args->{'infer_values_based_on'}{$col}
$args->{'infer_values_based_on'} exists $args->{'infer_values_based_on'}{$col}
Truth table0%0/3
A && B
A= $args->{'infer_values_based_on'}B= exists $args->{'infer_values_based_on'}{$col}
ABresult
0X0
100
111
1352 0 push @nonvalues, $col;
1353 }
1354 }
1355  
1356 # all or nothing
1357 5322 ▶ delete $ret->{inferred_values} if @nonvalues;
Branch: 1 branch
BranchTrueFalseTotal
if @nonvalues 0 5322 5322
1358 }
1359 }
1360  
1361 # did the user explicitly ask
1362 5506 ▶ if ($args->{infer_values_based_on}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"infer_values_based_on"}) 3160 2346 5506
1363  
1364 $self->throw_exception(sprintf (
1365 "Unable to complete value inferrence - custom $exception_rel_id returns conditions instead of values for column(s): %s",
1366 0 ▶ map { "'$_'" } @nonvalues
Branch: 1 branch
BranchTrueFalseTotal
if @nonvalues 0 3160 3160
1367 )) if @nonvalues;
1368  
1369  
1370 3160 ▶ $ret->{inferred_values} ||= {};
Condition50%1/2
$ret->{"inferred_values"} ||= {}
l!l
31600
MC/DC0%0/1
$ret->{"inferred_values"} ||= {}
$ret->{"inferred_values"}
Truth table50%1/2
A
A= $ret->{"inferred_values"}
Aresult
11
00
1371  
1372 $ret->{inferred_values}{$_} = $args->{infer_values_based_on}{$_}
1373 3160 for keys %{$args->{infer_values_based_on}};
1374 }
1375  
1376 # add the identities based on the main condition
1377 # (may already be there, since easy to calculate on the fly in the HASH case)
1378 5506 ▶ if ( ! $ret->{identity_map} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ret->{"identity_map"}) 16 5490 5506
1379  
1380 16 my $col_eqs = $storage->_extract_fixed_condition_columns($ret->{condition});
1381  
1382 16 my $colinfos;
1383 16 for my $lhs (keys %$col_eqs) {
1384  
1385 1 ▶ next if $col_eqs->{$lhs} eq UNRESOLVABLE_CONDITION;
Branch: 1 branch
BranchTrueFalseTotal
if $col_eqs->{$lhs} eq \"1 = 0" 0 1 1
1386  
1387 # TEMP
1388 1 ▶ $rel_rsrc ||= $self->related_source($args->{rel_name});
Condition33%1/3
$rel_rsrc ||= $self->related_source($args->{"rel_name"})
l!l&&r!l&&!r
100
MC/DC0%0/2
$rel_rsrc ||= $self->related_source($args->{"rel_name"})
$rel_rsrc $self->related_source($args->{"rel_name"})
Truth table33%1/3
A ||= B
A= $rel_rsrcB= $self->related_source($args->{"rel_name"})
ABresult
1X1
011
000
1389  
1390 # there is no way to know who is right and who is left in a cref
1391 # therefore a full blown resolution call, and figure out the
1392 # direction a bit further below
1393 $colinfos ||= $storage->_resolve_column_info([
1394 { -alias => $args->{self_alias}, -rsrc => $self },
1395 1 ▶ { -alias => $args->{foreign_alias}, -rsrc => $rel_rsrc },
Condition33%1/3
$colinfos ||= $storage->_resolve_column_info([{"-alias", $args->{"self_alias"}, "-rsrc", $self}, {"-alias", $args->{"foreign_alias"}, "-rsrc", $rel_rsrc}])
l!l&&r!l&&!r
010
MC/DC0%0/2
$colinfos ||= $storage->_resolve_column_info([{"-alias", $args->{"self_alias"}, "-rsrc", $self}, {"-alias", $args->{"foreign_alias"}, "-rsrc", $rel_rsrc}])
$colinfos $storage->_resolve_column_info([{"-alias", $args->{"self_alias"}, "-rsrc", $self}, {"-alias", $args->{"foreign_alias"}, "-rsrc", $rel_rsrc}])
Truth table33%1/3
A ||= B
A= $colinfosB= $storage->_resolve_column_info([{"-alias", $args->{"self_alias"}, "-rsrc", $self}, {"-alias", $args->{"foreign_alias"}, "-rsrc", $rel_rsrc}])
ABresult
1X1
011
000
1396 ]);
1397  
1398 1 ▶ next unless $colinfos->{$lhs}; # someone is engaging in witchcraft
Branch: 1 branch
BranchTrueFalseTotal
unless $colinfos->{$lhs} 0 1 1
1399  
1400 1 ▶ if ( my $rhs_ref = is_literal_value( $col_eqs->{$lhs} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $rhs_ref = &is_literal_value($col_eqs->{$lhs})) { } 0 1 1
elsif ($col_eqs->{$lhs} =~ /^ ( \Q$args->{'self_alias'}\E \. .+ ) /x and +($colinfos->{$1} || {})->{'-result_source'} == $rel_rsrc) { } 0 2 2
1401  
1402 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($$colinfos{$rhs_ref->[0]} and $colinfos->{$lhs}{"-source_alias"} ne $$colinfos{$rhs_ref->[0]}{"-source_alias"}) 0 0 0
Condition0%0/3
$$colinfos{$rhs_ref->[0]} and $colinfos->{$lhs}{"-source_alias"} ne $$colinfos{$rhs_ref->[0]}{"-source_alias"}
!ll&&!rl&&r
000
MC/DC0%0/2
$$colinfos{$rhs_ref->[0]} and $colinfos->{$lhs}{"-source_alias"} ne $$colinfos{$rhs_ref->[0]}{"-source_alias"}
$$colinfos{$rhs_ref->[0]} $colinfos->{$lhs}{"-source_alias"} ne $$colinfos{$rhs_ref->[0]}{"-source_alias"}
Truth table0%0/3
A and B
A= $$colinfos{$rhs_ref->[0]}B= $colinfos->{$lhs}{"-source_alias"} ne $$colinfos{$rhs_ref->[0]}{"-source_alias"}
ABresult
0X0
100
111
1403 $colinfos->{$rhs_ref->[0]}
1404 and
1405 $colinfos->{$lhs}{-source_alias} ne $colinfos->{$rhs_ref->[0]}{-source_alias}
1406 ) {
1407 ( $colinfos->{$lhs}{-source_alias} eq $args->{self_alias} )
1408 ? ( $ret->{identity_map}{$colinfos->{$lhs}{-colname}} = $colinfos->{$rhs_ref->[0]}{-colname} )
1409 : ( $ret->{identity_map}{$colinfos->{$rhs_ref->[0]}{-colname}} = $colinfos->{$lhs}{-colname} )
1410 0 ▶ ;
Branch: 1 branch
BranchTrueFalseTotal
$colinfos->{$lhs}{'-source_alias'} eq $args->{'self_alias'} ? : 0 0 0
1411 }
1412 }
1413 ▶ elsif (
Condition20%1/5
$col_eqs->{$lhs} =~ /^ ( \Q$args->{"self_alias"}\E \. .+ ) /x and +($colinfos->{$1} || {})->{"-result_source"} == $rel_rsrc
!ll&&!rl&&r
100
$colinfos->{$1} || {}
l!l
00
MC/DC0%0/2
$col_eqs->{$lhs} =~ /^ ( \Q$args->{"self_alias"}\E \. .+ ) /x and +($colinfos->{$1} || {})->{"-result_source"} == $rel_rsrc
$col_eqs->{$lhs} =~ /^ ( \Q$args->{"self_alias"}\E \. .+ ) /x $colinfos->{$1}
Truth table33%1/3
A and B
A= $col_eqs->{$lhs} =~ /^ ( \Q$args->{"self_alias"}\E \. .+ ) /xB= $colinfos->{$1}
ABresult
0X0
100
111
1414 $col_eqs->{$lhs} =~ /^ ( \Q$args->{self_alias}\E \. .+ ) /x
1415 and
1416 ($colinfos->{$1}||{})->{-result_source} == $rel_rsrc
1417 ) {
1418 my ($lcol, $rcol) = map
1419 0 { $colinfos->{$_}{-colname} }
1420 ( $lhs, $1 )
1421 ;
1422 0 carp_unique(
1423 "The $exception_rel_id specifies equality of column '$lcol' and the "
1424 . "*VALUE* '$rcol' (you did not use the { -ident => ... } operator)"
1425 );
1426 }
1427 }
1428 }
1429  
1430 # FIXME - temporary, to fool the idiotic check in SQLMaker::_join_condition
1431 $ret->{condition} = { -and => [ $ret->{condition} ] }
1432 5506 ▶ unless $ret->{condition} eq UNRESOLVABLE_CONDITION;
Branch: 1 branch
BranchTrueFalseTotal
unless $ret->{"condition"} eq \"1 = 0" 5506 0 5506
1433  
1434 5506 $ret;
1435 }
1436  
1437  
1438 6059 ▶sub related_source {
Subroutine related_source: called CC=3 SCAR=11.0
Pod documented
1439 6059 my ($self, $rel) = @_;
1440 6059 ▶ if( !$self->has_relationship( $rel ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_relationship($rel)) 1 6058 6059
1441 1 $self->throw_exception("No such relationship '$rel' on " . $self->source_name);
1442 }
1443  
1444 # if we are not registered with a schema - just use the prototype
1445 # however if we do have a schema - ask for the source by name (and
1446 # throw in the process if all fails)
1447 6058 ▶ if (my $schema = try { $self->schema }) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (my $schema = &try(sub { $self->schema; } )) { } 6039 19 6058
1448 6039 $schema->source($self->relationship_info($rel)->{source});
1449 }
1450 else {
1451 19 my $class = $self->relationship_info($rel)->{class};
1452 19 $self->ensure_class_loaded($class);
1453 19 $class->result_source_instance;
1454 }
1455 }
1456  
1457  
1458 1 ▶sub related_class {
Subroutine related_class: called CC=2 SCAR=7.6
Pod documented
1459 1 my ($self, $rel) = @_;
1460 1 ▶ if( !$self->has_relationship( $rel ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_relationship($rel)) 0 1 1
1461 0 $self->throw_exception("No such relationship '$rel' on " . $self->source_name);
1462 }
1463 1 return $self->schema->class($self->relationship_info($rel)->{source});
1464 }
1465  
1466 379 my $global_phase_destroy;
1467 183108 ▶sub DESTROY {
Subroutine DESTROY: called CC=10 SCAR=24.1
1468 ### NO detected_reinvoked_destructor check
1469 ### This code very much relies on being called multuple times
1470  
1471 183108 ▶ return if $global_phase_destroy ||= in_global_destruction;
Branch: 1 branch
BranchTrueFalseTotal
if $global_phase_destroy ||= &in_global_destruction() 0 183108 183108
Condition33%1/3
$global_phase_destroy ||= &in_global_destruction()
l!l&&r!l&&!r
00183108
MC/DC0%0/2
$global_phase_destroy ||= &in_global_destruction()
$global_phase_destroy &in_global_destruction()
Truth table33%1/3
A ||= B
A= $global_phase_destroyB= &in_global_destruction()
ABresult
1X1
011
000
1472  
1473 ######
1474 # !!! ACHTUNG !!!!
1475 ######
1476 #
1477 # Under no circumstances shall $_[0] be stored anywhere else (like copied to
1478 # a lexical variable, or shifted, or anything else). Doing so will mess up
1479 # the refcount of this particular result source, and will allow the $schema
1480 # we are trying to save to reattach back to the source we are destroying.
1481 # The relevant code checking refcounts is in ::Schema::DESTROY()
1482  
1483 # if we are not a schema instance holder - we don't matter
1484 return if(
1485 ! ref $_[0]->{schema}
1486 or
1487 isweak $_[0]->{schema}
1488 183108 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[0]{"schema"} or builtin::is_weak($_[0]{"schema"}) 139462 43646 183108
Condition100%3/3
not ref $_[0]{"schema"} or builtin::is_weak($_[0]{"schema"})
l!l&&r!l&&!r
136579288343646
MC/DC100%2/2
not ref $_[0]{"schema"} or builtin::is_weak($_[0]{"schema"})
not ref $_[0]{"schema"} builtin::is_weak($_[0]{"schema"})
Truth table100%3/3
not(A) or B
A= not ref $_[0]{"schema"}B= builtin::is_weak($_[0]{"schema"})
ABresult
1X1
011
000
1489  
1490 # weaken our schema hold forcing the schema to find somewhere else to live
1491 # during global destruction (if we have not yet bailed out) this will throw
1492 # which will serve as a signal to not try doing anything else
1493 # however beware - on older perls the exception seems randomly untrappable
1494 # due to some weird race condition during thread joining :(((
1495 43646 local $@;
1496 eval {
1497 43646 weaken $_[0]->{schema};
1498  
1499 # if schema is still there reintroduce ourselves with strong refs back to us
1500 43646 ▶ if ($_[0]->{schema}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"schema"}) 43617 29 43646
1501 43617 my $srcregs = $_[0]->{schema}->source_registrations;
1502 43617 for (keys %$srcregs) {
1503 1943957 ▶ next unless $srcregs->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $srcregs->{$_} 0 1943957 1943957
1504 1943957 ▶ $srcregs->{$_} = $_[0] if $srcregs->{$_} == $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $srcregs->{$_} == $_[0] 0 1943957 1943957
1505 }
1506 }
1507  
1508 43646 1;
1509 43646 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { builtin::weaken($_[0]{"schema"}); if ($_[0]{"schema"}) { my $srcregs = $_[0]{"schema"}->source_registrations; foreach $_ (keys %$srcregs) { next unless $srcregs->{$_}; $srcregs->{$_} = $_[0] if $srcregs->{$_} == $_[0]; } ; } ; 1 } } or do { $global_phase_destroy = 1 } 43646 0 43646
1510 0 $global_phase_destroy = 1;
1511 };
1512  
1513 43646 return;
1514 }
1515  
1516 # Schema instance to (re)attach to while thawing. Localized by
1517 # $schema->thaw / $schema->dclone (see DBIO::Schema); left unset for a
1518 # schema-less Storable::dclone, which then resolves a detached source.
1519 379 our $thaw_schema;
1520  
1521 42 ▶sub STORABLE_freeze {
Subroutine STORABLE_freeze: called CC=2 SCAR=7.2
Pod undocumented
1522 42 my ($self) = @_;
1523  
1524 # A ResultSource is not serialized directly (it may carry CODErefs in
1525 # relationship definitions and a schema backref). Freeze only the minimal
1526 # identity needed to re-resolve the canonical source on thaw.
1527 Storable::nfreeze({
1528 source_moniker => $self->source_name,
1529 _frozen_from_class => $self->{_detached_thaw}
1530 42 ▶ ? $self->result_class
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_detached_thaw'} ? : 0 42 42
1531 : $self->schema->class($self->source_name),
1532 });
1533 }
1534  
1535  
1536 46 ▶sub STORABLE_thaw {
Subroutine STORABLE_thaw: called CC=7 SCAR=19.6
Pod documented
1537 46 my ($self, $cloning, $ice) = @_;
1538  
1539 46 my $frozen = Storable::thaw($ice);
1540 46 my $moniker = $frozen->{source_moniker};
1541 46 my $from_class = $frozen->{_frozen_from_class};
1542  
1543 46 DBIO::Util::assert_class_name($from_class);
1544  
1545 44 my $resolved;
1546 44 ▶ if ($thaw_schema) {
Branch: 2 branches
BranchTrueFalseTotal
if ($DBIO::ResultSource::thaw_schema) { } 32 12 44
elsif ($from_class->isa('DBIO::ResultSourceProxy') and my $rs = $from_class->result_source_instance) { } 11 1 12
1547 DBIO::Exception->throw(
1548 "Thaw failed - class '$from_class' is not the result class of a source registered on the schema"
1549 1440 ▶ ) unless grep { $_ and $_->result_class eq $from_class }
Condition66%2/3
$_ && $_->result_class eq $from_class
!ll&&!rl&&r
0140931
MC/DC50%1/2
$_ && $_->result_class eq $from_class
$_ $_->result_class eq $from_class
Truth table66%2/3
A && B
A= $_B= $_->result_class eq $from_class
ABresult
0X0
100
111
1550 32 ▶ values %{ $thaw_schema->source_registrations };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ and $_->result_class eq $from_class;} values %{$DBIO::ResultSource::thaw_schema->source_registrations;} 1 31 32
1551  
1552 31 $resolved = $thaw_schema->source($moniker);
1553 }
1554 ▶ elsif ($from_class->isa('DBIO::ResultSourceProxy') and my $rs = $from_class->result_source_instance) {
Condition66%2/3
$from_class->isa("DBIO::ResultSourceProxy") and my $rs = $from_class->result_source_instance
!ll&&!rl&&r
1011
MC/DC50%1/2
$from_class->isa("DBIO::ResultSourceProxy") and my $rs = $from_class->result_source_instance
$from_class->isa("DBIO::ResultSourceProxy") my $rs = $from_class->result_source_instance
Truth table66%2/3
A and B
A= $from_class->isa("DBIO::ResultSourceProxy")B= my $rs = $from_class->result_source_instance
ABresult
0X0
100
111
1555 # A class-level result source only counts as a resolution channel if it
1556 # holds an actual schema *instance*. A schema *class name* is not good
1557 # enough: that is what compose_namespace leaves on the composed result
1558 # classes, and such a source has no storage, so resolving through it hands
1559 # out a half-attached source that blows up with an obscure "method call on
1560 # an undefined value" the first time anything storage-dependent runs.
1561 11 ▶ my $leaked_schema = try { $rs->schema };
Subroutine __ANON__: called CC=1 SCAR=0.0
1562  
1563 11 ▶ if (blessed $leaked_schema) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($leaked_schema)) { } 0 11 11
1564 0 $resolved = $leaked_schema->source($moniker);
1565 }
1566 else {
1567 # Detached: metadata still works, every storage-dependent operation
1568 # throws a pointed exception naming $schema->thaw / $thaw_schema. Copy
1569 # rather than brand the shared class-level source itself.
1570 11 $resolved = bless {
1571 %$rs,
1572 schema => undef,
1573 source_name => $moniker,
1574 _detached_thaw => 1,
1575 }, ref $rs;
1576 }
1577 }
1578 else {
1579 1 DBIO::Exception->throw(
1580 "Thaw failed - original result class '$from_class' does not exist on this system"
1581 );
1582 }
1583  
1584 42 %$self = %$resolved;
1585 }
1586  
1587  
1588 497 ▶sub throw_exception {
Subroutine throw_exception: called CC=2 SCAR=6.9
Pod documented
1589 497 my $self = shift;
1590  
1591 $self->{schema}
1592 497 ▶ ? $self->{schema}->throw_exception(@_)
Branch: 1 branch
BranchTrueFalseTotal
$self->{'schema'} ? : 392 105 497
1593 : DBIO::Exception->throw(@_)
1594 ;
1595 }
1596  
1597  
1598 379 1;
1599  
1600 __END__
↑ Summary blib/lib/DBIO/Test/Util/LeakTracer.pm »