DBIx/Class/Relationship/BelongsTo.pm

filter: Statementstmt 95.5% 43 / 45 Branchbran 83.3% 20 / 24 Conditioncond 86.6% 13 / 15 MC/DCmcdc 75.0% 6 / 8 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 88.0% 88 / 100 CC 19 SCAR 27.2
CC
19
Cov
90%
belongs_to
19.5
__ANON__
2.0
BEGIN
1.0
CRAP 15.1
« DBIx/Class/Storage/DBI/ODBC/ACCESS.pm ↑ Summary DBIx/Class/Relationship/ManyToMany.pm »
1 package # hide from PAUSE
2 DBIx::Class::Relationship::BelongsTo;
3  
4 # Documentation for these methods can be found in
5 # DBIx::Class::Relationship
6  
7 308 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 308 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 308 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 308 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 308 our %_pod_inherit_config =
13 (
14 class_map => { 'DBIx::Class::Relationship::BelongsTo' => 'DBIx::Class::Relationship' }
15 );
16  
17 sub belongs_to {
18 12342 ▶ my ($class, $rel, $f_class, $cond, $attrs) = @_;
Subroutine belongs_to: called CC=19 SCAR=29.7
Pod undocumented
19  
20 # assume a foreign key constraint unless defined otherwise
21 $attrs->{is_foreign_key_constraint} = 1
22 12342 ▶ if not exists $attrs->{is_foreign_key_constraint};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attrs->{"is_foreign_key_constraint"} 12034 308 12342
23 $attrs->{undef_on_null_fk} = 1
24 12342 ▶ if not exists $attrs->{undef_on_null_fk};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attrs->{"undef_on_null_fk"} 12034 308 12342
25  
26 # no join condition or just a column name
27 12342 ▶ if (!ref $cond) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $cond) { } 8016 4326 12342
28  
29 8016 my ($f_key, $guess);
30 8016 ▶ if (defined $cond and length $cond) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cond and length $cond) { } 5548 2468 8016
Condition66%2/3
defined $cond and length $cond
!ll&&!rl&&r
246805548
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
31 5548 $f_key = $cond;
32 5548 $guess = "caller specified foreign key '$f_key'";
33 }
34 else {
35 2468 $f_key = $rel;
36 2468 $guess = "using given relationship name '$rel' as foreign key column name";
37 }
38  
39 8016 ▶ $class->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless $class->has_column($f_key) 0 8016 8016
40 "No such column '$f_key' declared yet on ${class} ($guess)"
41 ) unless $class->has_column($f_key);
42  
43 8016 $class->ensure_class_loaded($f_class);
44 my $f_rsrc = try {
45 8016 ▶ $f_class->result_source_instance;
Subroutine __ANON__: called CC=1 SCAR=0.0
46 }
47 catch {
48 0 ▶ $class->throw_exception(
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 "Foreign class '$f_class' does not seem to be a Result class "
50 . "(or it simply did not load entirely due to a circular relation chain)"
51 );
52 8016 };
53  
54 8016 my $pri = $f_rsrc->_single_pri_col_or_die;
55  
56 8016 $cond = { "foreign.${pri}" => "self.${f_key}" };
57  
58 }
59 # explicit join condition
60 else {
61 4326 ▶ if (ref $cond eq 'HASH') { # ARRAY is also valid
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cond eq "HASH") 3710 616 4326
62 3710 my $cond_rel;
63 3710 for (keys %$cond) {
64 3710 ▶ if (m/\./) { # Explicit join condition
Branch: 1 branch
BranchTrueFalseTotal
if (/\./) 3710 0 3710
65 3710 $cond_rel = $cond;
66 3710 last;
67 }
68 0 $cond_rel->{"foreign.$_"} = "self.".$cond->{$_};
69 }
70 3710 $cond = $cond_rel;
71 }
72 }
73  
74 12342 ▶ my $acc_type = (
Branch: 1 branch
BranchTrueFalseTotal
ref $cond eq 'HASH' && keys %$cond == 1 && (keys %$cond)[0] =~ /^foreign\./ && $class->has_column($rel) ? : 5252 7090 12342
Condition88%8/9
ref $cond eq "HASH" and keys %$cond == 1 and (keys %$cond)[0] =~ /^foreign\./ and $class->has_column($rel)
!ll&&!rl&&r
154055505252
ref $cond eq "HASH" and keys %$cond == 1 and (keys %$cond)[0] =~ /^foreign\./
!ll&&!rl&&r
1540010802
ref $cond eq "HASH" and keys %$cond == 1
!ll&&!rl&&r
61692410802
MC/DC75%3/4
ref $cond eq "HASH" and keys %$cond == 1 and (keys %$cond)[0] =~ /^foreign\./ and $class->has_column($rel)
ref $cond eq "HASH" keys %$cond == 1 (keys %$cond)[0] =~ /^foreign\./ $class->has_column($rel)
Truth table80%4/5
A and B and C and D
A= ref $cond eq "HASH"B= keys %$cond == 1C= (keys %$cond)[0] =~ /^foreign\./D= $class->has_column($rel)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
75 ref $cond eq 'HASH'
76 and
77 keys %$cond == 1
78 and
79 (keys %$cond)[0] =~ /^foreign\./
80 and
81 $class->has_column($rel)
82 ) ? 'filter' : 'single';
83  
84 my $fk_columns = ($acc_type eq 'single' and ref $cond eq 'HASH')
85 12342 ▶ ? { map { $_ =~ /^self\.(.+)/ ? ( $1 => 1 ) : () } (values %$cond ) }
Branch: 2 branches
BranchTrueFalseTotal
$acc_type eq 'single' && ref $cond eq 'HASH' ? : 6474 5868 12342
$_ =~ /^self\.(.+)/ ? : 8014 0 8014
Condition100%3/3
$acc_type eq "single" and ref $cond eq "HASH"
!ll&&!rl&&r
52526166474
MC/DC100%2/2
$acc_type eq "single" and ref $cond eq "HASH"
$acc_type eq "single" ref $cond eq "HASH"
Truth table100%3/3
A and B
A= $acc_type eq "single"B= ref $cond eq "HASH"
ABresult
0X0
100
111
86 : undef
87 ;
88  
89 $class->add_relationship($rel, $f_class,
90 $cond,
91 {
92 accessor => $acc_type,
93 $fk_columns ? ( fk_columns => $fk_columns ) : (),
94 12342 ▶ %{$attrs || {}}
Branch: 2 branches
BranchTrueFalseTotal
$fk_columns ? : 6474 5868 12342
$attrs or {} 0 12342 12342
95 }
96 );
97  
98 12342 return 1;
99 }
100  
101 # Attempt to remove the POD so it (maybe) falls off the indexer
102  
103 #=head1 AUTHORS
104 #
105 #Alexander Hartmaier <Alexander.Hartmaier@t-systems.at>
106 #
107 #Matt S. Trout <mst@shadowcatsystems.co.uk>
108 #
109 #=cut
110  
111 308 1;
« DBIx/Class/Storage/DBI/ODBC/ACCESS.pm ↑ Summary DBIx/Class/Relationship/ManyToMany.pm »