blib/lib/DBIO/Relationship/HasMany.pm

filter: Statementstmt 100% 29 / 29 Branchbran 100% 6 / 6 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 95.9% 47 / 49 CC 6 SCAR 13.9
CC
6
Cov
98%
has_many
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« blib/lib/DBIO/Replicated/Balancer.pm ↑ Summary blib/lib/DBIO/Exception/Server.pm »
1 package DBIO::Relationship::HasMany;
2 # ABSTRACT: Declare a one-to-many relationship
3  
4 378 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 378 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 378 our $VERSION = '0.900007';
8  
9 378 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 378 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 378 our %_pod_inherit_config =
13 (
14 class_map => { 'DBIO::Relationship::HasMany' => 'DBIO::Relationship' }
15 );
16  
17  
18 9514 ▶sub has_many {
Subroutine has_many: called CC=6 SCAR=17.9
Pod documented
19 9514 my ($class, $rel, $f_class, $cond, $attrs) = @_;
20  
21 9514 ▶ unless (ref $cond) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $cond) 5668 3846 9514
22  
23 5668 my $pri = $class->result_source_instance->_single_pri_col_or_die;
24  
25 5668 my ($f_key,$guess);
26 5668 ▶ if (defined $cond && length $cond) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cond and length $cond) { } 3876 1792 5668
Condition66%2/3
defined $cond and length $cond
!ll&&!rl&&r
179203876
MC/DC50%1/2
defined $cond and length $cond
defined $cond length $cond
Truth table66%2/3
A and B
A= defined $condB= length $cond
ABresult
0X0
100
111
27 3876 $f_key = $cond;
28 3876 $guess = "caller specified foreign key '$f_key'";
29 } else {
30 1792 $class =~ /([^\:]+)$/; # match is safe - $class can't be ''
31 1792 $f_key = lc $1; # go ahead and guess; best we can do
32 1792 $guess = "using our class name '$class' as foreign key source";
33 }
34  
35 # FIXME - this check needs to be moved to schema-composition time...
36 # # only perform checks if the far side appears already loaded
37 # if (my $f_rsrc = try { $f_class->result_source_instance } ) {
38 # $class->throw_exception(
39 # "No such column '$f_key' on foreign class ${f_class} ($guess)"
40 # ) if !$f_rsrc->has_column($f_key);
41 # }
42  
43 5668 $cond = { "foreign.${f_key}" => "self.${pri}" };
44 }
45  
46 9514 ▶ my $default_cascade = ref $cond eq 'CODE' ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
ref $cond eq 'CODE' ? : 2048 7466 9514
47  
48 $class->add_relationship($rel, $f_class, $cond, {
49 accessor => 'multi',
50 join_type => 'LEFT',
51 cascade_delete => $default_cascade,
52 cascade_copy => $default_cascade,
53 is_depends_on => 0,
54 9514 ▶ %{$attrs||{}}
Condition100%2/2
$attrs || {}
l!l
15367978
MC/DC100%1/1
$attrs || {}
$attrs
Truth table100%2/2
A
A= $attrs
Aresult
11
00
55 });
56 }
57  
58 378 1;
59  
60 __END__
« blib/lib/DBIO/Replicated/Balancer.pm ↑ Summary blib/lib/DBIO/Exception/Server.pm »