Object/Helpers.pm

filter: Statementstmt 12.9% 52 / 401 Branchbran 0.0% 0 / 216 Conditioncond 0.0% 0 / 77 MC/DCmcdc 0.0% 0 / 45 Subroutinesub 20.6% 12 / 58 Podpod 87.8% 29 / 33 totaltotal 11.2% 93 / 830 CC 156 SCAR 55.2
CC
156
Cov
7%
_traverse_depth_first
930.0
init_with_tree
552.0
strip
342.0
CRAP 249.5
« Object/Metadata/Auto.pm ↑ Summary Object/Metadata/Auto/MySQL.pm »
1 package Rose::DB::Object::Helpers;
2  
3 63 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 63 ▶use Rose::DB::Object::Constants qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 63 ▶use Rose::Object::MixIn;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 63 our @ISA = qw(Rose::Object::MixIn);
9  
10 63 require Rose::DB::Object::Util;
11  
12 63 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 63 our $VERSION = '0.812';
15  
16 63 __PACKAGE__->export_tags
17 (
18 all =>
19 [
20 qw(clone clone_and_reset load_or_insert load_or_save insert_or_update
21 insert_or_update_on_duplicate_key load_speculative
22 column_value_pairs column_accessor_value_pairs
23 column_mutator_value_pairs
24 column_values_as_yaml column_values_as_json
25 traverse_depth_first as_tree init_with_tree new_from_tree
26 init_with_deflated_tree new_from_deflated_tree
27 as_yaml new_from_yaml init_with_yaml
28 as_json new_from_json init_with_json
29 init_with_column_value_pairs
30 has_loaded_related strip forget_related
31 dirty_columns)
32 ],
33  
34 # This exists for the benefit of the test suite
35 all_noprereq =>
36 [
37 qw(clone clone_and_reset load_or_insert load_or_save insert_or_update
38 insert_or_update_on_duplicate_key load_speculative
39 column_value_pairs column_accessor_value_pairs
40 column_mutator_value_pairs
41 traverse_depth_first as_tree init_with_tree new_from_tree
42 init_with_deflated_tree new_from_deflated_tree
43 init_with_column_value_pairs
44 has_loaded_related strip forget_related
45 dirty_columns)
46 ],
47 );
48  
49 #
50 # Class data
51 #
52  
53 use Rose::Class::MakeMethods::Generic
54 63 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
55 63 inheritable_scalar =>
56 [
57 '_json_object'
58 ],
59 63 );
60  
61 #
62 # Class methods
63 #
64  
65 sub json_encoder
66 0 ▶{
Subroutine json_encoder: not called CC=2 SCAR=17.9
Pod undocumented
67 0 my($class) = shift;
68  
69 0 my $json = $class->_json_object;
70  
71 0 ▶ unless(defined $json)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $json) 0 0 0
72 {
73 0 $json = $class->init_json_encoder;
74 }
75  
76 0 return $json;
77 }
78  
79 sub init_json_encoder
80 0 ▶{
Subroutine init_json_encoder: not called CC=2 SCAR=17.9
Pod undocumented
81 0 require JSON;
82  
83 0 ▶ croak "JSON version 2.00 or later is required. You have $JSON::VERSION"
Branch: 1 branch
BranchTrueFalseTotal
unless $JSON::VERSION >= 2 0 0 0
84 unless($JSON::VERSION >= 2.00);
85  
86 0 return JSON->new->utf8->space_after;
87 }
88  
89 63 *json_decoder = \&json_encoder;
90  
91 #
92 # Object methods
93 #
94  
95 0 ▶sub load_speculative { shift->load(@_, speculative => 1) }
Subroutine load_speculative: not called CC=1 SCAR=6.9
Pod documented
96  
97 sub load_or_insert
98 0 ▶{
Subroutine load_or_insert: not called CC=9 SCAR=45.0
Pod documented
99 0 my($self) = shift;
100  
101 0 my($ret, @ret, $loaded, $error);
102  
103 TRY:
104 {
105 0 local $@;
106  
107 # Ignore any errors due to missing primary/unique keys
108 $loaded = eval
109 0 {
110 0 ▶ if(wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
111 {
112 0 @ret = $self->load(@_, speculative => 1);
113 0 ▶ return $ret[0] if($ret[0]); # return from eval
Branch: 1 branch
BranchTrueFalseTotal
if $ret[0] 0 0 0
114 }
115 else
116 {
117 0 $ret = $self->load(@_, speculative => 1);
118 0 ▶ return $ret if($ret); # return from eval
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 0 0
119 }
120  
121 0 return 0; # return from eval
122 };
123  
124 0 $error = $@;
125 }
126  
127 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
128 {
129 # ...but re-throw all other errors
130 0 ▶ unless(UNIVERSAL::isa($error, 'Rose::DB::Object::Exception') &&
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($error, "Rose::DB::Object::Exception") and $error->code == 5) 0 0 0
Condition0%0/3
UNIVERSAL::isa($error, "Rose::DB::Object::Exception") and $error->code == 5
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::isa($error, "Rose::DB::Object::Exception") and $error->code == 5
UNIVERSAL::isa($error, "Rose::DB::Object::Exception") $error->code == 5
Truth table0%0/3
A and B
A= UNIVERSAL::isa($error, "Rose::DB::Object::Exception")B= $error->code == 5
ABresult
0X0
100
111
131 $error->code == EXCEPTION_CODE_NO_KEY)
132 {
133 0 $self->meta->handle_error($self);
134 0 return 0;
135 }
136 }
137  
138 0 ▶ return wantarray ? @ret : $ret if($loaded);
Branch: 2 branches
BranchTrueFalseTotal
if $loaded 0 0 0
wantarray ? : 0 0 0
139  
140 0 return $self->insert;
141 }
142  
143 sub load_or_save
144 0 ▶{
Subroutine load_or_save: not called CC=9 SCAR=45.0
Pod documented
145 0 my($self) = shift;
146  
147 0 my($ret, @ret, $loaded, $error);
148  
149 TRY:
150 {
151 0 local $@;
152  
153 # Ignore any errors due to missing primary/unique keys
154 $loaded = eval
155 0 {
156 0 ▶ if(wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
157 {
158 0 @ret = $self->load(@_, speculative => 1);
159 0 ▶ return $ret[0] if($ret[0]); # return from eval
Branch: 1 branch
BranchTrueFalseTotal
if $ret[0] 0 0 0
160 }
161 else
162 {
163 0 $ret = $self->load(@_, speculative => 1);
164 0 ▶ return $ret if($ret); # return from eval
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 0 0
165 }
166  
167 0 return 0; # return from eval
168 };
169  
170 0 $error = $@;
171 }
172  
173 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
174 {
175 # ...but re-throw all other errors
176 0 ▶ unless(UNIVERSAL::isa($error, 'Rose::DB::Object::Exception') &&
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($error, "Rose::DB::Object::Exception") and $error->code == 5) 0 0 0
Condition0%0/3
UNIVERSAL::isa($error, "Rose::DB::Object::Exception") and $error->code == 5
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::isa($error, "Rose::DB::Object::Exception") and $error->code == 5
UNIVERSAL::isa($error, "Rose::DB::Object::Exception") $error->code == 5
Truth table0%0/3
A and B
A= UNIVERSAL::isa($error, "Rose::DB::Object::Exception")B= $error->code == 5
ABresult
0X0
100
111
177 $error->code == EXCEPTION_CODE_NO_KEY)
178 {
179 0 $self->meta->handle_error($self);
180 0 return 0;
181 }
182 }
183  
184 0 ▶ return wantarray ? @ret : $ret if($loaded);
Branch: 2 branches
BranchTrueFalseTotal
if $loaded 0 0 0
wantarray ? : 0 0 0
185  
186 0 return $self->save;
187 }
188  
189  
190 sub insert_or_update
191 0 ▶{
Subroutine insert_or_update: not called CC=8 SCAR=42.8
Pod documented
192 0 my($self) = shift;
193  
194 # Initially trust the metadata
195 0 ▶ if($self->{STATE_IN_DB()})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__xrdbopriv_in_db"}) 0 0 0
196 {
197 0 local $@;
198 0 eval { $self->save(@_, update => 1) };
199 0 ▶ return $self || 1 unless($@);
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
Condition0%0/2
$self || 1
l!l
00
MC/DC0%0/1
$self || 1
$self
Truth table0%0/2
A
A= $self
Aresult
11
00
200 }
201  
202 0 my $meta = $self->meta;
203  
204 # This is more "correct"
205 #my $clone = clone($self);
206  
207 # ...but this is a lot faster
208 0 my $clone = bless { %$self }, ref($self);
209  
210 0 my($loaded, $error);
211  
212 TRY:
213 {
214 0 local $@;
215  
216 # Ignore any errors due to missing primary/unique keys
217 0 eval { $loaded = $clone->load(speculative => 1) };
218  
219 0 $error = $@;
220 }
221  
222 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
223 {
224 # ...but re-throw all other errors
225 0 ▶ unless(UNIVERSAL::isa($error, 'Rose::DB::Object::Exception') &&
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($error, "Rose::DB::Object::Exception") and $error->code == 5) 0 0 0
Condition0%0/3
UNIVERSAL::isa($error, "Rose::DB::Object::Exception") and $error->code == 5
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::isa($error, "Rose::DB::Object::Exception") and $error->code == 5
UNIVERSAL::isa($error, "Rose::DB::Object::Exception") $error->code == 5
Truth table0%0/3
A and B
A= UNIVERSAL::isa($error, "Rose::DB::Object::Exception")B= $error->code == 5
ABresult
0X0
100
111
226 $error->code == EXCEPTION_CODE_NO_KEY)
227 {
228 0 $meta->handle_error($self);
229 0 return 0;
230 }
231 }
232  
233 0 ▶ if($loaded)
Branch: 1 branch
BranchTrueFalseTotal
if ($loaded) 0 0 0
234 {
235 # The long way...
236 0 my %pk;
237 @pk{$meta->primary_key_column_mutator_names} =
238 0 map { $clone->$_() } $meta->primary_key_column_accessor_names;
239 0 $self->init(%pk);
240  
241 # The short (but dirty) way
242 #my @pk_keys = $meta->primary_key_column_db_value_hash_keys;
243 #@$self{@pk_keys} = @$clone{@pk_keys};
244  
245 0 return $self->save(@_, update => 1);
246 }
247  
248 0 return $self->save(@_, insert => 1)
249 }
250  
251 sub insert_or_update_on_duplicate_key
252 0 ▶{
Subroutine insert_or_update_on_duplicate_key: not called CC=2 SCAR=17.9
Pod documented
253 0 my($self) = shift;
254  
255 0 ▶ unless($self->db->supports_on_duplicate_key_update)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->db->supports_on_duplicate_key_update) 0 0 0
256 {
257 0 return insert_or_update($self, @_);
258 }
259  
260 0 return $self->save(@_, insert => 1, on_duplicate_key_update => 1);
261 }
262  
263 0 ▶__PACKAGE__->pre_import_hook(column_values_as_yaml => sub { require YAML::Syck });
Subroutine __ANON__: not called CC=1 SCAR=1.2
264  
265 sub column_values_as_yaml
266 0 ▶{
Subroutine column_values_as_yaml: not called CC=1 SCAR=6.9
Pod documented
267 0 local $_[0]->{STATE_SAVING()} = 1;
268 0 YAML::Syck::Dump(scalar Rose::DB::Object::Helpers::column_value_pairs(shift))
269 }
270  
271 0 ▶__PACKAGE__->pre_import_hook(column_values_as_json => sub { require JSON });
Subroutine __ANON__: not called CC=1 SCAR=1.2
272  
273 sub column_values_as_json
274 0 ▶{
Subroutine column_values_as_json: not called CC=1 SCAR=6.9
Pod documented
275 0 local $_[0]->{STATE_SAVING()} = 1;
276 0 __PACKAGE__->json_encoder->encode(scalar Rose::DB::Object::Helpers::column_value_pairs(shift))
277 }
278  
279 sub init_with_column_value_pairs
280 0 ▶{
Subroutine init_with_column_value_pairs: not called CC=4 SCAR=30.0
Pod documented
281 0 my($self) = shift;
282  
283 0 ▶ my $hash = @_ == 1 ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
284 0 my $meta = $self->meta;
285  
286 0 local $self->{STATE_LOADING()} = 1;
287  
288 0 ▶ while(my($name, $value) = each(%$hash))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$hash) 0 0 0
289 {
290 0 ▶ next unless(length $name);
Branch: 1 branch
BranchTrueFalseTotal
unless length $name 0 0 0
291 0 my $method = $meta->column($name)->mutator_method_name;
292 0 $self->$method($value);
293 }
294  
295 0 return $self;
296 }
297  
298 sub column_value_pairs
299 0 ▶{
Subroutine column_value_pairs: not called CC=3 SCAR=24.8
Pod documented
300 0 my($self) = shift;
301  
302 0 my %pairs;
303  
304 0 my $methods = $self->meta->column_accessor_method_names_hash;
305  
306 0 ▶ while(my($column, $method) = each(%$methods))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$methods) 0 0 0
307 {
308 0 $pairs{$column} = $self->$method();
309 }
310  
311 0 ▶ return wantarray ? %pairs : \%pairs;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
312 }
313  
314 sub key_column_value_pairs
315 0 ▶{
Subroutine key_column_value_pairs: not called CC=3 SCAR=24.8
Pod undocumented
316 0 my($self) = shift;
317  
318 0 my %pairs;
319  
320 0 my $methods = $self->meta->key_column_accessor_method_names_hash;
321  
322 0 ▶ while(my($column, $method) = each(%$methods))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$methods) 0 0 0
323 {
324 0 $pairs{$column} = $self->$method();
325 }
326  
327 0 ▶ return wantarray ? %pairs : \%pairs;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
328 }
329  
330 sub column_accessor_value_pairs
331 0 ▶{
Subroutine column_accessor_value_pairs: not called CC=3 SCAR=24.8
Pod documented
332 0 my($self) = shift;
333  
334 0 my %pairs;
335  
336 0 foreach my $method ($self->meta->column_accessor_method_names)
337 {
338 0 $pairs{$method} = $self->$method();
339 }
340  
341 0 ▶ return wantarray ? %pairs : \%pairs;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
342 }
343  
344 sub column_mutator_value_pairs
345 0 ▶{
Subroutine column_mutator_value_pairs: not called CC=3 SCAR=24.8
Pod documented
346 0 my($self) = shift;
347  
348 0 my %pairs;
349  
350 0 foreach my $column ($self->meta->columns)
351 {
352 0 my $method = $column->accessor_method_name;
353 0 $pairs{$column->mutator_method_name} = $self->$method();
354 }
355  
356 0 ▶ return wantarray ? %pairs : \%pairs;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
357 }
358  
359 sub clone
360 0 ▶{
Subroutine clone: not called CC=3 SCAR=24.8
Pod documented
361 0 my($self) = shift;
362 0 my $class = ref $self;
363 0 local $self->{STATE_CLONING()} = 1;
364 0 my @mutators = $self->meta->column_mutator_method_names;
365 0 my $mutator;
366 return $class->new(map
367 {
368 0 ▶ (defined($mutator = shift(@mutators)) && defined $_) ?
Branch: 1 branch
BranchTrueFalseTotal
defined($mutator = shift @mutators) && defined $_ ? : 0 0 0
Condition0%0/3
defined($mutator = shift @mutators) and defined $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined($mutator = shift @mutators) and defined $_
defined($mutator = shift @mutators) defined $_
Truth table0%0/3
A and B
A= defined($mutator = shift @mutators)B= defined $_
ABresult
0X0
100
111
369 ($mutator => $self->$_()) : ()
370 }
371 $self->meta->column_accessor_method_names);
372 }
373  
374 sub clone_and_reset
375 0 ▶{
Subroutine clone_and_reset: not called CC=7 SCAR=37.2
Pod documented
376 0 my($self) = shift;
377 0 my $class = ref $self;
378 0 local $self->{STATE_CLONING()} = 1;
379 0 my @mutators = $self->meta->column_mutator_method_names;
380 0 my $mutator;
381 my $clone = $class->new(map
382 {
383 0 ▶ (defined($mutator = shift(@mutators)) && defined $_) ?
Branch: 1 branch
BranchTrueFalseTotal
defined($mutator = shift @mutators) && defined $_ ? : 0 0 0
Condition0%0/3
defined($mutator = shift @mutators) and defined $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined($mutator = shift @mutators) and defined $_
defined($mutator = shift @mutators) defined $_
Truth table0%0/3
A and B
A= defined($mutator = shift @mutators)B= defined $_
ABresult
0X0
100
111
384 ($mutator => $self->$_()) : ()
385 }
386 $self->meta->column_accessor_method_names);
387  
388 0 my $meta = $class->meta;
389  
390 63 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
391  
392 # Blank all primary and unique key columns
393 0 foreach my $method ($meta->primary_key_column_mutator_names)
394 {
395 0 $clone->$method(undef);
396 }
397  
398 0 foreach my $uk ($meta->unique_keys)
399 {
400 0 foreach my $column ($uk->columns)
401 {
402 0 my $method = $meta->column_mutator_method_name($column);
403 0 $clone->$method(undef);
404 }
405 }
406  
407 # Also copy db object, if any
408 0 ▶ if(my $db = $self->{'db'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $db = $self->{"db"}) 0 0 0
409 {
410 #$self->{FLAG_DB_IS_PRIVATE()} = 0;
411 0 $clone->db($db);
412 }
413  
414 0 return $clone;
415 }
416  
417 sub has_loaded_related
418 0 ▶{
Subroutine has_loaded_related: not called CC=12 SCAR=50.5
Pod documented
419 0 my($self) = shift;
420  
421 0 my $rel; # really a relationship or fk
422  
423 0 my $meta = $self->meta;
424  
425 0 ▶ if(@_ == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
426 {
427 0 my $name = shift;
428  
429 0 ▶ if($rel = $meta->foreign_key($name))
Branch: 2 branches
BranchTrueFalseTotal
if ($rel = $meta->foreign_key($name)) { } 0 0 0
elsif ($rel = $meta->relationship($name)) { } 0 0 0
430 {
431 0 ▶ return $rel->object_has_foreign_object($self) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$rel->object_has_foreign_object($self) ? : 0 0 0
432 }
433 elsif($rel = $meta->relationship($name))
434 {
435 0 ▶ return $rel->object_has_related_objects($self) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$rel->object_has_related_objects($self) ? : 0 0 0
436 }
437 else
438 {
439 0 croak "No foreign key or relationship named '$name' found in ",
440 $meta->class;
441 }
442 }
443 else
444 {
445 0 my %args = @_;
446 0 my $name;
447  
448 0 ▶ if($name = $args{'foreign_key'})
Branch: 2 branches
BranchTrueFalseTotal
if ($name = $args{'foreign_key'}) { } 0 0 0
elsif ($name = $args{'relationship'}) { } 0 0 0
449 {
450 0 ▶ $rel = $meta->foreign_key($name)
Branch: 1 branch
BranchTrueFalseTotal
$rel = $meta->foreign_key($name) or croak("No foreign key named '${name}' found in ", $meta->class) 0 0 0
451 or croak "No foreign key named '$name' found in ", $meta->class;
452  
453 0 ▶ return $rel->object_has_foreign_object($self) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$rel->object_has_foreign_object($self) ? : 0 0 0
454 }
455 elsif($name = $args{'relationship'})
456 {
457 0 ▶ $rel = $meta->relationship($name)
Branch: 1 branch
BranchTrueFalseTotal
$rel = $meta->relationship($name) or croak("No relationship named '${name}' found in ", $meta->class) 0 0 0
458 or croak "No relationship named '$name' found in ", $meta->class;
459  
460 0 ▶ return $rel->object_has_related_objects($self) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$rel->object_has_related_objects($self) ? : 0 0 0
461 }
462 else
463 {
464 0 croak "Missing foreign key or relationship name argument";
465 }
466 }
467 }
468  
469 sub forget_related
470 0 ▶{
Subroutine forget_related: not called CC=8 SCAR=42.8
Pod documented
471 0 my($self) = shift;
472  
473 0 my $rel; # really a relationship or fk
474  
475 0 my $meta = $self->meta;
476  
477 0 ▶ if(@_ == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
478 {
479 0 my $name = shift;
480  
481 0 ▶ if($rel = $meta->foreign_key($name))
Branch: 2 branches
BranchTrueFalseTotal
if ($rel = $meta->foreign_key($name)) { } 0 0 0
elsif ($rel = $meta->relationship($name)) { } 0 0 0
482 {
483 0 return $rel->forget_foreign_object($self);
484 }
485 elsif($rel = $meta->relationship($name))
486 {
487 0 return $rel->forget_related_objects($self);
488 }
489 else
490 {
491 0 croak "No foreign key or relationship named '$name' found in ",
492 $meta->class;
493 }
494 }
495 else
496 {
497 0 my %args = @_;
498 0 my $name;
499  
500 0 ▶ if($name = $args{'foreign_key'})
Branch: 2 branches
BranchTrueFalseTotal
if ($name = $args{'foreign_key'}) { } 0 0 0
elsif ($name = $args{'relationship'}) { } 0 0 0
501 {
502 0 ▶ $rel = $meta->foreign_key($name)
Branch: 1 branch
BranchTrueFalseTotal
$rel = $meta->foreign_key($name) or croak("No foreign key named '${name}' found in ", $meta->class) 0 0 0
503 or croak "No foreign key named '$name' found in ", $meta->class;
504  
505 0 return $rel->forget_foreign_object($self);
506 }
507 elsif($name = $args{'relationship'})
508 {
509 0 ▶ $rel = $meta->relationship($name)
Branch: 1 branch
BranchTrueFalseTotal
$rel = $meta->relationship($name) or croak("No relationship named '${name}' found in ", $meta->class) 0 0 0
510 or croak "No relationship named '$name' found in ", $meta->class;
511  
512 0 return $rel->forget_related_objects($self);
513 }
514 else
515 {
516 0 croak "Missing foreign key or relationship name argument";
517 }
518 }
519 }
520  
521 sub strip
522 0 ▶{
Subroutine strip: not called CC=18 SCAR=58.3
Pod documented
523 0 my($self) = shift;
524  
525 0 my %args = @_;
526  
527 0 ▶ my %leave = map { $_ => 1 } (ref $args{'leave'} ? @{$args{'leave'}} : ($args{'leave'} || ''));
Branch: 1 branch
BranchTrueFalseTotal
ref $args{'leave'} ? : 0 0 0
Condition0%0/2
$args{"leave"} or ""
l!l
00
MC/DC0%0/1
$args{"leave"} or ""
$args{"leave"}
Truth table0%0/2
A
A= $args{"leave"}
Aresult
11
00
528  
529 0 my $meta = $self->meta;
530  
531 0 ▶ if($leave{'relationships'} || $leave{'related_objects'})
Branch: 1 branch
BranchTrueFalseTotal
if ($leave{'relationships'} or $leave{'related_objects'}) { } 0 0 0
Condition0%0/3
$leave{"relationships"} or $leave{"related_objects"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$leave{"relationships"} or $leave{"related_objects"}
$leave{"relationships"} $leave{"related_objects"}
Truth table0%0/3
A or B
A= $leave{"relationships"}B= $leave{"related_objects"}
ABresult
1X1
011
000
532 {
533 0 foreach my $rel ($meta->relationships)
534 {
535 0 ▶ if(my $objs = $rel->object_has_related_objects($self))
Branch: 1 branch
BranchTrueFalseTotal
if (my $objs = $rel->object_has_related_objects($self)) 0 0 0
536 {
537 0 foreach my $obj (@$objs)
538 {
539 0 Rose::DB::Object::Helpers::strip($obj, @_);
540 }
541 }
542 }
543 }
544 else
545 {
546 0 foreach my $rel ($meta->relationships)
547 {
548 0 delete $self->{$rel->name};
549 }
550 }
551  
552 0 ▶ if($leave{'foreign_keys'} || $leave{'related_objects'})
Branch: 1 branch
BranchTrueFalseTotal
if ($leave{'foreign_keys'} or $leave{'related_objects'}) { } 0 0 0
Condition0%0/3
$leave{"foreign_keys"} or $leave{"related_objects"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$leave{"foreign_keys"} or $leave{"related_objects"}
$leave{"foreign_keys"} $leave{"related_objects"}
Truth table0%0/3
A or B
A= $leave{"foreign_keys"}B= $leave{"related_objects"}
ABresult
1X1
011
000
553 {
554 0 foreach my $rel ($meta->foreign_keys)
555 {
556 0 ▶ if(my $obj = $rel->object_has_foreign_object($self))
Branch: 1 branch
BranchTrueFalseTotal
if (my $obj = $rel->object_has_foreign_object($self)) 0 0 0
557 {
558 0 Rose::DB::Object::Helpers::strip($obj, @_);
559 }
560 }
561 }
562 else
563 {
564 0 foreach my $fk ($meta->foreign_keys)
565 {
566 0 delete $self->{$fk->name};
567 }
568 }
569  
570 0 ▶ if($leave{'db'})
Branch: 1 branch
BranchTrueFalseTotal
if ($leave{'db'}) { } 0 0 0
571 {
572 0 ▶ $self->{'db'}->dbh(undef) if($self->{'db'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"db"} 0 0 0
573 }
574 else
575 {
576 0 delete $self->{'db'};
577 }
578  
579 # Strip "on-save" code references: destructive!
580 0 ▶ unless($args{'strip_on_save_ok'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"strip_on_save_ok"}) 0 0 0
581 {
582 0 ▶ if(__contains_code_ref($self->{ON_SAVE_ATTR_NAME()}))
Branch: 1 branch
BranchTrueFalseTotal
if (__contains_code_ref($self->{"__xrdbopriv_on_save"})) 0 0 0
583 {
584 0 croak qq(Refusing to strip "on-save" actions from ), ref($self),
585 qq( object without strip_on_save_ok parameter);
586 }
587 }
588  
589 0 delete $self->{ON_SAVE_ATTR_NAME()};
590  
591 # Reference to metadata object will be regenerated as needed
592 0 delete $self->{META_ATTR_NAME()};
593  
594 0 return $self;
595 }
596  
597 sub __contains_code_ref
598 0 ▶{
Subroutine __contains_code_ref: not called CC=5 SCAR=34.0
599 0 my($hash_ref) = shift;
600  
601 0 foreach my $key (keys %$hash_ref)
602 {
603 0 ▶ return 1 if(ref $hash_ref->{$key} eq 'CODE');
Branch: 1 branch
BranchTrueFalseTotal
if ref $hash_ref->{$key} eq "CODE" 0 0 0
604  
605 0 ▶ if(ref $hash_ref->{$key} eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash_ref->{$key} eq 'HASH') { } 0 0 0
606 {
607 0 ▶ return 1 if(__contains_code_ref($hash_ref->{$key}));
Branch: 1 branch
BranchTrueFalseTotal
if __contains_code_ref($hash_ref->{$key}) 0 0 0
608 }
609 else
610 {
611 0 Carp::confess "Unexpected reference encountered: $hash_ref->{$key}";
612 }
613 }
614 }
615  
616 # XXX: A value that is unlikely to exist in a primary key column value
617 63 ▶use constant PK_JOIN => "\0\2,\3\0";
Subroutine BEGIN: called CC=1 SCAR=0.0
618  
619 sub primary_key_as_string
620 0 ▶{
Subroutine primary_key_as_string: not called CC=2 SCAR=17.9
Pod undocumented
621 0 my($self, $joiner) = @_;
622 0 ▶ return join($joiner || PK_JOIN, grep { defined } map { $self->$_() } $self->meta->primary_key_column_accessor_names);
Condition0%0/2
$joiner || "\000\cB,\cC\000"
l!l
00
MC/DC0%0/1
$joiner || "\000\cB,\cC\000"
$joiner
Truth table0%0/2
A
A= $joiner
Aresult
11
00
623 }
624  
625 63 ▶use constant DEFAULT_MAX_DEPTH => 100;
Subroutine BEGIN: called CC=1 SCAR=0.0
626  
627 sub traverse_depth_first
628 0 ▶{
Subroutine traverse_depth_first: not called CC=8 SCAR=42.8
Pod documented
629 0 my($self) = shift;
630  
631 0 my($context, $handlers, $exclude, $prune, $max_depth);
632  
633 0 my $visited = {};
634 0 my $force_load = 0;
635  
636 0 ▶ if(@_ == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
637 {
638 0 $handlers->{'object'} = shift;
639 }
640 else
641 {
642 0 my %args = @_;
643 0 ▶ $handlers = $args{'handlers'} || {};
Condition0%0/2
$args{'handlers'} || {}
l!l
00
MC/DC0%0/1
$args{'handlers'} || {}
$args{'handlers'}
Truth table0%0/2
A
A= $args{'handlers'}
Aresult
11
00
644 0 ▶ $force_load = $args{'force_load'} || 0;
Condition0%0/2
$args{'force_load'} || 0
l!l
00
MC/DC0%0/1
$args{'force_load'} || 0
$args{'force_load'}
Truth table0%0/2
A
A= $args{'force_load'}
Aresult
11
00
645 0 $context = $args{'context'};
646 0 ▶ $exclude = $args{'exclude'} || 0;
Condition0%0/2
$args{'exclude'} || 0
l!l
00
MC/DC0%0/1
$args{'exclude'} || 0
$args{'exclude'}
Truth table0%0/2
A
A= $args{'exclude'}
Aresult
11
00
647 0 $prune = $args{'prune'};
648 0 ▶ $max_depth = exists $args{'max_depth'} ? $args{'max_depth'} : DEFAULT_MAX_DEPTH;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_depth'} ? : 0 0 0
649 0 ▶ $visited = undef if($args{'allow_loops'});
Branch: 1 branch
BranchTrueFalseTotal
if $args{"allow_loops"} 0 0 0
650 }
651  
652 0 ▶ _traverse_depth_first($self, $context ||= {}, $handlers, $exclude, $prune, 0, $max_depth, undef, undef, $visited, $force_load);
Condition0%0/2
$context ||= {}
l!l
00
MC/DC0%0/1
$context ||= {}
$context
Truth table0%0/2
A
A= $context
Aresult
11
00
653  
654 0 return $context;
655 }
656  
657 63 require Rose::DB::Object::Util;
658  
659 63 ▶use constant OK => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
660 63 ▶use constant LOOP_AVOIDED => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
661 63 ▶use constant HIT_MAX_DEPTH => -2;
Subroutine BEGIN: called CC=1 SCAR=0.0
662 63 ▶use constant FILTERED_OUT => -3;
Subroutine BEGIN: called CC=1 SCAR=0.0
663  
664 sub _traverse_depth_first
665 0 ▶{
Subroutine _traverse_depth_first: not called CC=30 SCAR=68.4
666 0 my($self, $context, $handlers, $exclude, $prune, $depth, $max_depth, $parent, $rel_meta, $visited, $force_load) = @_;
667  
668 0 ▶ if($visited && $visited->{ref($self),Rose::DB::Object::Helpers::primary_key_as_string($self)}++)
Branch: 1 branch
BranchTrueFalseTotal
if ($visited and $$visited{join $;, ref $self, primary_key_as_string($self)}++) 0 0 0
Condition0%0/3
$visited and $$visited{join $;, ref $self, primary_key_as_string($self)}++
!ll&&!rl&&r
000
MC/DC0%0/2
$visited and $$visited{join $;, ref $self, primary_key_as_string($self)}++
$visited $$visited{join $;, ref $self, primary_key_as_string($self)}++
Truth table0%0/3
A and B
A= $visitedB= $$visited{join $;, ref $self, primary_key_as_string($self)}++
ABresult
0X0
100
111
669 {
670 0 return LOOP_AVOIDED;
671 }
672  
673 0 ▶ if($handlers->{'object'})
Branch: 1 branch
BranchTrueFalseTotal
if ($handlers->{"object"}) 0 0 0
674 {
675 0 ▶ if($exclude && $exclude->($self, $parent, $rel_meta))
Branch: 1 branch
BranchTrueFalseTotal
if ($exclude and &$exclude($self, $parent, $rel_meta)) 0 0 0
Condition0%0/3
$exclude and &$exclude($self, $parent, $rel_meta)
!ll&&!rl&&r
000
MC/DC0%0/2
$exclude and &$exclude($self, $parent, $rel_meta)
$exclude &$exclude($self, $parent, $rel_meta)
Truth table0%0/3
A and B
A= $excludeB= &$exclude($self, $parent, $rel_meta)
ABresult
0X0
100
111
676 {
677 0 return FILTERED_OUT;
678 }
679  
680 0 ▶ if($force_load && !Rose::DB::Object::Util::is_in_db($self))
Branch: 1 branch
BranchTrueFalseTotal
if ($force_load and not Rose::DB::Object::Util::is_in_db($self)) 0 0 0
Condition0%0/3
$force_load and not Rose::DB::Object::Util::is_in_db($self)
!ll&&!rl&&r
000
MC/DC0%0/2
$force_load and not Rose::DB::Object::Util::is_in_db($self)
$force_load not Rose::DB::Object::Util::is_in_db($self)
Truth table0%0/3
A and not(B)
A= $force_loadB= not Rose::DB::Object::Util::is_in_db($self)
ABresult
0X0
100
111
681 {
682 0 $self->load(speculative => 1);
683 }
684  
685 0 $context = $handlers->{'object'}->($self, $context, $parent, $rel_meta, $depth);
686 }
687  
688 0 ▶ if(defined $max_depth && $depth == $max_depth)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max_depth and $depth == $max_depth) 0 0 0
Condition0%0/3
defined $max_depth and $depth == $max_depth
!ll&&!rl&&r
000
MC/DC0%0/2
defined $max_depth and $depth == $max_depth
defined $max_depth $depth == $max_depth
Truth table0%0/3
A and B
A= defined $max_depthB= $depth == $max_depth
ABresult
0X0
100
111
689 {
690 0 return HIT_MAX_DEPTH;
691 }
692  
693 0 REL: foreach my $rel ($self->meta->relationships)
694 {
695 0 ▶ next if($prune && $prune->($rel, $self, $depth));
Branch: 1 branch
BranchTrueFalseTotal
if $prune and &$prune($rel, $self, $depth) 0 0 0
Condition0%0/3
$prune and &$prune($rel, $self, $depth)
!ll&&!rl&&r
000
MC/DC0%0/2
$prune and &$prune($rel, $self, $depth)
$prune &$prune($rel, $self, $depth)
Truth table0%0/3
A and B
A= $pruneB= &$prune($rel, $self, $depth)
ABresult
0X0
100
111
696  
697 0 my $objs = $rel->object_has_related_objects($self);
698 # XXX: Call above returns 0 if the collection is an empty array ref
699 # XXX: and undef if it's not even a reference (e.g., undef). This
700 # XXX: distinguishes between a collection that has been loaded and
701 # XXX: found to have zero items, and one that has never been loaded.
702 # XXX: To "un-hack" this, we'd need true tracking of load/store
703 # XXX: actions to related collections. Or we could just omit the
704 # XXX: empty collections from the traversal.
705 0 ▶ $objs = [] if(defined $objs && !ref $objs);
Branch: 1 branch
BranchTrueFalseTotal
if defined $objs and not ref $objs 0 0 0
Condition0%0/3
defined $objs and not ref $objs
!ll&&!rl&&r
000
MC/DC0%0/2
defined $objs and not ref $objs
defined $objs not ref $objs
Truth table0%0/3
A and not(B)
A= defined $objsB= not ref $objs
ABresult
0X0
100
111
706  
707 0 ▶ if($force_load || $objs)
Branch: 1 branch
BranchTrueFalseTotal
if ($force_load or $objs) 0 0 0
Condition0%0/3
$force_load or $objs
l!l&&r!l&&!r
000
MC/DC0%0/2
$force_load or $objs
$force_load $objs
Truth table0%0/3
A or B
A= $force_loadB= $objs
ABresult
1X1
011
000
708 {
709 0 ▶ unless($objs)
Branch: 1 branch
BranchTrueFalseTotal
unless ($objs) 0 0 0
710 {
711 0 ▶ my $method = $rel->method_name('get_set_on_save') ||
Condition0%0/8
$rel->method_name('get_set_on_save') || $rel->method_name('get_set_now') || $rel->method_name('get_set') || (next REL)
l!l
00
$rel->method_name("get_set_on_save") or $rel->method_name("get_set_now") or $rel->method_name("get_set")
l!l&&r!l&&!r
000
$rel->method_name("get_set_on_save") or $rel->method_name("get_set_now")
l!l&&r!l&&!r
000
MC/DC0%0/3
$rel->method_name('get_set_on_save') || $rel->method_name('get_set_now') || $rel->method_name('get_set') || (next REL)
$rel->method_name("get_set_on_save") $rel->method_name("get_set_now") $rel->method_name("get_set")
Truth table0%0/4
A or B or C
A= $rel->method_name("get_set_on_save")B= $rel->method_name("get_set_now")C= $rel->method_name("get_set")
ABCresult
1XX1
01X1
0011
0000
712 $rel->method_name('get_set_now') ||
713 $rel->method_name('get_set') ||
714 next REL;
715  
716 0 ▶ $objs = $self->$method() || next REL;
Condition0%0/2
$self->$method || (next REL)
l!l
00
MC/DC0%0/1
$self->$method || (next REL)
$self->$method
Truth table0%0/2
A
A= $self->$method
Aresult
11
00
717 0 ▶ $objs = [ $objs ] unless(ref $objs eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $objs eq "ARRAY" 0 0 0
718 }
719  
720 my $c = $handlers->{'relationship'} ?
721 0 ▶ $handlers->{'relationship'}->($self, $context, $rel) : $context;
Branch: 1 branch
BranchTrueFalseTotal
$handlers->{'relationship'} ? : 0 0 0
722  
723 0 OBJ: foreach my $obj (@$objs)
724 {
725 0 ▶ next OBJ if($exclude && $exclude->($obj, $self, $rel));
Branch: 1 branch
BranchTrueFalseTotal
if $exclude and &$exclude($obj, $self, $rel) 0 0 0
Condition0%0/3
$exclude and &$exclude($obj, $self, $rel)
!ll&&!rl&&r
000
MC/DC0%0/2
$exclude and &$exclude($obj, $self, $rel)
$exclude &$exclude($obj, $self, $rel)
Truth table0%0/3
A and B
A= $excludeB= &$exclude($obj, $self, $rel)
ABresult
0X0
100
111
726  
727 0 my $ret = _traverse_depth_first($obj, $c, $handlers, $exclude, $prune, $depth + 1, $max_depth, $self, $rel, $visited, $force_load);
728  
729 0 ▶ if($ret == LOOP_AVOIDED && $handlers->{'loop_avoided'})
Branch: 1 branch
BranchTrueFalseTotal
if ($ret == -1 and $handlers->{"loop_avoided"}) 0 0 0
Condition0%0/3
$ret == -1 and $handlers->{"loop_avoided"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ret == -1 and $handlers->{"loop_avoided"}
$ret == -1 $handlers->{"loop_avoided"}
Truth table0%0/3
A and B
A= $ret == -1B= $handlers->{"loop_avoided"}
ABresult
0X0
100
111
730 {
731 0 ▶ $handlers->{'loop_avoided'}->($obj, $c, $self, $context, $rel) && last OBJ;
Branch: 1 branch
BranchTrueFalseTotal
$handlers->{"loop_avoided"}->($obj, $c, $self, $context, $rel) and last OBJ 0 0 0
732 }
733 }
734 }
735 }
736  
737 0 return OK;
738 }
739  
740 sub as_tree
741 0 ▶{
Subroutine as_tree: not called CC=3 SCAR=24.8
Pod documented
742 0 my($self) = shift;
743  
744 0 my %args = @_;
745  
746 0 ▶ my $deflate = exists $args{'deflate'} ? $args{'deflate'} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'deflate'} ? : 0 0 0
747 0 ▶ my $persistent_columns_only = exists $args{'persistent_columns_only'} ? $args{'persistent_columns_only'} : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'persistent_columns_only'} ? : 0 0 0
748  
749 0 my %tree;
750  
751 Rose::DB::Object::Helpers::traverse_depth_first($self,
752 context => \%tree,
753 handlers =>
754 {
755 object => sub
756 0 ▶ {
Subroutine __ANON__: not called CC=5 SCAR=34.0
757 0 my($self, $context, $parent, $relationship, $depth) = @_;
758  
759 0 ▶ local $self->{STATE_SAVING()} = 1 if($deflate);
Branch: 1 branch
BranchTrueFalseTotal
if $deflate 0 0 0
760  
761 0 my $cols = Rose::DB::Object::Helpers::column_value_pairs($self);
762  
763 0 ▶ unless($persistent_columns_only)
Branch: 1 branch
BranchTrueFalseTotal
unless ($persistent_columns_only) 0 0 0
764 {
765 # XXX: Inlined version of what would be nonpersistent_column_value_pairs()
766 0 my $methods = $self->meta->nonpersistent_column_accessor_method_names_hash;
767  
768 0 ▶ while(my($column, $method) = each(%$methods))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$methods) 0 0 0
769 {
770 0 $cols->{$column} = $self->$method();
771 }
772 }
773  
774 0 ▶ if(ref $context eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $context eq 'ARRAY') { } 0 0 0
775 {
776 0 push(@$context, $cols);
777 0 return $cols;
778 }
779 else
780 {
781 0 @$context{keys %$cols} = values %$cols;
782 0 return $context;
783 }
784 },
785  
786 relationship => sub
787 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
788 0 my($self, $context, $relationship) = @_;
789  
790 0 my $name = $relationship->name;
791  
792 # Croak on name conflicts with columns
793 0 ▶ if($self->meta->column($name))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->meta->column($name)) 0 0 0
794 {
795 0 croak "$self: relationship '", $relationship->name,
796 "' conflicts with column of the same name";
797 }
798  
799 0 ▶ if($relationship->is_singular)
Branch: 1 branch
BranchTrueFalseTotal
if ($relationship->is_singular) 0 0 0
800 {
801 0 return $context->{$name} = {};
802 }
803  
804 0 return $context->{$name} = [];
805 },
806  
807 loop_avoided => sub
808 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
809 0 my($object, $context, $parent_object, $parent_context, $relationship) = @_;
810 # If any item can't be included due to loops, wipe entire collection and bail
811 0 delete $parent_context->{$relationship->name};
812 0 return 1; # true return means stop processing items in this collection
813 },
814 },
815 0 @_);
816  
817 0 return \%tree;
818 }
819  
820 # XXX: This version requires all relationship and column mutators to have
821 # XXX: the same names as the relationships and columns themselves.
822 # sub init_with_tree { shift->init(@_) }
823  
824 # XXX: This version requires all relationship mutators to have the same
825 # XXX: names as the relationships themselves.
826 # sub init_with_tree
827 # {
828 # my($self) = shift;
829 #
830 # my $meta = $self->meta;
831 #
832 # while(my($name, $value) = each(%{@_ == 1 ? $_[0] : {@_}}))
833 # {
834 # next unless(length $name);
835 # my $method;
836 #
837 # if(my $column = $meta->column($name))
838 # {
839 # $method = $column->mutator_method_name;
840 # $self->$method($value);
841 # }
842 # elsif($meta->relationship($name))
843 # {
844 # $self->$name($value);
845 # }
846 # }
847 #
848 # return $self;
849 # }
850  
851 63 our $Deflated = 0;
852  
853 sub init_with_deflated_tree
854 0 ▶{
Subroutine init_with_deflated_tree: not called CC=1 SCAR=6.9
Pod documented
855 0 local $Deflated = 1;
856 0 Rose::DB::Object::Helpers::init_with_tree(@_);
857 }
858  
859 sub init_with_tree
860 0 ▶{
Subroutine init_with_tree: not called CC=23 SCAR=63.1
Pod documented
861 0 my($self) = shift;
862  
863 0 my $meta = $self->meta;
864  
865 0 my %non_column;
866  
867 # Process all columns first
868 0 ▶ while(my($name, $value) = each(%{@_ == 1 ? $_[0] : {@_}}))
Branch: 2 branches
BranchTrueFalseTotal
if (() = each %{@_ == 1 ? $_[0] : {@_};}) 0 0 0
@_ == 1 ? : 0 0 0
869 {
870 0 ▶ next unless(length $name);
Branch: 1 branch
BranchTrueFalseTotal
unless length $name 0 0 0
871  
872 0 ▶ if(my $column = $meta->column($name))
Branch: 1 branch
BranchTrueFalseTotal
if (my $column = $meta->column($name)) { } 0 0 0
873 {
874 0 ▶ local $self->{STATE_LOADING()} = 1 if($Deflated);
Branch: 1 branch
BranchTrueFalseTotal
if $Rose::DB::Object::Helpers::Deflated 0 0 0
875 0 my $method = $column->mutator_method_name;
876 0 $self->$method($value);
877 }
878 else
879 {
880 0 $non_column{$name} = $value;
881 }
882 }
883  
884 # Process relationships and non-column attributes next
885 0 ▶ while(my($name, $value) = each(%non_column))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %non_column) 0 0 0
886 {
887 0 ▶ if(my $rel = $meta->relationship($name))
Branch: 2 branches
BranchTrueFalseTotal
if (my $rel = $meta->relationship($name)) { } 0 0 0
elsif ($self->can($name)) { } 0 0 0
888 {
889 0 ▶ my $method = $rel->method_name('get_set_on_save') ||
Condition0%0/5
$rel->method_name('get_set_on_save') || $rel->method_name('get_set') || (next)
l!l
00
$rel->method_name("get_set_on_save") or $rel->method_name("get_set")
l!l&&r!l&&!r
000
MC/DC0%0/2
$rel->method_name('get_set_on_save') || $rel->method_name('get_set') || (next)
$rel->method_name("get_set_on_save") $rel->method_name("get_set")
Truth table0%0/3
A or B
A= $rel->method_name("get_set_on_save")B= $rel->method_name("get_set")
ABresult
1X1
011
000
890 $rel->method_name('get_set') ||
891 next;
892  
893 0 my $ref = ref $value;
894  
895 0 ▶ if($ref eq 'HASH')
Branch: 2 branches
BranchTrueFalseTotal
if ($ref eq 'HASH') { } 0 0 0
elsif ($ref eq 'ARRAY') { } 0 0 0
896 {
897 # Split hash into relationship values and everything else
898 0 my %rel_vals;
899  
900 0 ▶ my %is_rel = map { $_->name => 1 } $rel->can('foreign_class') ?
Branch: 1 branch
BranchTrueFalseTotal
$rel->can('foreign_class') ? : 0 0 0
901 $rel->foreign_class->meta->relationships : $rel->class->meta->relationships;
902  
903 0 foreach my $k (keys %$value)
904 {
905 0 ▶ $rel_vals{$k} = delete $value->{$k} if($is_rel{$k});
Branch: 1 branch
BranchTrueFalseTotal
if $is_rel{$k} 0 0 0
906 }
907  
908 # %$value now has non-relationship keys only
909 0 my $object = $self->$method(%$value);
910  
911 # Recurse on relationship key
912 0 ▶ Rose::DB::Object::Helpers::init_with_tree($object, \%rel_vals) if(%rel_vals);
Branch: 1 branch
BranchTrueFalseTotal
if %rel_vals 0 0 0
913  
914 # Repair original hash
915 0 @$value{keys %rel_vals} = values %rel_vals;
916 }
917 elsif($ref eq 'ARRAY')
918 {
919 0 my(@objects, @sub_objects);
920  
921 0 foreach my $item (@$value)
922 {
923 # Split hash into relationship values and everything else
924 0 my %rel_vals;
925  
926 0 ▶ my %is_rel = map { $_->name => 1 } $rel->can('foreign_class') ?
Branch: 1 branch
BranchTrueFalseTotal
$rel->can('foreign_class') ? : 0 0 0
927 $rel->foreign_class->meta->relationships : $rel->class->meta->relationships;
928  
929 0 foreach my $k (keys %$item)
930 {
931 0 ▶ $rel_vals{$k} = delete $item->{$k} if($is_rel{$k});
Branch: 1 branch
BranchTrueFalseTotal
if $is_rel{$k} 0 0 0
932 }
933  
934 # %$item now has non-relationship keys only
935 0 push(@objects, { %$item }); # shallow copy is sufficient
936  
937 0 push(@sub_objects, \%rel_vals);
938  
939 # Repair original hash
940 0 @$item{keys %rel_vals} = values %rel_vals;
941 }
942  
943 # Add the related objects
944 0 $self->$method(\@objects);
945  
946 # Recurse on the sub-objects
947 0 foreach my $object (@{ $self->$method() })
948 {
949 0 my $sub_objects = shift(@sub_objects);
950 0 ▶ Rose::DB::Object::Helpers::init_with_tree($object, $sub_objects) if(%$sub_objects);
Branch: 1 branch
BranchTrueFalseTotal
if %$sub_objects 0 0 0
951 }
952 }
953 else
954 {
955 0 Carp::cluck "Unknown reference encountered in $self tree: $name => $value";
956 }
957 }
958 elsif($self->can($name))
959 {
960 0 $self->$name($value);
961 }
962  
963 # XXX: Silently ignore all other name/value pairs
964 }
965  
966 0 return $self;
967 }
968  
969 sub new_from_tree
970 0 ▶{
Subroutine new_from_tree: not called CC=1 SCAR=6.9
Pod documented
971 0 my $self = shift->new;
972 0 $self->Rose::DB::Object::Helpers::init_with_tree(@_);
973 }
974  
975 sub new_from_deflated_tree
976 0 ▶{
Subroutine new_from_deflated_tree: not called CC=1 SCAR=6.9
Pod documented
977 0 my $self = shift->new;
978 0 $self->Rose::DB::Object::Helpers::init_with_deflated_tree(@_);
979 }
980  
981 0 ▶__PACKAGE__->pre_import_hook(new_from_json => sub { require JSON });
Subroutine __ANON__: not called CC=1 SCAR=1.2
982 0 ▶__PACKAGE__->pre_import_hook(new_from_yaml => sub { require YAML::Syck });
Subroutine __ANON__: not called CC=1 SCAR=1.2
983  
984 0 ▶sub new_from_json { new_from_tree(shift, __PACKAGE__->json_decoder->decode(@_)) }
Subroutine new_from_json: not called CC=1 SCAR=6.9
Pod documented
985 0 ▶sub new_from_yaml { new_from_tree(shift, YAML::Syck::Load(@_)) }
Subroutine new_from_yaml: not called CC=1 SCAR=6.9
Pod documented
986  
987 0 ▶__PACKAGE__->pre_import_hook(init_with_json => sub { require JSON });
Subroutine __ANON__: not called CC=1 SCAR=1.2
988 0 ▶__PACKAGE__->pre_import_hook(init_with_yaml => sub { require YAML::Syck });
Subroutine __ANON__: not called CC=1 SCAR=1.2
989  
990 0 ▶sub init_with_json { init_with_tree(shift, __PACKAGE__->json_decoder->decode(@_)) }
Subroutine init_with_json: not called CC=1 SCAR=6.9
Pod documented
991 0 ▶sub init_with_yaml { init_with_tree(shift, YAML::Syck::Load(@_)) }
Subroutine init_with_yaml: not called CC=1 SCAR=6.9
Pod documented
992  
993 0 ▶__PACKAGE__->pre_import_hook(as_json => sub { require JSON });
Subroutine __ANON__: not called CC=1 SCAR=1.2
994 0 ▶__PACKAGE__->pre_import_hook(as_yaml => sub { require YAML::Syck });
Subroutine __ANON__: not called CC=1 SCAR=1.2
995  
996 0 ▶sub as_json { __PACKAGE__->json_encoder->encode(scalar as_tree(@_, deflate => 1)) }
Subroutine as_json: not called CC=1 SCAR=6.9
Pod documented
997 0 ▶sub as_yaml { YAML::Syck::Dump(scalar as_tree(@_, deflate => 1)) }
Subroutine as_yaml: not called CC=1 SCAR=6.9
Pod documented
998  
999 sub dirty_columns
1000 0 ▶{
Subroutine dirty_columns: not called CC=5 SCAR=34.0
Pod documented
1001 0 my($self) = shift;
1002  
1003 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1004 {
1005 0 foreach my $column (@_)
1006 {
1007 0 ▶ my $name =
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($column, 'Rose::DB::Object::Metadata::Column') ? : 0 0 0
1008 UNIVERSAL::isa($column, 'Rose::DB::Object::Metadata::Column') ?
1009 $column->name : $column;
1010 0 Rose::DB::Object::Util::set_column_value_modified($self, $name);
1011 }
1012  
1013 0 return;
1014 }
1015  
1016 0 return wantarray ? keys %{$self->{MODIFIED_COLUMNS()}} :
1017 0 ▶ scalar keys %{$self->{MODIFIED_COLUMNS()}};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1018 }
1019  
1020 63 1;
1021  
1022 __END__
« Object/Metadata/Auto.pm ↑ Summary Object/Metadata/Auto/MySQL.pm »