Object/Manager.pm

filter: Statementstmt 8.0% 136 / 1690 Branchbran 3.7% 39 / 1044 Conditioncond 1.6% 10 / 618 MC/DCmcdc 0.0% 0 / 341 Subroutinesub 41.3% 24 / 58 Podpod 87.5% 14 / 16 totaltotal 5.9% 223 / 3767 CC 796 SCAR 119.2
CC
796
Cov
6%
get_objects
250976.0
__ANON__
3551.1
delete_objects
930.0
CRAP 149576.0
↑ Summary Object/QueryBuilder.pm »
1 package Rose::DB::Object::Manager;
2  
3 61 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 61 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 61 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 #use List::Util 1.45 qw(uniq);
9 61 ▶use Scalar::Util qw(weaken refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 61 ▶use Rose::DB::Object::Iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 61 ▶use Rose::DB::Object::QueryBuilder qw(build_select build_where_clause);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 use Rose::DB::Object::Constants
14 61 ▶ qw(PRIVATE_PREFIX STATE_LOADING STATE_IN_DB MODIFIED_COLUMNS);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # XXX: A value that is unlikely to exist in a primary key column value
17 61 ▶use constant PK_JOIN => "\0\2,\3\0";
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 61 our $VERSION = '0.813';
20  
21 61 our $Debug = 0;
22  
23 #
24 # Class data
25 #
26  
27 use Rose::Class::MakeMethods::Generic
28 61 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
29 61 inheritable_scalar =>
30 [
31 'error',
32 'total',
33 'error_mode',
34 '_object_class',
35 '_base_name',
36 '_default_manager_method_types',
37 'default_objects_per_page',
38 'default_limit_with_subselect',
39 'default_nested_joins',
40 'dbi_prepare_cached',
41 'strict_ops',
42 ],
43 61 );
44  
45 61 __PACKAGE__->error_mode('fatal');
46 61 __PACKAGE__->default_objects_per_page(20);
47 61 __PACKAGE__->default_limit_with_subselect(1);
48 61 __PACKAGE__->default_nested_joins(1);
49 61 __PACKAGE__->dbi_prepare_cached(0);
50 61 __PACKAGE__->strict_ops(0);
51 61 __PACKAGE__->default_manager_method_types(qw(objects iterator count delete update));
52  
53 sub handle_error
54 0 ▶{
Subroutine handle_error: not called CC=7 SCAR=40.3
Pod undocumented
55 0 my($class, $object) = @_;
56  
57 0 my $mode = $class->error_mode;
58  
59 0 ▶ return if($mode eq 'return');
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "return" 0 0 0
60  
61 0 my $level = $Carp::CarpLevel;
62 0 local $Carp::CarpLevel = $level + 1;
63  
64 0 ▶ if($mode eq 'croak' || $mode eq 'fatal')
Branch: 4 branches
BranchTrueFalseTotal
if ($mode eq 'croak' or $mode eq 'fatal') { } 0 0 0
elsif ($mode eq 'carp') { } 0 0 0
elsif ($mode eq 'cluck') { } 0 0 0
elsif ($mode eq 'confess') { } 0 0 0
Condition0%0/3
$mode eq "croak" or $mode eq "fatal"
l!l&&r!l&&!r
000
MC/DC0%0/2
$mode eq "croak" or $mode eq "fatal"
$mode eq "croak" $mode eq "fatal"
Truth table0%0/3
A or B
A= $mode eq "croak"B= $mode eq "fatal"
ABresult
1X1
011
000
65 {
66 0 Carp::croak $object->error;
67 }
68 elsif($mode eq 'carp')
69 {
70 0 Carp::carp $object->error;
71 }
72 elsif($mode eq 'cluck')
73 {
74 0 Carp::croak $object->error;
75 }
76 elsif($mode eq 'confess')
77 {
78 0 Carp::confess $object->error;
79 }
80 else
81 {
82 0 Carp::croak "(Invalid error mode set: '$mode') - ", $object->error;
83 }
84  
85 0 return 1;
86 }
87  
88 sub normalize_get_objects_args
89 0 ▶{
Subroutine normalize_get_objects_args: not called CC=4 SCAR=30.0
Pod documented
90 # Handle all these arg forms:
91 #
92 # get_objects(a => b, c => d, ...);
93 # get_objects([ ... ], a => b, c => d, ...)
94 # get_objects({ ... }, a => b, c => d, ...)
95  
96 0 ▶ if(ref $_[1])
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[1]) 0 0 0
97 {
98 0 my $class = shift;
99  
100 0 ▶ if(ref $_[0] eq 'HASH')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
elsif (ref $_[0] eq 'ARRAY') { } 0 0 0
101 {
102 0 return ($class, query => [ %{shift(@_)} ], @_);
103 }
104 elsif(ref $_[0] eq 'ARRAY')
105 {
106 0 return ($class, query => shift, @_);
107 }
108 0 else { Carp::croak 'Invalid arguments: ', join(', ', @_) }
109 }
110  
111 0 return @_;
112 }
113  
114 # XXX: These are duplicated from ManyToMany.pm because I don't want to use()
115 # XXX: that module from here if I don't have to. Lazy or foolish? Hm.
116 # XXX: Anyway, make sure they stay in sync!
117 61 ▶use constant MAP_RECORD_METHOD => 'map_record';
Subroutine BEGIN: called CC=1 SCAR=0.0
118 61 ▶use constant DEFAULT_REL_KEY => PRIVATE_PREFIX . '_default_rel_key';
Subroutine BEGIN: called CC=1 SCAR=0.0
119  
120 0 ▶sub object_class { }
Subroutine object_class: not called CC=1 SCAR=0.0
Pod documented
121  
122 sub default_manager_method_types
123 63 ▶{
Subroutine default_manager_method_types: called CC=5 SCAR=16.8
Pod documented
124 63 my($class) = shift;
125  
126 63 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 62 1 63
127 {
128 62 ▶ if(@_ == 1 && ref $_[0] eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 0 62 62
Condition33%1/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
6200
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
129 {
130 0 $class->_default_manager_method_types(@_);
131 }
132 else
133 {
134 62 $class->_default_manager_method_types([ @_ ]);
135 }
136 }
137  
138 return wantarray ?
139 63 ▶ @{$class->_default_manager_method_types} : $class->_default_manager_method_types;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 62 63
140 }
141  
142 sub make_manager_methods
143 1 ▶{
Subroutine make_manager_methods: called CC=61 SCAR=64.5
Pod documented
144 1 my($class) = shift;
145  
146 1 ▶ if(@_ == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 1 0 1
147 {
148 1 @_ = (methods => { $_[0] => [ $class->default_manager_method_types ] });
149 }
150 else
151 {
152 0 ▶ Carp::croak "make_manager_methods() called with an odd number of arguments"
Branch: 1 branch
BranchTrueFalseTotal
unless @_ % 2 == 0 0 0 0
153 unless(@_ % 2 == 0);
154 }
155  
156 1 my %args = @_;
157  
158 1 ▶ local $Debug = $args{'debug'} if(exists $args{'debug'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"debug"} 0 1 1
159  
160 1 ▶ my $calling_class = ($class eq __PACKAGE__) ? (caller)[0] : $class;
Branch: 1 branch
BranchTrueFalseTotal
$class eq __PACKAGE__ ? : 0 1 1
161 1 ▶ my $target_class = $args{'target_class'} || $calling_class;
Condition33%1/3
$args{'target_class'} || $calling_class
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{'target_class'} || $calling_class
$args{'target_class'} $calling_class
Truth table33%1/3
A || B
A= $args{'target_class'}B= $calling_class
ABresult
1X1
011
000
162 1 my $object_class = $args{'object_class'};
163 1 ▶ my $class_invocant = UNIVERSAL::isa($target_class, __PACKAGE__) ?
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($target_class, __PACKAGE__) ? : 1 0 1
164 $target_class : __PACKAGE__;
165  
166 1 ▶ unless($object_class)
Branch: 1 branch
BranchTrueFalseTotal
unless ($object_class) 1 0 1
167 {
168 1 ▶ if(UNIVERSAL::isa($target_class, 'Rose::DB::Object::Manager'))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($target_class, "Rose::DB::Object::Manager")) 1 0 1
169 {
170 1 $object_class = $target_class->object_class;
171 }
172  
173 1 ▶ if(!$object_class && UNIVERSAL::isa($target_class, 'Rose::DB::Object'))
Branch: 1 branch
BranchTrueFalseTotal
if (not $object_class and UNIVERSAL::isa($target_class, "Rose::DB::Object")) 0 1 1
Condition33%1/3
not $object_class and UNIVERSAL::isa($target_class, "Rose::DB::Object")
!ll&&!rl&&r
100
MC/DC0%0/2
not $object_class and UNIVERSAL::isa($target_class, "Rose::DB::Object")
not $object_class UNIVERSAL::isa($target_class, "Rose::DB::Object")
Truth table33%1/3
not(A) and B
A= not $object_classB= UNIVERSAL::isa($target_class, "Rose::DB::Object")
ABresult
0X0
100
111
174 {
175 0 $object_class = $target_class;
176 }
177 }
178  
179 1 ▶ unless($object_class)
Branch: 1 branch
BranchTrueFalseTotal
unless ($object_class) 0 1 1
180 {
181 0 ▶ Carp::croak "Could not determine object class. Please pass a value for ",
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($target_class, 'Rose::DB::Object::Manager') ? : 0 0 0
182 "the object_class parameter",
183 (UNIVERSAL::isa($target_class, 'Rose::DB::Object::Manager') ?
184 " or override the object_class() method in $target_class" : '');
185 }
186  
187 1 ▶ unless(UNIVERSAL::isa($object_class, 'Rose::DB::Object'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($object_class, "Rose::DB::Object")) 0 1 1
188 {
189 0 my $error;
190  
191 TRY:
192 {
193 0 local $@;
194 0 eval "require $object_class";
195 0 $error = $@;
196 }
197  
198 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
199 {
200 0 Carp::croak "Could not load object class $object_class - $error";
201 }
202 }
203  
204 1 my $meta = $object_class->meta;
205 1 my $cm = $meta->convention_manager;
206  
207 1 ▶ my $base_name = $args{'base_name'} || $cm->auto_manager_base_name($meta->table, $object_class);
Condition33%1/3
$args{'base_name'} || $cm->auto_manager_base_name($meta->table, $object_class)
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{'base_name'} || $cm->auto_manager_base_name($meta->table, $object_class)
$args{'base_name'} $cm->auto_manager_base_name($meta->table, $object_class)
Truth table33%1/3
A || B
A= $args{'base_name'}B= $cm->auto_manager_base_name($meta->table, $object_class)
ABresult
1X1
011
000
208  
209 1 ▶ if(!$args{'methods'})
Branch: 2 branches
BranchTrueFalseTotal
if (not $args{'methods'}) { } 0 1 1
elsif ($args{'base_name'}) { } 0 1 1
210 {
211 0 ▶ unless($base_name)
Branch: 1 branch
BranchTrueFalseTotal
unless ($base_name) 0 0 0
212 {
213 0 Carp::croak "Missing methods parameter and base_name parameter, and the ",
214 "convention manager's auto_manager_base_name() method did not ",
215 "return a true value"
216 }
217  
218 0 $args{'methods'} =
219 {
220 $base_name => [ $class->default_manager_method_types ]
221 };
222 }
223 elsif($args{'base_name'})
224 {
225 0 Carp::croak "Please pass the methods parameter OR the base_name parameter, not both";
226 }
227  
228 Carp::croak "Invalid 'methods' parameter - should be a hash ref"
229 1 ▶ unless(ref $args{'methods'} eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{"methods"} eq "HASH" 0 1 1
230  
231 1 $class->_base_name($base_name);
232 1 $class->_object_class($object_class);
233  
234 1 ▶ while(my($name, $types) = each %{$args{'methods'}})
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$args{"methods"};}) 1 1 2
235 {
236 1 ▶ $class->_base_name($name) unless($base_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $base_name 0 1 1
237  
238 1 ▶ my $have_full_name = ($name =~ s/\(\)$//) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$name =~ s/\(\)$// ? : 0 1 1
239  
240 1 ▶ Carp::croak "Invalid value for the '$name' parameter"
Branch: 1 branch
BranchTrueFalseTotal
if ref $types and ref $types ne "ARRAY" 0 1 1
Condition33%1/3
ref $types and ref $types ne "ARRAY"
!ll&&!rl&&r
010
MC/DC0%0/2
ref $types and ref $types ne "ARRAY"
ref $types ref $types ne "ARRAY"
Truth table33%1/3
A and B
A= ref $typesB= ref $types ne "ARRAY"
ABresult
0X0
100
111
241 if(ref $types && ref $types ne 'ARRAY');
242  
243 1 ▶ if($have_full_name && ref $types && @$types > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($have_full_name and ref $types and @$types > 1) 0 1 1
Condition33%2/6
$have_full_name and ref $types and @$types > 1
!ll&&!rl&&r
100
$have_full_name and ref $types
!ll&&!rl&&r
100
MC/DC0%0/3
$have_full_name and ref $types and @$types > 1
$have_full_name ref $types @$types > 1
Truth table25%1/4
A and B and C
A= $have_full_nameB= ref $typesC= @$types > 1
ABCresult
0XX0
10X0
1100
1111
244 {
245 0 Carp::croak "Cannot use explicit method name $name() with more ",
246 "than one method type";
247 }
248  
249 1 ▶ foreach my $type ((ref $types ? @$types : ($types)))
Branch: 1 branch
BranchTrueFalseTotal
ref $types ? : 1 0 1
250 {
251 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
252  
253 3 ▶ if($type eq 'objects')
Branch: 5 branches
BranchTrueFalseTotal
if ($type eq 'objects') { } 0 3 3
elsif ($type eq 'count') { } 1 2 3
elsif ($type eq 'iterator') { } 1 1 2
elsif ($type eq 'delete') { } 1 0 1
elsif ($type eq 'update') { } 0 0 0
254 {
255 0 ▶ my $method_name =
Branch: 1 branch
BranchTrueFalseTotal
$have_full_name ? : 0 0 0
Condition0%0/2
$cm->auto_manager_method_name($type, $base_name, $object_class) or "get_$name"
l!l
00
MC/DC0%0/1
$cm->auto_manager_method_name($type, $base_name, $object_class) or "get_$name"
$cm->auto_manager_method_name($type, $base_name, $object_class)
Truth table0%0/2
A
A= $cm->auto_manager_method_name($type, $base_name, $object_class)
Aresult
11
00
256 $have_full_name ? $name :
257 ($cm->auto_manager_method_name($type, $base_name, $object_class) || "get_$name");
258  
259 0 foreach my $class ($target_class, $class_invocant)
260 {
261 0 my $method = "${class}::$method_name";
262 0 my $short_method = $method_name;
263 Carp::croak "A $method method already exists"
264 0 ▶ if(defined &{$method});
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$method;} 0 0 0
265  
266 0 ▶ Carp::croak "The $short_method method is inherited from Rose::DB::Object::Manager ",
Branch: 1 branch
BranchTrueFalseTotal
if "Rose::DB::Object::Manager"->can($short_method) 0 0 0
267 "and cannot be overriden in $target_class"
268 if(Rose::DB::Object::Manager->can($short_method));
269 }
270  
271 0 ▶ $Debug && warn "Making method: $target_class->$method_name()\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Object::Manager::Debug and warn "Making method: $target_class->$method_name()\n" 0 0 0
272 0 *{"${target_class}::$method_name"} = sub
273 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
274 0 shift;
275 0 $class_invocant->get_objects(@_, object_class => $object_class);
276 0 };
277 }
278 elsif($type eq 'count')
279 {
280 1 ▶ my $method_name =
Branch: 1 branch
BranchTrueFalseTotal
$have_full_name ? : 0 1 1
Condition50%1/2
$cm->auto_manager_method_name($type, $base_name, $object_class) or "get_${name}_count"
l!l
01
MC/DC0%0/1
$cm->auto_manager_method_name($type, $base_name, $object_class) or "get_${name}_count"
$cm->auto_manager_method_name($type, $base_name, $object_class)
Truth table50%1/2
A
A= $cm->auto_manager_method_name($type, $base_name, $object_class)
Aresult
11
00
281 $have_full_name ? $name :
282 ($cm->auto_manager_method_name($type, $base_name, $object_class) || "get_${name}_count");
283  
284 1 foreach my $class ($target_class, $class_invocant)
285 {
286 2 my $method = "${class}::$method_name";
287 Carp::croak "A $method method already exists"
288 2 ▶ if(defined &{$method});
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$method;} 0 2 2
289 }
290  
291 1 ▶ $Debug && warn "Making method: $target_class->$method_name()\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Object::Manager::Debug and warn "Making method: $target_class->$method_name()\n" 0 1 1
292 1 *{"${target_class}::$method_name"} = sub
293 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
294 0 shift;
295 0 $class_invocant->get_objects(
296 @_, count_only => 1, object_class => $object_class)
297 1 };
298 }
299 elsif($type eq 'iterator')
300 {
301 1 ▶ my $method_name =
Branch: 1 branch
BranchTrueFalseTotal
$have_full_name ? : 0 1 1
Condition50%1/2
$cm->auto_manager_method_name($type, $base_name, $object_class) or "get_${name}_iterator"
l!l
10
MC/DC0%0/1
$cm->auto_manager_method_name($type, $base_name, $object_class) or "get_${name}_iterator"
$cm->auto_manager_method_name($type, $base_name, $object_class)
Truth table50%1/2
A
A= $cm->auto_manager_method_name($type, $base_name, $object_class)
Aresult
11
00
302 $have_full_name ? $name :
303 ($cm->auto_manager_method_name($type, $base_name, $object_class) || "get_${name}_iterator");
304  
305 1 foreach my $class ($target_class, $class_invocant)
306 {
307 2 my $method = "${class}::$method_name";
308 Carp::croak "A $method method already exists"
309 2 ▶ if(defined &{$method});
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$method;} 0 2 2
310 }
311  
312 1 ▶ $Debug && warn "Making method: $target_class->$method_name()\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Object::Manager::Debug and warn "Making method: $target_class->$method_name()\n" 0 1 1
313 1 *{"${target_class}::$method_name"} = sub
314 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
315 0 shift;
316 0 $class_invocant->get_objects(
317 @_, return_iterator => 1, object_class => $object_class)
318 1 };
319 }
320 elsif($type eq 'delete')
321 {
322 1 ▶ my $method_name =
Branch: 1 branch
BranchTrueFalseTotal
$have_full_name ? : 0 1 1
Condition50%1/2
$cm->auto_manager_method_name($type, $base_name, $object_class) or "delete_$name"
l!l
10
MC/DC0%0/1
$cm->auto_manager_method_name($type, $base_name, $object_class) or "delete_$name"
$cm->auto_manager_method_name($type, $base_name, $object_class)
Truth table50%1/2
A
A= $cm->auto_manager_method_name($type, $base_name, $object_class)
Aresult
11
00
323 $have_full_name ? $name :
324 ($cm->auto_manager_method_name($type, $base_name, $object_class) || "delete_$name");
325  
326 1 foreach my $class ($target_class, $class_invocant)
327 {
328 2 my $method = "${class}::$method_name";
329 Carp::croak "A $method method already exists"
330 2 ▶ if(defined &{$method});
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$method;} 0 2 2
331 }
332  
333 1 ▶ $Debug && warn "Making method: $target_class->$method_name()\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Object::Manager::Debug and warn "Making method: $target_class->$method_name()\n" 0 1 1
334 1 *{"${target_class}::$method_name"} = sub
335 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
336 0 shift;
337 0 $class_invocant->delete_objects(@_, object_class => $object_class);
338 1 };
339 }
340 elsif($type eq 'update')
341 {
342 0 ▶ my $method_name =
Branch: 1 branch
BranchTrueFalseTotal
$have_full_name ? : 0 0 0
Condition0%0/2
$cm->auto_manager_method_name($type, $base_name, $object_class) or "update_$name"
l!l
00
MC/DC0%0/1
$cm->auto_manager_method_name($type, $base_name, $object_class) or "update_$name"
$cm->auto_manager_method_name($type, $base_name, $object_class)
Truth table0%0/2
A
A= $cm->auto_manager_method_name($type, $base_name, $object_class)
Aresult
11
00
343 $have_full_name ? $name :
344 ($cm->auto_manager_method_name($type, $base_name, $object_class) || "update_$name");
345  
346 0 foreach my $class ($target_class, $class_invocant)
347 {
348 0 my $method = "${class}::$method_name";
349 Carp::croak "A $method method already exists"
350 0 ▶ if(defined &{$method});
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$method;} 0 0 0
351 }
352  
353 0 ▶ $Debug && warn "Making method: $target_class->$method_name()\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Object::Manager::Debug and warn "Making method: $target_class->$method_name()\n" 0 0 0
354 0 *{"${target_class}::$method_name"} = sub
355 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
356 0 shift;
357 0 $class_invocant->update_objects(@_, object_class => $object_class);
358 0 };
359 }
360 else
361 {
362 0 Carp::croak "Invalid method type: $type";
363 }
364 }
365 }
366 }
367  
368 sub get_objects_count
369 0 ▶{
Subroutine get_objects_count: not called CC=1 SCAR=6.9
Pod documented
370 0 my($class) = shift;
371 0 $class->get_objects(@_, count_only => 1);
372 }
373  
374 0 ▶sub get_objects_iterator { shift->get_objects(@_, return_iterator => 1) }
Subroutine get_objects_iterator: not called CC=1 SCAR=6.9
Pod documented
375 0 ▶sub get_objects_sql { shift->get_objects(@_, return_sql => 1) }
Subroutine get_objects_sql: not called CC=1 SCAR=6.9
Pod documented
376  
377 sub _include_sort_column
378 0 ▶{
Subroutine _include_sort_column: not called CC=6 SCAR=37.4
379 0 my($columns, $methods, $di_keys, $table, $class, $meta, $column) = @_;
380  
381 0 ▶ my $col_meta = $meta->column($column) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $col_meta = $meta->column($column) or return 0 0 0
382  
383 0 ▶ my $cols = $columns->{$table} ||= [];
Condition0%0/2
$columns->{$table} ||= []
l!l
00
MC/DC0%0/1
$columns->{$table} ||= []
$columns->{$table}
Truth table0%0/2
A
A= $columns->{$table}
Aresult
11
00
384 0 ▶ return if(grep { $_ eq $column } @$cols);
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $column;} @$cols 0 0 0
385  
386 0 $columns->{$table} = $cols = [ @$cols ];
387 0 push(@$cols, $column);
388  
389 0 my $method = $meta->column_mutator_method_name($column);
390 0 ▶ my $method_list = $methods->{$table} ||= [];
Condition0%0/2
$methods->{$table} ||= []
l!l
00
MC/DC0%0/1
$methods->{$table} ||= []
$methods->{$table}
Truth table0%0/2
A
A= $methods->{$table}
Aresult
11
00
391 0 $methods->{$table} = $method_list = [ @$method_list ];
392 0 push(@$method_list, $method);
393  
394 0 ▶ $di_keys->{$class} = { %{ $di_keys->{$class} || {} } };
Condition0%0/2
$di_keys->{$class} || {}
l!l
00
MC/DC0%0/1
$di_keys->{$class} || {}
$di_keys->{$class}
Truth table0%0/2
A
A= $di_keys->{$class}
Aresult
11
00
395 0 $di_keys->{$class}{$method} = $col_meta->db_value_hash_key;
396 }
397  
398 61 ▶use constant WITH => 555; # arbitrary
Subroutine BEGIN: called CC=1 SCAR=0.0
399  
400 sub get_objects
401 0 ▶{
Subroutine get_objects: not called CC=507 SCAR=124.3
Pod documented
402 0 my($class, %args);
403  
404 0 ▶ if(ref $_[1])
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[1]) { } 0 0 0
405 {
406 0 $class = shift;
407  
408 0 ▶ if(ref $_[0] eq 'HASH')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
elsif (ref $_[0] eq 'ARRAY') { } 0 0 0
409 {
410 0 %args = (query => [ %{shift(@_)} ], @_);
411 }
412 elsif(ref $_[0] eq 'ARRAY')
413 {
414 0 %args = (query => shift, @_);
415 }
416 0 else { Carp::croak 'Invalid arguments: ', join(', ', @_) }
417  
418 0 unshift(@_, $class); # restore original args
419 }
420 else
421 {
422 0 ($class, %args) = @_;
423 }
424  
425 0 $class->error(undef);
426  
427 0 ▶ my $object_class = delete $args{'object_class'}
Condition0%0/5
delete $args{'object_class'} || $class->object_class || Carp::croak('Missing object class argument')
l!l
00
delete $args{"object_class"} or $class->object_class
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $args{'object_class'} || $class->object_class || Carp::croak('Missing object class argument')
delete $args{"object_class"} $class->object_class
Truth table0%0/3
A or B
A= delete $args{"object_class"}B= $class->object_class
ABresult
1X1
011
000
428 || $class->object_class || Carp::croak "Missing object class argument";
429  
430 0 my $return_sql = delete $args{'return_sql'};
431 0 my $return_iterator = delete $args{'return_iterator'};
432 0 my $count_only = delete $args{'count_only'};
433 0 my $require_objects = delete $args{'require_objects'};
434 0 my $with_objects = delete $args{'with_objects'};
435  
436 0 ▶ my $skip_first = delete $args{'skip_first'} || 0;
Condition0%0/2
delete $args{'skip_first'} || 0
l!l
00
MC/DC0%0/1
delete $args{'skip_first'} || 0
delete $args{'skip_first'}
Truth table0%0/2
A
A= delete $args{'skip_first'}
Aresult
11
00
437 0 my $distinct = delete $args{'distinct'};
438 0 my $fetch = delete $args{'fetch_only'};
439 0 ▶ my $hints = delete $args{'hints'} || {};
Condition0%0/2
delete $args{'hints'} || {}
l!l
00
MC/DC0%0/1
delete $args{'hints'} || {}
delete $args{'hints'}
Truth table0%0/2
A
A= delete $args{'hints'}
Aresult
11
00
440 0 my $select = $args{'select'};
441  
442 # Alias by popular demand...
443 $args{'query'} = delete $args{'where'}
444 0 ▶ if($args{'where'} && !exists $args{'query'});
Branch: 1 branch
BranchTrueFalseTotal
if $args{"where"} and not exists $args{"query"} 0 0 0
Condition0%0/3
$args{"where"} and not exists $args{"query"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"where"} and not exists $args{"query"}
$args{"where"} not exists $args{"query"}
Truth table0%0/3
A and not(B)
A= $args{"where"}B= not exists $args{"query"}
ABresult
0X0
100
111
445  
446 0 ▶ $args{'strict_ops'} = $class->strict_ops unless(exists $args{'strict_ops'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"strict_ops"} 0 0 0
447  
448 0 my $no_forced_sort = delete $args{'no_forced_sort'};
449  
450 my $table_aliases = exists $args{'table_aliases'} ?
451 0 ▶ $args{'table_aliases'} : ($args{'table_aliases'} = 1);
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'table_aliases'} ? : 0 0 0
452  
453 # Coerce for_update boolean alias into lock argument
454 0 ▶ if(delete $args{'for_update'})
Branch: 1 branch
BranchTrueFalseTotal
if (delete $args{"for_update"}) 0 0 0
455 {
456 0 ▶ $args{'lock'}{'type'} ||= 'for update';
Condition0%0/2
$args{"lock"}{"type"} ||= "for update"
l!l
00
MC/DC0%0/1
$args{"lock"}{"type"} ||= "for update"
$args{"lock"}{"type"}
Truth table0%0/2
A
A= $args{"lock"}{"type"}
Aresult
11
00
457 }
458  
459 0 ▶ $with_objects = undef if(ref $with_objects && !@$with_objects);
Branch: 1 branch
BranchTrueFalseTotal
if ref $with_objects and not @$with_objects 0 0 0
Condition0%0/3
ref $with_objects and not @$with_objects
!ll&&!rl&&r
000
MC/DC0%0/2
ref $with_objects and not @$with_objects
ref $with_objects not @$with_objects
Truth table0%0/3
A and not(B)
A= ref $with_objectsB= not @$with_objects
ABresult
0X0
100
111
460 0 ▶ $require_objects = undef if(ref $require_objects && !@$require_objects);
Branch: 1 branch
BranchTrueFalseTotal
if ref $require_objects and not @$require_objects 0 0 0
Condition0%0/3
ref $require_objects and not @$require_objects
!ll&&!rl&&r
000
MC/DC0%0/2
ref $require_objects and not @$require_objects
ref $require_objects not @$require_objects
Truth table0%0/3
A and not(B)
A= ref $require_objectsB= not @$require_objects
ABresult
0X0
100
111
461  
462 0 ▶ local $Debug = $args{'debug'} if(exists $args{'debug'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"debug"} 0 0 0
463  
464 my $try_subselect_limit = (exists $args{'limit_with_subselect'}) ?
465 0 ▶ $args{'limit_with_subselect'} : $class->default_limit_with_subselect;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'limit_with_subselect'} ? : 0 0 0
466  
467 0 my $subselect_limit = 0;
468  
469 # Can't do direct inject with custom select lists
470 0 ▶ my $direct_inject = $select ? 0 : delete $args{'inject_results'};
Branch: 1 branch
BranchTrueFalseTotal
$select ? : 0 0 0
471  
472 0 my(%fetch, %rel_name, %di_keys);
473  
474 0 my $meta = $object_class->meta;
475  
476 0 ▶ $args{'hints'} = $hints->{'t1'} || $hints->{$meta->table} || $hints;
Condition0%0/6
$hints->{'t1'} || $$hints{$meta->table} || $hints
l!l&&r!l&&!r
000
$hints->{"t1"} or $$hints{$meta->table}
l!l&&r!l&&!r
000
MC/DC0%0/3
$hints->{'t1'} || $$hints{$meta->table} || $hints
$hints->{"t1"} $$hints{$meta->table} $hints
Truth table0%0/4
A or B || C
A= $hints->{"t1"}B= $$hints{$meta->table}C= $hints
ABCresult
1XX1
01X1
0011
0000
477  
478 my $prepare_cached =
479 0 ▶ exists $args{'prepare_cached'} ? $args{'prepare_cached'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'prepare_cached'} ? : 0 0 0
480 $class->dbi_prepare_cached;
481  
482 0 ▶ my $db = delete $args{'db'} || $object_class->init_db;
Condition0%0/3
delete $args{'db'} || $object_class->init_db
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $args{'db'} || $object_class->init_db
delete $args{'db'} $object_class->init_db
Truth table0%0/3
A || B
A= delete $args{'db'}B= $object_class->init_db
ABresult
1X1
011
000
483 0 my $dbh = delete $args{'dbh'};
484 0 my $dbh_retained = 0;
485  
486 0 ▶ unless($dbh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh) 0 0 0
487 {
488 0 ▶ unless($dbh = $db->retain_dbh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh = $db->retain_dbh) 0 0 0
489 {
490 0 $class->error($db->error);
491 0 $class->handle_error($class);
492 0 return undef;
493 }
494  
495 0 $dbh_retained = 1;
496 }
497  
498 # Work-around for http://rt.cpan.org//Ticket/Display.html?id=33193
499 local $dbh->{'pg_expand_array'} = 0
500 0 ▶ if($dbh->{'Driver'}{'Name'} eq 'Pg' && index($dbh->{'Driver'}{'Version'}, '2.0.') == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->{"Driver"}{"Name"} eq "Pg" and index($dbh->{"Driver"}{"Version"}, "2.0.") == 0 0 0 0
Condition0%0/3
$dbh->{"Driver"}{"Name"} eq "Pg" and index($dbh->{"Driver"}{"Version"}, "2.0.") == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$dbh->{"Driver"}{"Name"} eq "Pg" and index($dbh->{"Driver"}{"Version"}, "2.0.") == 0
$dbh->{"Driver"}{"Name"} eq "Pg" index($dbh->{"Driver"}{"Version"}, "2.0.") == 0
Truth table0%0/3
A and B
A= $dbh->{"Driver"}{"Name"} eq "Pg"B= index($dbh->{"Driver"}{"Version"}, "2.0.") == 0
ABresult
0X0
100
111
501  
502 my $nested_joins = $args{'nested_joins'} = $db->supports_nested_joins ?
503 0 ▶ (defined $args{'nested_joins'} ? $args{'nested_joins'} : $class->default_nested_joins) : 0;
Branch: 2 branches
BranchTrueFalseTotal
$db->supports_nested_joins ? : 0 0 0
defined $args{'nested_joins'} ? : 0 0 0
504  
505 my $use_explicit_joins = (defined $args{'explicit_joins'}) ?
506 0 ▶ $args{'explicit_joins'} : !$db->likes_implicit_joins;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'explicit_joins'} ? : 0 0 0
507  
508 0 my $with_map_records;
509  
510 0 ▶ if($with_map_records = delete $args{'with_map_records'})
Branch: 1 branch
BranchTrueFalseTotal
if ($with_map_records = delete $args{"with_map_records"}) 0 0 0
511 {
512 0 ▶ unless(ref $with_map_records)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $with_map_records) 0 0 0
513 {
514 0 ▶ if($with_map_records =~ /^[A-Za-z_]\w*$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($with_map_records =~ /^[A-Za-z_]\w*$/) { } 0 0 0
elsif ($with_map_records) { } 0 0 0
515 {
516 0 $with_map_records = { DEFAULT_REL_KEY() => $with_map_records };
517 }
518 elsif($with_map_records)
519 {
520 0 $with_map_records = { DEFAULT_REL_KEY() => MAP_RECORD_METHOD };
521 }
522 else
523 {
524 0 $with_map_records = 0;
525 }
526 }
527 }
528  
529 0 ▶ my $outer_joins = ($with_objects && !$require_objects) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$with_objects && !$require_objects ? : 0 0 0
Condition0%0/3
$with_objects and not $require_objects
!ll&&!rl&&r
000
MC/DC0%0/2
$with_objects and not $require_objects
$with_objects not $require_objects
Truth table0%0/3
A and not(B)
A= $with_objectsB= not $require_objects
ABresult
0X0
100
111
530  
531 0 my($num_required_objects, %required_object, $num_with_objects,
532 %with_objects, @belongs_to, %seen_rel, %rel_tn, %join_type);
533  
534 0 ▶ $with_objects = [ $with_objects ] if($with_objects && !ref $with_objects);
Branch: 1 branch
BranchTrueFalseTotal
if $with_objects and not ref $with_objects 0 0 0
Condition0%0/3
$with_objects and not ref $with_objects
!ll&&!rl&&r
000
MC/DC0%0/2
$with_objects and not ref $with_objects
$with_objects not ref $with_objects
Truth table0%0/3
A and not(B)
A= $with_objectsB= not ref $with_objects
ABresult
0X0
100
111
535 0 ▶ $require_objects = [ $require_objects ] if($require_objects && !ref $require_objects);
Branch: 1 branch
BranchTrueFalseTotal
if $require_objects and not ref $require_objects 0 0 0
Condition0%0/3
$require_objects and not ref $require_objects
!ll&&!rl&&r
000
MC/DC0%0/2
$require_objects and not ref $require_objects
$require_objects not ref $require_objects
Truth table0%0/3
A and not(B)
A= $require_objectsB= not ref $require_objects
ABresult
0X0
100
111
536  
537 #print STDERR 'WITH: ', Dumper($with_objects);
538 #print STDERR 'REQUIRE: ', Dumper($require_objects);
539  
540 # XXX: Currently, the most robust join-type conflict checking only
541 # XXX: happens if a least one join-type override is present. In
542 # XXX: other cases, the "with" wins. This is "safe" but not
543 # XXX: necessarily efficient.
544  
545 # If there are any join-type overrides
546 0 ▶ if(first { index($_, '!') > 0 || index($_, '?') > 0 }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 4 branches
BranchTrueFalseTotal
if (&first(sub { index($_, "!") > 0 or index($_, "?") > 0; } , $with_objects ? @$with_objects : (), $require_objects ? @$require_objects : ())) 0 0 0
$with_objects ? : 0 0 0
$require_objects ? : 0 0 0
index($_, "!") > 0 or index($_, "?") > 0 0 0 0
547 (($with_objects ? @$with_objects : ()),
548 ($require_objects ? @$require_objects : ())))
549 {
550 0 my $i = 0;
551 0 ▶ my $requires_start = $with_objects ? @$with_objects : 0;
Branch: 1 branch
BranchTrueFalseTotal
$with_objects ? : 0 0 0
552 0 my $in_require = 0;
553 0 my $join_type;
554  
555 # Pull out the join modifiers
556 0 ▶ foreach my $arg (($with_objects ? @$with_objects : ()),
Branch: 2 branches
BranchTrueFalseTotal
$with_objects ? : 0 0 0
$require_objects ? : 0 0 0
557 ($require_objects ? @$require_objects : ()))
558 {
559 0 ▶ $in_require = 1 if(!$in_require && $i++ == $requires_start);
Branch: 1 branch
BranchTrueFalseTotal
if not $in_require and $i++ == $requires_start 0 0 0
Condition0%0/3
not $in_require and $i++ == $requires_start
!ll&&!rl&&r
000
MC/DC0%0/2
not $in_require and $i++ == $requires_start
not $in_require $i++ == $requires_start
Truth table0%0/3
not(A) and B
A= not $in_requireB= $i++ == $requires_start
ABresult
0X0
100
111
560  
561 0 my $save_arg = $arg;
562 0 $arg =~ tr/!?//d;
563  
564 0 ▶ if(index($arg, '.') < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (index($arg, '.') == -1) { } 0 0 0
565 {
566 0 $save_arg =~ s/([!?])$//;
567  
568 61 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
569 0 ▶ $join_type = ($1 eq '!' || (!$1 && $in_require)) ? 'JOIN' : 'LEFT OUTER JOIN';
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '!' || !$1 && $in_require ? : 0 0 0
Condition0%0/6
$1 eq "!" or not $1 and $in_require
l!l&&r!l&&!r
000
not $1 and $in_require
!ll&&!rl&&r
000
MC/DC0%0/3
$1 eq "!" or not $1 and $in_require
$1 eq "!" not $1 $in_require
Truth table0%0/4
A or not(B) and C
A= $1 eq "!"B= not $1C= $in_require
ABCresult
1XX1
0111
00X0
0100
570  
571 Carp::croak "Conflicting suffix for '$arg' - please choose either ! or ?"
572 0 ▶ if($join_type{$arg} && $join_type{$arg} ne $join_type);
Branch: 1 branch
BranchTrueFalseTotal
if $join_type{$arg} and $join_type{$arg} ne $join_type 0 0 0
Condition0%0/3
$join_type{$arg} and $join_type{$arg} ne $join_type
!ll&&!rl&&r
000
MC/DC0%0/2
$join_type{$arg} and $join_type{$arg} ne $join_type
$join_type{$arg} $join_type{$arg} ne $join_type
Truth table0%0/3
A and B
A= $join_type{$arg}B= $join_type{$arg} ne $join_type
ABresult
0X0
100
111
573  
574 0 $join_type{$arg} = $join_type;
575 }
576 else
577 {
578 0 $save_arg =~ s/([!?])$//;
579  
580 61 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
581 0 ▶ $join_type = ($1 eq '!' || (!$1 && $in_require)) ? 'JOIN' : 'LEFT OUTER JOIN';
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '!' || !$1 && $in_require ? : 0 0 0
Condition0%0/6
$1 eq "!" or not $1 and $in_require
l!l&&r!l&&!r
000
not $1 and $in_require
!ll&&!rl&&r
000
MC/DC0%0/3
$1 eq "!" or not $1 and $in_require
$1 eq "!" not $1 $in_require
Truth table0%0/4
A or not(B) and C
A= $1 eq "!"B= not $1C= $in_require
ABCresult
1XX1
0111
00X0
0100
582  
583 Carp::croak "Conflicting suffix for '$arg' - please choose either ! or ?"
584 0 ▶ if($join_type{$arg} && $join_type{$arg} ne $join_type);
Branch: 1 branch
BranchTrueFalseTotal
if $join_type{$arg} and $join_type{$arg} ne $join_type 0 0 0
Condition0%0/3
$join_type{$arg} and $join_type{$arg} ne $join_type
!ll&&!rl&&r
000
MC/DC0%0/2
$join_type{$arg} and $join_type{$arg} ne $join_type
$join_type{$arg} $join_type{$arg} ne $join_type
Truth table0%0/3
A and B
A= $join_type{$arg}B= $join_type{$arg} ne $join_type
ABresult
0X0
100
111
585  
586 0 $join_type{$arg} = $join_type;
587  
588 0 ▶ while($save_arg =~ s/\.[^.]+$//)
Branch: 1 branch
BranchTrueFalseTotal
if ($save_arg =~ s/\.[^.]+$//) 0 0 0
589 {
590 0 $save_arg =~ s/([!?])$//;
591  
592 0 ▶ $join_type = ($1 eq '!' || (!$1 && $in_require)) ? 'JOIN' : 'LEFT OUTER JOIN';
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '!' || !$1 && $in_require ? : 0 0 0
Condition0%0/6
$1 eq "!" or not $1 and $in_require
l!l&&r!l&&!r
000
not $1 and $in_require
!ll&&!rl&&r
000
MC/DC0%0/3
$1 eq "!" or not $1 and $in_require
$1 eq "!" not $1 $in_require
Truth table0%0/4
A or not(B) and C
A= $1 eq "!"B= not $1C= $in_require
ABCresult
1XX1
0111
00X0
0100
593  
594 0 (my $clean_arg = $save_arg) =~ tr/!?//d;
595  
596 Carp::croak "Conflicting suffix for '$clean_arg' - please choose either ! or ?"
597 0 ▶ if($join_type{$clean_arg} && $join_type{$clean_arg} ne $join_type);
Branch: 1 branch
BranchTrueFalseTotal
if $join_type{$clean_arg} and $join_type{$clean_arg} ne $join_type 0 0 0
Condition0%0/3
$join_type{$clean_arg} and $join_type{$clean_arg} ne $join_type
!ll&&!rl&&r
000
MC/DC0%0/2
$join_type{$clean_arg} and $join_type{$clean_arg} ne $join_type
$join_type{$clean_arg} $join_type{$clean_arg} ne $join_type
Truth table0%0/3
A and B
A= $join_type{$clean_arg}B= $join_type{$clean_arg} ne $join_type
ABresult
0X0
100
111
598  
599 0 $join_type{$clean_arg} = $join_type;
600 }
601 }
602 }
603  
604 0 ▶ if(grep { $_ eq 'LEFT OUTER JOIN' } values %join_type)
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "LEFT OUTER JOIN";} values %join_type) 0 0 0
605 {
606 0 $outer_joins = 1;
607 }
608 }
609  
610 # Putting join conditions in the WHERE clause can change the meaning of
611 # the query when outer joins are used, so disable them in that case.
612 my $use_redundant_join_conditions =
613 0 ▶ $outer_joins ? 0 : delete $args{'redundant_join_conditions'};
Branch: 1 branch
BranchTrueFalseTotal
$outer_joins ? : 0 0 0
614  
615 #use Data::Dumper;
616 #print STDERR 'JOIN TYPES: ', Dumper(\%join_type);
617 #print STDERR 'POST WITH: ', Dumper($with_objects);
618 #print STDERR 'POST REQUIRE: ', Dumper($require_objects);
619  
620 0 ▶ if($with_objects)
Branch: 1 branch
BranchTrueFalseTotal
if ($with_objects) 0 0 0
621 {
622 # Doing this implicitly is never a good idea
623 #unless(defined $use_redundant_join_conditions)
624 #{
625 # $use_redundant_join_conditions = $db->likes_redundant_join_conditions;
626 #}
627  
628 # Copy argument (shallow copy)
629 0 $with_objects = [ @$with_objects ]; #[ uniq @$with_objects ];
630  
631 # Expand multi-level arguments
632 0 ▶ if(first { index($_, '.') >= 0 } @$with_objects)
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&first(sub { index($_, '.') != -1; } , @$with_objects)) { } 0 0 0
633 {
634 0 my @with_objects;
635  
636 0 foreach my $arg (@$with_objects)
637 {
638 0 ▶ next if($seen_rel{$arg});
Branch: 1 branch
BranchTrueFalseTotal
if $seen_rel{$arg} 0 0 0
639  
640 0 ▶ if(index($arg, '.') < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (index($arg, '.') == -1) { } 0 0 0
641 {
642 0 $seen_rel{$arg} = WITH;
643 0 push(@with_objects, $arg);
644 }
645 else
646 {
647 0 my @expanded = ($arg);
648 0 $seen_rel{$arg} = WITH;
649  
650 0 ▶ while($arg =~ s/\.([^.]+)$//)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ s/\.([^.]+)$//) 0 0 0
651 {
652 0 ▶ next if($seen_rel{$arg}++);
Branch: 1 branch
BranchTrueFalseTotal
if $seen_rel{$arg}++ 0 0 0
653 0 unshift(@expanded, $arg);
654 }
655  
656 0 push(@with_objects, @expanded);
657 }
658 }
659  
660 0 $with_objects = \@with_objects;
661 }
662 else
663 {
664 0 $seen_rel{$_} = WITH for(@$with_objects);
665 }
666  
667 0 $num_with_objects = @$with_objects;
668 0 %with_objects = map { $_ => 1 } @$with_objects;
669 }
670  
671 0 ▶ if($require_objects)
Branch: 1 branch
BranchTrueFalseTotal
if ($require_objects) 0 0 0
672 {
673 # Copy argument (shallow copy)
674 0 $require_objects = [ @$require_objects ]; #[ uniq @$require_objects ];
675  
676 # Expand multi-level arguments
677 0 ▶ if(first { index($_, '.') >= 0 } @$require_objects)
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&first(sub { index($_, '.') != -1; } , @$require_objects)) { } 0 0 0
678 {
679 0 my @require_objects;
680  
681 0 foreach my $arg (@$require_objects)
682 {
683 0 ▶ if(index($arg, '.') < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (index($arg, '.') == -1) { } 0 0 0
684 {
685 0 ▶ if(my $seen = $seen_rel{$arg})
Branch: 1 branch
BranchTrueFalseTotal
if (my $seen = $seen_rel{$arg}) 0 0 0
686 {
687 0 ▶ if($seen == WITH)
Branch: 1 branch
BranchTrueFalseTotal
if ($seen == 555) 0 0 0
688 {
689 0 Carp::croak "require_objects argument '$arg' conflicts with ",
690 "with_objects argument of the same name";
691 }
692 0 next;
693 }
694  
695 0 $seen_rel{$arg}++;
696 0 push(@require_objects, $arg);
697 }
698 else
699 {
700 0 my @expanded = ($arg);
701  
702 0 ▶ if(my $seen = $seen_rel{$arg})
Branch: 1 branch
BranchTrueFalseTotal
if (my $seen = $seen_rel{$arg}) 0 0 0
703 {
704 0 ▶ if($seen == WITH)
Branch: 1 branch
BranchTrueFalseTotal
if ($seen == 555) 0 0 0
705 {
706 0 Carp::croak "require_objects argument '$arg' conflicts with ",
707 "with_objects argument of the same name";
708 }
709 0 next;
710 }
711  
712 0 $seen_rel{$arg}++;
713  
714 0 ▶ while($arg =~ s/\.[^.]+$//)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ s/\.[^.]+$//) 0 0 0
715 {
716 0 ▶ next if($seen_rel{$arg});
Branch: 1 branch
BranchTrueFalseTotal
if $seen_rel{$arg} 0 0 0
717 0 unshift(@expanded, $arg);
718 0 $seen_rel{$arg}++;
719 }
720  
721 0 push(@require_objects, @expanded);
722 }
723 }
724  
725 0 $require_objects = \@require_objects;
726 }
727 else
728 {
729 0 foreach my $arg (@$require_objects)
730 {
731 0 ▶ if($seen_rel{$arg})
Branch: 1 branch
BranchTrueFalseTotal
if ($seen_rel{$arg}) 0 0 0
732 {
733 0 Carp::croak "require_objects argument '$arg' conflicts with ",
734 "with_objects argument of the same name";
735 }
736 }
737 }
738  
739 0 $num_required_objects = @$require_objects;
740 0 %required_object = map { $_ => 1 } @$require_objects;
741 0 push(@$with_objects, @$require_objects)
742 }
743  
744 0 ▶ my %object_args = (ref $args{'object_args'} eq 'HASH') ? %{$args{'object_args'}} : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $args{'object_args'} eq 'HASH' ? : 0 0 0
745 0 my %subobject_args;
746  
747 0 ▶ $args{'share_db'} = 1 unless(exists $args{'share_db'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"share_db"} 0 0 0
748  
749 0 ▶ if(delete $args{'share_db'})
Branch: 1 branch
BranchTrueFalseTotal
if (delete $args{"share_db"}) 0 0 0
750 {
751 0 $object_args{'db'} = $db;
752 0 $subobject_args{'db'} = $db;
753 }
754  
755 0 my($fields, $fields_string, $table);
756  
757 0 ▶ $args{'nonlazy'} = [] unless(defined $args{'nonlazy'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"nonlazy"} 0 0 0
758 0 my $nonlazy = $args{'nonlazy'};
759 0 ▶ my %nonlazy = (ref $nonlazy ? map { $_ => 1 } @$nonlazy : ());
Branch: 1 branch
BranchTrueFalseTotal
ref $nonlazy ? : 0 0 0
760  
761 0 my @tables = ($meta->fq_table($db));
762 0 my @tables_sql = ($meta->fq_table_sql($db));
763  
764 0 ▶ my $use_lazy_columns = (!ref $nonlazy || $nonlazy{'self'}) ? 0 : $meta->has_lazy_columns;
Branch: 1 branch
BranchTrueFalseTotal
!ref($nonlazy) || $nonlazy{'self'} ? : 0 0 0
Condition0%0/3
not ref $nonlazy or $nonlazy{"self"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $nonlazy or $nonlazy{"self"}
not ref $nonlazy $nonlazy{"self"}
Truth table0%0/3
not(A) or B
A= not ref $nonlazyB= $nonlazy{"self"}
ABresult
1X1
011
000
765  
766 0 my(%columns, %methods, %all_columns);
767  
768 0 ▶ if($use_lazy_columns)
Branch: 1 branch
BranchTrueFalseTotal
if ($use_lazy_columns) { } 0 0 0
769 {
770 0 %columns = ($tables[0] => scalar $meta->nonlazy_columns);
771 0 %all_columns = ($tables[0] => scalar $meta->columns);
772 0 %methods = ($tables[0] => scalar $meta->nonlazy_column_mutator_method_names);
773 0 %di_keys = ($object_class => scalar $meta->nonlazy_column_db_value_hash_keys);
774 }
775 else
776 {
777 0 %columns = ($tables[0] => scalar $meta->columns);
778 0 %methods = ($tables[0] => scalar $meta->column_mutator_method_names);
779 0 %di_keys = ($object_class => scalar $meta->column_db_value_hash_keys);
780 }
781  
782 0 my %classes = ($tables[0] => $object_class);
783 0 my @classes = ($object_class);
784 0 my %meta = ($object_class => $meta);
785  
786 0 my @table_names = ($meta->table);
787 0 my @rel_names = ($meta->table);
788  
789 0 my(@joins, @subobject_methods, @mapped_object_methods, $clauses);
790  
791 0 my $handle_dups = 0;
792 #my $deep_joins = 0;
793 0 my @has_dups;
794  
795 0 my $manual_limit = 0;
796  
797 0 ▶ my $num_subtables = $with_objects ? @$with_objects : 0;
Branch: 1 branch
BranchTrueFalseTotal
$with_objects ? : 0 0 0
798  
799 0 ▶ if($distinct || $fetch)
Branch: 1 branch
BranchTrueFalseTotal
if ($distinct or $fetch) 0 0 0
Condition0%0/3
$distinct or $fetch
l!l&&r!l&&!r
000
MC/DC0%0/2
$distinct or $fetch
$distinct $fetch
Truth table0%0/3
A or B
A= $distinctB= $fetch
ABresult
1X1
011
000
800 {
801 0 ▶ if($fetch && ref $distinct)
Branch: 1 branch
BranchTrueFalseTotal
if ($fetch and ref $distinct) 0 0 0
Condition0%0/3
$fetch and ref $distinct
!ll&&!rl&&r
000
MC/DC0%0/2
$fetch and ref $distinct
$fetch ref $distinct
Truth table0%0/3
A and B
A= $fetchB= ref $distinct
ABresult
0X0
100
111
802 {
803 0 Carp::croak "The 'distinct' and 'fetch' parameters cannot be used ",
804 "together if they both contain lists of tables";
805 }
806  
807 0 ▶ $args{'distinct'} = 1 if($distinct);
Branch: 1 branch
BranchTrueFalseTotal
if $distinct 0 0 0
808  
809 0 %fetch = (t1 => 1, $tables[0] => 1, $meta->table => 1);
810  
811 0 ▶ if(ref $fetch || ref $distinct)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fetch or ref $distinct) 0 0 0
Condition0%0/3
ref $fetch or ref $distinct
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $fetch or ref $distinct
ref $fetch ref $distinct
Truth table0%0/3
A or B
A= ref $fetchB= ref $distinct
ABresult
1X1
011
000
812 {
813 0 ▶ foreach my $arg (ref $distinct ? @$distinct : @$fetch)
Branch: 1 branch
BranchTrueFalseTotal
ref $distinct ? : 0 0 0
814 {
815 0 $fetch{$arg} = 1;
816 }
817 }
818 }
819  
820 # Handle "page" arguments
821 0 ▶ if(exists $args{'page'} || exists $args{'per_page'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"page"} or exists $args{"per_page"}) 0 0 0
Condition0%0/3
exists $args{"page"} or exists $args{"per_page"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $args{"page"} or exists $args{"per_page"}
exists $args{"page"} exists $args{"per_page"}
Truth table0%0/3
A or B
A= exists $args{"page"}B= exists $args{"per_page"}
ABresult
1X1
011
000
822 {
823 0 ▶ if(exists $args{'limit'} || exists $args{'offset'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"limit"} or exists $args{"offset"}) 0 0 0
Condition0%0/3
exists $args{"limit"} or exists $args{"offset"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $args{"limit"} or exists $args{"offset"}
exists $args{"limit"} exists $args{"offset"}
Truth table0%0/3
A or B
A= exists $args{"limit"}B= exists $args{"offset"}
ABresult
1X1
011
000
824 {
825 0 Carp::croak 'Cannot include the "page" or "per_page" ',
826 'options when the "limit" or "offset" option ',
827 'is used';
828 }
829  
830 0 ▶ my $page = delete $args{'page'} || 1;
Condition0%0/2
delete $args{'page'} || 1
l!l
00
MC/DC0%0/1
delete $args{'page'} || 1
delete $args{'page'}
Truth table0%0/2
A
A= delete $args{'page'}
Aresult
11
00
831 0 ▶ my $per_page = delete $args{'per_page'} || $class->default_objects_per_page;
Condition0%0/3
delete $args{'per_page'} || $class->default_objects_per_page
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $args{'per_page'} || $class->default_objects_per_page
delete $args{'per_page'} $class->default_objects_per_page
Truth table0%0/3
A || B
A= delete $args{'per_page'}B= $class->default_objects_per_page
ABresult
1X1
011
000
832  
833 0 ▶ $page = 1 if($page < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $page < 1 0 0 0
834 0 ▶ $per_page = $class->default_objects_per_page if($per_page < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $per_page < 1 0 0 0
835  
836 0 $args{'limit'} = $per_page;
837  
838 0 ▶ if($page > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($page > 1) 0 0 0
839 {
840 0 $args{'offset'} = ($page - 1) * $per_page;
841 }
842 }
843  
844 # Pre-process sort_by args
845 0 ▶ if(my $sort_by = $args{'sort_by'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $sort_by = $args{"sort_by"}) 0 0 0
846 {
847 0 ▶ $sort_by = [ $sort_by ] unless(ref $sort_by eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sort_by eq "ARRAY" 0 0 0
848  
849 0 ▶ if($num_subtables == 0 && defined $table_aliases && $table_aliases == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($num_subtables == 0 and defined $table_aliases and $table_aliases == 0) 0 0 0
Condition0%0/6
$num_subtables == 0 and defined $table_aliases and $table_aliases == 0
!ll&&!rl&&r
000
$num_subtables == 0 and defined $table_aliases
!ll&&!rl&&r
000
MC/DC0%0/3
$num_subtables == 0 and defined $table_aliases and $table_aliases == 0
$num_subtables == 0 defined $table_aliases $table_aliases == 0
Truth table0%0/4
A and B and C
A= $num_subtables == 0B= defined $table_aliasesC= $table_aliases == 0
ABCresult
0XX0
10X0
1100
1111
850 {
851 # trim t1. or primary table prefixes
852 0 my $prefix_re = '\b(?:t1|' . $meta->table . ')\.';
853 0 $prefix_re = qr($prefix_re);
854  
855 0 foreach my $sort (@$sort_by)
856 {
857 0 ▶ $sort =~ s/$prefix_re//g unless(ref $sort);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sort 0 0 0
858 }
859 }
860  
861 0 $args{'sort_by'} = $sort_by;
862 }
863  
864 0 my $num_to_many_rels = 0;
865 # Adjust for explicitly included map_record tables, which should
866 # not count towards the multi_many_ok warning.
867 0 my $num_to_many_rels_adjustment = 0;
868  
869 0 my($multi_many, @subobject_method_map);
870  
871 0 ▶ if($with_objects)
Branch: 1 branch
BranchTrueFalseTotal
if ($with_objects) 0 0 0
872 {
873 # XXX: Hack to avoid spurious ORA-00918 errors
874 # XXX: http://ora-00918.ora-code.com/msg/28663.html
875 0 ▶ if(($args{'limit'} || $args{'offset'}) && $dbh->{'Driver'}{'Name'} eq 'Oracle')
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"limit"} || $args{"offset"} and $dbh->{"Driver"}{"Name"} eq "Oracle") 0 0 0
Condition0%0/6
$args{"limit"} || $args{"offset"} and $dbh->{"Driver"}{"Name"} eq "Oracle"
!ll&&!rl&&r
000
$args{"limit"} or $args{"offset"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{"limit"} || $args{"offset"} and $dbh->{"Driver"}{"Name"} eq "Oracle"
$args{"limit"} $args{"offset"} $dbh->{"Driver"}{"Name"} eq "Oracle"
Truth table0%0/5
A or B and C
A= $args{"limit"}B= $args{"offset"}C= $dbh->{"Driver"}{"Name"} eq "Oracle"
ABCresult
00X0
1X00
0100
1X11
0111
876 {
877 0 $args{'unique_aliases'} = 1;
878 }
879  
880 # Copy clauses arg
881 0 ▶ $clauses = $args{'clauses'} ? [ @{$args{'clauses'}} ] : [];
Branch: 1 branch
BranchTrueFalseTotal
$args{'clauses'} ? : 0 0 0
882  
883 0 my $i = 1;
884  
885 # Sanity check with_objects arguments, and determine if we're going to
886 # have to handle duplicate data from multiple joins. If so, note
887 # which with_objects arguments refer to relationships that may return
888 # more than one object.
889 0 foreach my $name (@$with_objects)
890 {
891 0 my $tn_name = $name;
892  
893 0 ▶ if(index($tn_name, '.') > 0) # dot at start is invalid, so "> 0" is correct
Branch: 1 branch
BranchTrueFalseTotal
if (index($tn_name, ".") > 0) 0 0 0
894 {
895 0 $tn_name =~ /^(.+)\.([^.]+)$/;
896 }
897  
898 0 $rel_tn{$tn_name} = $i + 1; # note the tN table number of this relationship
899  
900 0 my $key;
901  
902 # Chase down multi-level keys: e.g., colors.name.types
903 0 ▶ if(index($name, '.') >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (index($name, '.') != -1) { } 0 0 0
904 {
905 #$deep_joins = 1;
906  
907 0 my $chase_meta = $meta;
908  
909 0 ▶ while($name =~ /\G([^.]+)(?:\.|$)/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\G([^.]+)(?:\.|$)/g) 0 0 0
910 {
911 0 my $sub_name = $1;
912  
913 0 ▶ $key = $chase_meta->foreign_key($sub_name) ||
Condition0%0/5
$chase_meta->foreign_key($sub_name) || $chase_meta->relationship($sub_name) || Carp::confess('Invalid with_objects or require_objects argument: ', "no foreign key or relationship named '${sub_name}' ", 'found in ', $chase_meta->class)
l!l
00
$chase_meta->foreign_key($sub_name) or $chase_meta->relationship($sub_name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$chase_meta->foreign_key($sub_name) || $chase_meta->relationship($sub_name) || Carp::confess('Invalid with_objects or require_objects argument: ', "no foreign key or relationship named '${sub_name}' ", 'found in ', $chase_meta->class)
$chase_meta->foreign_key($sub_name) $chase_meta->relationship($sub_name)
Truth table0%0/3
A or B
A= $chase_meta->foreign_key($sub_name)B= $chase_meta->relationship($sub_name)
ABresult
1X1
011
000
914 $chase_meta->relationship($sub_name) ||
915 Carp::confess "Invalid with_objects or require_objects argument: ",
916 "no foreign key or relationship named '$sub_name' ",
917 'found in ', $chase_meta->class;
918  
919 0 ▶ $chase_meta = $key->can('foreign_class') ?
Branch: 1 branch
BranchTrueFalseTotal
$key->can('foreign_class') ? : 0 0 0
920 $key->foreign_class->meta : $key->class->meta;
921 }
922 }
923 else
924 {
925 0 ▶ $key = $meta->foreign_key($name) || $meta->relationship($name) ||
Condition0%0/5
$meta->foreign_key($name) || $meta->relationship($name) || Carp::confess('Invalid with_objects or require_objects argument: ', "no foreign key or relationship named '${name}' ", "found in $class")
l!l
00
$meta->foreign_key($name) or $meta->relationship($name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$meta->foreign_key($name) || $meta->relationship($name) || Carp::confess('Invalid with_objects or require_objects argument: ', "no foreign key or relationship named '${name}' ", "found in $class")
$meta->foreign_key($name) $meta->relationship($name)
Truth table0%0/3
A or B
A= $meta->foreign_key($name)B= $meta->relationship($name)
ABresult
1X1
011
000
926 Carp::confess "Invalid with_objects or require_objects argument: ",
927 "no foreign key or relationship named '$name' ",
928 "found in $class";
929 }
930  
931 0 my $rel_type = $key->type;
932  
933 0 ▶ if($rel_type =~ /\bmany$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($rel_type =~ /\bmany$/) 0 0 0
934 {
935 0 $handle_dups = 1;
936 0 $has_dups[$i] = 1;
937  
938 # "many to many" relationships have an extra table (the mapping table)
939 0 ▶ if($rel_type eq 'many to many')
Branch: 1 branch
BranchTrueFalseTotal
if ($rel_type eq "many to many") 0 0 0
940 {
941 0 $i++;
942 0 $has_dups[$i] = 1;
943 # $num_subtables will be incremented elsewhere (below)
944  
945 # Adjust for explicitly included map_record tables, which should
946 # not count towards the multi_many_ok warning.
947 0 $num_to_many_rels_adjustment++;
948 }
949  
950 0 ▶ if($args{'limit'})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"limit"}) 0 0 0
951 {
952 0 ▶ if($try_subselect_limit && $db->supports_select_from_subselect &&
Branch: 1 branch
BranchTrueFalseTotal
if ($try_subselect_limit and $db->supports_select_from_subselect and !$args{'offset'} || $db->supports_limit_with_offset and not $args{'select'}) { } 0 0 0
Condition0%0/12
$try_subselect_limit and $db->supports_select_from_subselect and !$args{"offset"} || $db->supports_limit_with_offset and not $args{"select"}
!ll&&!rl&&r
000
$try_subselect_limit and $db->supports_select_from_subselect and !$args{"offset"} || $db->supports_limit_with_offset
!ll&&!rl&&r
000
$try_subselect_limit and $db->supports_select_from_subselect
!ll&&!rl&&r
000
not $args{"offset"} or $db->supports_limit_with_offset
l!l&&r!l&&!r
000
MC/DC0%0/5
$try_subselect_limit and $db->supports_select_from_subselect and !$args{"offset"} || $db->supports_limit_with_offset and not $args{"select"}
$try_subselect_limit $db->supports_select_from_subselect not $args{"offset"} $db->supports_limit_with_offset not $args{"select"}
Truth table0%0/7
A and B and not(C) or D and not(E)
A= $try_subselect_limitB= $db->supports_select_from_subselectC= not $args{"offset"}D= $db->supports_limit_with_offsetE= not $args{"select"}
ABCDEresult
0XXXX0
10XXX0
1100X0
111X00
110100
111X11
110111
953 (!$args{'offset'} || $db->supports_limit_with_offset) &&
954 !$args{'select'})
955 {
956 0 ▶ unless($fetch && @$fetch && $fetch->[0] eq 't1')
Branch: 1 branch
BranchTrueFalseTotal
unless ($fetch and @$fetch and $fetch->[0] eq "t1") 0 0 0
Condition0%0/6
$fetch and @$fetch and $fetch->[0] eq "t1"
!ll&&!rl&&r
000
$fetch and @$fetch
!ll&&!rl&&r
000
MC/DC0%0/3
$fetch and @$fetch and $fetch->[0] eq "t1"
$fetch @$fetch $fetch->[0] eq "t1"
Truth table0%0/4
A and B and C
A= $fetchB= @$fetchC= $fetch->[0] eq "t1"
ABCresult
0XX0
10X0
1100
1111
957 {
958 0 $subselect_limit = 1;
959 0 delete $args{'limit'};
960 0 delete $args{'offset'};
961 }
962 }
963 else
964 {
965 0 $manual_limit = delete $args{'limit'};
966 }
967 }
968  
969 # This restriction seems unnecessary now
970 #if($required_object{$name} && $num_required_objects > 1 && $num_subtables > 1)
971 #{
972 # Carp::croak
973 # qq(The "require_objects" parameter cannot be used with ),
974 # qq(a "... to many" relationship ("$name" in this case) ),
975 # qq(unless that relationship is the only one listed and ),
976 # qq(the "with_objects" parameter is not used);
977 #}
978 }
979  
980 0 $i++;
981 }
982  
983 0 $num_to_many_rels = grep { defined $_ } @has_dups;
984  
985 # Adjust for explicitly included map_record tables, which should
986 # not count towards the multi_many_ok warning.
987 0 ▶ $multi_many = (($num_to_many_rels - $num_to_many_rels_adjustment) > 1) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$num_to_many_rels - $num_to_many_rels_adjustment > 1 ? : 0 0 0
988  
989 0 ▶ unless($args{'multi_many_ok'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"multi_many_ok"}) 0 0 0
990 {
991 0 ▶ if($multi_many)
Branch: 1 branch
BranchTrueFalseTotal
if ($multi_many) 0 0 0
992 {
993 0 Carp::carp
994 qq(WARNING: Fetching sub-objects via more than one ),
995 qq("one to many" relationship in a single query may ),
996 qq(produce many redundant rows, and the query may be ),
997 qq(slow. If you're sure you want to do this, you can ),
998 qq(silence this warning by using the "multi_many_ok" ),
999 qq(parameter\n);
1000 }
1001 }
1002  
1003 0 $i = 1; # reset iterator for second pass through with_objects
1004  
1005 # Build lists of columns, classes, methods, and join conditions for all
1006 # of the with_objects and/or require_objects arguments.
1007 0 foreach my $arg (@$with_objects)
1008 {
1009 0 my($parent_meta, $parent_tn, $name);
1010  
1011 0 ▶ if(index($arg, '.') > 0) # dot at start is invalid, so "> 0" is correct
Branch: 1 branch
BranchTrueFalseTotal
if (index($arg, '.') > 0) { } 0 0 0
1012 {
1013 0 $arg =~ /^(.+)\.([^.]+)$/;
1014 0 my $parent = $1;
1015 0 $name = $2;
1016  
1017 # value of $i as of last iteration
1018 0 ▶ $parent_tn = defined $rel_tn{$parent} ? $rel_tn{$parent}: $i;
Branch: 1 branch
BranchTrueFalseTotal
defined $rel_tn{$parent} ? : 0 0 0
1019  
1020 0 $belongs_to[$i] = $parent_tn - 1;
1021 0 $parent_meta = $classes[$parent_tn - 1]->meta;
1022 }
1023 else
1024 {
1025 0 $parent_meta = $meta;
1026 0 $name = $arg;
1027 0 $parent_tn = 1;
1028 0 $belongs_to[$i] = 0;
1029 }
1030  
1031 #$rel_tn{$arg} = $i + 1; # note the tN table number of this relationship
1032  
1033 0 ▶ my $rel = $parent_meta->foreign_key($name) ||
Condition0%0/5
$parent_meta->foreign_key($name) || $parent_meta->relationship($name) || Carp::croak("No relationship named '${name}' in class ", $parent_meta->class)
l!l
00
$parent_meta->foreign_key($name) or $parent_meta->relationship($name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$parent_meta->foreign_key($name) || $parent_meta->relationship($name) || Carp::croak("No relationship named '${name}' in class ", $parent_meta->class)
$parent_meta->foreign_key($name) $parent_meta->relationship($name)
Truth table0%0/3
A or B
A= $parent_meta->foreign_key($name)B= $parent_meta->relationship($name)
ABresult
1X1
011
000
1034 $parent_meta->relationship($name) ||
1035 Carp::croak "No relationship named '$name' in class ",
1036 $parent_meta->class;
1037  
1038 0 my $rel_type = $rel->type;
1039  
1040 0 ▶ if($rel_type eq 'foreign key' || $rel_type eq 'one to one' ||
Branch: 2 branches
BranchTrueFalseTotal
if ($rel_type eq 'foreign key' or $rel_type eq 'one to one' or $rel_type eq 'many to one' or $rel_type eq 'one to many') { } 0 0 0
elsif ($rel_type eq 'many to many') { } 0 0 0
Condition0%0/9
$rel_type eq "foreign key" or $rel_type eq "one to one" or $rel_type eq "many to one" or $rel_type eq "one to many"
l!l&&r!l&&!r
000
$rel_type eq "foreign key" or $rel_type eq "one to one" or $rel_type eq "many to one"
l!l&&r!l&&!r
000
$rel_type eq "foreign key" or $rel_type eq "one to one"
l!l&&r!l&&!r
000
MC/DC0%0/4
$rel_type eq "foreign key" or $rel_type eq "one to one" or $rel_type eq "many to one" or $rel_type eq "one to many"
$rel_type eq "foreign key" $rel_type eq "one to one" $rel_type eq "many to one" $rel_type eq "one to many"
Truth table0%0/5
A or B or C or D
A= $rel_type eq "foreign key"B= $rel_type eq "one to one"C= $rel_type eq "many to one"D= $rel_type eq "one to many"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1041 $rel_type eq 'many to one' || $rel_type eq 'one to many')
1042 {
1043 0 ▶ my $ft_class = $rel->class
Branch: 1 branch
BranchTrueFalseTotal
my $ft_class = $rel->class or Carp::confess("$class - Missing foreign object class for '${name}'") 0 0 0
1044 or Carp::confess "$class - Missing foreign object class for '$name'";
1045  
1046 0 my $ft_columns = $rel->key_columns;
1047  
1048 0 ▶ if(!$ft_columns && $rel_type ne 'one to many')
Branch: 1 branch
BranchTrueFalseTotal
if (not $ft_columns and $rel_type ne "one to many") 0 0 0
Condition0%0/3
not $ft_columns and $rel_type ne "one to many"
!ll&&!rl&&r
000
MC/DC0%0/2
not $ft_columns and $rel_type ne "one to many"
not $ft_columns $rel_type ne "one to many"
Truth table0%0/3
not(A) and B
A= not $ft_columnsB= $rel_type ne "one to many"
ABresult
0X0
100
111
1049 {
1050 0 Carp::confess "$class - Missing key columns for '$name'";
1051 }
1052  
1053 0 ▶ if($rel->can('query_args') && (my $query_args = $rel->query_args))
Branch: 1 branch
BranchTrueFalseTotal
if ($rel->can("query_args") and my $query_args = $rel->query_args) 0 0 0
Condition0%0/3
$rel->can("query_args") and my $query_args = $rel->query_args
!ll&&!rl&&r
000
MC/DC0%0/2
$rel->can("query_args") and my $query_args = $rel->query_args
$rel->can("query_args") my $query_args = $rel->query_args
Truth table0%0/3
A and B
A= $rel->can("query_args")B= my $query_args = $rel->query_args
ABresult
0X0
100
111
1054 {
1055 # (Re)map query parameters to the correct table
1056 # t1 -> No change (the primary table)
1057 # t2 -> The foreign table
1058 0 ▶ for(my $i = 0; $i < @$query_args; $i += 2)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$query_args) 0 0 0
1059 {
1060 0 my $param = $query_args->[$i];
1061  
1062 0 ▶ if(ref $param)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $param) 0 0 0
1063 {
1064 0 push(@{$args{'query'}}, $param);
1065 0 $i--;
1066 0 next;
1067 }
1068  
1069 0 ▶ unless($param =~ s/^t2\./t$rel_tn{$arg}./)
Branch: 1 branch
BranchTrueFalseTotal
unless ($param =~ s/^t2\./t$rel_tn{$arg}./) 0 0 0
1070 {
1071 0 ▶ $param = "t$rel_tn{$arg}.$param" unless($param =~ /^t\d+\./);
Branch: 1 branch
BranchTrueFalseTotal
unless $param =~ /^t\d+\./ 0 0 0
1072 }
1073  
1074 0 push(@{$args{'query'}}, $param, $query_args->[$i + 1]);
1075 }
1076 }
1077  
1078 0 my $ft_meta = $ft_class->meta;
1079  
1080 0 $meta{$ft_class} = $ft_meta;
1081  
1082 0 push(@tables, $ft_meta->fq_table($db));
1083 0 push(@tables_sql, $ft_meta->fq_table_sql($db));
1084 0 push(@rel_names, $rel_name{'t' . (scalar @tables)} = $rel->name);
1085 0 push(@table_names, $ft_meta->table);
1086 0 push(@classes, $ft_class);
1087  
1088 # Iterator will be the tN value: the first sub-table is t2, and so on
1089 0 $i++;
1090  
1091 0 ▶ my $use_lazy_columns = (!ref $nonlazy || $nonlazy{$name}) ? 0 : $ft_meta->has_lazy_columns;
Branch: 1 branch
BranchTrueFalseTotal
!ref($nonlazy) || $nonlazy{$name} ? : 0 0 0
Condition0%0/3
not ref $nonlazy or $nonlazy{$name}
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $nonlazy or $nonlazy{$name}
not ref $nonlazy $nonlazy{$name}
Truth table0%0/3
not(A) or B
A= not ref $nonlazyB= $nonlazy{$name}
ABresult
1X1
011
000
1092  
1093 0 ▶ if($use_lazy_columns)
Branch: 1 branch
BranchTrueFalseTotal
if ($use_lazy_columns) { } 0 0 0
1094 {
1095 0 $columns{$tables[-1]} = $ft_meta->nonlazy_columns;
1096 0 $all_columns{$tables[-1]} = $ft_meta->columns;
1097 0 $methods{$tables[-1]} = $ft_meta->nonlazy_column_mutator_method_names;
1098 0 $di_keys{$classes[-1]} = $ft_meta->nonlazy_column_db_value_hash_keys;
1099 }
1100 else
1101 {
1102 0 $columns{$tables[-1]} = $ft_meta->columns;
1103 0 $methods{$tables[-1]} = $ft_meta->column_mutator_method_names;
1104 0 $di_keys{$classes[-1]} = $ft_meta->column_db_value_hash_keys;
1105 }
1106  
1107 0 $classes{$tables[-1]} = $ft_class;
1108  
1109 0 ▶ $subobject_methods[$i - 1] =
Branch: 1 branch
BranchTrueFalseTotal
$direct_inject ? : 0 0 0
Condition0%0/8
$rel->method_name("get_set") or $rel->method_name("get_set_now") or $rel->method_name("get_set_on_save") or Carp::confess("No 'get_set', 'get_set_now', or 'get_set_on_save' ", "method found for $rel_type '${name}' in class ", $rel->parent->class)
l!l
00
$rel->method_name("get_set") or $rel->method_name("get_set_now") or $rel->method_name("get_set_on_save")
l!l&&r!l&&!r
000
$rel->method_name("get_set") or $rel->method_name("get_set_now")
l!l&&r!l&&!r
000
MC/DC0%0/3
$rel->method_name("get_set") or $rel->method_name("get_set_now") or $rel->method_name("get_set_on_save") or Carp::confess("No 'get_set', 'get_set_now', or 'get_set_on_save' ", "method found for $rel_type '${name}' in class ", $rel->parent->class)
$rel->method_name("get_set") $rel->method_name("get_set_now") $rel->method_name("get_set_on_save")
Truth table0%0/4
A or B or C
A= $rel->method_name("get_set")B= $rel->method_name("get_set_now")C= $rel->method_name("get_set_on_save")
ABCresult
1XX1
01X1
0011
0000
1110 $direct_inject ? $rel->hash_key :
1111 $rel->method_name('get_set') ||
1112 $rel->method_name('get_set_now') ||
1113 $rel->method_name('get_set_on_save') ||
1114 Carp::confess "No 'get_set', 'get_set_now', or 'get_set_on_save' ",
1115 "method found for $rel_type '$name' in class ",
1116 $rel->parent->class;
1117  
1118 #$subobject_keys[$i - 1] = $rel->hash_key;
1119  
1120 # Reset each() iterator
1121 #keys(%$ft_columns);
1122  
1123 0 my(@redundant, @redundant_null);
1124  
1125 0 ▶ unless($ft_columns && %$ft_columns)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ft_columns and %$ft_columns) 0 0 0
Condition0%0/3
$ft_columns and %$ft_columns
!ll&&!rl&&r
000
MC/DC0%0/2
$ft_columns and %$ft_columns
$ft_columns %$ft_columns
Truth table0%0/3
A and B
A= $ft_columnsB= %$ft_columns
ABresult
0X0
100
111
1126 {
1127 0 ▶ if($with_objects{$arg})
Branch: 2 branches
BranchTrueFalseTotal
if ($with_objects{$arg}) { } 0 0 0
elsif ($use_explicit_joins) { } 0 0 0
1128 {
1129 0 ▶ $joins[$i]{'type'} = $join_type{$arg} || 'LEFT OUTER JOIN';
Condition0%0/2
$join_type{$arg} || 'LEFT OUTER JOIN'
l!l
00
MC/DC0%0/1
$join_type{$arg} || 'LEFT OUTER JOIN'
$join_type{$arg}
Truth table0%0/2
A
A= $join_type{$arg}
Aresult
11
00
1130 }
1131 elsif($use_explicit_joins)
1132 {
1133 0 ▶ $joins[$i]{'type'} = $join_type{$arg} || 'JOIN';
Condition0%0/2
$join_type{$arg} || 'JOIN'
l!l
00
MC/DC0%0/1
$join_type{$arg} || 'JOIN'
$join_type{$arg}
Truth table0%0/2
A
A= $join_type{$arg}
Aresult
11
00
1134 }
1135 }
1136  
1137 # Add join condition(s)
1138 0 ▶ while(my($local_column, $foreign_column) = each(%$ft_columns))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$ft_columns) 0 0 0
1139 {
1140 # Use outer joins to handle duplicate or optional information.
1141 # Foreign keys that have all non-null columns are not outer-
1142 # joined when nested joins are enabled, however.
1143 0 ▶ if(!($rel_type eq 'foreign key' && $rel->is_required &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $rel_type eq 'foreign key' && $rel->is_required && $rel->referential_integrity && $nested_joins and $outer_joins || $with_objects{$arg}) { } 0 0 0
Condition0%0/15
not $rel_type eq "foreign key" && $rel->is_required && $rel->referential_integrity && $nested_joins and $outer_joins || $with_objects{$arg}
!ll&&!rl&&r
000
$rel_type eq 'foreign key' && $rel->is_required && $rel->referential_integrity && $nested_joins
!ll&&!rl&&r
000
$rel_type eq "foreign key" and $rel->is_required and $rel->referential_integrity
!ll&&!rl&&r
000
$rel_type eq "foreign key" and $rel->is_required
!ll&&!rl&&r
000
$outer_joins or $with_objects{$arg}
l!l&&r!l&&!r
000
MC/DC0%0/6
not $rel_type eq "foreign key" && $rel->is_required && $rel->referential_integrity && $nested_joins and $outer_joins || $with_objects{$arg}
$rel_type eq "foreign key" $rel->is_required $rel->referential_integrity $nested_joins $outer_joins $with_objects{$arg}
Truth table0%0/13
not(A and B and C && D) and E or F
A= $rel_type eq "foreign key"B= $rel->is_requiredC= $rel->referential_integrityD= $nested_joinsE= $outer_joinsF= $with_objects{$arg}
ABCDEFresult
1111XX0
0XXX000
10XX000
110X000
1110000
0XXX1X1
0XXX011
10XX1X1
10XX011
110X1X1
110X011
11101X1
1110011
1144 $rel->referential_integrity && $nested_joins) &&
1145 ($outer_joins || $with_objects{$arg}))
1146 {
1147 # Aliased table names
1148 0 push(@{$joins[$i]{'conditions'}}, "t${parent_tn}.$local_column = t$i.$foreign_column");
1149  
1150 0 ▶ if($multi_many)
Branch: 1 branch
BranchTrueFalseTotal
if ($multi_many) 0 0 0
1151 {
1152 0 my $local_method = $parent_meta->column_mutator_method_name($local_column);
1153 0 my $foreign_method = $ft_meta->column_accessor_method_name($foreign_column);
1154 0 push(@{$subobject_method_map[$i][$belongs_to[$i - 1]]}, [ $local_method, $foreign_method ]);
1155 }
1156  
1157 # Fully-qualified table names
1158 #push(@{$joins[$i]{'conditions'}}, "$tables[0].$local_column = $tables[-1].$foreign_column");
1159  
1160 0 ▶ $joins[$i]{'type'} = $join_type{$arg} || 'LEFT OUTER JOIN';
Condition0%0/2
$join_type{$arg} || 'LEFT OUTER JOIN'
l!l
00
MC/DC0%0/1
$join_type{$arg} || 'LEFT OUTER JOIN'
$join_type{$arg}
Truth table0%0/2
A
A= $join_type{$arg}
Aresult
11
00
1161 0 ▶ $joins[$i]{'hints'} = $hints->{"t$i"} || $hints->{$name};
Condition0%0/3
$$hints{"t$i"} || $hints->{$name}
l!l&&r!l&&!r
000
MC/DC0%0/2
$$hints{"t$i"} || $hints->{$name}
$$hints{"t$i"} $hints->{$name}
Truth table0%0/3
A || B
A= $$hints{"t$i"}B= $hints->{$name}
ABresult
1X1
011
000
1162  
1163 # MySQL is stupid about using its indexes when "JOIN ... ON (...)"
1164 # conditions are the only ones given, so the code below adds some
1165 # redundant WHERE conditions. They should only be added when they
1166 # do not change the meaning of the query, in which case they
1167 # should nudge MySQL into using its indexes.
1168 # The clauses: "((<ON conditions>) OR (<any columns are null>))"
1169 # We build the two clauses separately in the loop below, then
1170 # combine it all after the loop is done.
1171 0 ▶ if($use_redundant_join_conditions)
Branch: 1 branch
BranchTrueFalseTotal
if ($use_redundant_join_conditions) 0 0 0
1172 {
1173 # Aliased table names
1174 0 push(@redundant, "t${parent_tn}.$local_column = t$i.$foreign_column");
1175 0 ▶ push(@redundant_null, ($has_dups[$i - 1] ?
Branch: 1 branch
BranchTrueFalseTotal
$has_dups[$i - 1] ? : 0 0 0
1176 "t$i.$foreign_column IS NULL" :
1177 "t${parent_tn}.$local_column IS NULL"));
1178  
1179 # Fully-qualified table names
1180 #push(@redundant, "$tables[$parent_tn - 1].$local_column = $tables[-1].$foreign_column");
1181 #push(@redundant_null, ($has_dups[$i - 1] ?
1182 # "$tables[-1].$foreign_column IS NULL" :
1183 # "$tables[$parent_tn - 1].$local_column IS NULL"));
1184 }
1185 }
1186 else
1187 {
1188 0 ▶ if($use_explicit_joins)
Branch: 1 branch
BranchTrueFalseTotal
if ($use_explicit_joins) { } 0 0 0
1189 {
1190 # Aliased table names
1191 0 push(@{$joins[$i]{'conditions'}}, "t${parent_tn}.$local_column = t$i.$foreign_column");
1192  
1193 # Fully-qualified table names
1194 #push(@{$joins[$i]{'conditions'}}, "$tables[$parent_tn - 1].$local_column = $tables[-1].$foreign_column");
1195  
1196 0 ▶ $joins[$i]{'type'} = $join_type{$arg} || 'JOIN';
Condition0%0/2
$join_type{$arg} || 'JOIN'
l!l
00
MC/DC0%0/1
$join_type{$arg} || 'JOIN'
$join_type{$arg}
Truth table0%0/2
A
A= $join_type{$arg}
Aresult
11
00
1197 0 ▶ $joins[$i]{'hints'} = $hints->{"t$i"} || $hints->{$name};
Condition0%0/3
$$hints{"t$i"} || $hints->{$name}
l!l&&r!l&&!r
000
MC/DC0%0/2
$$hints{"t$i"} || $hints->{$name}
$$hints{"t$i"} $hints->{$name}
Truth table0%0/3
A || B
A= $$hints{"t$i"}B= $hints->{$name}
ABresult
1X1
011
000
1198 }
1199 else # implicit join with no ON clause
1200 {
1201 # Aliased table names
1202 0 push(@$clauses, "t${parent_tn}.$local_column = t$i.$foreign_column");
1203  
1204 # Fully-qualified table names
1205 #push(@$clauses, "$tables[$parent_tn - 1].$local_column = $tables[-1].$foreign_column");
1206 }
1207 }
1208 }
1209  
1210 0 ▶ $joins[$i]{'parent_tn'} = $parent_tn if($joins[$i] && $joins[$i]{'type'} eq 'JOIN');
Branch: 1 branch
BranchTrueFalseTotal
if $joins[$i] and $joins[$i]{"type"} eq "JOIN" 0 0 0
Condition0%0/3
$joins[$i] and $joins[$i]{"type"} eq "JOIN"
!ll&&!rl&&r
000
MC/DC0%0/2
$joins[$i] and $joins[$i]{"type"} eq "JOIN"
$joins[$i] $joins[$i]{"type"} eq "JOIN"
Truth table0%0/3
A and B
A= $joins[$i]B= $joins[$i]{"type"} eq "JOIN"
ABresult
0X0
100
111
1211  
1212 # XXX: Undocumented for now...
1213 0 ▶ if($rel->can('join_args') && (my $join_args = $rel->join_args))
Branch: 1 branch
BranchTrueFalseTotal
if ($rel->can("join_args") and my $join_args = $rel->join_args) 0 0 0
Condition0%0/3
$rel->can("join_args") and my $join_args = $rel->join_args
!ll&&!rl&&r
000
MC/DC0%0/2
$rel->can("join_args") and my $join_args = $rel->join_args
$rel->can("join_args") my $join_args = $rel->join_args
Truth table0%0/3
A and B
A= $rel->can("join_args")B= my $join_args = $rel->join_args
ABresult
0X0
100
111
1214 {
1215 0 my $cond =
1216 build_where_clause(dbh => $dbh,
1217 tables => [ @tables[$parent_tn - 1, $i - 1] ],
1218 columns => \%columns,
1219 all_columns => \%all_columns,
1220 classes => \%classes,
1221 meta => \%meta,
1222 db => $db,
1223 pretty => $Debug,
1224 query => $join_args);
1225  
1226 # XXX: Ugly hack...
1227 0 for($cond)
1228 {
1229 0 s/(?:^| )@{[ $tables[$parent_tn - 1] ]}\./t$parent_tn./mg;
1230 0 s/(?:^| )@{[ $tables[$i - 1] ]}\./t$i./mg;
1231 0 s/(?:^| )t1\./t$parent_tn./mg;
1232 0 s/(?:^| )t2\./t$i./mg;
1233 0 s/^\s\s+/ /mg;
1234 0 s/\A\s+//;
1235 0 s/\n/ /g;
1236 }
1237  
1238 0 push(@{$joins[$i]{'conditions'}}, $cond);
1239 }
1240  
1241 0 ▶ if(@redundant)
Branch: 1 branch
BranchTrueFalseTotal
if (@redundant) 0 0 0
1242 {
1243 0 push(@$clauses, '((' . join(' AND ', @redundant) . ') OR (' .
1244 join(' OR ', @redundant_null) . '))');
1245 }
1246  
1247 0 ▶ $joins[$i]{'conditions'} ||= [ '1 = 1' ] if($joins[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $joins[$i] 0 0 0
Condition0%0/2
$joins[$i]{"conditions"} ||= ["1 = 1"]
l!l
00
MC/DC0%0/1
$joins[$i]{"conditions"} ||= ["1 = 1"]
$joins[$i]{"conditions"}
Truth table0%0/2
A
A= $joins[$i]{"conditions"}
Aresult
11
00
1248  
1249 # Add sub-object sort conditions
1250 0 ▶ if($rel->can('manager_args') && (my $mgr_args = $rel->manager_args))
Branch: 1 branch
BranchTrueFalseTotal
if ($rel->can("manager_args") and my $mgr_args = $rel->manager_args) 0 0 0
Condition0%0/3
$rel->can("manager_args") and my $mgr_args = $rel->manager_args
!ll&&!rl&&r
000
MC/DC0%0/2
$rel->can("manager_args") and my $mgr_args = $rel->manager_args
$rel->can("manager_args") my $mgr_args = $rel->manager_args
Truth table0%0/3
A and B
A= $rel->can("manager_args")B= my $mgr_args = $rel->manager_args
ABresult
0X0
100
111
1251 {
1252 # Don't bother sorting by columns if we're not even selecting them
1253 0 ▶ if($mgr_args->{'sort_by'} && (!%fetch ||
Branch: 1 branch
BranchTrueFalseTotal
if ($mgr_args->{"sort_by"} and !%fetch || $fetch{$tables[-1]} && !$fetch{$rel_names[-1]}) 0 0 0
Condition0%0/9
$mgr_args->{"sort_by"} and !%fetch || $fetch{$tables[-1]} && !$fetch{$rel_names[-1]}
!ll&&!rl&&r
000
not %fetch or $fetch{$tables[-1]} and not $fetch{$rel_names[-1]}
l!l&&r!l&&!r
000
$fetch{$tables[-1]} and not $fetch{$rel_names[-1]}
!ll&&!rl&&r
000
MC/DC0%0/4
$mgr_args->{"sort_by"} and !%fetch || $fetch{$tables[-1]} && !$fetch{$rel_names[-1]}
$mgr_args->{"sort_by"} not %fetch $fetch{$tables[-1]} not $fetch{$rel_names[-1]}
Truth table0%0/5
A and not(B) or C and not(D)
A= $mgr_args->{"sort_by"}B= not %fetchC= $fetch{$tables[-1]}D= not $fetch{$rel_names[-1]}
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1254 ($fetch{$tables[-1]} && !$fetch{$rel_names[-1]})))
1255 {
1256 my $sort_by = ref $mgr_args->{'sort_by'} eq 'ARRAY' ?
1257 0 ▶ [ @{$mgr_args->{'sort_by'}} ] : [ $mgr_args->{'sort_by'} ];
Branch: 1 branch
BranchTrueFalseTotal
ref $mgr_args->{'sort_by'} eq 'ARRAY' ? : 0 0 0
1258  
1259 0 my $mysql = $db->dbi_driver eq 'mysql';
1260  
1261 0 foreach my $sort (@$sort_by)
1262 {
1263 61 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1264 0 ▶ if(!ref $sort && $sort =~ /^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/i)
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $sort and $sort =~ /^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/i) 0 0 0
Condition0%0/3
not ref $sort and $sort =~ /^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/i
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $sort and $sort =~ /^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/i
not ref $sort $sort =~ /^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/i
Truth table0%0/3
not(A) and B
A= not ref $sortB= $sort =~ /^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/i
ABresult
0X0
100
111
1265 {
1266 0 my $matched_col = $2;
1267  
1268 0 ▶ $sort =~ s/^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/t$i.$1$2$1$3/i
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sort 0 0 0
1269 unless(ref $sort);
1270  
1271 # When ONLY_FULL_GROUP_BY is enabled in MySQL, we need to make sure
1272 # the ORDER BY columns are in the SELECT list when DISTINCT is used.
1273 # Do it for all MySQL SELECT DISTINCT queries, because it's simpler.
1274 0 ▶ if($mysql && $args{'distinct'})
Branch: 1 branch
BranchTrueFalseTotal
if ($mysql and $args{"distinct"}) 0 0 0
Condition0%0/3
$mysql and $args{"distinct"}
!ll&&!rl&&r
000
MC/DC0%0/2
$mysql and $args{"distinct"}
$mysql $args{"distinct"}
Truth table0%0/3
A and B
A= $mysqlB= $args{"distinct"}
ABresult
0X0
100
111
1275 {
1276 0 _include_sort_column(\%columns, \%methods, \%di_keys, $tables[-1], $ft_class, $ft_meta, $matched_col);
1277 }
1278 }
1279 }
1280  
1281 0 push(@{$args{'sort_by'}}, @$sort_by);
1282 }
1283 }
1284 }
1285 elsif($rel_type eq 'many to many')
1286 {
1287 #
1288 # First add table, columns, and clauses for the map table itself
1289 #
1290  
1291 0 ▶ my $map_class = $rel->map_class
Branch: 1 branch
BranchTrueFalseTotal
my $map_class = $rel->map_class or Carp::confess("$class - Missing map class for '${name}'") 0 0 0
1292 or Carp::confess "$class - Missing map class for '$name'";
1293  
1294 0 my $map_meta = $map_class->meta;
1295  
1296 0 $meta{$map_class} = $map_meta;
1297  
1298 0 push(@tables, $map_meta->fq_table($db));
1299 0 push(@tables_sql, $map_meta->fq_table_sql($db));
1300 # %rel_name gets the foreign table (below), not the map table here
1301 0 push(@rel_names, $rel->name);
1302 0 push(@table_names, $map_meta->table);
1303 0 push(@classes, $map_class);
1304  
1305 0 ▶ my $rel_mgr_args = $rel->manager_args || {};
Condition0%0/2
$rel->manager_args || {}
l!l
00
MC/DC0%0/1
$rel->manager_args || {}
$rel->manager_args
Truth table0%0/2
A
A= $rel->manager_args
Aresult
11
00
1306  
1307 0 my $map_record_method;
1308 0 my $rel_map_record_method = $rel->map_record_method;
1309  
1310 0 ▶ if(my $rel_with_map_records = $rel_mgr_args->{'with_map_records'})
Branch: 2 branches
BranchTrueFalseTotal
if (my $rel_with_map_records = $rel_mgr_args->{'with_map_records'}) { } 0 0 0
elsif ($with_map_records) { } 0 0 0
1311 {
1312 $map_record_method =
1313 0 ▶ ($with_map_records && exists $with_map_records->{$name}) ? $with_map_records->{$name} :
Branch: 2 branches
BranchTrueFalseTotal
$with_map_records && exists $with_map_records->{$name} ? : 0 0 0
$rel_map_record_method ? : 0 0 0
Condition0%0/3
$with_map_records and exists $with_map_records->{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$with_map_records and exists $with_map_records->{$name}
$with_map_records exists $with_map_records->{$name}
Truth table0%0/3
A and B
A= $with_map_recordsB= exists $with_map_records->{$name}
ABresult
0X0
100
111
1314 $rel_map_record_method ? $rel_map_record_method : MAP_RECORD_METHOD;
1315 }
1316 elsif($with_map_records)
1317 {
1318 $map_record_method =
1319 exists $with_map_records->{$name} ? $with_map_records->{$name} :
1320 0 ▶ $with_map_records->{DEFAULT_REL_KEY()} || 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $with_map_records->{$name} ? : 0 0 0
Condition0%0/2
$with_map_records->{"__xrdbopriv_default_rel_key"} or 0
l!l
00
MC/DC0%0/1
$with_map_records->{"__xrdbopriv_default_rel_key"} or 0
$with_map_records->{"__xrdbopriv_default_rel_key"}
Truth table0%0/2
A
A= $with_map_records->{"__xrdbopriv_default_rel_key"}
Aresult
11
00
1321 }
1322  
1323 0 ▶ if($map_record_method)
Branch: 1 branch
BranchTrueFalseTotal
if ($map_record_method) { } 0 0 0
1324 {
1325 0 ▶ my $use_lazy_columns = (!ref $nonlazy || $nonlazy{$name}) ? 0 : $map_meta->has_lazy_columns;
Branch: 1 branch
BranchTrueFalseTotal
!ref($nonlazy) || $nonlazy{$name} ? : 0 0 0
Condition0%0/3
not ref $nonlazy or $nonlazy{$name}
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $nonlazy or $nonlazy{$name}
not ref $nonlazy $nonlazy{$name}
Truth table0%0/3
not(A) or B
A= not ref $nonlazyB= $nonlazy{$name}
ABresult
1X1
011
000
1326  
1327 0 ▶ if($use_lazy_columns)
Branch: 1 branch
BranchTrueFalseTotal
if ($use_lazy_columns) { } 0 0 0
1328 {
1329 0 $columns{$tables[-1]} = $map_meta->nonlazy_columns;
1330 0 $all_columns{$tables[-1]} = $map_meta->columns;
1331 0 $methods{$tables[-1]} = $map_meta->nonlazy_column_mutator_method_names;
1332 0 $di_keys{$classes[-1]} = $map_meta->nonlazy_column_db_value_hash_keys;
1333 }
1334 else
1335 {
1336 0 $columns{$tables[-1]} = $map_meta->columns;
1337 0 $methods{$tables[-1]} = $map_meta->column_mutator_method_names;
1338 0 $di_keys{$classes[-1]} = $map_meta->column_db_value_hash_keys;
1339 }
1340 }
1341 else
1342 {
1343 0 $columns{$tables[-1]} = []; # Don't fetch map class columns
1344 0 $methods{$tables[-1]} = [];
1345 }
1346  
1347 0 $classes{$tables[-1]} = $map_class;
1348  
1349 0 my $column_map = $rel->column_map;
1350  
1351 # Iterator will be the tN value: the first sub-table is t2, and so on.
1352 # Increase once for map table.
1353 0 $i++;
1354  
1355 # Increase the tN table number of this relationship as well
1356 0 $rel_tn{$arg} = $i + 1;
1357  
1358 0 $belongs_to[$i] = $belongs_to[$i - 1];
1359  
1360 0 ▶ $mapped_object_methods[$i - 1] = $map_record_method || 0;
Condition0%0/2
$map_record_method || 0
l!l
00
MC/DC0%0/1
$map_record_method || 0
$map_record_method
Truth table0%0/2
A
A= $map_record_method
Aresult
11
00
1361  
1362 0 ▶ if($map_record_method)
Branch: 1 branch
BranchTrueFalseTotal
if ($map_record_method) 0 0 0
1363 {
1364 0 ▶ my $ft_class = $rel->foreign_class
Branch: 1 branch
BranchTrueFalseTotal
my $ft_class = $rel->foreign_class or Carp::confess("$class - Missing foreign class for '${name}'") 0 0 0
1365 or Carp::confess "$class - Missing foreign class for '$name'";
1366  
1367 0 ▶ if($ft_class->can($map_record_method))
Branch: 1 branch
BranchTrueFalseTotal
if ($ft_class->can($map_record_method)) { } 0 0 0
1368 {
1369 0 ▶ if($direct_inject && (my $map_record_key = $ft_class->meta->map_record_method_key($map_record_method)))
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject and my $map_record_key = $ft_class->meta->map_record_method_key($map_record_method)) 0 0 0
Condition0%0/3
$direct_inject and my $map_record_key = $ft_class->meta->map_record_method_key($map_record_method)
!ll&&!rl&&r
000
MC/DC0%0/2
$direct_inject and my $map_record_key = $ft_class->meta->map_record_method_key($map_record_method)
$direct_inject my $map_record_key = $ft_class->meta->map_record_method_key($map_record_method)
Truth table0%0/3
A and B
A= $direct_injectB= my $map_record_key = $ft_class->meta->map_record_method_key($map_record_method)
ABresult
0X0
100
111
1370 {
1371 0 $mapped_object_methods[$i - 1] = $map_record_key;
1372 }
1373 }
1374 else
1375 {
1376 0 my $map_record_key =
1377 Rose::DB::Object::Metadata::Relationship::ManyToMany::make_map_record_method(
1378 $ft_class, $map_record_method, $map_class);
1379  
1380 0 ▶ if($direct_inject && $mapped_object_methods[$i - 1])
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject and $mapped_object_methods[$i - 1]) 0 0 0
Condition0%0/3
$direct_inject and $mapped_object_methods[$i - 1]
!ll&&!rl&&r
000
MC/DC0%0/2
$direct_inject and $mapped_object_methods[$i - 1]
$direct_inject $mapped_object_methods[$i - 1]
Truth table0%0/3
A and B
A= $direct_injectB= $mapped_object_methods[$i - 1]
ABresult
0X0
100
111
1381 {
1382 0 $mapped_object_methods[$i - 1] = $map_record_key;
1383 }
1384 }
1385 }
1386  
1387 # Add join condition(s)
1388 0 ▶ while(my($local_column, $foreign_column) = each(%$column_map))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$column_map) 0 0 0
1389 {
1390 # Use outer joins to handle duplicate or optional information.
1391 0 ▶ if($outer_joins || $with_objects{$arg})
Branch: 1 branch
BranchTrueFalseTotal
if ($outer_joins or $with_objects{$arg}) { } 0 0 0
Condition0%0/3
$outer_joins or $with_objects{$arg}
l!l&&r!l&&!r
000
MC/DC0%0/2
$outer_joins or $with_objects{$arg}
$outer_joins $with_objects{$arg}
Truth table0%0/3
A or B
A= $outer_joinsB= $with_objects{$arg}
ABresult
1X1
011
000
1392 {
1393 # Aliased table names
1394 0 push(@{$joins[$i]{'conditions'}}, "t$i.$local_column = t${parent_tn}.$foreign_column");
1395  
1396 # Fully-qualified table names
1397 #push(@{$joins[$i]{'conditions'}}, "$tables[-1].$local_column = $tables[$parent_tn - 1].$foreign_column");
1398  
1399 0 ▶ $joins[$i]{'type'} = $join_type{$arg} || 'LEFT OUTER JOIN';
Condition0%0/2
$join_type{$arg} || 'LEFT OUTER JOIN'
l!l
00
MC/DC0%0/1
$join_type{$arg} || 'LEFT OUTER JOIN'
$join_type{$arg}
Truth table0%0/2
A
A= $join_type{$arg}
Aresult
11
00
1400 0 ▶ $joins[$i]{'hints'} = $hints->{"t$i"} || $hints->{$name};
Condition0%0/3
$$hints{"t$i"} || $hints->{$name}
l!l&&r!l&&!r
000
MC/DC0%0/2
$$hints{"t$i"} || $hints->{$name}
$$hints{"t$i"} $hints->{$name}
Truth table0%0/3
A || B
A= $$hints{"t$i"}B= $hints->{$name}
ABresult
1X1
011
000
1401 }
1402 else
1403 {
1404 0 ▶ if($use_explicit_joins)
Branch: 1 branch
BranchTrueFalseTotal
if ($use_explicit_joins) { } 0 0 0
1405 {
1406 # Aliased table names
1407 0 push(@{$joins[$i]{'conditions'}}, "t$i.$local_column = t${parent_tn}.$foreign_column");
1408  
1409 # Fully-qualified table names
1410 #push(@{$joins[$i]{'conditions'}}, "$tables[-1].$local_column = $tables[$parent_tn - 1].$foreign_column");
1411  
1412 0 ▶ $joins[$i]{'type'} = $join_type{$arg} || 'JOIN';
Condition0%0/2
$join_type{$arg} || 'JOIN'
l!l
00
MC/DC0%0/1
$join_type{$arg} || 'JOIN'
$join_type{$arg}
Truth table0%0/2
A
A= $join_type{$arg}
Aresult
11
00
1413 0 ▶ $joins[$i]{'hints'} = $hints->{"t$i"} || $hints->{$name};
Condition0%0/3
$$hints{"t$i"} || $hints->{$name}
l!l&&r!l&&!r
000
MC/DC0%0/2
$$hints{"t$i"} || $hints->{$name}
$$hints{"t$i"} $hints->{$name}
Truth table0%0/3
A || B
A= $$hints{"t$i"}B= $hints->{$name}
ABresult
1X1
011
000
1414 }
1415 else # implicit join with no ON clause
1416 {
1417 # Aliased table names
1418 0 push(@$clauses, "t$i.$local_column = t${parent_tn}.$foreign_column");
1419  
1420 # Fully-qualified table names
1421 #push(@$clauses, "$tables[-1].$local_column = $tables[$parent_tn - 1].$foreign_column");
1422 }
1423 }
1424 }
1425  
1426 0 ▶ $joins[$i]{'parent_tn'} = $parent_tn if($joins[$i] && $joins[$i]{'type'} eq 'JOIN');
Branch: 1 branch
BranchTrueFalseTotal
if $joins[$i] and $joins[$i]{"type"} eq "JOIN" 0 0 0
Condition0%0/3
$joins[$i] and $joins[$i]{"type"} eq "JOIN"
!ll&&!rl&&r
000
MC/DC0%0/2
$joins[$i] and $joins[$i]{"type"} eq "JOIN"
$joins[$i] $joins[$i]{"type"} eq "JOIN"
Truth table0%0/3
A and B
A= $joins[$i]B= $joins[$i]{"type"} eq "JOIN"
ABresult
0X0
100
111
1427  
1428 #
1429 # Now add table, columns, and clauses for the foreign object
1430 #
1431  
1432 0 $num_subtables++; # Account for the extra table
1433  
1434 0 ▶ my $ft_class = $rel->foreign_class
Branch: 1 branch
BranchTrueFalseTotal
my $ft_class = $rel->foreign_class or Carp::confess("$class - Missing foreign class for '${name}'") 0 0 0
1435 or Carp::confess "$class - Missing foreign class for '$name'";
1436  
1437 0 my $ft_meta = $ft_class->meta;
1438 0 $meta{$ft_class} = $ft_meta;
1439  
1440 0 ▶ my $map_to = $rel->map_to
Branch: 1 branch
BranchTrueFalseTotal
my $map_to = $rel->map_to or Carp::confess("Missing map_to value for relationship '${name}' ", "in clas $class") 0 0 0
1441 or Carp::confess "Missing map_to value for relationship '$name' ",
1442 "in clas $class";
1443  
1444 0 ▶ my $foreign_rel =
Condition0%0/5
$map_meta->foreign_key($map_to) || $map_meta->relationship($map_to) || Carp::confess("No foreign key or relationship named '${map_to}' ", "found in $map_class")
l!l
00
$map_meta->foreign_key($map_to) or $map_meta->relationship($map_to)
l!l&&r!l&&!r
000
MC/DC0%0/2
$map_meta->foreign_key($map_to) || $map_meta->relationship($map_to) || Carp::confess("No foreign key or relationship named '${map_to}' ", "found in $map_class")
$map_meta->foreign_key($map_to) $map_meta->relationship($map_to)
Truth table0%0/3
A or B
A= $map_meta->foreign_key($map_to)B= $map_meta->relationship($map_to)
ABresult
1X1
011
000
1445 $map_meta->foreign_key($map_to) || $map_meta->relationship($map_to) ||
1446 Carp::confess "No foreign key or relationship named '$map_to' ",
1447 "found in $map_class";
1448  
1449 0 ▶ my $ft_columns = $foreign_rel->key_columns
Branch: 1 branch
BranchTrueFalseTotal
my $ft_columns = $foreign_rel->key_columns or Carp::confess("$ft_class - Missing key columns for '${map_to}'") 0 0 0
1450 or Carp::confess "$ft_class - Missing key columns for '$map_to'";
1451  
1452 0 push(@tables, $ft_meta->fq_table($db));
1453 0 push(@tables_sql, $ft_meta->fq_table_sql($db));
1454 0 push(@rel_names, $rel_name{'t' . (scalar @tables)} = $rel->name);
1455 0 push(@table_names, $ft_meta->table);
1456 0 push(@classes, $ft_class);
1457  
1458 0 ▶ my $use_lazy_columns = (!ref $nonlazy || $nonlazy{$name}) ? 0 : $ft_meta->has_lazy_columns;
Branch: 1 branch
BranchTrueFalseTotal
!ref($nonlazy) || $nonlazy{$name} ? : 0 0 0
Condition0%0/3
not ref $nonlazy or $nonlazy{$name}
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $nonlazy or $nonlazy{$name}
not ref $nonlazy $nonlazy{$name}
Truth table0%0/3
not(A) or B
A= not ref $nonlazyB= $nonlazy{$name}
ABresult
1X1
011
000
1459  
1460 0 ▶ if($use_lazy_columns)
Branch: 1 branch
BranchTrueFalseTotal
if ($use_lazy_columns) { } 0 0 0
1461 {
1462 0 $columns{$tables[-1]} = $ft_meta->nonlazy_columns;
1463 0 $all_columns{$tables[-1]} = $ft_meta->columns;
1464 0 $methods{$tables[-1]} = $ft_meta->nonlazy_column_mutator_method_names;
1465 0 $di_keys{$classes[-1]} = $ft_meta->nonlazy_column_db_value_hash_keys;
1466 }
1467 else
1468 {
1469 0 $columns{$tables[-1]} = $ft_meta->columns;
1470 0 $methods{$tables[-1]} = $ft_meta->column_mutator_method_names;
1471 0 $di_keys{$classes[-1]} = $ft_meta->column_db_value_hash_keys;
1472 }
1473  
1474 0 $classes{$tables[-1]} = $ft_class;
1475  
1476 # Iterator will be the tN value: the first sub-table is t2, and so on.
1477 # Increase again for foreign table.
1478 0 $i++;
1479  
1480 0 ▶ $subobject_methods[$i - 1] =
Branch: 1 branch
BranchTrueFalseTotal
$direct_inject ? : 0 0 0
Condition0%0/8
$rel->method_name("get_set") or $rel->method_name("get_set_now") or $rel->method_name("get_set_on_save") or Carp::confess("No 'get_set', 'get_set_now', or 'get_set_on_save' ", "method found for relationship '${name}' in class ", "$class")
l!l
00
$rel->method_name("get_set") or $rel->method_name("get_set_now") or $rel->method_name("get_set_on_save")
l!l&&r!l&&!r
000
$rel->method_name("get_set") or $rel->method_name("get_set_now")
l!l&&r!l&&!r
000
MC/DC0%0/3
$rel->method_name("get_set") or $rel->method_name("get_set_now") or $rel->method_name("get_set_on_save") or Carp::confess("No 'get_set', 'get_set_now', or 'get_set_on_save' ", "method found for relationship '${name}' in class ", "$class")
$rel->method_name("get_set") $rel->method_name("get_set_now") $rel->method_name("get_set_on_save")
Truth table0%0/4
A or B or C
A= $rel->method_name("get_set")B= $rel->method_name("get_set_now")C= $rel->method_name("get_set_on_save")
ABCresult
1XX1
01X1
0011
0000
1481 $direct_inject ? $rel->hash_key :
1482 $rel->method_name('get_set') ||
1483 $rel->method_name('get_set_now') ||
1484 $rel->method_name('get_set_on_save') ||
1485 Carp::confess "No 'get_set', 'get_set_now', or 'get_set_on_save' ",
1486 "method found for relationship '$name' in class ",
1487 "$class";
1488  
1489 #$subobject_keys[$i - 1] = $rel->hash_key;
1490  
1491 # Reset each() iterator
1492 #keys(%$ft_columns);
1493  
1494 # Add join condition(s)
1495 0 ▶ while(my($local_column, $foreign_column) = each(%$ft_columns))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$ft_columns) 0 0 0
1496 {
1497 # Use left joins if the map table used an outer join above
1498 0 ▶ if($outer_joins || $with_objects{$arg})
Branch: 1 branch
BranchTrueFalseTotal
if ($outer_joins or $with_objects{$arg}) { } 0 0 0
Condition0%0/3
$outer_joins or $with_objects{$arg}
l!l&&r!l&&!r
000
MC/DC0%0/2
$outer_joins or $with_objects{$arg}
$outer_joins $with_objects{$arg}
Truth table0%0/3
A or B
A= $outer_joinsB= $with_objects{$arg}
ABresult
1X1
011
000
1499 {
1500 # Aliased table names
1501 0 push(@{$joins[$i]{'conditions'}}, 't' . ($i - 1) . ".$local_column = t$i.$foreign_column");
1502  
1503 # Fully-qualified table names
1504 #push(@{$joins[$i]{'conditions'}}, "$tables[-2].$local_column = $tables[-1].$foreign_column");
1505  
1506 0 ▶ $joins[$i]{'type'} = $join_type{$arg} || 'LEFT OUTER JOIN';
Condition0%0/2
$join_type{$arg} || 'LEFT OUTER JOIN'
l!l
00
MC/DC0%0/1
$join_type{$arg} || 'LEFT OUTER JOIN'
$join_type{$arg}
Truth table0%0/2
A
A= $join_type{$arg}
Aresult
11
00
1507 0 ▶ $joins[$i]{'hints'} = $hints->{"t$i"} || $hints->{$name};
Condition0%0/3
$$hints{"t$i"} || $hints->{$name}
l!l&&r!l&&!r
000
MC/DC0%0/2
$$hints{"t$i"} || $hints->{$name}
$$hints{"t$i"} $hints->{$name}
Truth table0%0/3
A || B
A= $$hints{"t$i"}B= $hints->{$name}
ABresult
1X1
011
000
1508 }
1509 else
1510 {
1511 0 ▶ if($use_explicit_joins)
Branch: 1 branch
BranchTrueFalseTotal
if ($use_explicit_joins) { } 0 0 0
1512 {
1513 # Aliased table names
1514 0 push(@{$joins[$i]{'conditions'}}, 't' . ($i - 1) . ".$local_column = t$i.$foreign_column");
1515  
1516 # Fully-qualified table names
1517 #push(@{$joins[$i]{'conditions'}}, "$tables[-2].$local_column = $tables[-1].$foreign_column");
1518  
1519 0 ▶ $joins[$i]{'type'} = $join_type{$arg} || 'JOIN';
Condition0%0/2
$join_type{$arg} || 'JOIN'
l!l
00
MC/DC0%0/1
$join_type{$arg} || 'JOIN'
$join_type{$arg}
Truth table0%0/2
A
A= $join_type{$arg}
Aresult
11
00
1520 0 ▶ $joins[$i]{'hints'} = $hints->{"t$i"} || $hints->{$name};
Condition0%0/3
$$hints{"t$i"} || $hints->{$name}
l!l&&r!l&&!r
000
MC/DC0%0/2
$$hints{"t$i"} || $hints->{$name}
$$hints{"t$i"} $hints->{$name}
Truth table0%0/3
A || B
A= $$hints{"t$i"}B= $hints->{$name}
ABresult
1X1
011
000
1521 }
1522 else # implicit join with no ON clause
1523 {
1524 # Aliased table names
1525 0 push(@$clauses, 't' . ($i - 1) . ".$local_column = t$i.$foreign_column");
1526  
1527 # Fully-qualified table names
1528 #push(@$clauses, "$tables[-2].$local_column = $tables[-1].$foreign_column");
1529 }
1530 }
1531 }
1532  
1533 0 ▶ $joins[$i]{'parent_tn'} = $i - 1 if($joins[$i] && $joins[$i]{'type'} eq 'JOIN');
Branch: 1 branch
BranchTrueFalseTotal
if $joins[$i] and $joins[$i]{"type"} eq "JOIN" 0 0 0
Condition0%0/3
$joins[$i] and $joins[$i]{"type"} eq "JOIN"
!ll&&!rl&&r
000
MC/DC0%0/2
$joins[$i] and $joins[$i]{"type"} eq "JOIN"
$joins[$i] $joins[$i]{"type"} eq "JOIN"
Truth table0%0/3
A and B
A= $joins[$i]B= $joins[$i]{"type"} eq "JOIN"
ABresult
0X0
100
111
1534  
1535 # Add sub-object sort conditions
1536 0 ▶ if($rel->can('manager_args') && (my $mgr_args = $rel->manager_args))
Branch: 1 branch
BranchTrueFalseTotal
if ($rel->can("manager_args") and my $mgr_args = $rel->manager_args) 0 0 0
Condition0%0/3
$rel->can("manager_args") and my $mgr_args = $rel->manager_args
!ll&&!rl&&r
000
MC/DC0%0/2
$rel->can("manager_args") and my $mgr_args = $rel->manager_args
$rel->can("manager_args") my $mgr_args = $rel->manager_args
Truth table0%0/3
A and B
A= $rel->can("manager_args")B= my $mgr_args = $rel->manager_args
ABresult
0X0
100
111
1537 {
1538 # Don't bother sorting by columns if we're not even selecting them
1539 0 ▶ if($mgr_args->{'sort_by'} && (!%fetch ||
Branch: 1 branch
BranchTrueFalseTotal
if ($mgr_args->{"sort_by"} and !%fetch || $fetch{$tables[-1]} && !$fetch{$rel_names[-1]}) 0 0 0
Condition0%0/9
$mgr_args->{"sort_by"} and !%fetch || $fetch{$tables[-1]} && !$fetch{$rel_names[-1]}
!ll&&!rl&&r
000
not %fetch or $fetch{$tables[-1]} and not $fetch{$rel_names[-1]}
l!l&&r!l&&!r
000
$fetch{$tables[-1]} and not $fetch{$rel_names[-1]}
!ll&&!rl&&r
000
MC/DC0%0/4
$mgr_args->{"sort_by"} and !%fetch || $fetch{$tables[-1]} && !$fetch{$rel_names[-1]}
$mgr_args->{"sort_by"} not %fetch $fetch{$tables[-1]} not $fetch{$rel_names[-1]}
Truth table0%0/5
A and not(B) or C and not(D)
A= $mgr_args->{"sort_by"}B= not %fetchC= $fetch{$tables[-1]}D= not $fetch{$rel_names[-1]}
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1540 ($fetch{$tables[-1]} && !$fetch{$rel_names[-1]})))
1541 {
1542 my $sort_by = ref $mgr_args->{'sort_by'} eq 'ARRAY' ?
1543 0 ▶ [ @{$mgr_args->{'sort_by'}} ] : [ $mgr_args->{'sort_by'} ];
Branch: 1 branch
BranchTrueFalseTotal
ref $mgr_args->{'sort_by'} eq 'ARRAY' ? : 0 0 0
1544  
1545 0 my $mysql = $db->dbi_driver eq 'mysql';
1546  
1547 # translate un-prefixed simple columns
1548 0 foreach my $sort (@$sort_by)
1549 {
1550 61 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1551 0 ▶ if(!ref $sort && $sort =~ /^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/i)
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $sort and $sort =~ /^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/i) 0 0 0
Condition0%0/3
not ref $sort and $sort =~ /^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/i
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $sort and $sort =~ /^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/i
not ref $sort $sort =~ /^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/i
Truth table0%0/3
not(A) and B
A= not ref $sortB= $sort =~ /^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/i
ABresult
0X0
100
111
1552 {
1553 0 my $matched_col = $2;
1554  
1555 0 ▶ $sort =~ s/^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/t$i.$1$2$1$3/i
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sort 0 0 0
1556 unless(ref $sort);
1557  
1558 # When ONLY_FULL_GROUP_BY is enabled in MySQL, we need to make sure
1559 # the ORDER BY columns are in the SELECT list when DISTINCT is used.
1560 # We will just do this for all MySQL queries, because it's simpler.
1561 0 ▶ if($mysql && $args{'distinct'})
Branch: 1 branch
BranchTrueFalseTotal
if ($mysql and $args{"distinct"}) 0 0 0
Condition0%0/3
$mysql and $args{"distinct"}
!ll&&!rl&&r
000
MC/DC0%0/2
$mysql and $args{"distinct"}
$mysql $args{"distinct"}
Truth table0%0/3
A and B
A= $mysqlB= $args{"distinct"}
ABresult
0X0
100
111
1562 {
1563 0 _include_sort_column(\%columns, \%methods, \%di_keys, $tables[-1], $ft_class, $ft_meta, $matched_col);
1564 }
1565 }
1566 }
1567  
1568 0 push(@{$args{'sort_by'}}, @$sort_by);
1569 }
1570 }
1571 }
1572 else
1573 {
1574 0 Carp::croak "Don't know how to auto-join relationship '$name' of type '$rel_type'";
1575 }
1576 }
1577  
1578 0 $args{'clauses'} = $clauses; # restore clauses arg
1579 }
1580  
1581 # Flesh out list of fetch tables and cull columns for those tables
1582 0 ▶ if(%fetch)
Branch: 1 branch
BranchTrueFalseTotal
if (%fetch) 0 0 0
1583 {
1584 0 foreach my $i (1 .. $#tables) # skip first table, which is always selected
1585 {
1586 0 my $tn = 't' . ($i + 1);
1587 0 ▶ my $rel_name = $rel_name{$tn} || '';
Condition0%0/2
$rel_name{$tn} || ''
l!l
00
MC/DC0%0/1
$rel_name{$tn} || ''
$rel_name{$tn}
Truth table0%0/2
A
A= $rel_name{$tn}
Aresult
11
00
1588  
1589 0 (my $trimmed_table = $tables[$i]) =~ s/^[^.]+\.//;
1590  
1591 0 ▶ unless($fetch{$tn} || $fetch{$tables[$i]} || $fetch{$trimmed_table} ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($fetch{$tn} or $fetch{$tables[$i]} or $fetch{$trimmed_table} or $fetch{$rel_names[$i]} or $fetch{$rel_name}) 0 0 0
Condition0%0/12
$fetch{$tn} or $fetch{$tables[$i]} or $fetch{$trimmed_table} or $fetch{$rel_names[$i]} or $fetch{$rel_name}
l!l&&r!l&&!r
000
$fetch{$tn} or $fetch{$tables[$i]} or $fetch{$trimmed_table} or $fetch{$rel_names[$i]}
l!l&&r!l&&!r
000
$fetch{$tn} or $fetch{$tables[$i]} or $fetch{$trimmed_table}
l!l&&r!l&&!r
000
$fetch{$tn} or $fetch{$tables[$i]}
l!l&&r!l&&!r
000
MC/DC0%0/5
$fetch{$tn} or $fetch{$tables[$i]} or $fetch{$trimmed_table} or $fetch{$rel_names[$i]} or $fetch{$rel_name}
$fetch{$tn} $fetch{$tables[$i]} $fetch{$trimmed_table} $fetch{$rel_names[$i]} $fetch{$rel_name}
Truth table0%0/6
A or B or C or D or E
A= $fetch{$tn}B= $fetch{$tables[$i]}C= $fetch{$trimmed_table}D= $fetch{$rel_names[$i]}E= $fetch{$rel_name}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1592 $fetch{$rel_names[$i]} || $fetch{$rel_name})
1593 {
1594 0 $columns{$tables[$i]} = [];
1595 0 $methods{$tables[$i]} = [];
1596 }
1597 }
1598 }
1599  
1600 0 $args{'table_map'} = { reverse %rel_tn };
1601  
1602 0 my %tn;
1603  
1604 0 ▶ if($select)
Branch: 1 branch
BranchTrueFalseTotal
if ($select) 0 0 0
1605 {
1606 0 ▶ if($fetch)
Branch: 1 branch
BranchTrueFalseTotal
if ($fetch) 0 0 0
1607 {
1608 0 Carp::croak "The 'select' and 'fetch' parameters cannot be used together";
1609 }
1610  
1611 0 ▶ $select = [ split(/\s*,\s*/, $select) ] unless(ref $select);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $select 0 0 0
1612  
1613 0 my $i = 1;
1614 0 %tn = map { $_ => $i++ } @table_names; # @tables;
1615 0 my $expand_dotstar = 0;
1616  
1617 0 foreach my $item (@$select)
1618 {
1619 0 my($column, $tn);
1620  
1621 0 ▶ next if(ref $item eq 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $item eq "SCALAR" 0 0 0
1622  
1623 0 ▶ if(index($item, '.') < 0 && $item !~ /\s+ AS \s+ \w+ \s* \Z/xi)
Branch: 3 branches
BranchTrueFalseTotal
if (index($item, '.') == -1 and not $item =~ /\s+ AS \s+ \w+ \s* \Z/xi) { } 0 0 0
elsif ($item =~ /^t(\d+)\.(.+)$/) { } 0 0 0
elsif ($item =~ /^(['"]?)([^.(]+)\1\.(['"]?)(.+)(\3)$/) { } 0 0 0
Condition0%0/3
index($item, ".") == -1 and not $item =~ /\s+ AS \s+ \w+ \s* \Z/xi
!ll&&!rl&&r
000
MC/DC0%0/2
index($item, ".") == -1 and not $item =~ /\s+ AS \s+ \w+ \s* \Z/xi
index($item, ".") == -1 not $item =~ /\s+ AS \s+ \w+ \s* \Z/xi
Truth table0%0/3
A and not(B)
A= index($item, ".") == -1B= not $item =~ /\s+ AS \s+ \w+ \s* \Z/xi
ABresult
0X0
100
111
1624 {
1625 0 ▶ $expand_dotstar = 1 if($item eq '*');
Branch: 1 branch
BranchTrueFalseTotal
if $item eq "*" 0 0 0
1626 0 $column = $item;
1627 0 ▶ $item = "t1.$item" if($table_aliases > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $table_aliases > 0 0 0 0
1628 0 $tn = 1;
1629 }
1630 elsif($item =~ /^t(\d+)\.(.+)$/)
1631 {
1632 0 $tn = $1;
1633 0 ▶ $item = $2 unless($table_aliases);
Branch: 1 branch
BranchTrueFalseTotal
unless $table_aliases 0 0 0
1634 0 $column = $2;
1635 0 ▶ $expand_dotstar = 1 if($item =~ /^t\d+\.\*$/);
Branch: 1 branch
BranchTrueFalseTotal
if $item =~ /^t\d+\.\*$/ 0 0 0
1636 }
1637 elsif($item =~ /^(['"]?)([^.(]+)\1\.(['"]?)(.+)(\3)$/)
1638 {
1639 0 ▶ my $num = $tn{$2} || $rel_tn{$2};
Condition0%0/3
$tn{$2} || $rel_tn{$2}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tn{$2} || $rel_tn{$2}
$tn{$2} $rel_tn{$2}
Truth table0%0/3
A || B
A= $tn{$2}B= $rel_tn{$2}
ABresult
1X1
011
000
1640 0 $item = "t$num.$3$4$5";
1641 0 $tn = $num;
1642 0 $column = $4;
1643 0 ▶ $expand_dotstar = 1 if($item =~ /^t\d+\.\*$/);
Branch: 1 branch
BranchTrueFalseTotal
if $item =~ /^t\d+\.\*$/ 0 0 0
1644 }
1645  
1646 0 ▶ if(defined $tn)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tn) 0 0 0
1647 {
1648 0 my $meta = $meta{$classes{$tables[$tn - 1]}};
1649  
1650 0 ▶ if($meta->column($column) && (my $alias = $meta->column($column)->alias))
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->column($column) and my $alias = $meta->column($column)->alias) 0 0 0
Condition0%0/3
$meta->column($column) and my $alias = $meta->column($column)->alias
!ll&&!rl&&r
000
MC/DC0%0/2
$meta->column($column) and my $alias = $meta->column($column)->alias
$meta->column($column) my $alias = $meta->column($column)->alias
Truth table0%0/3
A and B
A= $meta->column($column)B= my $alias = $meta->column($column)->alias
ABresult
0X0
100
111
1651 {
1652 0 ▶ $item .= ' AS ' . $alias unless($alias eq $column);
Branch: 1 branch
BranchTrueFalseTotal
unless $alias eq $column 0 0 0
1653 }
1654 }
1655 }
1656  
1657 # Expand tN.* specifiers, if necessary
1658 0 ▶ if($expand_dotstar)
Branch: 1 branch
BranchTrueFalseTotal
if ($expand_dotstar) 0 0 0
1659 {
1660 0 my @select;
1661  
1662 0 foreach my $item (@$select)
1663 {
1664 0 ▶ next if(ref $item eq 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $item eq "SCALAR" 0 0 0
1665  
1666 0 ▶ unless($item =~ /^(?: t(\d+)\. )? \* $/x)
Branch: 1 branch
BranchTrueFalseTotal
unless ($item =~ /^(?: t(\d+)\. )? \* $/x) 0 0 0
1667 {
1668 0 push(@select, $item);
1669 0 next;
1670 }
1671  
1672 0 ▶ my $tn = $1 || 1;
Condition0%0/2
$1 || 1
l!l
00
MC/DC0%0/1
$1 || 1
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
1673 0 my $meta = $meta{$classes{$tables[$tn - 1]}};
1674 0 ▶ my $prefix = $table_aliases ? "t$tn." : '';
Branch: 1 branch
BranchTrueFalseTotal
$table_aliases ? : 0 0 0
1675  
1676 0 foreach my $column ($meta->columns)
1677 {
1678 0 ▶ if(my $alias = $column->alias)
Branch: 1 branch
BranchTrueFalseTotal
if (my $alias = $column->alias) { } 0 0 0
1679 {
1680 0 push(@select, "$prefix$column AS $alias");
1681 }
1682 else
1683 {
1684 0 push(@select, "$prefix$column");
1685 }
1686 }
1687 }
1688  
1689 0 $select = \@select;
1690 }
1691  
1692 0 $args{'select'} = $select;
1693 }
1694  
1695 0 ▶ if($count_only)
Branch: 1 branch
BranchTrueFalseTotal
if ($count_only) 0 0 0
1696 {
1697 0 delete $args{'limit'};
1698 0 delete $args{'offset'};
1699 0 delete $args{'sort_by'};
1700  
1701 0 my($sql, $bind, @bind_params);
1702  
1703 # Do we have to use DISTINCT to count?
1704 0 ▶ my $use_distinct = (delete $args{'distinct'} || $with_objects) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $args{'distinct'} || $with_objects ? : 0 0 0
Condition0%0/3
delete $args{"distinct"} or $with_objects
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $args{"distinct"} or $with_objects
delete $args{"distinct"} $with_objects
Truth table0%0/3
A or B
A= delete $args{"distinct"}B= $with_objects
ABresult
1X1
011
000
1705  
1706 0 ▶ if(!$use_distinct && $require_objects)
Branch: 1 branch
BranchTrueFalseTotal
if (not $use_distinct and $require_objects) 0 0 0
Condition0%0/3
not $use_distinct and $require_objects
!ll&&!rl&&r
000
MC/DC0%0/2
not $use_distinct and $require_objects
not $use_distinct $require_objects
Truth table0%0/3
not(A) and B
A= not $use_distinctB= $require_objects
ABresult
0X0
100
111
1707 {
1708 0 foreach my $name (@$require_objects)
1709 {
1710 # Ignore error here since it'll be caught and handled later anyway
1711 0 ▶ my $key =
Condition0%0/5
$meta->foreign_key($name) || $meta->relationship($name) || (next)
l!l
00
$meta->foreign_key($name) or $meta->relationship($name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$meta->foreign_key($name) || $meta->relationship($name) || (next)
$meta->foreign_key($name) $meta->relationship($name)
Truth table0%0/3
A or B
A= $meta->foreign_key($name)B= $meta->relationship($name)
ABresult
1X1
011
000
1712 $meta->foreign_key($name) || $meta->relationship($name) || next;
1713  
1714 0 my $rel_type = $key->type;
1715  
1716 0 ▶ if(index($key->type, 'many') >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (index($key->type, "many") != -1) 0 0 0
1717 {
1718 0 $use_distinct = 1;
1719 0 last;
1720 }
1721 }
1722 }
1723  
1724 BUILD_SQL:
1725 {
1726 0 my($select, $wrap);
1727  
1728 0 my $pk_columns = $meta->primary_key_column_names;
1729  
1730 0 ▶ if(!$use_distinct || @$pk_columns == 1 ||
Branch: 1 branch
BranchTrueFalseTotal
if (not $use_distinct or @$pk_columns == 1 or $db->supports_multi_column_count_distinct) { } 0 0 0
Condition0%0/6
not $use_distinct or @$pk_columns == 1 or $db->supports_multi_column_count_distinct
l!l&&r!l&&!r
000
not $use_distinct or @$pk_columns == 1
l!l&&r!l&&!r
000
MC/DC0%0/3
not $use_distinct or @$pk_columns == 1 or $db->supports_multi_column_count_distinct
not $use_distinct @$pk_columns == 1 $db->supports_multi_column_count_distinct
Truth table0%0/4
not(A) or B or C
A= not $use_distinctB= @$pk_columns == 1C= $db->supports_multi_column_count_distinct
ABCresult
1XX1
01X1
0011
0000
1731 $db->supports_multi_column_count_distinct)
1732 {
1733 0 my $select_arg = delete $args{'select'};
1734  
1735 $select = $use_distinct ?
1736 0 ▶ 'COUNT(DISTINCT ' . join(', ', ($select_arg ? @$select_arg : (map { "t1.$_" } @$pk_columns))) . ')' :
Branch: 2 branches
BranchTrueFalseTotal
$use_distinct ? : 0 0 0
$select_arg ? : 0 0 0
1737 'COUNT(*)';
1738 }
1739 else
1740 {
1741 $select = $use_distinct ?
1742 0 ▶ 'DISTINCT ' . join(', ', map { "t1.$_" } @$pk_columns) : 'COUNT(*)';
Branch: 1 branch
BranchTrueFalseTotal
$use_distinct ? : 0 0 0
1743 0 $wrap = 1;
1744 }
1745  
1746 0 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
1747  
1748 0 ($sql, $bind) =
1749 build_select(dbh => $dbh,
1750 select => $select,
1751 tables => \@tables,
1752 tables_sql => \@tables_sql,
1753 columns => \%columns,
1754 all_columns => \%all_columns,
1755 classes => \%classes,
1756 joins => \@joins,
1757 meta => \%meta,
1758 db => $db,
1759 pretty => $Debug,
1760 bind_params => \@bind_params,
1761 object_class => $object_class,
1762 %args);
1763  
1764 0 ▶ if($wrap)
Branch: 1 branch
BranchTrueFalseTotal
if ($wrap) 0 0 0
1765 {
1766 0 $sql = "SELECT COUNT(*) FROM ($sql) sq";
1767 }
1768 }
1769  
1770 0 ▶ if($return_sql)
Branch: 1 branch
BranchTrueFalseTotal
if ($return_sql) 0 0 0
1771 {
1772 0 ▶ $db->release_dbh if($dbh_retained);
Branch: 1 branch
BranchTrueFalseTotal
if $dbh_retained 0 0 0
1773 0 ▶ return wantarray ? ($sql, $bind) : $sql;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1774 }
1775  
1776 0 my $count = 0;
1777  
1778 0 my $error;
1779  
1780 TRY:
1781 {
1782 0 local $@;
1783  
1784 eval
1785 0 {
1786 0 local $dbh->{'RaiseError'} = 1;
1787 0 ▶ $Debug && warn "$sql (", join(', ', @$bind), ")\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Object::Manager::Debug and warn "$sql (", join(", ", @$bind), ")\n" 0 0 0
1788 0 ▶ my $sth = $prepare_cached ? $dbh->prepare_cached($sql, undef, 3) :
Branch: 1 branch
BranchTrueFalseTotal
$prepare_cached ? : 0 0 0
1789 $dbh->prepare($sql);
1790  
1791 0 ▶ if(@bind_params)
Branch: 1 branch
BranchTrueFalseTotal
if (@bind_params) { } 0 0 0
1792 {
1793 0 my $i = 1;
1794  
1795 0 foreach my $value (@$bind)
1796 {
1797 0 $sth->bind_param($i, $value, $bind_params[$i - 1]);
1798 0 $i++;
1799 }
1800  
1801 0 $sth->execute;
1802 }
1803 else
1804 {
1805 0 $sth->execute(@$bind);
1806 }
1807  
1808 0 ($count) = $sth->fetchrow_array;
1809 0 $sth->finish;
1810 };
1811  
1812 0 $error = $@;
1813 }
1814  
1815 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
1816 {
1817 0 $class->total(undef);
1818 0 ▶ $class->error(ref $error ? $error : "get_objects() - $error");
Branch: 1 branch
BranchTrueFalseTotal
ref $error ? : 0 0 0
1819 0 $class->handle_error($class);
1820 0 return undef;
1821 }
1822  
1823 0 $class->total($count);
1824 0 return $count;
1825 }
1826  
1827 # Post-process sort_by args
1828 0 ▶ if(my $sort_by = $args{'sort_by'})
Branch: 2 branches
BranchTrueFalseTotal
if (my $sort_by = $args{'sort_by'}) { } 0 0 0
elsif ($num_to_many_rels > 0 and !%fetch || (keys %fetch || 0) > 3 and not $no_forced_sort) { } 0 0 0
1829 {
1830 # Alter sort_by SQL, replacing table and relationship names with aliases.
1831 # This is to prevent databases like PostgreSQL from "adding missing FROM
1832 # clause"s. See: http://sql-info.de/postgresql/postgres-gotchas.html#1_5
1833 0 ▶ if($table_aliases)
Branch: 1 branch
BranchTrueFalseTotal
if ($table_aliases) { } 0 0 0
1834 {
1835 0 my $i = 0;
1836  
1837 0 foreach my $table (@tables)
1838 {
1839 0 $i++; # Table aliases are 1-based
1840  
1841 0 my $table_unquoted = $db->unquote_table_name($table);
1842  
1843 # Conditionalize schema part, if necessary
1844 0 $table_unquoted =~ s/^([^.]+\.)/(?:\Q$1\E)?/;
1845  
1846 0 foreach my $sort (grep { !ref } @$sort_by)
1847 {
1848 61 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1849 0 ▶ unless($sort =~ s/^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/t1.$1$2$1$3/i ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($sort =~ s/^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/t1.$1$2$1$3/i or $sort =~ s/\b$table_unquoted\./t$i./g) 0 0 0
Condition0%0/3
$sort =~ s/^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/t1.$1$2$1$3/i or $sort =~ s/\b$table_unquoted\./t$i./g
l!l&&r!l&&!r
000
MC/DC0%0/2
$sort =~ s/^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/t1.$1$2$1$3/i or $sort =~ s/\b$table_unquoted\./t$i./g
$sort =~ s/^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/t1.$1$2$1$3/i $sort =~ s/\b$table_unquoted\./t$i./g
Truth table0%0/3
A or B
A= $sort =~ s/^(['"`]?)(\w+)\1(\s+(?:ASC|DESC))?$/t1.$1$2$1$3/iB= $sort =~ s/\b$table_unquoted\./t$i./g
ABresult
1X1
011
000
1850 $sort =~ s/\b$table_unquoted\./t$i./g)
1851 {
1852 0 ▶ if(my $rel_name = $rel_name{"t$i"})
Branch: 1 branch
BranchTrueFalseTotal
if (my $rel_name = $rel_name{"t$i"}) 0 0 0
1853 {
1854 0 ▶ $sort =~ s/\b$rel_name\./t$i./g unless($rel_name =~ /^t\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $rel_name =~ /^t\d+$/ 0 0 0
1855 }
1856 }
1857 }
1858 }
1859  
1860 # When selecting sub-objects via a "... to many" relationship, force
1861 # a sort by t1's primary key unless sorting by some other column in
1862 # t1. This is required to ensure that all result rows from each row
1863 # in t1 are grouped together. But don't do it when we're selecting
1864 # columns from just one table. (Compare to 3 because the primary table
1865 # name, fully-qualified name, and the "t1" alias are always in the list.)
1866 0 ▶ if($num_to_many_rels > 0 && (!%fetch || (keys %fetch || 0) > 3) && !$no_forced_sort)
Branch: 1 branch
BranchTrueFalseTotal
if ($num_to_many_rels > 0 and !%fetch || (keys %fetch || 0) > 3 and not $no_forced_sort) 0 0 0
Condition0%0/11
$num_to_many_rels > 0 and !%fetch || (keys %fetch || 0) > 3 and not $no_forced_sort
!ll&&!rl&&r
000
$num_to_many_rels > 0 and !%fetch || (keys %fetch || 0) > 3
!ll&&!rl&&r
000
not %fetch or (keys %fetch || 0) > 3
l!l&&r!l&&!r
000
keys %fetch || 0
l!l
00
MC/DC0%0/4
$num_to_many_rels > 0 and !%fetch || (keys %fetch || 0) > 3 and not $no_forced_sort
$num_to_many_rels > 0 not %fetch keys %fetch not $no_forced_sort
Truth table0%0/6
A and not(B) or C and not(D)
A= $num_to_many_rels > 0B= not %fetchC= keys %fetchD= not $no_forced_sort
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
1867 {
1868 0 my $do_prefix = 1;
1869  
1870 0 foreach my $sort (@$sort_by)
1871 {
1872 0 ▶ if(!ref $sort && $sort =~ /^t1\./)
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $sort and $sort =~ /^t1\./) 0 0 0
Condition0%0/3
not ref $sort and $sort =~ /^t1\./
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $sort and $sort =~ /^t1\./
not ref $sort $sort =~ /^t1\./
Truth table0%0/3
not(A) and B
A= not ref $sortB= $sort =~ /^t1\./
ABresult
0X0
100
111
1873 {
1874 0 $do_prefix = 0;
1875 0 last;
1876 }
1877 }
1878  
1879 0 ▶ if($do_prefix)
Branch: 1 branch
BranchTrueFalseTotal
if ($do_prefix) 0 0 0
1880 {
1881 0 unshift(@$sort_by, join(', ', map { "t1.$_" } $meta->primary_key_column_names));
1882 }
1883 }
1884 }
1885 else # otherwise, trim t1. prefixes
1886 {
1887 0 my $prefix_re = '\b(?:t1|' . $meta->table . ')\.';
1888 0 $prefix_re = qr($prefix_re);
1889  
1890 0 foreach my $sort (@$sort_by)
1891 {
1892 0 ▶ $sort =~ s/$prefix_re//g unless(ref $sort);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sort 0 0 0
1893 }
1894 }
1895  
1896 # TODO: remove duplicate/redundant sort conditions
1897 0 $args{'sort_by'} = $sort_by;
1898 }
1899 ▶ elsif($num_to_many_rels > 0 && (!%fetch || (keys %fetch || 0) > 3) && !$no_forced_sort)
Condition0%0/11
$num_to_many_rels > 0 and !%fetch || (keys %fetch || 0) > 3 and not $no_forced_sort
!ll&&!rl&&r
000
$num_to_many_rels > 0 and !%fetch || (keys %fetch || 0) > 3
!ll&&!rl&&r
000
not %fetch or (keys %fetch || 0) > 3
l!l&&r!l&&!r
000
keys %fetch || 0
l!l
00
MC/DC0%0/4
$num_to_many_rels > 0 and !%fetch || (keys %fetch || 0) > 3 and not $no_forced_sort
$num_to_many_rels > 0 not %fetch keys %fetch not $no_forced_sort
Truth table0%0/6
A and not(B) or C and not(D)
A= $num_to_many_rels > 0B= not %fetchC= keys %fetchD= not $no_forced_sort
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
1900 {
1901 # When selecting sub-objects via a "... to many" relationship, force a
1902 # sort by t1's primary key to ensure that all result rows from each
1903 # row in t1 are grouped together. But don't do it when we're selecting
1904 # columns from just one table. (Compare to 3 because the primary table
1905 # name, fully-qualified name, and the "t1" alias are always in the list.)
1906 0 $args{'sort_by'} = [ join(', ', map { "t1.$_" } $meta->primary_key_column_names) ];
1907 }
1908  
1909 0 ▶ if(defined $args{'offset'})
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args{'offset'}) { } 0 0 0
elsif ($args{'limit'}) { } 0 0 0
1910 {
1911 Carp::croak "Offset argument is invalid without a limit argument"
1912 0 ▶ unless($args{'limit'} || $manual_limit);
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"limit"} or $manual_limit 0 0 0
Condition0%0/3
$args{"limit"} or $manual_limit
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"limit"} or $manual_limit
$args{"limit"} $manual_limit
Truth table0%0/3
A or B
A= $args{"limit"}B= $manual_limit
ABresult
1X1
011
000
1913  
1914 0 ▶ if($db->supports_limit_with_offset && !$manual_limit && !$subselect_limit)
Branch: 2 branches
BranchTrueFalseTotal
if ($db->supports_limit_with_offset and not $manual_limit and not $subselect_limit) { } 0 0 0
elsif ($manual_limit) { } 0 0 0
Condition0%0/6
$db->supports_limit_with_offset and not $manual_limit and not $subselect_limit
!ll&&!rl&&r
000
$db->supports_limit_with_offset and not $manual_limit
!ll&&!rl&&r
000
MC/DC0%0/3
$db->supports_limit_with_offset and not $manual_limit and not $subselect_limit
$db->supports_limit_with_offset not $manual_limit not $subselect_limit
Truth table0%0/4
A and not(B) and not(C)
A= $db->supports_limit_with_offsetB= not $manual_limitC= not $subselect_limit
ABCresult
0XX0
10X0
1100
1111
1915 {
1916 0 $db->format_limit_with_offset($args{'limit'}, $args{'offset'}, \%args);
1917 #$args{'limit'} = $db->format_limit_with_offset($args{'limit'}, $args{'offset'});
1918 #delete $args{'offset'};
1919 0 $skip_first = 0;
1920 }
1921 elsif($manual_limit)
1922 {
1923 0 $skip_first += delete $args{'offset'};
1924 }
1925 else
1926 {
1927 0 $skip_first += delete $args{'offset'};
1928 0 $args{'limit'} += $skip_first;
1929 0 $db->format_limit_with_offset($args{'limit'}, undef, \%args);
1930 #$args{'limit'} = $db->format_limit_with_offset($args{'limit'});
1931 }
1932 }
1933 elsif($args{'limit'})
1934 {
1935 0 $db->format_limit_with_offset($args{'limit'}, undef, \%args);
1936 #$args{'limit'} = $db->format_limit_with_offset($args{'limit'});
1937 }
1938  
1939 0 my($count, @objects, $iterator);
1940  
1941 0 my($sql, $bind, @bind_params);
1942  
1943 BUILD_SQL:
1944 {
1945 0 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
1946  
1947 0 ($sql, $bind) =
1948 build_select(dbh => $dbh,
1949 tables => \@tables,
1950 tables_sql => \@tables_sql,
1951 columns => \%columns,
1952 all_columns => \%all_columns,
1953 classes => \%classes,
1954 joins => \@joins,
1955 meta => \%meta,
1956 db => $db,
1957 pretty => $Debug,
1958 bind_params => \@bind_params,
1959 object_class => $object_class,
1960 %args);
1961  
1962 0 ▶ if($subselect_limit)
Branch: 1 branch
BranchTrueFalseTotal
if ($subselect_limit) 0 0 0
1963 {
1964 0 my($class, %sub_args) = @_;
1965  
1966 # The sort clause is important, so it can't be deleted, but it
1967 # also can't contain references to any table but t1.
1968 0 ▶ if($args{'sort_by'} && $num_subtables > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"sort_by"} and $num_subtables > 0) 0 0 0
Condition0%0/3
$args{"sort_by"} and $num_subtables > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"sort_by"} and $num_subtables > 0
$args{"sort_by"} $num_subtables > 0
Truth table0%0/3
A and B
A= $args{"sort_by"}B= $num_subtables > 0
ABresult
0X0
100
111
1969 {
1970 0 my @sort_by;
1971  
1972 0 foreach my $arg (@{$args{'sort_by'}})
1973 {
1974 0 ▶ push(@sort_by, $arg) if(index((ref $arg ? $$arg : $arg), 't1.') == 0);
Branch: 2 branches
BranchTrueFalseTotal
if index(ref $arg ? $$arg : $arg, "t1.") == 0 0 0 0
ref $arg ? : 0 0 0
1975 }
1976  
1977 0 $sub_args{'sort_by'} = \@sort_by;
1978 }
1979  
1980 # Not safe to delete this if the query references columns in these tables
1981 #delete $sub_args{'with_objects'};
1982  
1983 0 $sub_args{'fetch_only'} = [ 't1' ];
1984 0 $sub_args{'from_and_where_only'} = 1;
1985  
1986 0 my @t1_bind_params;
1987 0 $sub_args{'bind_params'} = \@t1_bind_params;
1988  
1989 0 my($t1_sql, $t1_bind) = $class->get_objects_sql(%sub_args);
1990  
1991 0 my $columns = $sub_args{'select'};
1992  
1993 0 ▶ unless($columns)
Branch: 1 branch
BranchTrueFalseTotal
unless ($columns) 0 0 0
1994 {
1995 my $multi_table =
1996 0 ▶ ($sub_args{'with_objects'} && (!ref $sub_args{'with_objects'} || @{$sub_args{'with_objects'}})) ||
Condition0%0/6
$sub_args{"require_objects"} and !ref($sub_args{"require_objects"}) || @{$sub_args{"require_objects"};}
!ll&&!rl&&r
000
not ref $sub_args{"require_objects"} or @{$sub_args{"require_objects"};}
l!l&&r!l&&!r
000
MC/DC0%0/3
$sub_args{"require_objects"} and !ref($sub_args{"require_objects"}) || @{$sub_args{"require_objects"};}
$sub_args{"require_objects"} not ref $sub_args{"require_objects"} @{$sub_args{"require_objects"};}
Truth table0%0/4
A and not(B) or C
A= $sub_args{"require_objects"}B= not ref $sub_args{"require_objects"}C= @{$sub_args{"require_objects"};}
ABCresult
0XX0
1000
11X1
1011
1997 0 ▶ ($sub_args{'require_objects'} && (!ref $sub_args{'require_objects'} || @{$sub_args{'require_objects'}}));
Condition0%0/9
$sub_args{'with_objects'} && (!ref($sub_args{'with_objects'}) || @{$sub_args{'with_objects'};}) || $sub_args{'require_objects'} && (!ref($sub_args{'require_objects'}) || @{$sub_args{'require_objects'};})
l!l&&r!l&&!r
000
$sub_args{"with_objects"} and !ref($sub_args{"with_objects"}) || @{$sub_args{"with_objects"};}
!ll&&!rl&&r
000
not ref $sub_args{"with_objects"} or @{$sub_args{"with_objects"};}
l!l&&r!l&&!r
000
MC/DC0%0/4
$sub_args{'with_objects'} && (!ref($sub_args{'with_objects'}) || @{$sub_args{'with_objects'};}) || $sub_args{'require_objects'} && (!ref($sub_args{'require_objects'}) || @{$sub_args{'require_objects'};})
$sub_args{"with_objects"} not ref $sub_args{"with_objects"} @{$sub_args{"with_objects"};} $sub_args{'require_objects'} && (!ref($sub_args{'require_objects'}) || @{$sub_args{'require_objects'};})
Truth table0%0/6
A and not(B) or C || D
A= $sub_args{"with_objects"}B= not ref $sub_args{"with_objects"}C= @{$sub_args{"with_objects"};}D= $sub_args{'require_objects'} && (!ref($sub_args{'require_objects'}) || @{$sub_args{'require_objects'};})
ABCDresult
11XX1
101X1
0XX11
10011
0XX00
10000
1998  
1999 0 ▶ if($multi_table)
Branch: 1 branch
BranchTrueFalseTotal
if ($multi_table) { } 0 0 0
2000 {
2001 0 $table_aliases = 1;
2002 }
2003 else
2004 {
2005 0 ▶ $table_aliases = $multi_table unless(defined $table_aliases);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table_aliases 0 0 0
2006 }
2007  
2008 $columns = $table_aliases ?
2009 0 join(', ', map { "t1.$_" } @{$columns{$tables[0]}}) :
2010 0 ▶ join(', ', map { $_ } @{$columns{$tables[0]}});
Branch: 1 branch
BranchTrueFalseTotal
$table_aliases ? : 0 0 0
2011 }
2012  
2013 0 ▶ my $distinct = ($num_with_objects && scalar @{[ @has_dups[1 .. $num_with_objects] ]}) ? ' DISTINCT' : '';
Branch: 1 branch
BranchTrueFalseTotal
$num_with_objects && scalar @{[@has_dups[1 .. $num_with_objects]];} ? : 0 0 0
Condition0%0/2
$num_with_objects and scalar @{[@has_dups[1 .. $num_with_objects]];}
!ll
00
MC/DC0%0/1
$num_with_objects and scalar @{[@has_dups[1 .. $num_with_objects]];}
$num_with_objects
Truth table0%0/2
A
A= $num_with_objects
Aresult
00
11
2014  
2015 0 $t1_sql = "SELECT$distinct $columns FROM\n$t1_sql";
2016 0 ▶ $t1_sql =~ s/^/ /mg if($Debug);
Branch: 1 branch
BranchTrueFalseTotal
if $Rose::DB::Object::Manager::Debug 0 0 0
2017 0 $t1_sql = $db->format_select_from_subselect($t1_sql);
2018  
2019 0 $sql =~ s/(\nFROM\n\s*)\S.+\s+t1\b/$1$t1_sql t1/;
2020  
2021 0 unshift(@$bind, @$t1_bind);
2022  
2023 0 ▶ if(@t1_bind_params)
Branch: 1 branch
BranchTrueFalseTotal
if (@t1_bind_params) 0 0 0
2024 {
2025 0 unshift(@bind_params, @t1_bind_params);
2026 }
2027 }
2028 }
2029  
2030 0 ▶ if($return_sql)
Branch: 1 branch
BranchTrueFalseTotal
if ($return_sql) 0 0 0
2031 {
2032 0 ▶ $db->release_dbh if($dbh_retained);
Branch: 1 branch
BranchTrueFalseTotal
if $dbh_retained 0 0 0
2033 0 ▶ return wantarray ? ($sql, $bind) : $sql;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2034 }
2035  
2036 0 my $error;
2037  
2038 TRY:
2039 {
2040 0 local $@;
2041  
2042 eval
2043 0 {
2044 0 local $dbh->{'RaiseError'} = 1;
2045  
2046 0 ▶ $Debug && warn "$sql (", join(', ', @$bind), ")\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Object::Manager::Debug and warn "$sql (", join(", ", @$bind), ")\n" 0 0 0
2047 # $meta->prepare_select_options (defunct)
2048 0 ▶ my $sth = $prepare_cached ? $dbh->prepare_cached($sql, undef, 3) :
Branch: 2 branches
BranchTrueFalseTotal
my $sth = $prepare_cached ? $dbh->prepare_cached($sql, undef, 3) : $dbh->prepare($sql) or die $dbh->errstr 0 0 0
$prepare_cached ? : 0 0 0
2049 $dbh->prepare($sql) or die $dbh->errstr;
2050  
2051 0 $sth->{'RaiseError'} = 1;
2052  
2053 0 ▶ if(@bind_params)
Branch: 1 branch
BranchTrueFalseTotal
if (@bind_params) { } 0 0 0
2054 {
2055 0 my $i = 1;
2056  
2057 0 foreach my $value (@$bind)
2058 {
2059 0 $sth->bind_param($i, $value, $bind_params[$i - 1]);
2060 0 $i++;
2061 }
2062  
2063 0 $sth->execute;
2064 }
2065 else
2066 {
2067 0 $sth->execute(@$bind);
2068 }
2069  
2070 0 my %row;
2071  
2072 0 my $col_num = 1;
2073 0 my $table_num = 0;
2074  
2075 0 ▶ if($select)
Branch: 1 branch
BranchTrueFalseTotal
if ($select) { } 0 0 0
2076 {
2077 0 foreach my $orig_item (@$select)
2078 {
2079 0 my($class, $table_num, $column);
2080  
2081 0 ▶ my $item = (ref $orig_item eq 'SCALAR') ? $$orig_item : $orig_item;
Branch: 1 branch
BranchTrueFalseTotal
ref $orig_item eq 'SCALAR' ? : 0 0 0
2082  
2083 0 ▶ if($item =~ s/\s+AS\s+(\w.+)$//i)
Branch: 1 branch
BranchTrueFalseTotal
if ($item =~ s/\s+AS\s+(\w.+)$//i) 0 0 0
2084 {
2085 0 $column = $1;
2086 }
2087  
2088 0 ▶ if(index($item, '.') < 0)
Branch: 3 branches
BranchTrueFalseTotal
if (index($item, '.') == -1) { } 0 0 0
elsif ($item =~ /^t(\d+)\.(.+)$/) { } 0 0 0
elsif ($item =~ /^(['"]?)([^.(]+)\1\.(['"]?)(.+)\3$/) { } 0 0 0
2089 {
2090 0 $table_num = 0;
2091 0 $class = $classes[$table_num];
2092 0 ▶ $column ||= $item;
Condition0%0/3
$column ||= $item
l!l&&r!l&&!r
000
MC/DC0%0/2
$column ||= $item
$column $item
Truth table0%0/3
A ||= B
A= $columnB= $item
ABresult
1X1
011
000
2093 }
2094 elsif($item =~ /^t(\d+)\.(.+)$/)
2095 {
2096 0 $table_num = $1 - 1;
2097 0 $class = $classes[$table_num];
2098 0 ▶ $column ||= $2;
Condition0%0/3
$column ||= $2
l!l&&r!l&&!r
000
MC/DC0%0/2
$column ||= $2
$column $2
Truth table0%0/3
A ||= B
A= $columnB= $2
ABresult
1X1
011
000
2099 }
2100 elsif($item =~ /^(['"]?)([^.(]+)\1\.(['"]?)(.+)\3$/)
2101 {
2102 0 my $table = $2;
2103 0 $class = $classes{$table};
2104 0 ▶ $column ||= $4;
Condition0%0/3
$column ||= $4
l!l&&r!l&&!r
000
MC/DC0%0/2
$column ||= $4
$column $4
Truth table0%0/3
A ||= B
A= $columnB= $4
ABresult
1X1
011
000
2105 0 ▶ my $table_num = $tn{$table} || $rel_tn{$table};
Condition0%0/3
$tn{$table} || $rel_tn{$table}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tn{$table} || $rel_tn{$table}
$tn{$table} $rel_tn{$table}
Truth table0%0/3
A || B
A= $tn{$table}B= $rel_tn{$table}
ABresult
1X1
011
000
2106 }
2107 else
2108 {
2109 0 $table_num = 0;
2110 0 $class = $classes[$table_num];
2111 0 ▶ $column ||= $item;
Condition0%0/3
$column ||= $item
l!l&&r!l&&!r
000
MC/DC0%0/2
$column ||= $item
$column $item
Truth table0%0/3
A ||= B
A= $columnB= $item
ABresult
1X1
011
000
2112 }
2113  
2114 0 $sth->bind_col($col_num++, \$row{$class,$table_num}{$column});
2115 }
2116 }
2117 else
2118 {
2119 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2120 {
2121 0 ▶ my $driver = $db->driver || 'unknown';
Condition0%0/2
$db->driver || 'unknown'
l!l
00
MC/DC0%0/1
$db->driver || 'unknown'
$db->driver
Truth table0%0/2
A
A= $db->driver
Aresult
11
00
2122  
2123 0 foreach my $table (@tables)
2124 {
2125 0 my $class = $classes{$table};
2126 0 my $key_map = $di_keys{$class};
2127  
2128 0 foreach my $column (@{$methods{$table}})
2129 {
2130 0 ▶ if($key_map->{$column} eq $column)
Branch: 1 branch
BranchTrueFalseTotal
if ($key_map->{$column} eq $column) { } 0 0 0
2131 {
2132 0 $sth->bind_col($col_num++, \$row{$class,$table_num}{$column});
2133 }
2134 else # attribute uses a db-formatted key
2135 {
2136 0 $sth->bind_col($col_num++, \$row{$class,$table_num}{$key_map->{$column},$driver});
2137 }
2138 }
2139  
2140 0 $table_num++;
2141 }
2142 }
2143 else
2144 {
2145 0 foreach my $table (@tables)
2146 {
2147 0 my $class = $classes{$table};
2148  
2149 0 foreach my $column (@{$methods{$table}})
2150 {
2151 0 $sth->bind_col($col_num++, \$row{$class,$table_num}{$column});
2152 }
2153  
2154 0 $table_num++;
2155 }
2156 }
2157 }
2158  
2159 0 ▶ if($return_iterator)
Branch: 1 branch
BranchTrueFalseTotal
if ($return_iterator) 0 0 0
2160 {
2161 0 $iterator = Rose::DB::Object::Iterator->new(active => 1);
2162  
2163 0 my $count = 0;
2164  
2165 # More trading of code duplication for performance: build custom
2166 # subroutines depending on how much work needs to be done for
2167 # each iteration.
2168  
2169 0 ▶ if($with_objects)
Branch: 1 branch
BranchTrueFalseTotal
if ($with_objects) { } 0 0 0
2170 {
2171 # Ug, we have to handle duplicate data due to "...to many" relationships
2172 # fetched via outer joins.
2173 0 ▶ if($handle_dups)# || $deep_joins)
Branch: 1 branch
BranchTrueFalseTotal
if ($handle_dups) { } 0 0 0
2174 {
2175 0 my(@seen, %seen, @sub_objects);
2176  
2177 #my @pk_columns = $meta->primary_key_column_names;
2178 0 my $pk_columns = $meta->primary_key_column_names_or_aliases;
2179  
2180 # Get list of primary key columns for each sub-table
2181 0 my @sub_pk_columns;
2182  
2183 0 foreach my $i (1 .. $num_subtables)
2184 {
2185 #$sub_pk_columns[$i + 1] = [ $classes[$i]->meta->primary_key_column_names ];
2186 0 $sub_pk_columns[$i + 1] = $classes[$i]->meta->primary_key_column_names_or_aliases;
2187 }
2188  
2189 0 my($last_object, %subobjects, %parent_objects);
2190  
2191 0 weaken(my $witerator = $iterator);
2192  
2193 $iterator->_next_code(sub
2194 0 ▶ {
Subroutine __ANON__: not called CC=61 SCAR=81.8
2195 0 my($self) = shift;
2196  
2197 0 my $object = 0;
2198 0 my $object_is_ready = 0;
2199  
2200 0 my(@objects, $error);
2201  
2202 TRY:
2203 {
2204 0 local $@;
2205  
2206 eval
2207 0 {
2208 0 ROW: for(;;)
2209 {
2210 0 ▶ last ROW unless($sth);
Branch: 1 branch
BranchTrueFalseTotal
unless $sth 0 0 0
2211  
2212 0 ▶ while($sth->fetch)
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
2213 {
2214 0 my $pk = join(PK_JOIN, map { $row{$object_class,0}{$_} } @$pk_columns);
2215  
2216 # If this is a new main (t1) table row that we haven't seen before
2217 0 ▶ unless($seen[0]{$pk}++)
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen[0]{$pk}++) 0 0 0
2218 {
2219 # First, finish building the last object, if it exists
2220 0 ▶ if($last_object)
Branch: 1 branch
BranchTrueFalseTotal
if ($last_object) 0 0 0
2221 {
2222 #$Debug && warn "Finish $object_class $last_object->{'id'}\n";
2223  
2224 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2225 {
2226 0 ▶ while(my($ident, $parent) = each(%parent_objects))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %parent_objects) 0 0 0
2227 {
2228 0 ▶ while(my($method, $subobjects) = each(%{$subobjects{$ident}}))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$subobjects{$ident};}) 0 0 0
2229 {
2230 0 $parent->{$method} = $subobjects;
2231 }
2232 }
2233 }
2234 else
2235 {
2236 0 ▶ while(my($ident, $parent) = each(%parent_objects))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %parent_objects) 0 0 0
2237 {
2238 0 local $parent->{STATE_LOADING()} = 1;
2239  
2240 0 ▶ while(my($method, $subobjects) = each(%{$subobjects{$ident}}))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$subobjects{$ident};}) 0 0 0
2241 {
2242 0 $parent->$method($subobjects);
2243 }
2244 }
2245 }
2246  
2247 0 %subobjects = ();
2248 0 %parent_objects = ();
2249  
2250 # Add the object to the final list of objects that we'll return
2251 0 push(@objects, $last_object);
2252  
2253 0 $object_is_ready = 1;
2254 }
2255  
2256 #$Debug && warn "Make $object_class $pk\n";
2257  
2258 # Now, create the object from this new main table row
2259 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2260 {
2261 0 $object = bless { STATE_IN_DB() => 1, %{$row{$object_class,0}}, %object_args }, $object_class;
2262 }
2263 else
2264 {
2265 0 $object = $object_class->new(%object_args);
2266  
2267 0 local $object->{STATE_LOADING()} = 1;
2268 0 $object->init(%{$row{$object_class,0}});
2269 0 $object->{STATE_IN_DB()} = 1;
2270 }
2271  
2272 0 $last_object = $object; # This is the "last object" from now on
2273 0 @sub_objects = (); # The list of sub-objects is per-object
2274 0 splice(@seen, 1); # Sub-objects seen is also per-object,
2275 # so trim it, but leave the t1 table info
2276 0 %seen = (); # Wipe sub-object parent tracking.
2277 }
2278  
2279 0 ▶ $object ||= $last_object or die "Missing object for primary key '$pk'";
Branch: 1 branch
BranchTrueFalseTotal
$object ||= $last_object or die "Missing object for primary key '${pk}'" 0 0 0
Condition0%0/3
$object ||= $last_object
l!l&&r!l&&!r
000
MC/DC0%0/2
$object ||= $last_object
$object $last_object
Truth table0%0/3
A ||= B
A= $objectB= $last_object
ABresult
1X1
011
000
2280  
2281 0 my $map_record;
2282  
2283 0 foreach my $i (1 .. $num_subtables)
2284 {
2285 0 my $mapped_object_method = $mapped_object_methods[$i];
2286 0 ▶ next if(defined $mapped_object_method && !$mapped_object_method);
Branch: 1 branch
BranchTrueFalseTotal
if defined $mapped_object_method and not $mapped_object_method 0 0 0
Condition0%0/3
defined $mapped_object_method and not $mapped_object_method
!ll&&!rl&&r
000
MC/DC0%0/2
defined $mapped_object_method and not $mapped_object_method
defined $mapped_object_method not $mapped_object_method
Truth table0%0/3
A and not(B)
A= defined $mapped_object_methodB= not $mapped_object_method
ABresult
0X0
100
111
2287  
2288 0 my $class = $classes[$i];
2289 0 my $tn = $i + 1;
2290  
2291 # Null primary key columns are not allowed
2292 0 my $sub_pk = join(PK_JOIN, grep { defined } map { $row{$class,$i}{$_} } @{$sub_pk_columns[$tn]});
2293 0 ▶ next unless(length $sub_pk);
Branch: 1 branch
BranchTrueFalseTotal
unless length $sub_pk 0 0 0
2294  
2295 0 my $subobject = $seen[$i]{$sub_pk};
2296  
2297 0 ▶ unless($subobject)
Branch: 1 branch
BranchTrueFalseTotal
unless ($subobject) 0 0 0
2298 {
2299 # Make sub-object
2300 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2301 {
2302 0 $subobject = bless { STATE_IN_DB() => 1, %{$row{$class,$i}}, %subobject_args }, $class;
2303 }
2304 else
2305 {
2306 0 $subobject = $class->new(%subobject_args);
2307 0 local $subobject->{STATE_LOADING()} = 1;
2308 0 $subobject->init(%{$row{$class,$i}});
2309 0 $subobject->{STATE_IN_DB()} = 1;
2310 }
2311  
2312 0 $seen[$i]{$sub_pk} = $subobject;
2313 }
2314  
2315 # If this object belongs to an attribute that can have more
2316 # than one object then just save it for later in the
2317 # per-object sub-objects list.
2318 0 ▶ if($has_dups[$i])
Branch: 1 branch
BranchTrueFalseTotal
if ($has_dups[$i]) { } 0 0 0
2319 {
2320 0 ▶ if($mapped_object_methods[$i])
Branch: 1 branch
BranchTrueFalseTotal
if ($mapped_object_methods[$i]) { } 0 0 0
2321 {
2322 0 $map_record = $subobject;
2323 }
2324 else
2325 {
2326 0 ▶ if($map_record)
Branch: 1 branch
BranchTrueFalseTotal
if ($map_record) 0 0 0
2327 {
2328 0 ▶ my $method = $mapped_object_methods[$i - 1] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $method = $mapped_object_methods[$i - 1] or next 0 0 0
2329  
2330 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2331 {
2332 0 $subobject->{$method} = $map_record;
2333 }
2334 else
2335 {
2336 0 local $subobject->{STATE_LOADING()} = 1;
2337 0 $subobject->$method($map_record);
2338 }
2339  
2340 0 $map_record = 0;
2341 }
2342  
2343 0 ▶ next if(defined $mapped_object_methods[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $mapped_object_methods[$i] 0 0 0
2344  
2345 0 ▶ if($has_dups[$i] && (my $bt = $belongs_to[$i]))
Branch: 1 branch
BranchTrueFalseTotal
if ($has_dups[$i] and my $bt = $belongs_to[$i]) { } 0 0 0
Condition0%0/3
$has_dups[$i] and my $bt = $belongs_to[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
$has_dups[$i] and my $bt = $belongs_to[$i]
$has_dups[$i] my $bt = $belongs_to[$i]
Truth table0%0/3
A and B
A= $has_dups[$i]B= my $bt = $belongs_to[$i]
ABresult
0X0
100
111
2346 {
2347 #$subobjects_belong_to[$i] = $#{$sub_objects[$bt]};
2348  
2349 0 my $parent_object = $sub_objects[$bt];
2350  
2351 # XXX: Special heavyweight subobject pairing in multi-many queries
2352 0 ▶ if($multi_many && ref $parent_object eq 'ARRAY' && @$parent_object > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($multi_many and ref $parent_object eq "ARRAY" and @$parent_object > 1) 0 0 0
Condition0%0/6
$multi_many and ref $parent_object eq "ARRAY" and @$parent_object > 1
!ll&&!rl&&r
000
$multi_many and ref $parent_object eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
$multi_many and ref $parent_object eq "ARRAY" and @$parent_object > 1
$multi_many ref $parent_object eq "ARRAY" @$parent_object > 1
Truth table0%0/4
A and B and C
A= $multi_manyB= ref $parent_object eq "ARRAY"C= @$parent_object > 1
ABCresult
0XX0
10X0
1100
1111
2353 {
2354 0 my $maps = $subobject_method_map[$i + 1][$bt];
2355 0 my %check;
2356  
2357 0 foreach my $map (@$maps)
2358 {
2359 0 my $subobject_method = $map->[1];
2360 0 $check{$subobject_method} = $subobject->$subobject_method();
2361 }
2362  
2363 0 PARENT: foreach my $check_parent (reverse @$parent_object)
2364 {
2365 0 foreach my $map (@$maps)
2366 {
2367 0 my $parent_method = $map->[0];
2368 0 ▶ next PARENT unless($check_parent->$parent_method() eq $check{$map->[1]});
Branch: 1 branch
BranchTrueFalseTotal
unless $check_parent->$parent_method eq $check{$map->[1]} 0 0 0
2369 }
2370  
2371 0 $parent_object = $check_parent;
2372 0 last PARENT;
2373 }
2374 }
2375  
2376 # XXX: This relies on parent objects coming before child
2377 # objects in the list of tables in the FROM clause.
2378 0 ▶ $parent_object = $parent_object->[-1] #$parent_object->[$subobjects_belong_to[$i]]
Branch: 1 branch
BranchTrueFalseTotal
if ref $parent_object eq "ARRAY" 0 0 0
2379 if(ref $parent_object eq 'ARRAY');
2380  
2381 0 my $method = $subobject_methods[$i];
2382  
2383 0 my $ident = refaddr $parent_object;
2384 0 ▶ next if($seen{$ident,$method}{$sub_pk}++);
Branch: 1 branch
BranchTrueFalseTotal
if $seen{join $;, $ident, $method}{$sub_pk}++ 0 0 0
2385 0 $parent_objects{$ident} = $parent_object;
2386 0 push(@{$subobjects{$ident}{$method}}, $subobject);
2387 }
2388 else
2389 {
2390 0 my $ident = refaddr $object;
2391 0 my $method = $subobject_methods[$i];
2392 0 ▶ next if($seen{$ident,$method}{$sub_pk}++);
Branch: 1 branch
BranchTrueFalseTotal
if $seen{join $;, $ident, $method}{$sub_pk}++ 0 0 0
2393 0 $parent_objects{$ident} = $object;
2394 0 push(@{$subobjects{$ident}{$method}}, $subobject);
2395 }
2396  
2397 0 push(@{$sub_objects[$i]}, $subobject);
2398 }
2399 }
2400 else # Otherwise, just assign it
2401 {
2402 0 $sub_objects[$i] = $subobject;
2403 0 my $parent_object;
2404  
2405 0 ▶ if(my $bt = $belongs_to[$i])
Branch: 1 branch
BranchTrueFalseTotal
if (my $bt = $belongs_to[$i]) { } 0 0 0
2406 {
2407 0 $parent_object = $sub_objects[$bt];
2408 # XXX: This relies on parent objects coming before
2409 # child objects in the list of tables in the FROM
2410 # clause.
2411 0 ▶ $parent_object = $parent_object->[-1] if(ref $parent_object eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $parent_object eq "ARRAY" 0 0 0
2412 }
2413 else
2414 {
2415 0 $parent_object = $object;
2416 }
2417  
2418 0 my $method = $subobject_methods[$i];
2419  
2420 # Only assign "... to one" values once
2421 0 ▶ next if($seen{refaddr $parent_object,$method}++);
Branch: 1 branch
BranchTrueFalseTotal
if $seen{join $;, builtin::refaddr($parent_object), $method}++ 0 0 0
2422  
2423 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2424 {
2425 0 $parent_object->{$method} = $subobject;
2426 }
2427 else
2428 {
2429 0 local $parent_object->{STATE_LOADING()} = 1;
2430 0 $parent_object->$method($subobject);
2431 }
2432 }
2433 }
2434  
2435 0 ▶ if($skip_first)
Branch: 1 branch
BranchTrueFalseTotal
if ($skip_first) 0 0 0
2436 {
2437 0 ▶ next ROW if($seen[0]{$pk} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $seen[0]{$pk} > 1 0 0 0
2438 0 ▶ ++$count if($seen[0]{$pk} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $seen[0]{$pk} == 1 0 0 0
2439 0 ▶ next ROW if($count <= $skip_first);
Branch: 1 branch
BranchTrueFalseTotal
if $count <= $skip_first 0 0 0
2440  
2441 0 $skip_first = 0;
2442 0 @objects = (); # Discard all skipped objects...
2443 0 $object_is_ready = 0; # ...so none are ready now
2444 0 next ROW;
2445 }
2446  
2447 0 ▶ if($object_is_ready)
Branch: 1 branch
BranchTrueFalseTotal
if ($object_is_ready) 0 0 0
2448 {
2449 0 $self->{'_count'}++;
2450 0 last ROW;
2451 }
2452  
2453 61 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2454 0 ▶ if($manual_limit && $self->{'_count'} == $manual_limit)
Branch: 1 branch
BranchTrueFalseTotal
if ($manual_limit and $self->{"_count"} == $manual_limit) 0 0 0
Condition0%0/3
$manual_limit and $self->{"_count"} == $manual_limit
!ll&&!rl&&r
000
MC/DC0%0/2
$manual_limit and $self->{"_count"} == $manual_limit
$manual_limit $self->{"_count"} == $manual_limit
Truth table0%0/3
A and B
A= $manual_limitB= $self->{"_count"} == $manual_limit
ABresult
0X0
100
111
2455 {
2456 0 $self->finish;
2457 0 last ROW;
2458 }
2459 }
2460  
2461 # Handle the left-over "last object" that needs to be finished and
2462 # added to the final list of objects to return.
2463 0 ▶ if($last_object && !$object_is_ready)
Branch: 1 branch
BranchTrueFalseTotal
if ($last_object and not $object_is_ready) 0 0 0
Condition0%0/3
$last_object and not $object_is_ready
!ll&&!rl&&r
000
MC/DC0%0/2
$last_object and not $object_is_ready
$last_object not $object_is_ready
Truth table0%0/3
A and not(B)
A= $last_objectB= not $object_is_ready
ABresult
0X0
100
111
2464 {
2465 #$Debug && warn "Finish straggler $object_class $last_object->{'id'}\n";
2466  
2467 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2468 {
2469 0 ▶ while(my($ident, $parent) = each(%parent_objects))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %parent_objects) 0 0 0
2470 {
2471 0 ▶ while(my($method, $subobjects) = each(%{$subobjects{$ident}}))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$subobjects{$ident};}) 0 0 0
2472 {
2473 0 $parent->{$method} = $subobjects;
2474 }
2475 }
2476 }
2477 else
2478 {
2479 0 ▶ while(my($ident, $parent) = each(%parent_objects))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %parent_objects) 0 0 0
2480 {
2481 0 local $parent->{STATE_LOADING()} = 1;
2482  
2483 0 ▶ while(my($method, $subobjects) = each(%{$subobjects{$ident}}))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$subobjects{$ident};}) 0 0 0
2484 {
2485 0 $parent->$method($subobjects);
2486 }
2487 }
2488 }
2489  
2490 0 push(@objects, $last_object);
2491  
2492 # Set everything up to return this object, then be done
2493 0 $last_object = undef;
2494 0 $self->{'_count'}++;
2495 0 $sth = undef;
2496 0 last ROW;
2497 }
2498  
2499 0 last ROW;
2500 }
2501 };
2502  
2503 0 $error = $@;
2504 }
2505  
2506 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
2507 {
2508 0 ▶ $self->error(ref $error ? $error : "next() - $error");
Branch: 1 branch
BranchTrueFalseTotal
ref $error ? : 0 0 0
2509 0 $class->handle_error($self);
2510 0 return undef;
2511 }
2512  
2513 0 ▶ @objects = () if($skip_first);
Branch: 1 branch
BranchTrueFalseTotal
if $skip_first 0 0 0
2514  
2515 0 ▶ if(@objects)
Branch: 1 branch
BranchTrueFalseTotal
if (@objects) 0 0 0
2516 {
2517 61 ▶ no warnings; # undef count okay
Subroutine BEGIN: called CC=1 SCAR=0.0
2518 0 ▶ if($manual_limit && $self->{'_count'} == $manual_limit)
Branch: 1 branch
BranchTrueFalseTotal
if ($manual_limit and $self->{"_count"} == $manual_limit) 0 0 0
Condition0%0/3
$manual_limit and $self->{"_count"} == $manual_limit
!ll&&!rl&&r
000
MC/DC0%0/2
$manual_limit and $self->{"_count"} == $manual_limit
$manual_limit $self->{"_count"} == $manual_limit
Truth table0%0/3
A and B
A= $manual_limitB= $self->{"_count"} == $manual_limit
ABresult
0X0
100
111
2519 {
2520 0 $self->total($self->{'_count'});
2521 0 $self->finish;
2522 }
2523  
2524 #$Debug && warn "Return $object_class $objects[-1]{'id'}\n";
2525 0 return shift(@objects);
2526 }
2527  
2528 #$Debug && warn "Return 0\n";
2529 0 return 0;
2530 0 });
2531  
2532 }
2533 else # no duplicate rows to handle
2534 {
2535 $iterator->_next_code(sub
2536 0 ▶ {
Subroutine __ANON__: not called CC=15 SCAR=54.8
2537 0 my($self) = shift;
2538  
2539 0 my $object = 0;
2540  
2541 0 my $error;
2542  
2543 TRY:
2544 {
2545 0 local $@;
2546  
2547 eval
2548 0 {
2549 0 ROW: for(;;)
2550 {
2551 0 ▶ unless($sth->fetch)
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth->fetch) 0 0 0
2552 {
2553 0 return 0;
2554 }
2555  
2556 0 ▶ next ROW if($skip_first && ++$count <= $skip_first);
Branch: 1 branch
BranchTrueFalseTotal
if $skip_first and ++$count <= $skip_first 0 0 0
Condition0%0/3
$skip_first and ++$count <= $skip_first
!ll&&!rl&&r
000
MC/DC0%0/2
$skip_first and ++$count <= $skip_first
$skip_first ++$count <= $skip_first
Truth table0%0/3
A and B
A= $skip_firstB= ++$count <= $skip_first
ABresult
0X0
100
111
2557  
2558 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2559 {
2560 0 $object = bless { STATE_IN_DB() => 1, %{$row{$object_class,0}}, %object_args }, $object_class;
2561 }
2562 else
2563 {
2564 0 $object = $object_class->new(%object_args);
2565  
2566 0 local $object->{STATE_LOADING()} = 1;
2567 0 $object->init(%{$row{$object_class,0}});
2568 0 $object->{STATE_IN_DB()} = 1;
2569 }
2570  
2571 0 my @sub_objects;
2572  
2573 0 ▶ if($with_objects)
Branch: 1 branch
BranchTrueFalseTotal
if ($with_objects) 0 0 0
2574 {
2575 0 foreach my $i (1 .. $num_subtables)
2576 {
2577 0 my $method = $subobject_methods[$i];
2578 0 my $class = $classes[$i];
2579  
2580 # Skip undefined subobjects
2581 0 ▶ next unless(grep { defined } values %{$row{$class,$i}});
Branch: 1 branch
BranchTrueFalseTotal
unless grep {defined $_;} values %{$row{join $;, $class, $i};} 0 0 0
2582  
2583 0 my $subobject;
2584  
2585 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2586 {
2587 0 $subobject = bless { STATE_IN_DB() => 1, %{$row{$class,$i}}, %subobject_args }, $class;
2588 }
2589 else
2590 {
2591 0 $subobject = $class->new(%subobject_args);
2592 0 local $subobject->{STATE_LOADING()} = 1;
2593 0 $subobject->init(%{$row{$class,$i}});
2594 0 $subobject->{STATE_IN_DB()} = 1;
2595 }
2596  
2597 0 $sub_objects[$i] = $subobject;
2598  
2599 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2600 {
2601 0 ▶ if(my $bt = $belongs_to[$i])
Branch: 1 branch
BranchTrueFalseTotal
if (my $bt = $belongs_to[$i]) { } 0 0 0
2602 {
2603 0 $sub_objects[$bt]->{$method} = $subobject;
2604 }
2605 else
2606 {
2607 0 $object->{$method} = $subobject;
2608 }
2609 }
2610 else
2611 {
2612 0 ▶ if(my $bt = $belongs_to[$i])
Branch: 1 branch
BranchTrueFalseTotal
if (my $bt = $belongs_to[$i]) { } 0 0 0
2613 {
2614 0 local $sub_objects[$bt]->{STATE_LOADING()} = 1;
2615 0 $sub_objects[$bt]->$method($subobject);
2616 }
2617 else
2618 {
2619 0 local $object->{STATE_LOADING()} = 1;
2620 0 $object->$method($subobject);
2621 }
2622 }
2623 }
2624 }
2625  
2626 0 $skip_first = 0;
2627 0 $self->{'_count'}++;
2628 0 last ROW;
2629 }
2630 };
2631  
2632 0 $error = $@;
2633 }
2634  
2635 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
2636 {
2637 0 ▶ $self->error(ref $error ? $error : "next() - $error");
Branch: 1 branch
BranchTrueFalseTotal
ref $error ? : 0 0 0
2638 0 $class->handle_error($self);
2639 0 return undef;
2640 }
2641  
2642 0 ▶ return $skip_first ? undef : $object;
Branch: 1 branch
BranchTrueFalseTotal
$skip_first ? : 0 0 0
2643 0 });
2644 }
2645 }
2646 else # no sub-objects at all
2647 {
2648 $iterator->_next_code(sub
2649 0 ▶ {
Subroutine __ANON__: not called CC=7 SCAR=40.3
2650 0 my($self) = shift;
2651  
2652 0 my $object = 0;
2653  
2654 0 my $error;
2655  
2656 TRY:
2657 {
2658 0 local $@;
2659  
2660 eval
2661 0 {
2662 0 ROW: for(;;)
2663 {
2664 0 ▶ unless($sth->fetch)
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth->fetch) 0 0 0
2665 {
2666 #$self->total($self->{'_count'});
2667 0 return 0;
2668 }
2669  
2670 0 ▶ next ROW if($skip_first && ++$count <= $skip_first);
Branch: 1 branch
BranchTrueFalseTotal
if $skip_first and ++$count <= $skip_first 0 0 0
Condition0%0/3
$skip_first and ++$count <= $skip_first
!ll&&!rl&&r
000
MC/DC0%0/2
$skip_first and ++$count <= $skip_first
$skip_first ++$count <= $skip_first
Truth table0%0/3
A and B
A= $skip_firstB= ++$count <= $skip_first
ABresult
0X0
100
111
2671  
2672 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2673 {
2674 0 $object = bless { STATE_IN_DB() => 1, %{$row{$object_class,0}}, %object_args }, $object_class;
2675 }
2676 else
2677 {
2678 0 $object = $object_class->new(%object_args);
2679  
2680 0 local $object->{STATE_LOADING()} = 1;
2681 0 $object->init(%{$row{$object_class,0}});
2682 0 $object->{STATE_IN_DB()} = 1;
2683 }
2684  
2685 0 $skip_first = 0;
2686 0 $self->{'_count'}++;
2687 0 last ROW;
2688 }
2689 };
2690  
2691 0 $error = $@;
2692 }
2693  
2694 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
2695 {
2696 0 ▶ $self->error(ref $error ? $error : "next() - $error");
Branch: 1 branch
BranchTrueFalseTotal
ref $error ? : 0 0 0
2697 0 $class->handle_error($self);
2698 0 return undef;
2699 }
2700  
2701 0 return $object;
2702 0 });
2703 }
2704  
2705 $iterator->_finish_code(sub
2706 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
2707 0 ▶ $sth->finish if($sth);
Branch: 1 branch
BranchTrueFalseTotal
if $sth 0 0 0
2708 0 ▶ $db->release_dbh if($db && $dbh_retained);
Branch: 1 branch
BranchTrueFalseTotal
if $db and $dbh_retained 0 0 0
Condition0%0/3
$db and $dbh_retained
!ll&&!rl&&r
000
MC/DC0%0/2
$db and $dbh_retained
$db $dbh_retained
Truth table0%0/3
A and B
A= $dbB= $dbh_retained
ABresult
0X0
100
111
2709 0 $sth = undef;
2710 0 $db = undef;
2711 0 });
2712  
2713 $iterator->_destroy_code(sub
2714 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
2715 0 ▶ $db->release_dbh if($db && $dbh_retained);
Branch: 1 branch
BranchTrueFalseTotal
if $db and $dbh_retained 0 0 0
Condition0%0/3
$db and $dbh_retained
!ll&&!rl&&r
000
MC/DC0%0/2
$db and $dbh_retained
$db $dbh_retained
Truth table0%0/3
A and B
A= $dbB= $dbh_retained
ABresult
0X0
100
111
2716 0 $sth = undef;
2717 0 $db = undef;
2718 0 });
2719  
2720 0 return $iterator;
2721 }
2722  
2723 0 $count = 0;
2724  
2725 0 ▶ if($with_objects)
Branch: 1 branch
BranchTrueFalseTotal
if ($with_objects) { } 0 0 0
2726 {
2727 # This "if" clause is a totally separate code path for handling
2728 # duplicates rows. I'm doing this for performance reasons.
2729 0 ▶ if($handle_dups)# || $deep_joins)
Branch: 1 branch
BranchTrueFalseTotal
if ($handle_dups) { } 0 0 0
2730 {
2731 0 my(@seen, %seen, @sub_objects);
2732  
2733 #my @pk_columns = $meta->primary_key_column_names;
2734 0 my $pk_columns = $meta->primary_key_column_names_or_aliases;
2735  
2736 # Get list of primary key columns for each sub-table
2737 0 my @sub_pk_columns;
2738  
2739 0 foreach my $i (1 .. $num_subtables)
2740 {
2741 #$sub_pk_columns[$i + 1] = [ $classes[$i]->meta->primary_key_column_names ];
2742 0 $sub_pk_columns[$i + 1] = $classes[$i]->meta->primary_key_column_names_or_aliases;
2743 }
2744  
2745 0 my($last_object, %subobjects, %parent_objects);
2746  
2747 0 ▶ ROW: while($sth->fetch)
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
2748 {
2749 0 my $pk = join(PK_JOIN, map { $row{$object_class,0}{$_} } @$pk_columns);
2750  
2751 0 my $object;
2752  
2753 # If this is a new main (t1) table row that we haven't seen before
2754 0 ▶ unless($seen[0]{$pk}++)
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen[0]{$pk}++) 0 0 0
2755 {
2756 # First, finish building the last object, if it exists
2757 0 ▶ if($last_object)
Branch: 1 branch
BranchTrueFalseTotal
if ($last_object) 0 0 0
2758 {
2759 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2760 {
2761 0 ▶ while(my($ident, $parent) = each(%parent_objects))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %parent_objects) 0 0 0
2762 {
2763 0 ▶ while(my($method, $subobjects) = each(%{$subobjects{$ident}}))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$subobjects{$ident};}) 0 0 0
2764 {
2765 0 $parent->{$method} = $subobjects; # XXX
2766 }
2767 }
2768 }
2769 else
2770 {
2771 0 ▶ while(my($ident, $parent) = each(%parent_objects))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %parent_objects) 0 0 0
2772 {
2773 0 local $parent->{STATE_LOADING()} = 1;
2774  
2775 0 ▶ while(my($method, $subobjects) = each(%{$subobjects{$ident}}))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$subobjects{$ident};}) 0 0 0
2776 {
2777 0 $parent->$method($subobjects);
2778 }
2779 }
2780 }
2781  
2782 0 %subobjects = ();
2783 0 %parent_objects = ();
2784  
2785 # Add the object to the final list of objects that we'll return
2786 0 push(@objects, $last_object);
2787  
2788 0 ▶ if(!$skip_first && $manual_limit && @objects == $manual_limit)
Branch: 1 branch
BranchTrueFalseTotal
if (not $skip_first and $manual_limit and @objects == $manual_limit) 0 0 0
Condition0%0/6
not $skip_first and $manual_limit and @objects == $manual_limit
!ll&&!rl&&r
000
not $skip_first and $manual_limit
!ll&&!rl&&r
000
MC/DC0%0/3
not $skip_first and $manual_limit and @objects == $manual_limit
not $skip_first $manual_limit @objects == $manual_limit
Truth table0%0/4
not(A) and B and C
A= not $skip_firstB= $manual_limitC= @objects == $manual_limit
ABCresult
0XX0
10X0
1100
1111
2789 {
2790 0 last ROW;
2791 }
2792 }
2793  
2794 # Now, create the object from this new main table row
2795 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2796 {
2797 0 $object = bless { STATE_IN_DB() => 1, %{$row{$object_class,0}}, %object_args }, $object_class;
2798 }
2799 else
2800 {
2801 0 $object = $object_class->new(%object_args);
2802  
2803 0 local $object->{STATE_LOADING()} = 1;
2804 0 $object->init(%{$row{$object_class,0}});
2805 0 $object->{STATE_IN_DB()} = 1;
2806 }
2807  
2808 0 $last_object = $object; # This is the "last object" from now on.
2809 0 @sub_objects = (); # The list of sub-objects is per-object.
2810 0 splice(@seen, 1); # Sub-objects seen is also per-object,
2811 # so trim it, but leave the t1 table info.
2812 0 %seen = (); # Wipe sub-object parent tracking.
2813 }
2814  
2815 0 ▶ $object ||= $last_object or die "Missing object for primary key '$pk'";
Branch: 1 branch
BranchTrueFalseTotal
$object ||= $last_object or die "Missing object for primary key '${pk}'" 0 0 0
Condition0%0/3
$object ||= $last_object
l!l&&r!l&&!r
000
MC/DC0%0/2
$object ||= $last_object
$object $last_object
Truth table0%0/3
A ||= B
A= $objectB= $last_object
ABresult
1X1
011
000
2816  
2817 0 my $map_record;
2818  
2819 0 foreach my $i (1 .. $num_subtables)
2820 {
2821 0 my $mapped_object_method = $mapped_object_methods[$i];
2822 0 ▶ next if(defined $mapped_object_method && !$mapped_object_method);
Branch: 1 branch
BranchTrueFalseTotal
if defined $mapped_object_method and not $mapped_object_method 0 0 0
Condition0%0/3
defined $mapped_object_method and not $mapped_object_method
!ll&&!rl&&r
000
MC/DC0%0/2
defined $mapped_object_method and not $mapped_object_method
defined $mapped_object_method not $mapped_object_method
Truth table0%0/3
A and not(B)
A= defined $mapped_object_methodB= not $mapped_object_method
ABresult
0X0
100
111
2823  
2824 0 my $class = $classes[$i];
2825 0 my $tn = $i + 1;
2826  
2827 # Null primary key columns are not allowed
2828 0 my $sub_pk = join(PK_JOIN, grep { defined } map { $row{$class,$i}{$_} } @{$sub_pk_columns[$tn]});
2829 0 ▶ next unless(length $sub_pk);
Branch: 1 branch
BranchTrueFalseTotal
unless length $sub_pk 0 0 0
2830  
2831 0 my $subobject = $seen[$i]{$sub_pk};
2832  
2833 0 ▶ unless($subobject)
Branch: 1 branch
BranchTrueFalseTotal
unless ($subobject) 0 0 0
2834 {
2835 # Make sub-object
2836 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2837 {
2838 0 $subobject = bless { STATE_IN_DB() => 1, %{$row{$class,$i}}, %subobject_args }, $class;
2839 }
2840 else
2841 {
2842 0 $subobject = $class->new(%subobject_args);
2843 0 local $subobject->{STATE_LOADING()} = 1;
2844 0 $subobject->init(%{$row{$class,$i}});
2845 0 $subobject->{STATE_IN_DB()} = 1;
2846 }
2847  
2848 0 $seen[$i]{$sub_pk} = $subobject;
2849 }
2850  
2851 # If this object belongs to an attribute that can have more
2852 # than one object then just save it for later in the
2853 # per-object sub-objects list.
2854 0 ▶ if($has_dups[$i])
Branch: 1 branch
BranchTrueFalseTotal
if ($has_dups[$i]) { } 0 0 0
2855 {
2856 0 ▶ if($mapped_object_method)
Branch: 1 branch
BranchTrueFalseTotal
if ($mapped_object_method) { } 0 0 0
2857 {
2858 0 $map_record = $subobject;
2859 }
2860 else
2861 {
2862 0 ▶ if($map_record)
Branch: 1 branch
BranchTrueFalseTotal
if ($map_record) 0 0 0
2863 {
2864 0 ▶ my $method = $mapped_object_methods[$i - 1] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $method = $mapped_object_methods[$i - 1] or next 0 0 0
2865  
2866 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2867 {
2868 0 $subobject->{$method} = $map_record;
2869 }
2870 else
2871 {
2872 0 local $subobject->{STATE_LOADING()} = 1;
2873 0 $subobject->$method($map_record);
2874 }
2875  
2876 0 $map_record = 0;
2877 }
2878  
2879 0 ▶ next if(defined $mapped_object_methods[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $mapped_object_methods[$i] 0 0 0
2880  
2881 0 ▶ if($has_dups[$i] && (my $bt = $belongs_to[$i]))
Branch: 1 branch
BranchTrueFalseTotal
if ($has_dups[$i] and my $bt = $belongs_to[$i]) { } 0 0 0
Condition0%0/3
$has_dups[$i] and my $bt = $belongs_to[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
$has_dups[$i] and my $bt = $belongs_to[$i]
$has_dups[$i] my $bt = $belongs_to[$i]
Truth table0%0/3
A and B
A= $has_dups[$i]B= my $bt = $belongs_to[$i]
ABresult
0X0
100
111
2882 {
2883 #$subobjects_belong_to[$i] = $#{$sub_objects[$bt]};
2884  
2885 0 my $parent_object = $sub_objects[$bt];
2886  
2887 # XXX: Special heavyweight subobject pairing in multi-many queries
2888 0 ▶ if($multi_many && ref $parent_object eq 'ARRAY' && @$parent_object > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($multi_many and ref $parent_object eq "ARRAY" and @$parent_object > 1) 0 0 0
Condition0%0/6
$multi_many and ref $parent_object eq "ARRAY" and @$parent_object > 1
!ll&&!rl&&r
000
$multi_many and ref $parent_object eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
$multi_many and ref $parent_object eq "ARRAY" and @$parent_object > 1
$multi_many ref $parent_object eq "ARRAY" @$parent_object > 1
Truth table0%0/4
A and B and C
A= $multi_manyB= ref $parent_object eq "ARRAY"C= @$parent_object > 1
ABCresult
0XX0
10X0
1100
1111
2889 {
2890 0 my $maps = $subobject_method_map[$i + 1][$bt];
2891 0 my %check;
2892  
2893 0 foreach my $map (@$maps)
2894 {
2895 0 my $subobject_method = $map->[1];
2896 0 $check{$subobject_method} = $subobject->$subobject_method();
2897 }
2898  
2899 0 PARENT: foreach my $check_parent (reverse @$parent_object)
2900 {
2901 0 foreach my $map (@$maps)
2902 {
2903 0 my $parent_method = $map->[0];
2904 0 ▶ next PARENT unless($check_parent->$parent_method() eq $check{$map->[1]});
Branch: 1 branch
BranchTrueFalseTotal
unless $check_parent->$parent_method eq $check{$map->[1]} 0 0 0
2905 }
2906  
2907 0 $parent_object = $check_parent;
2908 0 last PARENT;
2909 }
2910 }
2911  
2912 # XXX: This relies on parent objects coming before child
2913 # objects in the list of tables in the FROM clause.
2914 0 ▶ $parent_object = $parent_object->[-1] #$parent_object->[$subobjects_belong_to[$i]]
Branch: 1 branch
BranchTrueFalseTotal
if ref $parent_object eq "ARRAY" 0 0 0
2915 if(ref $parent_object eq 'ARRAY');
2916  
2917 0 my $method = $subobject_methods[$i];
2918  
2919 0 my $ident = refaddr $parent_object;
2920 0 ▶ next if($seen{$ident,$method}{$sub_pk}++);
Branch: 1 branch
BranchTrueFalseTotal
if $seen{join $;, $ident, $method}{$sub_pk}++ 0 0 0
2921 0 $parent_objects{$ident} = $parent_object;
2922 0 push(@{$subobjects{$ident}{$method}}, $subobject);
2923 }
2924 else
2925 {
2926 0 my $ident = refaddr $object;
2927 0 my $method = $subobject_methods[$i];
2928 0 ▶ next if($seen{$ident,$method}{$sub_pk}++);
Branch: 1 branch
BranchTrueFalseTotal
if $seen{join $;, $ident, $method}{$sub_pk}++ 0 0 0
2929 0 $parent_objects{$ident} = $object;
2930 0 push(@{$subobjects{$ident}{$method}}, $subobject);
2931 }
2932  
2933 0 push(@{$sub_objects[$i]}, $subobject);
2934 }
2935 }
2936 else # Otherwise, just assign it
2937 {
2938 0 push(@{$sub_objects[$i]}, $subobject);
2939  
2940 0 my $parent_object;
2941  
2942 0 ▶ if(my $bt = $belongs_to[$i])
Branch: 1 branch
BranchTrueFalseTotal
if (my $bt = $belongs_to[$i]) { } 0 0 0
2943 {
2944 0 $parent_object = $sub_objects[$bt];
2945 # XXX: This relies on parent objects coming before child
2946 # objects in the list of tables in the FROM clause.
2947 0 ▶ $parent_object = $parent_object->[-1] if(ref $parent_object eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $parent_object eq "ARRAY" 0 0 0
2948 }
2949 else
2950 {
2951 0 $parent_object = $object;
2952 }
2953  
2954 0 my $method = $subobject_methods[$i];
2955  
2956 # Only assign "... to one" values once
2957 0 ▶ next if($seen{refaddr $parent_object,$method}++);
Branch: 1 branch
BranchTrueFalseTotal
if $seen{join $;, builtin::refaddr($parent_object), $method}++ 0 0 0
2958  
2959 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2960 {
2961 0 $parent_object->{$method} = $subobject;
2962 }
2963 else
2964 {
2965 0 local $parent_object->{STATE_LOADING()} = 1;
2966 0 $parent_object->$method($subobject);
2967 }
2968 }
2969 }
2970  
2971 0 ▶ if($skip_first)
Branch: 1 branch
BranchTrueFalseTotal
if ($skip_first) 0 0 0
2972 {
2973 0 ▶ next ROW if($seen[0]{$pk} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $seen[0]{$pk} > 1 0 0 0
2974 0 ▶ next ROW if(@objects < $skip_first);
Branch: 1 branch
BranchTrueFalseTotal
if @objects < $skip_first 0 0 0
2975  
2976 0 $skip_first = 0;
2977 0 @objects = (); # Discard all skipped objects
2978 0 next ROW;
2979 }
2980 }
2981  
2982 # Handle the left-over "last object" that needs to be finished and
2983 # added to the final list of objects to return.
2984 0 ▶ if($last_object && !$skip_first)
Branch: 1 branch
BranchTrueFalseTotal
if ($last_object and not $skip_first) 0 0 0
Condition0%0/3
$last_object and not $skip_first
!ll&&!rl&&r
000
MC/DC0%0/2
$last_object and not $skip_first
$last_object not $skip_first
Truth table0%0/3
A and not(B)
A= $last_objectB= not $skip_first
ABresult
0X0
100
111
2985 {
2986 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
2987 {
2988 0 ▶ while(my($ident, $parent) = each(%parent_objects))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %parent_objects) 0 0 0
2989 {
2990 0 ▶ while(my($method, $subobjects) = each(%{$subobjects{$ident}}))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$subobjects{$ident};}) 0 0 0
2991 {
2992 0 $parent->{$method} = $subobjects; # XXX
2993 }
2994 }
2995 }
2996 else
2997 {
2998 0 ▶ while(my($ident, $parent) = each(%parent_objects))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %parent_objects) 0 0 0
2999 {
3000 0 local $parent->{STATE_LOADING()} = 1;
3001  
3002 0 ▶ while(my($method, $subobjects) = each(%{$subobjects{$ident}}))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$subobjects{$ident};}) 0 0 0
3003 {
3004 0 $parent->$method($subobjects);
3005 }
3006 }
3007 }
3008  
3009 0 ▶ unless($manual_limit && @objects >= $manual_limit)
Branch: 1 branch
BranchTrueFalseTotal
unless ($manual_limit and @objects >= $manual_limit) 0 0 0
Condition0%0/3
$manual_limit and @objects >= $manual_limit
!ll&&!rl&&r
000
MC/DC0%0/2
$manual_limit and @objects >= $manual_limit
$manual_limit @objects >= $manual_limit
Truth table0%0/3
A and B
A= $manual_limitB= @objects >= $manual_limit
ABresult
0X0
100
111
3010 {
3011 0 push(@objects, $last_object);
3012 }
3013 }
3014  
3015 0 ▶ @objects = () if($skip_first);
Branch: 1 branch
BranchTrueFalseTotal
if $skip_first 0 0 0
3016 }
3017 else # simple sub-objects case: nothing worse than one-to-one relationships
3018 {
3019 0 ▶ if($skip_first)
Branch: 1 branch
BranchTrueFalseTotal
if ($skip_first) 0 0 0
3020 {
3021 0 ▶ while($sth->fetch)
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
3022 {
3023 0 ▶ next if(++$count < $skip_first);
Branch: 1 branch
BranchTrueFalseTotal
if ++$count < $skip_first 0 0 0
3024 0 last;
3025 }
3026 }
3027  
3028 0 ▶ while($sth->fetch)
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
3029 {
3030 0 my $object;
3031  
3032 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
3033 {
3034 0 $object = bless { STATE_IN_DB() => 1, %{$row{$object_class,0}}, %object_args }, $object_class;
3035 }
3036 else
3037 {
3038 0 $object = $object_class->new(%object_args);
3039  
3040 0 local $object->{STATE_LOADING()} = 1;
3041 0 $object->init(%{$row{$object_class,0}});
3042 0 $object->{STATE_IN_DB()} = 1;
3043 }
3044  
3045 0 my @sub_objects;
3046  
3047 0 foreach my $i (1 .. $num_subtables)
3048 {
3049 0 my $method = $subobject_methods[$i];
3050 0 my $class = $classes[$i];
3051  
3052 # Skip undefined subobjects
3053 0 ▶ next unless(grep { defined } values %{$row{$class,$i}});
Branch: 1 branch
BranchTrueFalseTotal
unless grep {defined $_;} values %{$row{join $;, $class, $i};} 0 0 0
3054  
3055 0 my $subobject;
3056  
3057 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
3058 {
3059 0 $subobject = bless { STATE_IN_DB() => 1, %{$row{$class,$i}}, %subobject_args }, $class;
3060 }
3061 else
3062 {
3063 0 $subobject = $class->new(%subobject_args);
3064 0 local $subobject->{STATE_LOADING()} = 1;
3065 0 $subobject->init(%{$row{$class,$i}});
3066 0 $subobject->{STATE_IN_DB()} = 1;
3067 }
3068  
3069 0 $sub_objects[$i] = $subobject;
3070  
3071 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
3072 {
3073 0 ▶ if(my $bt = $belongs_to[$i])
Branch: 1 branch
BranchTrueFalseTotal
if (my $bt = $belongs_to[$i]) { } 0 0 0
3074 {
3075 0 $sub_objects[$bt]->{$method} = $subobject;
3076 }
3077 else
3078 {
3079 0 $object->{$method} = $subobject;
3080 }
3081 }
3082 else
3083 {
3084 0 ▶ if(my $bt = $belongs_to[$i])
Branch: 1 branch
BranchTrueFalseTotal
if (my $bt = $belongs_to[$i]) { } 0 0 0
3085 {
3086 0 local $sub_objects[$bt]->{STATE_LOADING()} = 1;
3087 0 $sub_objects[$bt]->$method($subobject);
3088 }
3089 else
3090 {
3091 0 local $object->{STATE_LOADING()} = 1;
3092 0 $object->$method($subobject);
3093 }
3094 }
3095 }
3096  
3097 0 push(@objects, $object);
3098 }
3099 }
3100 }
3101 else # even simpler: no sub-objects at all
3102 {
3103 0 ▶ if($skip_first)
Branch: 1 branch
BranchTrueFalseTotal
if ($skip_first) 0 0 0
3104 {
3105 0 ▶ while($sth->fetch)
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
3106 {
3107 0 ▶ next if(++$count < $skip_first);
Branch: 1 branch
BranchTrueFalseTotal
if ++$count < $skip_first 0 0 0
3108 0 last;
3109 }
3110 }
3111  
3112 0 ▶ if($direct_inject)
Branch: 1 branch
BranchTrueFalseTotal
if ($direct_inject) { } 0 0 0
3113 {
3114 0 my $key_map = $di_keys{$object_class};
3115  
3116 0 ▶ while($sth->fetch)
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
3117 {
3118 0 push(@objects, bless { STATE_IN_DB() => 1, %{$row{$object_class,0}}, %object_args }, $object_class);
3119 }
3120 }
3121 else
3122 {
3123 0 ▶ while($sth->fetch)
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->fetch) 0 0 0
3124 {
3125 0 my $object = $object_class->new(%object_args);
3126  
3127 0 local $object->{STATE_LOADING()} = 1;
3128 0 $object->init(%{$row{$object_class,0}});
3129 0 $object->{STATE_IN_DB()} = 1;
3130  
3131 0 push(@objects, $object);
3132 }
3133 }
3134 }
3135  
3136 0 $sth->finish;
3137 };
3138  
3139 0 $error = $@;
3140 }
3141  
3142 0 ▶ return $iterator if($iterator);
Branch: 1 branch
BranchTrueFalseTotal
if $iterator 0 0 0
3143  
3144 0 ▶ $db->release_dbh if($dbh_retained);
Branch: 1 branch
BranchTrueFalseTotal
if $dbh_retained 0 0 0
3145  
3146 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
3147 {
3148 0 ▶ $class->error(ref $error ? $error : "get_objects() - $error");
Branch: 1 branch
BranchTrueFalseTotal
ref $error ? : 0 0 0
3149 0 $class->handle_error($class);
3150 0 return undef;
3151 }
3152  
3153 0 return \@objects;
3154 }
3155  
3156 sub _map_action
3157 0 ▶{
Subroutine _map_action: not called CC=3 SCAR=24.8
3158 0 my($class, $action, @objects) = @_;
3159  
3160 0 $class->error(undef);
3161  
3162 0 foreach my $object (@objects)
3163 {
3164 0 ▶ unless($object->$action())
Branch: 1 branch
BranchTrueFalseTotal
unless ($object->$action) 0 0 0
3165 {
3166 0 $class->error($object->error);
3167 0 $class->handle_error($class);
3168 0 return;
3169 }
3170 }
3171  
3172 0 return 1;
3173 }
3174  
3175 0 ▶sub save_objects { shift->_map_action('save', @_) }
Subroutine save_objects: not called CC=1 SCAR=6.9
Pod undocumented
3176  
3177 sub delete_objects
3178 0 ▶{
Subroutine delete_objects: not called CC=30 SCAR=68.4
Pod documented
3179 0 my($class, %args);
3180  
3181 0 ▶ if(ref $_[1])
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[1]) { } 0 0 0
3182 {
3183 0 $class = shift;
3184  
3185 0 ▶ if(ref $_[0] eq 'HASH')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
elsif (ref $_[0] eq 'ARRAY') { } 0 0 0
3186 {
3187 0 %args = (where => [ %{shift(@_)} ], @_);
3188 }
3189 elsif(ref $_[0] eq 'ARRAY')
3190 {
3191 0 %args = (where => shift, @_);
3192 }
3193 0 else { Carp::croak 'Invalid arguments: ', join(', ', @_) }
3194  
3195 0 unshift(@_, $class); # restore original args
3196 }
3197 else
3198 {
3199 0 ($class, %args) = @_;
3200 }
3201  
3202 0 $class->error(undef);
3203  
3204 0 ▶ my $object_class = $args{'object_class'} || $class->object_class
Branch: 1 branch
BranchTrueFalseTotal
my $object_class = $args{"object_class"} || $class->object_class or Carp::croak("Missing object class argument") 0 0 0
Condition0%0/3
$args{'object_class'} || $class->object_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'object_class'} || $class->object_class
$args{'object_class'} $class->object_class
Truth table0%0/3
A || B
A= $args{'object_class'}B= $class->object_class
ABresult
1X1
011
000
3205 or Carp::croak "Missing object class argument";
3206  
3207 0 my $meta = $object_class->meta;
3208  
3209 my $prepare_cached =
3210 0 ▶ exists $args{'prepare_cached'} ? $args{'prepare_cached'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'prepare_cached'} ? : 0 0 0
3211 $class->dbi_prepare_cached;
3212  
3213 0 ▶ my $db = $args{'db'} ||= $object_class->init_db;
Condition0%0/3
$args{"db"} ||= $object_class->init_db
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"db"} ||= $object_class->init_db
$args{"db"} $object_class->init_db
Truth table0%0/3
A ||= B
A= $args{"db"}B= $object_class->init_db
ABresult
1X1
011
000
3214 0 my $dbh = $args{'dbh'};
3215 0 my $dbh_retained = 0;
3216  
3217 0 ▶ unless($dbh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh) 0 0 0
3218 {
3219 0 ▶ unless($dbh = $db->retain_dbh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh = $db->retain_dbh) 0 0 0
3220 {
3221 0 $class->error($db->error);
3222 0 $class->handle_error($class);
3223 0 return undef;
3224 }
3225  
3226 0 $args{'dbh'} = $dbh;
3227 0 $dbh_retained = 1;
3228 }
3229  
3230 0 $args{'query'} = delete $args{'where'};
3231  
3232 0 ▶ unless(($args{'query'} && @{$args{'query'}}) ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"query"} and @{$args{"query"};} or $args{"clauses"} and @{$args{"clauses"};} or delete $args{"all"}) 0 0 0
Condition0%0/12
$args{"query"} and @{$args{"query"};} or $args{"clauses"} and @{$args{"clauses"};} or delete $args{"all"}
l!l&&r!l&&!r
000
$args{"query"} and @{$args{"query"};} or $args{"clauses"} and @{$args{"clauses"};}
l!l&&r!l&&!r
000
$args{"query"} and @{$args{"query"};}
!ll&&!rl&&r
000
$args{"clauses"} and @{$args{"clauses"};}
!ll&&!rl&&r
000
MC/DC0%0/5
$args{"query"} and @{$args{"query"};} or $args{"clauses"} and @{$args{"clauses"};} or delete $args{"all"}
$args{"query"} @{$args{"query"};} $args{"clauses"} @{$args{"clauses"};} delete $args{"all"}
Truth table0%0/11
A and B or C and D or E
A= $args{"query"}B= @{$args{"query"};}C= $args{"clauses"}D= @{$args{"clauses"};}E= delete $args{"all"}
ABCDEresult
11XXX1
0X11X1
1011X1
0X0X11
0X1011
100X11
101011
0X0X00
0X1000
100X00
101000
3233 0 ($args{'clauses'} && @{$args{'clauses'}}) ||
3234 delete $args{'all'})
3235 {
3236 0 Carp::croak "$class - Refusing to delete all rows from the table '",
3237 $meta->fq_table($db), "' without an explict ",
3238 "'all => 1' parameter. (No 'where' or 'clauses' parameters ",
3239 "were passed to limit the scope of the delete operation.)";
3240 }
3241  
3242 0 ▶ if($args{'query'} && @{$args{'query'}} && $args{'all'})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"query"} and @{$args{"query"};} and $args{"all"}) 0 0 0
Condition0%0/6
$args{"query"} and @{$args{"query"};} and $args{"all"}
!ll&&!rl&&r
000
$args{"query"} and @{$args{"query"};}
!ll&&!rl&&r
000
MC/DC0%0/3
$args{"query"} and @{$args{"query"};} and $args{"all"}
$args{"query"} @{$args{"query"};} $args{"all"}
Truth table0%0/4
A and B and C
A= $args{"query"}B= @{$args{"query"};}C= $args{"all"}
ABCresult
0XX0
10X0
1100
1111
3243 {
3244 0 Carp::croak "Illegal use of the 'where' and 'all' parameters in the same call";
3245 }
3246  
3247 # Yes, I'm re-using get_objects() code like crazy, and often
3248 # in weird ways. Shhhh, it's a secret.
3249  
3250 0 my @bind_params;
3251 0 $args{'bind_params'} = \@bind_params;
3252  
3253 # Avert your eyes...
3254 0 my($where, $bind) =
3255 $class->get_objects(%args, return_sql => 1, where_only => 1, table_aliases => undef);
3256  
3257 0 ▶ my $sql = 'DELETE FROM ' . $meta->fq_table_sql($db) .
Branch: 1 branch
BranchTrueFalseTotal
$where ? : 0 0 0
3258 ($where ? " WHERE\n$where" : '');
3259  
3260 0 my($count, $error);
3261  
3262 TRY:
3263 {
3264 0 local $@;
3265  
3266 eval
3267 0 {
3268 0 local $dbh->{'RaiseError'} = 1;
3269 0 ▶ $Debug && warn "$sql - bind params: ", join(', ', @$bind), "\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Object::Manager::Debug and warn "$sql - bind params: ", join(", ", @$bind), "\n" 0 0 0
3270  
3271 # $meta->prepare_bulk_delete_options (defunct)
3272 0 ▶ my $sth = $prepare_cached ? $dbh->prepare_cached($sql, undef, 3) :
Branch: 2 branches
BranchTrueFalseTotal
my $sth = $prepare_cached ? $dbh->prepare_cached($sql, undef, 3) : $dbh->prepare($sql) or die $dbh->errstr 0 0 0
$prepare_cached ? : 0 0 0
3273 $dbh->prepare($sql) or die $dbh->errstr;
3274  
3275 0 my $rv;
3276  
3277 0 ▶ if(@bind_params)
Branch: 1 branch
BranchTrueFalseTotal
if (@bind_params) { } 0 0 0
3278 {
3279 0 my $i = 1;
3280  
3281 0 foreach my $value (@$bind)
3282 {
3283 0 $sth->bind_param($i, $value, $bind_params[$i - 1]);
3284 0 $i++;
3285 }
3286  
3287 0 $rv = $sth->execute;
3288 }
3289 else
3290 {
3291 0 $rv = $sth->execute(@$bind);
3292 }
3293  
3294 0 ▶ $count = $sth->rows || 0;
Condition0%0/2
$sth->rows || 0
l!l
00
MC/DC0%0/1
$sth->rows || 0
$sth->rows
Truth table0%0/2
A
A= $sth->rows
Aresult
11
00
3295 0 ▶ $count = $rv if($count < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $count < 0 0 0 0
3296 0 ▶ $count = 0 if(defined $count && $count eq '0E0');
Branch: 1 branch
BranchTrueFalseTotal
if defined $count and $count eq "0E0" 0 0 0
Condition0%0/3
defined $count and $count eq "0E0"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $count and $count eq "0E0"
defined $count $count eq "0E0"
Truth table0%0/3
A and B
A= defined $countB= $count eq "0E0"
ABresult
0X0
100
111
3297 };
3298  
3299 0 $error = $@;
3300 }
3301  
3302 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
3303 {
3304 0 ▶ $class->error(ref $error ? $error : "delete_objects() - $error");
Branch: 1 branch
BranchTrueFalseTotal
ref $error ? : 0 0 0
3305 0 $class->handle_error($class);
3306 0 return undef;
3307 }
3308  
3309 0 return $count;
3310 }
3311  
3312 sub update_objects
3313 0 ▶{
Subroutine update_objects: not called CC=25 SCAR=64.8
Pod documented
3314 0 my($class, %args) = @_;
3315  
3316 0 $class->error(undef);
3317  
3318 0 ▶ my $object_class = $args{'object_class'} || $class->object_class
Branch: 1 branch
BranchTrueFalseTotal
my $object_class = $args{"object_class"} || $class->object_class or Carp::croak("Missing object class argument") 0 0 0
Condition0%0/3
$args{'object_class'} || $class->object_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'object_class'} || $class->object_class
$args{'object_class'} $class->object_class
Truth table0%0/3
A || B
A= $args{'object_class'}B= $class->object_class
ABresult
1X1
011
000
3319 or Carp::croak "Missing object class argument";
3320  
3321 0 my $meta = $object_class->meta;
3322  
3323 my $prepare_cached =
3324 0 ▶ exists $args{'prepare_cached'} ? $args{'prepare_cached'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'prepare_cached'} ? : 0 0 0
3325 $class->dbi_prepare_cached;
3326  
3327 0 ▶ my $db = $args{'db'} ||= $object_class->init_db;
Condition0%0/3
$args{"db"} ||= $object_class->init_db
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"db"} ||= $object_class->init_db
$args{"db"} $object_class->init_db
Truth table0%0/3
A ||= B
A= $args{"db"}B= $object_class->init_db
ABresult
1X1
011
000
3328 0 my $dbh = $args{'dbh'};
3329 0 my $dbh_retained = 0;
3330  
3331 0 ▶ unless($dbh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh) 0 0 0
3332 {
3333 0 ▶ unless($dbh = $db->retain_dbh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh = $db->retain_dbh) 0 0 0
3334 {
3335 0 $class->error($db->error);
3336 0 $class->handle_error($class);
3337 0 return undef;
3338 }
3339  
3340 0 $args{'dbh'} = $dbh;
3341 0 $dbh_retained = 1;
3342 }
3343  
3344 0 ▶ unless(($args{'where'} && @{$args{'where'}}) || delete $args{'all'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"where"} and @{$args{"where"};} or delete $args{"all"}) 0 0 0
Condition0%0/6
$args{"where"} and @{$args{"where"};} or delete $args{"all"}
l!l&&r!l&&!r
000
$args{"where"} and @{$args{"where"};}
!ll&&!rl&&r
000
MC/DC0%0/3
$args{"where"} and @{$args{"where"};} or delete $args{"all"}
$args{"where"} @{$args{"where"};} delete $args{"all"}
Truth table0%0/5
A and B or C
A= $args{"where"}B= @{$args{"where"};}C= delete $args{"all"}
ABCresult
11X1
0X11
1011
0X00
1000
3345 {
3346 0 Carp::croak "$class - Refusing to update all rows in the table '",
3347 $meta->fq_table_sql($db), "' without an explict ",
3348 "'all => 1' parameter";
3349 }
3350  
3351 0 ▶ if($args{'where'} && @{$args{'where'}} && $args{'all'})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"where"} and @{$args{"where"};} and $args{"all"}) 0 0 0
Condition0%0/6
$args{"where"} and @{$args{"where"};} and $args{"all"}
!ll&&!rl&&r
000
$args{"where"} and @{$args{"where"};}
!ll&&!rl&&r
000
MC/DC0%0/3
$args{"where"} and @{$args{"where"};} and $args{"all"}
$args{"where"} @{$args{"where"};} $args{"all"}
Truth table0%0/4
A and B and C
A= $args{"where"}B= @{$args{"where"};}C= $args{"all"}
ABCresult
0XX0
10X0
1100
1111
3352 {
3353 0 Carp::croak "Illegal use of the 'where' and 'all' parameters in the same call";
3354 }
3355  
3356 0 my $where = delete $args{'where'};
3357 0 ▶ my $set = delete $args{'set'}
Branch: 1 branch
BranchTrueFalseTotal
my $set = delete $args{"set"} or Carp::croak("Missing requires 'set' parameter") 0 0 0
3358 or Carp::croak "Missing requires 'set' parameter";
3359  
3360 0 ▶ $set = [ %$set ] if(ref $set eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $set eq "HASH" 0 0 0
3361  
3362 # Yes, I'm re-using get_objects() code like crazy, and often
3363 # in weird ways. Shhhh, it's a secret.
3364  
3365 0 my @bind_params;
3366 0 $args{'bind_params'} = \@bind_params;
3367  
3368 0 $args{'query'} = $set;
3369  
3370 # Avert your eyes...
3371 0 my($set_sql, $set_bind) =
3372 $class->get_objects(%args,
3373 return_sql => 1,
3374 where_only => 1,
3375 logic => ',',
3376 set => 1,
3377 table_aliases => 0);
3378  
3379 0 my $sql;
3380  
3381 0 my $where_bind = [];
3382  
3383 0 ▶ if($args{'query'} = $where)
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'query'} = $where) { } 0 0 0
3384 {
3385 0 my $where_sql;
3386  
3387 0 ($where_sql, $where_bind) =
3388 $class->get_objects(%args,
3389 return_sql => 1,
3390 where_only => 1,
3391 table_aliases => 0);
3392  
3393 0 $sql = 'UPDATE ' . $meta->fq_table_sql($db) .
3394 "\nSET\n$set_sql\nWHERE\n$where_sql";
3395 }
3396 else
3397 {
3398 0 $sql = 'UPDATE ' . $meta->fq_table_sql($db) . "\nSET\n$set_sql";
3399 }
3400  
3401 0 my($count, $error);
3402  
3403 TRY:
3404 {
3405 0 local $@;
3406  
3407 eval
3408 0 {
3409 0 local $dbh->{'RaiseError'} = 1;
3410 0 ▶ $Debug && warn "$sql (", join(', ', @$set_bind, @$where_bind), ")\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Object::Manager::Debug and warn "$sql (", join(", ", @$set_bind, @$where_bind), ")\n" 0 0 0
3411  
3412 # $meta->prepare_bulk_update_options (defunct)
3413 0 ▶ my $sth = $prepare_cached ? $dbh->prepare_cached($sql, undef, 3) :
Branch: 2 branches
BranchTrueFalseTotal
my $sth = $prepare_cached ? $dbh->prepare_cached($sql, undef, 3) : $dbh->prepare($sql) or die $dbh->errstr 0 0 0
$prepare_cached ? : 0 0 0
3414 $dbh->prepare($sql) or die $dbh->errstr;
3415  
3416 0 my $rv;
3417  
3418 0 ▶ if(@bind_params)
Branch: 1 branch
BranchTrueFalseTotal
if (@bind_params) { } 0 0 0
3419 {
3420 0 my $i = 1;
3421  
3422 0 foreach my $value (@$set_bind, @$where_bind)
3423 {
3424 0 $sth->bind_param($i, $value, $bind_params[$i - 1]);
3425 0 $i++;
3426 }
3427  
3428 0 $rv = $sth->execute;
3429 }
3430 else
3431 {
3432 0 $rv = $sth->execute(@$set_bind, @$where_bind);
3433 }
3434  
3435 # When running queries that affect zero rows, DBD::Pg now returns
3436 # 0E0 from execute() and -1 from rows(), so handle that below.
3437 0 ▶ $count = $sth->rows || 0;
Condition0%0/2
$sth->rows || 0
l!l
00
MC/DC0%0/1
$sth->rows || 0
$sth->rows
Truth table0%0/2
A
A= $sth->rows
Aresult
11
00
3438 0 ▶ $count = int($rv) if($count < 0); # coerce 0E0 to 0
Branch: 1 branch
BranchTrueFalseTotal
if $count < 0 0 0 0
3439 };
3440  
3441 0 $error = $@;
3442 }
3443  
3444 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
3445 {
3446 0 ▶ $class->error(ref $error ? $error : "update_objects() - $error");
Branch: 1 branch
BranchTrueFalseTotal
ref $error ? : 0 0 0
3447 0 $class->handle_error($class);
3448 0 return undef;
3449 }
3450  
3451 0 return $count;
3452 }
3453  
3454 sub make_manager_method_from_sql
3455 0 ▶{
Subroutine make_manager_method_from_sql: not called CC=5 SCAR=31.5
Pod documented
3456 0 my($class) = shift;
3457  
3458 0 my %args;
3459  
3460 0 ▶ if(@_ == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 0 0 0
3461 {
3462 0 %args = (method => $_[0], sql => $_[1]);
3463 }
3464 0 else { %args = @_ }
3465  
3466 0 my $named_args = delete $args{'params'};
3467  
3468 0 ▶ my $method = delete $args{'method'} or Carp::croak "Missing method name";
Branch: 1 branch
BranchTrueFalseTotal
my $method = delete $args{"method"} or Carp::croak("Missing method name") 0 0 0
3469 0 my $code;
3470  
3471 0 $args{'_methods'} = {}; # Will fill in on first run
3472  
3473 0 ▶ my $worker_method = $args{'iterator'} ?
Branch: 1 branch
BranchTrueFalseTotal
$args{'iterator'} ? : 0 0 0
3474 'get_objects_iterator_from_sql' : 'get_objects_from_sql';
3475  
3476 0 ▶ if($named_args)
Branch: 1 branch
BranchTrueFalseTotal
if ($named_args) { } 0 0 0
3477 {
3478 0 my @params = @$named_args; # every little bit counts
3479  
3480 $code = sub
3481 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
3482 0 my($self, %margs) = @_;
3483 $self->$worker_method(
3484 %args,
3485 0 args => [ delete @margs{@params} ],
3486 %margs);
3487 0 };
3488 }
3489 else
3490 {
3491 0 ▶ $code = sub { shift->$worker_method(%args, args => \@_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
3492 }
3493  
3494 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
3495 0 *{"${class}::$method"} = $code;
3496  
3497 0 return $code;
3498 }
3499  
3500 sub get_objects_from_sql
3501 0 ▶{
Subroutine get_objects_from_sql: not called CC=30 SCAR=68.4
Pod documented
3502 0 my($class) = shift;
3503  
3504 0 my(%args, $sql);
3505  
3506 0 ▶ if(@_ == 1) { $sql = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
3507 else
3508 {
3509 0 %args = @_;
3510 0 $sql = $args{'sql'};
3511 }
3512  
3513 0 ▶ Carp::croak "Missing SQL" unless($sql);
Branch: 1 branch
BranchTrueFalseTotal
unless $sql 0 0 0
3514  
3515 0 ▶ my $object_class = $args{'object_class'} || $class->object_class ||
Condition0%0/5
$args{'object_class'} || $class->object_class || Carp::croak('Missing object class')
l!l
00
$args{"object_class"} or $class->object_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'object_class'} || $class->object_class || Carp::croak('Missing object class')
$args{"object_class"} $class->object_class
Truth table0%0/3
A or B
A= $args{"object_class"}B= $class->object_class
ABresult
1X1
011
000
3516 Carp::croak "Missing object class";
3517  
3518 0 ▶ my $meta = $object_class->meta
Branch: 1 branch
BranchTrueFalseTotal
my $meta = $object_class->meta or Carp::croak("Could not get meta for $object_class") 0 0 0
3519 or Carp::croak "Could not get meta for $object_class";
3520  
3521 my $prepare_cached =
3522 0 ▶ exists $args{'prepare_cached'} ? $args{'prepare_cached'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'prepare_cached'} ? : 0 0 0
3523 $class->dbi_prepare_cached;
3524  
3525 0 my $methods = $args{'_methods'};
3526 0 ▶ my $exec_args = $args{'args'} || [];
Condition0%0/2
$args{'args'} || []
l!l
00
MC/DC0%0/1
$args{'args'} || []
$args{'args'}
Truth table0%0/2
A
A= $args{'args'}
Aresult
11
00
3527 0 my $attr = $args{'prepare_options'};
3528  
3529 0 ▶ my $have_methods = ($args{'_methods'} && %{$args{'_methods'}}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args{'_methods'} && %{$args{'_methods'};} ? : 0 0 0
Condition0%0/3
$args{"_methods"} and %{$args{"_methods"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"_methods"} and %{$args{"_methods"};}
$args{"_methods"} %{$args{"_methods"};}
Truth table0%0/3
A and B
A= $args{"_methods"}B= %{$args{"_methods"};}
ABresult
0X0
100
111
3530  
3531 0 ▶ my $db = delete $args{'db'} || $object_class->init_db;
Condition0%0/3
delete $args{'db'} || $object_class->init_db
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $args{'db'} || $object_class->init_db
delete $args{'db'} $object_class->init_db
Truth table0%0/3
A || B
A= delete $args{'db'}B= $object_class->init_db
ABresult
1X1
011
000
3532 0 my $dbh = delete $args{'dbh'};
3533 0 my $dbh_retained = 0;
3534  
3535 0 ▶ unless($dbh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh) 0 0 0
3536 {
3537 0 ▶ unless($dbh = $db->retain_dbh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh = $db->retain_dbh) 0 0 0
3538 {
3539 0 $class->error($db->error);
3540 0 $class->handle_error($class);
3541 0 return undef;
3542 }
3543  
3544 0 $dbh_retained = 1;
3545 }
3546  
3547 my %object_args =
3548 (
3549 0 ▶ (exists $args{'share_db'} ? $args{'share_db'} : 1) ? (db => $db) : ()
Branch: 2 branches
BranchTrueFalseTotal
(exists $args{'share_db'} ? $args{'share_db'} : 1) ? : 0 0 0
exists $args{'share_db'} ? : 0 0 0
3550 );
3551  
3552 0 my(@objects, $error);
3553  
3554 TRY:
3555 {
3556 0 local $@;
3557  
3558 eval
3559 0 {
3560 0 local $dbh->{'RaiseError'} = 1;
3561  
3562 0 ▶ $Debug && warn "$sql (", join(', ', @$exec_args), ")\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Object::Manager::Debug and warn "$sql (", join(", ", @$exec_args), ")\n" 0 0 0
3563 0 ▶ my $sth = $prepare_cached ? $dbh->prepare_cached($sql, $attr, 3) :
Branch: 2 branches
BranchTrueFalseTotal
my $sth = $prepare_cached ? $dbh->prepare_cached($sql, $attr, 3) : $dbh->prepare($sql, $attr) or die $dbh->errstr 0 0 0
$prepare_cached ? : 0 0 0
3564 $dbh->prepare($sql, $attr) or die $dbh->errstr;
3565  
3566 0 $sth->execute(@$exec_args);
3567  
3568 0 ▶ while(my $row = $sth->fetchrow_hashref)
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
3569 {
3570 0 ▶ unless($have_methods)
Branch: 1 branch
BranchTrueFalseTotal
unless ($have_methods) 0 0 0
3571 {
3572 0 foreach my $col (keys %$row)
3573 {
3574 0 ▶ if($meta->column($col))
Branch: 4 branches
BranchTrueFalseTotal
if ($meta->column($col)) { } 0 0 0
elsif ($object_class->can($col)) { } 0 0 0
elsif ($meta->column(lc $col)) { } 0 0 0
elsif ($object_class->can(lc $col)) { } 0 0 0
3575 {
3576 0 $methods->{$col} = $meta->column_mutator_method_name($col);
3577 }
3578 elsif($object_class->can($col))
3579 {
3580 0 $methods->{$col} = $col;
3581 }
3582 elsif($meta->column(lc $col))
3583 {
3584 0 $methods->{$col} = $meta->column_mutator_method_name(lc $col);
3585 }
3586 elsif($object_class->can(lc $col))
3587 {
3588 0 $methods->{$col} = lc $col;
3589 }
3590 }
3591  
3592 0 $have_methods = 1;
3593 }
3594  
3595 0 my $object = $object_class->new(%object_args);
3596  
3597 0 local $object->{STATE_LOADING()} = 1;
3598 0 $object->{STATE_IN_DB()} = 1;
3599  
3600 0 ▶ while(my($col, $val) = each(%$row))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$row) 0 0 0
3601 {
3602 0 ▶ my $method = $methods->{$col} || $col;
Condition0%0/3
$methods->{$col} || $col
l!l&&r!l&&!r
000
MC/DC0%0/2
$methods->{$col} || $col
$methods->{$col} $col
Truth table0%0/3
A || B
A= $methods->{$col}B= $col
ABresult
1X1
011
000
3603 0 $object->$method($val);
3604 }
3605  
3606 0 $object->{MODIFIED_COLUMNS()} = {};
3607  
3608 0 push(@objects, $object);
3609 }
3610 };
3611  
3612 0 $error = $@;
3613 }
3614  
3615 0 ▶ $db->release_dbh if($dbh_retained);
Branch: 1 branch
BranchTrueFalseTotal
if $dbh_retained 0 0 0
3616  
3617 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
3618 {
3619 0 $class->total(undef);
3620 0 ▶ $class->error(ref $error ? $error : "get_objects_from_sql() - $error");
Branch: 1 branch
BranchTrueFalseTotal
ref $error ? : 0 0 0
3621 0 $class->handle_error($class);
3622 0 return undef;
3623 }
3624  
3625 0 return \@objects;
3626 }
3627  
3628 sub get_objects_iterator_from_sql
3629 0 ▶{
Subroutine get_objects_iterator_from_sql: not called CC=21 SCAR=61.4
Pod documented
3630 0 my($class) = shift;
3631  
3632 0 my(%args, $sql);
3633  
3634 0 ▶ if(@_ == 1) { $sql = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
3635 else
3636 {
3637 0 %args = @_;
3638 0 $sql = $args{'sql'};
3639 }
3640  
3641 0 ▶ Carp::croak "Missing SQL" unless($sql);
Branch: 1 branch
BranchTrueFalseTotal
unless $sql 0 0 0
3642  
3643 0 ▶ my $object_class = $args{'object_class'} || $class->object_class ||
Condition0%0/5
$args{'object_class'} || $class->object_class || Carp::croak('Missing object class')
l!l
00
$args{"object_class"} or $class->object_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'object_class'} || $class->object_class || Carp::croak('Missing object class')
$args{"object_class"} $class->object_class
Truth table0%0/3
A or B
A= $args{"object_class"}B= $class->object_class
ABresult
1X1
011
000
3644 Carp::croak "Missing object class";
3645  
3646 0 ▶ weaken(my $meta = $object_class->meta
Condition0%0/2
(my $meta = $object_class->meta) || Carp::croak("Could not get meta for $object_class")
l!l
00
MC/DC0%0/1
(my $meta = $object_class->meta) || Carp::croak("Could not get meta for $object_class")
(my $meta = $object_class->meta)
Truth table0%0/2
A
A= (my $meta = $object_class->meta)
Aresult
11
00
3647 or Carp::croak "Could not get meta for $object_class");
3648  
3649 my $prepare_cached =
3650 0 ▶ exists $args{'prepare_cached'} ? $args{'prepare_cached'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'prepare_cached'} ? : 0 0 0
3651 $class->dbi_prepare_cached;
3652  
3653 0 my $methods = $args{'_methods'};
3654 0 ▶ my $exec_args = $args{'args'} || [];
Condition0%0/2
$args{'args'} || []
l!l
00
MC/DC0%0/1
$args{'args'} || []
$args{'args'}
Truth table0%0/2
A
A= $args{'args'}
Aresult
11
00
3655 0 my $attr = $args{'prepare_options'};
3656  
3657 0 ▶ my $have_methods = ($args{'_methods'} && %{$args{'_methods'}}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args{'_methods'} && %{$args{'_methods'};} ? : 0 0 0
Condition0%0/3
$args{"_methods"} and %{$args{"_methods"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"_methods"} and %{$args{"_methods"};}
$args{"_methods"} %{$args{"_methods"};}
Truth table0%0/3
A and B
A= $args{"_methods"}B= %{$args{"_methods"};}
ABresult
0X0
100
111
3658  
3659 0 ▶ my $db = delete $args{'db'} || $object_class->init_db;
Condition0%0/3
delete $args{'db'} || $object_class->init_db
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $args{'db'} || $object_class->init_db
delete $args{'db'} $object_class->init_db
Truth table0%0/3
A || B
A= delete $args{'db'}B= $object_class->init_db
ABresult
1X1
011
000
3660 0 my $dbh = delete $args{'dbh'};
3661 0 my $dbh_retained = 0;
3662  
3663 0 ▶ unless($dbh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh) 0 0 0
3664 {
3665 0 ▶ unless($dbh = $db->retain_dbh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh = $db->retain_dbh) 0 0 0
3666 {
3667 0 $class->error($db->error);
3668 0 $class->handle_error($class);
3669 0 return undef;
3670 }
3671  
3672 0 $dbh_retained = 1;
3673 }
3674  
3675 my %object_args =
3676 (
3677 0 ▶ (exists $args{'share_db'} ? $args{'share_db'} : 1) ? (db => $db) : ()
Branch: 2 branches
BranchTrueFalseTotal
(exists $args{'share_db'} ? $args{'share_db'} : 1) ? : 0 0 0
exists $args{'share_db'} ? : 0 0 0
3678 );
3679  
3680 0 my($sth, $error);
3681  
3682 TRY:
3683 {
3684 0 local $@;
3685  
3686 eval
3687 0 {
3688 0 local $dbh->{'RaiseError'} = 1;
3689  
3690 0 ▶ $Debug && warn "$sql (", join(', ', @$exec_args), ")\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Object::Manager::Debug and warn "$sql (", join(", ", @$exec_args), ")\n" 0 0 0
3691 0 ▶ $sth = $prepare_cached ? $dbh->prepare_cached($sql, $attr, 3) :
Branch: 2 branches
BranchTrueFalseTotal
$sth = $prepare_cached ? $dbh->prepare_cached($sql, $attr, 3) : $dbh->prepare($sql, $attr) or die $dbh->errstr 0 0 0
$prepare_cached ? : 0 0 0
3692 $dbh->prepare($sql, $attr) or die $dbh->errstr;
3693  
3694 0 $sth->execute(@$exec_args);
3695 };
3696  
3697 0 $error = $@;
3698 }
3699  
3700 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
3701 {
3702 0 ▶ $db->release_dbh if($dbh_retained);
Branch: 1 branch
BranchTrueFalseTotal
if $dbh_retained 0 0 0
3703 0 $class->total(undef);
3704 0 ▶ $class->error(ref $error ? $error : "get_objects_iterator_from_sql() - $error");
Branch: 1 branch
BranchTrueFalseTotal
ref $error ? : 0 0 0
3705 0 $class->handle_error($class);
3706 0 return undef;
3707 }
3708  
3709 0 my $iterator = Rose::DB::Object::Iterator->new(active => 1);
3710  
3711 $iterator->_next_code(sub
3712 0 ▶ {
Subroutine __ANON__: not called CC=11 SCAR=48.8
3713 0 my($self) = shift;
3714  
3715 0 my $object = 0;
3716  
3717 0 my $error;
3718  
3719 TRY:
3720 {
3721 0 local $@;
3722  
3723 eval
3724 0 {
3725 0 ROW: for(;;)
3726 {
3727 0 ▶ my $row = $sth->fetchrow_hashref or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $row = $sth->fetchrow_hashref or return 0 0 0 0
3728  
3729 0 ▶ unless($have_methods)
Branch: 1 branch
BranchTrueFalseTotal
unless ($have_methods) 0 0 0
3730 {
3731 0 foreach my $col (keys %$row)
3732 {
3733 0 ▶ if($meta->column($col))
Branch: 4 branches
BranchTrueFalseTotal
if ($meta->column($col)) { } 0 0 0
elsif ($object_class->can($col)) { } 0 0 0
elsif ($meta->column(lc $col)) { } 0 0 0
elsif ($object_class->can(lc $col)) { } 0 0 0
3734 {
3735 0 $methods->{$col} = $meta->column_mutator_method_name($col);
3736 }
3737 elsif($object_class->can($col))
3738 {
3739 0 $methods->{$col} = $col;
3740 }
3741 elsif($meta->column(lc $col))
3742 {
3743 0 $methods->{$col} = $meta->column_mutator_method_name(lc $col);
3744 }
3745 elsif($object_class->can(lc $col))
3746 {
3747 0 $methods->{$col} = lc $col;
3748 }
3749 }
3750  
3751 0 $have_methods = 1;
3752 }
3753  
3754 0 $object = $object_class->new(%object_args);
3755  
3756 0 local $object->{STATE_LOADING()} = 1;
3757 0 $object->{STATE_IN_DB()} = 1;
3758  
3759 0 ▶ while(my($col, $val) = each(%$row))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$row) 0 0 0
3760 {
3761 0 my $method = $methods->{$col};
3762 0 $object->$method($val);
3763 }
3764  
3765 0 $object->{MODIFIED_COLUMNS()} = {};
3766  
3767 0 $self->{'_count'}++;
3768 0 last ROW;
3769 }
3770 };
3771  
3772 0 $error = $@;
3773 }
3774  
3775 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
3776 {
3777 0 ▶ $self->error(ref $error ? $error : "next() - $error");
Branch: 1 branch
BranchTrueFalseTotal
ref $error ? : 0 0 0
3778 0 $class->handle_error($self);
3779 0 return undef;
3780 }
3781  
3782 0 return $object;
3783 0 });
3784  
3785 $iterator->_finish_code(sub
3786 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
3787 0 ▶ $sth->finish if($sth);
Branch: 1 branch
BranchTrueFalseTotal
if $sth 0 0 0
3788 0 ▶ $db->release_dbh if($db && $dbh_retained);
Branch: 1 branch
BranchTrueFalseTotal
if $db and $dbh_retained 0 0 0
Condition0%0/3
$db and $dbh_retained
!ll&&!rl&&r
000
MC/DC0%0/2
$db and $dbh_retained
$db $dbh_retained
Truth table0%0/3
A and B
A= $dbB= $dbh_retained
ABresult
0X0
100
111
3789 0 $sth = undef;
3790 0 $db = undef;
3791 0 });
3792  
3793 $iterator->_destroy_code(sub
3794 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
3795 0 ▶ $db->release_dbh if($db && $dbh_retained);
Branch: 1 branch
BranchTrueFalseTotal
if $db and $dbh_retained 0 0 0
Condition0%0/3
$db and $dbh_retained
!ll&&!rl&&r
000
MC/DC0%0/2
$db and $dbh_retained
$db $dbh_retained
Truth table0%0/3
A and B
A= $dbB= $dbh_retained
ABresult
0X0
100
111
3796 0 $sth = undef;
3797 0 $db = undef;
3798 0 });
3799  
3800 0 return $iterator;
3801 }
3802  
3803 sub perl_class_definition
3804 0 ▶{
Subroutine perl_class_definition: not called CC=3 SCAR=20.8
Pod documented
3805 0 my($class) = shift;
3806  
3807 0 ▶ my $object_class = $class->object_class || $class->_object_class;
Condition0%0/3
$class->object_class || $class->_object_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$class->object_class || $class->_object_class
$class->object_class $class->_object_class
Truth table0%0/3
A || B
A= $class->object_classB= $class->_object_class
ABresult
1X1
011
000
3808  
3809 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
3810 0 my @isa = @{"${class}::ISA"};
3811  
3812 0 my $use_bases = "use base qw(@isa);";
3813  
3814 0 return<<"EOF";
3815 package $class;
3816  
3817 use strict;
3818  
3819 $use_bases
3820  
3821 use $object_class;
3822  
3823 0 ▶sub object_class { '@{[ $class->object_class || $class->_object_class ]}' }
Condition0%0/3
$class->object_class || $class->_object_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$class->object_class || $class->_object_class
$class->object_class $class->_object_class
Truth table0%0/3
A || B
A= $class->object_classB= $class->_object_class
ABresult
1X1
011
000
3824  
3825 0 __PACKAGE__->make_manager_methods('@{[ $class->_base_name ]}');
3826  
3827 1;
3828 EOF
3829 }
3830  
3831 61 1;
3832  
3833 __END__
↑ Summary Object/QueryBuilder.pm »