DBIx/Class/Relationship/Accessor.pm

filter: Statementstmt 79.1% 72 / 91 Branchbran 60.0% 24 / 40 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 85.0% 17 / 20 Podpod 0.0% 0 / 2 totaltotal 74.6% 118 / 158 CC 191 SCAR 22.7
CC
191
Cov
74%
__ANON__
13.9
artist
13.9
artist1
13.9
CRAP 9.7
« DBIx/Class/Storage/DBI/InterBase.pm ↑ Summary DBIx/Class/Componentised.pm »
1 package # hide from PAUSE
2 DBIx::Class::Relationship::Accessor;
3  
4 308 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 308 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 308 ▶use Sub::Name;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 308 ▶use DBIx::Class::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 308 ▶use DBIx::Class::_Util 'fail_on_internal_wantarray';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 308 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 221 our %_pod_inherit_config =
12 (
13 class_map => { 'DBIx::Class::Relationship::Accessor' => 'DBIx::Class::Relationship' }
14 );
15  
16 sub register_relationship {
17 25614 ▶ my ($class, $rel, $info) = @_;
Subroutine register_relationship: called CC=2 SCAR=6.9
Pod undocumented
18 25614 ▶ if (my $acc_type = $info->{attrs}{accessor}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $acc_type = $info->{"attrs"}{"accessor"}) 25611 3 25614
19 25611 $class->add_relationship_accessor($rel => $acc_type);
20 }
21 25614 $class->next::method($rel => $info);
22 }
23  
24 sub add_relationship_accessor {
25 25611 ▶ my ($class, $rel, $acc_type) = @_;
Subroutine add_relationship_accessor: called CC=6 SCAR=19.8
Pod undocumented
26 25611 my %meth;
27 25611 ▶ if ($acc_type eq 'single') {
Branch: 3 branches
BranchTrueFalseTotal
if ($acc_type eq 'single') { } 9864 15747 25611
elsif ($acc_type eq 'filter') { } 5252 10495 15747
elsif ($acc_type eq 'multi') { } 10495 0 10495
28 9864 my $rel_info = $class->relationship_info($rel);
29 $meth{$rel} = sub {
30 0 ▶ my $self = shift;
Subroutine existing_single_track: not called CC=7 SCAR=26.3
Subroutine artist1: called CC=7 SCAR=26.3
31 0 ▶ if (@_) {
Branch: 4 branches
BranchTrueFalseTotal
if (@_) { } 0 0 0
elsif (exists $self->{'_relationship_data'}{$rel}) { } 0 0 0
if (@_) { } 2 650 652
elsif (exists $self->{'_relationship_data'}{$rel}) { } 122 528 650
32 0 $self->set_from_related($rel, @_);
33 0 return $self->{_relationship_data}{$rel} = $_[0];
34 } elsif (exists $self->{_relationship_data}{$rel}) {
35 0 return $self->{_relationship_data}{$rel};
36 } else {
37 my $cond = $self->result_source->_resolve_condition(
38 0 $rel_info->{cond}, $rel, $self, $rel
39 );
40 0 ▶ if ($rel_info->{attrs}->{undef_on_null_fk}){
Branch: 2 branches
BranchTrueFalseTotal
if ($rel_info->{"attrs"}{"undef_on_null_fk"}) 0 0 0
if ($rel_info->{"attrs"}{"undef_on_null_fk"}) 485 42 527
41 0 ▶ return undef unless ref($cond) eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $cond eq "HASH" 0 0 0
unless ref $cond eq "HASH" 1 484 485
42 0 ▶ return undef if grep { not defined $_ } values %$cond;
Branch: 2 branches
BranchTrueFalseTotal
if grep {not defined $_;} values %$cond 0 0 0
if grep {not defined $_;} values %$cond 2 482 484
43 }
44 0 my $val = $self->find_related($rel, {}, {});
45 0 ▶ return $val unless $val; # $val instead of undef so that null-objects can go through
Branch: 2 branches
BranchTrueFalseTotal
unless $val 0 0 0
unless $val 34 490 524
46  
47 0 return $self->{_relationship_data}{$rel} = $val;
48 }
49 9864 };
50 } elsif ($acc_type eq 'filter') {
51 5252 ▶ $class->throw_exception("No such column '$rel' to filter")
Branch: 1 branch
BranchTrueFalseTotal
unless $class->has_column($rel) 0 5252 5252
52 unless $class->has_column($rel);
53 5252 my $f_class = $class->relationship_info($rel)->{class};
54 $class->inflate_column($rel,
55 { inflate => sub {
56 307 ▶ my ($val, $self) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
57 307 return $self->find_or_new_related($rel, {}, {});
58 },
59 deflate => sub {
60 112 ▶ my ($val, $self) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.2
61 112 ▶ $self->throw_exception("'$val' isn't a $f_class") unless $val->isa($f_class);
Branch: 1 branch
BranchTrueFalseTotal
unless $val->isa($f_class) 0 112 112
62  
63 # MASSIVE FIXME - this code assumes we pointed at the PK, but the belongs_to
64 # helper does not check any of this
65 # fixup the code a bit to make things saner, but ideally 'filter' needs to
66 # be deprecated ASAP and removed shortly after
67 # Not doing so before 0.08250 however, too many things in motion already
68 112 my ($pk_col, @rest) = $val->result_source->_pri_cols_or_die;
69 112 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
if @rest 0 112 112
70 "Relationship '$rel' of type 'filter' can not work with a multicolumn primary key on source '$f_class'"
71 ) if @rest;
72  
73 112 my $pk_val = $val->get_column($pk_col);
74 112 ▶ carp_unique (
Branch: 1 branch
BranchTrueFalseTotal
if not defined $pk_val and $val->in_storage 7 105 112
Condition100%3/3
not defined $pk_val and $val->in_storage
!ll&&!rl&&r
75307
MC/DC100%2/2
not defined $pk_val and $val->in_storage
not defined $pk_val $val->in_storage
Truth table100%3/3
not(A) and B
A= not defined $pk_valB= $val->in_storage
ABresult
0X0
100
111
75 "Unable to deflate 'filter'-type relationship '$rel' (related object "
76 . "primary key not retrieved), assuming undef instead"
77 ) if ( ! defined $pk_val and $val->in_storage );
78  
79 112 return $pk_val;
80 }
81 }
82 5252 );
83 } elsif ($acc_type eq 'multi') {
84 $meth{$rel} = sub {
85 653 ▶ DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_WANTARRAY and wantarray and my $sog = fail_on_internal_wantarray($_[0]);
Subroutine aliases: called CC=1 SCAR=0.0
Subroutine tracks: called CC=1 SCAR=0.0
86 653 shift->search_related($rel, @_)
87 10495 };
88 10495 ▶ $meth{"${rel}_rs"} = sub { shift->search_related_rs($rel, @_) };
Subroutine fourkeys_to_twokeys_rs: not called CC=1 SCAR=0.4
Subroutine tracks_rs: called CC=1 SCAR=0.4
89 10495 ▶ $meth{"add_to_${rel}"} = sub { shift->create_related($rel, @_); };
Subroutine add_to_artist_undirected_maps: not called CC=1 SCAR=2.6
Subroutine add_to_artwork_to_artist_test_m2m: called CC=1 SCAR=2.6
90 } else {
91 0 $class->throw_exception("No such relationship accessor type '$acc_type'");
92 }
93 {
94 308 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
95 308 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
96 25611 foreach my $meth (keys %meth) {
97 41349 my $name = join '::', $class, $meth;
98 41349 *$name = subname($name, $meth{$meth});
99 }
100 }
101 }
102  
103 221 1;
« DBIx/Class/Storage/DBI/InterBase.pm ↑ Summary DBIx/Class/Componentised.pm »