DBIx/Class/PK.pm

filter: Statementstmt 93.3% 42 / 45 Branchbran 63.6% 14 / 22 Conditioncond 46.6% 7 / 15 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 74.2% 78 / 105 CC 19 SCAR 17.0
CC
19
Cov
77%
_ident_values
9.8
_mk_ident_cond
7.0
_create_ID
3.2
CRAP 5.5
« DBIx/Class/Relationship/CascadeActions.pm ↑ Summary DBIx/Class/InflateColumn.pm »
1 package DBIx::Class::PK;
2  
3 308 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 308 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 308 ▶use base qw/DBIx::Class::Row/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 DBIx::Class::PK - Primary Key class
11  
12 =head1 SYNOPSIS
13  
14 =head1 DESCRIPTION
15  
16 This class contains methods for handling primary keys and methods
17 depending on them.
18  
19 =head1 METHODS
20  
21 =cut
22  
23 =head2 id
24  
25 Returns the primary key(s) for a row. Can't be called as
26 a class method.
27  
28 =cut
29  
30 sub id {
31 355 ▶ my ($self) = @_;
Subroutine id: called CC=3 SCAR=11.0
Pod documented
32 355 ▶ $self->throw_exception( "Can't call id() as a class method" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 355 355
33 unless ref $self;
34 355 my @id_vals = $self->_ident_values;
35 355 ▶ return (wantarray ? @id_vals : $id_vals[0]);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 67 288 355
36 }
37  
38 sub _ident_values {
39 1505 ▶ my ($self, $use_storage_state) = @_;
Subroutine _ident_values: called CC=8 SCAR=22.8
40  
41 1505 my (@ids, @missing);
42  
43 1505 for ($self->result_source->_pri_cols_or_die) {
44 push @ids, ($use_storage_state and exists $self->{_column_data_in_storage}{$_})
45 1546 ▶ ? $self->{_column_data_in_storage}{$_}
Branch: 1 branch
BranchTrueFalseTotal
$use_storage_state && exists $self->{'_column_data_in_storage'}{$_} ? : 7 1539 1546
Condition100%3/3
$use_storage_state and exists $self->{"_column_data_in_storage"}{$_}
!ll&&!rl&&r
44810917
MC/DC100%2/2
$use_storage_state and exists $self->{"_column_data_in_storage"}{$_}
$use_storage_state exists $self->{"_column_data_in_storage"}{$_}
Truth table100%3/3
A and B
A= $use_storage_stateB= exists $self->{"_column_data_in_storage"}{$_}
ABresult
0X0
100
111
46 : $self->get_column($_)
47 ;
48 1546 ▶ push @missing, $_ if (! defined $ids[-1] and ! $self->has_column_loaded ($_) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ids[-1] or $self->has_column_loaded($_) 0 1546 1546
Condition33%1/3
defined $ids[-1] or $self->has_column_loaded($_)
l!l&&r!l&&!r
154600
MC/DC0%0/2
defined $ids[-1] or $self->has_column_loaded($_)
defined $ids[-1] $self->has_column_loaded($_)
Truth table33%1/3
A or B
A= defined $ids[-1]B= $self->has_column_loaded($_)
ABresult
1X1
011
000
49 }
50  
51 1505 ▶ if (@missing && $self->in_storage) {
Branch: 1 branch
BranchTrueFalseTotal
if (@missing and $self->in_storage) 0 1505 1505
Condition33%1/3
@missing and $self->in_storage
!ll&&!rl&&r
150500
MC/DC0%0/2
@missing and $self->in_storage
@missing $self->in_storage
Truth table33%1/3
A and B
A= @missingB= $self->in_storage
ABresult
0X0
100
111
52 0 $self->throw_exception (
53 'Unable to uniquely identify result object with missing PK columns: '
54 . join (', ', @missing )
55 );
56 }
57  
58 1505 return @ids;
59 }
60  
61 =head2 ID
62  
63 Returns a unique id string identifying a result object by primary key.
64 Used by L<DBIx::Class::CDBICompat::LiveObjectIndex> and
65 L<DBIx::Class::ObjectCache>.
66  
67 =over
68  
69 =item WARNING
70  
71 The default C<_create_ID> method used by this function orders the returned
72 values by the alphabetical order of the primary column names, B<unlike>
73 the L</id> method, which follows the same order in which columns were fed
74 to L<DBIx::Class::ResultSource/set_primary_key>.
75  
76 =back
77  
78 =cut
79  
80 sub ID {
81 2 ▶ my ($self) = @_;
Subroutine ID: called CC=3 SCAR=11.3
Pod documented
82 2 ▶ $self->throw_exception( "Can't call ID() as a class method" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 2 2
83 unless ref $self;
84 2 ▶ return undef unless $self->in_storage;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in_storage 0 2 2
85 2 return $self->_create_ID(%{$self->ident_condition});
86 }
87  
88 sub _create_ID {
89 2 ▶ my ($self, %vals) = @_;
Subroutine _create_ID: called CC=3 SCAR=11.8
90 2 ▶ return undef unless 0 == grep { !defined } values %vals;
Branch: 1 branch
BranchTrueFalseTotal
unless 0 == grep({not defined $_;} values %vals) 0 2 2
91 return join '|', ref $self || $self, $self->result_source->name,
92 2 ▶ map { $_ . '=' . $vals{$_} } sort keys %vals;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
93 }
94  
95 =head2 ident_condition
96  
97 my $cond = $result_source->ident_condition();
98  
99 my $cond = $result_source->ident_condition('alias');
100  
101 Produces a condition hash to locate a row based on the primary key(s).
102  
103 =cut
104  
105 sub ident_condition {
106 83 ▶ shift->_mk_ident_cond(@_);
Subroutine ident_condition: called CC=1 SCAR=0.0
Pod documented
107 }
108  
109 sub _storage_ident_condition {
110 1069 ▶ shift->_mk_ident_cond(shift, 1);
Subroutine _storage_ident_condition: called CC=1 SCAR=0.0
111 }
112  
113 sub _mk_ident_cond {
114 1152 ▶ my ($self, $alias, $use_storage_state) = @_;
Subroutine _mk_ident_cond: called CC=6 SCAR=19.4
115  
116 1152 my @pks = $self->result_source->_pri_cols_or_die;
117 1150 my @vals = $self->_ident_values($use_storage_state);
118  
119 1150 my (%cond, @undef);
120 1150 ▶ my $prefix = defined $alias ? $alias.'.' : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $alias ? : 72 1078 1150
121 1150 for my $col (@pks) {
122 1186 ▶ if (! defined ($cond{$prefix.$col} = shift @vals) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($cond{$prefix . $col} = shift @vals)) 0 1186 1186
123 0 push @undef, $col;
124 }
125 }
126  
127 1150 ▶ if (@undef && $self->in_storage) {
Branch: 1 branch
BranchTrueFalseTotal
if (@undef and $self->in_storage) 0 1150 1150
Condition33%1/3
@undef and $self->in_storage
!ll&&!rl&&r
115000
MC/DC0%0/2
@undef and $self->in_storage
@undef $self->in_storage
Truth table33%1/3
A and B
A= @undefB= $self->in_storage
ABresult
0X0
100
111
128 0 $self->throw_exception (
129 'Unable to construct result object identity condition due to NULL PK columns: '
130 . join (', ', @undef)
131 );
132 }
133  
134 1150 return \%cond;
135 }
136  
137 308 1;
138  
139 =head1 AUTHOR AND CONTRIBUTORS
140  
141 See L<AUTHOR|DBIx::Class/AUTHOR> and L<CONTRIBUTORS|DBIx::Class/CONTRIBUTORS> in DBIx::Class
142  
143 =head1 LICENSE
144  
145 You may distribute this code under the same terms as Perl itself.
146  
147 =cut
148  
« DBIx/Class/Relationship/CascadeActions.pm ↑ Summary DBIx/Class/InflateColumn.pm »