blib/lib/DBIO/PK.pm

filter: Statementstmt 71.7% 33 / 46 Branchbran 45.4% 10 / 22 Conditioncond 40.0% 6 / 15 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 80.0% 8 / 10 Podpod 100% 3 / 3 totaltotal 58.4% 62 / 106 CC 19 SCAR 20.0
CC
19
Cov
59%
ID
12.0
_create_ID
12.0
_ident_values
9.8
CRAP 7.4
« blib/lib/DBIO.pm ↑ Summary blib/lib/DBIO/Diff/Base.pm »
1 package DBIO::PK;
2 # ABSTRACT: Primary Key class
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 base qw/DBIO::Row/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12  
13 19 ▶sub id {
Subroutine id: called CC=3 SCAR=11.4
Pod documented
14 19 my ($self) = @_;
15 19 ▶ $self->throw_exception( "Can't call id() as a class method" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 19 19
16 unless ref $self;
17 19 my @id_vals = $self->_ident_values;
18 19 ▶ return (wantarray ? @id_vals : $id_vals[0]);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 19 19
19 }
20  
21  
22 380 ▶sub _ident_values {
Subroutine _ident_values: called CC=8 SCAR=22.8
23 380 my ($self, $use_storage_state) = @_;
24  
25 380 my (@ids, @missing);
26  
27 380 for ($self->result_source->_pri_cols_or_die) {
28 push @ids, ($use_storage_state and exists $self->{_column_data_in_storage}{$_})
29 381 ▶ ? $self->{_column_data_in_storage}{$_}
Branch: 1 branch
BranchTrueFalseTotal
$use_storage_state && exists $self->{'_column_data_in_storage'}{$_} ? : 9 372 381
Condition100%3/3
$use_storage_state and exists $self->{"_column_data_in_storage"}{$_}
!ll&&!rl&&r
243489
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
30 : $self->get_column($_)
31 ;
32 381 ▶ 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 381 381
Condition33%1/3
defined $ids[-1] or $self->has_column_loaded($_)
l!l&&r!l&&!r
38100
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
33 }
34  
35 380 ▶ if (@missing && $self->in_storage) {
Branch: 1 branch
BranchTrueFalseTotal
if (@missing and $self->in_storage) 0 380 380
Condition33%1/3
@missing and $self->in_storage
!ll&&!rl&&r
38000
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
36 0 $self->throw_exception (
37 'Unable to uniquely identify result object with missing PK columns: '
38 . join (', ', @missing )
39 );
40 }
41  
42 380 return @ids;
43 }
44  
45  
46 0 ▶sub ID {
Subroutine ID: not called CC=3 SCAR=24.8
Pod documented
47 0 my ($self) = @_;
48 0 ▶ $self->throw_exception( "Can't call ID() as a class method" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
49 unless ref $self;
50 0 ▶ return undef unless $self->in_storage;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in_storage 0 0 0
51 0 return $self->_create_ID(%{$self->ident_condition});
52 }
53  
54  
55 0 ▶sub _create_ID {
Subroutine _create_ID: not called CC=3 SCAR=24.8
56 0 my ($self, %vals) = @_;
57 0 ▶ return undef if grep { !defined } values %vals;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} values %vals 0 0 0
58 return join '|', ref $self || $self, $self->result_source->name,
59 0 ▶ map { $_ . '=' . $vals{$_} } sort keys %vals;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
60 }
61  
62  
63 5 ▶sub ident_condition {
Subroutine ident_condition: called CC=1 SCAR=0.0
Pod documented
64 5 shift->_mk_ident_cond(@_);
65 }
66  
67  
68 356 ▶sub _storage_ident_condition {
Subroutine _storage_ident_condition: called CC=1 SCAR=0.0
69 356 shift->_mk_ident_cond(shift, 1);
70 }
71  
72  
73 361 ▶sub _mk_ident_cond {
Subroutine _mk_ident_cond: called CC=6 SCAR=19.4
74 361 my ($self, $alias, $use_storage_state) = @_;
75  
76 361 my @pks = $self->result_source->_pri_cols_or_die;
77 361 my @vals = $self->_ident_values($use_storage_state);
78  
79 361 my (%cond, @undef);
80 361 ▶ my $prefix = defined $alias ? $alias.'.' : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $alias ? : 5 356 361
81 361 for my $col (@pks) {
82 362 ▶ if (! defined ($cond{$prefix.$col} = shift @vals) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($cond{$prefix . $col} = shift @vals)) 0 362 362
83 0 push @undef, $col;
84 }
85 }
86  
87 361 ▶ if (@undef && $self->in_storage) {
Branch: 1 branch
BranchTrueFalseTotal
if (@undef and $self->in_storage) 0 361 361
Condition33%1/3
@undef and $self->in_storage
!ll&&!rl&&r
36100
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
88 0 $self->throw_exception (
89 'Unable to construct result object identity condition due to NULL PK columns: '
90 . join (', ', @undef)
91 );
92 }
93  
94 361 return \%cond;
95 }
96  
97  
98 378 1;
99  
100 __END__
« blib/lib/DBIO.pm ↑ Summary blib/lib/DBIO/Diff/Base.pm »