| 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 | 379 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 379 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 379 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 379 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 379 | our %_pod_inherit_config = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | class_map => { 'DBIx::Class::Relationship::BelongsTo' => 'DBIx::Class::Relationship' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 13768 | ▶ | sub belongs_to { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
belongs_to: called CC=19 SCAR=29.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 13768 | my ($class, $rel, $f_class, $cond, $attrs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # assume a foreign key constraint unless defined otherwise | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | $attrs->{is_foreign_key_constraint} = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 13768 | ▶ | if not exists $attrs->{is_foreign_key_constraint}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | $attrs->{undef_on_null_fk} = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 13768 | ▶ | if not exists $attrs->{undef_on_null_fk}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # no join condition or just a column name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 13768 | ▶ | if (!ref $cond) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 8519 | my ($f_key, $guess); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 8519 | ▶ | if (defined $cond and length $cond) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $cond and length $cond
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 5896 | $f_key = $cond; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 5896 | $guess = "caller specified foreign key '$f_key'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2623 | $f_key = $rel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2623 | $guess = "using given relationship name '$rel' as foreign key column name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 8519 | ▶ | $class->throw_exception( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | "No such column '$f_key' declared yet on ${class} ($guess)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ) unless $class->has_column($f_key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 8519 | $class->ensure_class_loaded($f_class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 8519 | ▶ | my $f_rsrc = try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 8519 | $f_class->result_source_instance; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $class->throw_exception( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 8519 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 8519 | my $pri = $f_rsrc->_single_pri_col_or_die; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 8519 | $cond = { "foreign.${pri}" => "self.${f_key}" }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # explicit join condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 5249 | ▶ | if (ref $cond eq 'HASH') { # ARRAY is also valid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 3936 | my $cond_rel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # FIXME This loop is ridiculously incomplete and dangerous | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # staving off changes until implmentation of the swindon consensus | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3936 | for (keys %$cond) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 3936 | ▶ | if (m/\./) { # Explicit join condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 3935 | $cond_rel = $cond; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 3935 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | $cond_rel->{"foreign.$_"} = "self.".$cond->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 3936 | $cond = $cond_rel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 13768 | ▶ | my $acc_type = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
ref $cond eq "HASH" and keys %$cond == 1 and (keys %$cond)[0] =~ /^foreign\./ and $class->has_column($rel)
ref $cond eq "HASH" and keys %$cond == 1 and (keys %$cond)[0] =~ /^foreign\./
ref $cond eq "HASH" and keys %$cond == 1
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ref $cond eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | keys %$cond == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | (keys %$cond)[0] =~ /^foreign\./ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | $class->has_column($rel) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ) ? 'filter' : 'single'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | my $fk_columns = ($acc_type eq 'single' and ref $cond eq 'HASH') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 13768 | ▶ | ? { map { $_ =~ /^self\.(.+)/ ? ( $1 => 1 ) : () } (values %$cond ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$acc_type eq "single" and ref $cond eq "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | : undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | $class->add_relationship($rel, $f_class, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | $cond, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | is_depends_on => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | accessor => $acc_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | $fk_columns ? ( fk_columns => $fk_columns ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 13768 | ▶ | %{$attrs || {}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$attrs || {}
MC/DC0%0/1
$attrs || {}
$attrs
Truth table50%1/2
A
A= $attrs
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 13768 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 379 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||