blib/lib/DBIO/InflateColumn.pm

filter: Statementstmt 87.2% 48 / 55 Branchbran 60.7% 17 / 28 Conditioncond 38.1% 8 / 21 MC/DCmcdc 14.2% 2 / 14 Subroutinesub 90.9% 10 / 11 Podpod 100% 4 / 4 totaltotal 66.9% 89 / 133 CC 22 SCAR 17.9
CC
22
Cov
70%
store_inflated_column
12.0
_deflated_column
8.5
_inflated_column
6.9
CRAP 6.0
« blib/lib/DBIO/Storage/DBI/AccessBroker.pm ↑ Summary blib/lib/DBIO/Replicated/Balancer/Random.pm »
1 package DBIO::InflateColumn;
2 # ABSTRACT: Automatically create references from column data
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 'DBIO::Row';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 378 ▶use DBIO::Util qw(is_literal_value);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 378 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 6180 ▶sub inflate_column {
Subroutine inflate_column: called CC=6 SCAR=18.8
Pod documented
15 6180 my ($self, $col, $attrs) = @_;
16  
17 6180 my $colinfo = $self->column_info($col);
18  
19 $self->throw_exception("InflateColumn can not be used on a column with a declared FilterColumn filter")
20 6180 ▶ if defined $colinfo->{_filter_info} and $self->isa('DBIO::FilterColumn');
Branch: 1 branch
BranchTrueFalseTotal
if defined $colinfo->{"_filter_info"} and $self->isa("DBIO::FilterColumn") 0 6180 6180
Condition33%1/3
defined $colinfo->{"_filter_info"} and $self->isa("DBIO::FilterColumn")
!ll&&!rl&&r
618000
MC/DC0%0/2
defined $colinfo->{"_filter_info"} and $self->isa("DBIO::FilterColumn")
defined $colinfo->{"_filter_info"} $self->isa("DBIO::FilterColumn")
Truth table33%1/3
A and B
A= defined $colinfo->{"_filter_info"}B= $self->isa("DBIO::FilterColumn")
ABresult
0X0
100
111
21  
22 6180 ▶ $self->throw_exception("No such column $col to inflate")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_column($col) 0 6180 6180
23 unless $self->has_column($col);
24 6180 ▶ $self->throw_exception("inflate_column needs attr hashref")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attrs eq "HASH" 0 6180 6180
25 unless ref $attrs eq 'HASH';
26 6180 $colinfo->{_inflate_info} = $attrs;
27 6180 my $acc = $colinfo->{accessor};
28 6180 ▶ $self->mk_group_accessors('inflated_column' => [ (defined $acc ? $acc : $col), $col]);
Branch: 1 branch
BranchTrueFalseTotal
defined $acc ? : 256 5924 6180
29 6180 return 1;
30 }
31  
32 66 ▶sub _inflated_column {
Subroutine _inflated_column: called CC=6 SCAR=19.3
33 66 my ($self, $col, $value) = @_;
34  
35 66 ▶ return $value if (
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or &is_literal_value($value) 1 65 66
Condition66%2/3
not defined $value or &is_literal_value($value)
l!l&&r!l&&!r
1065
MC/DC50%1/2
not defined $value or &is_literal_value($value)
not defined $value &is_literal_value($value)
Truth table66%2/3
not(A) or B
A= not defined $valueB= &is_literal_value($value)
ABresult
1X1
011
000
36 ! defined $value # NULL is NULL is NULL
37 or
38 is_literal_value($value) #that would be a not-yet-reloaded literal update
39 );
40  
41 65 ▶ my $info = $self->result_source->column_info($col)
Branch: 1 branch
BranchTrueFalseTotal
my $info = $self->result_source->column_info($col) or $self->throw_exception("No column info for $col") 65 0 65
42 or $self->throw_exception("No column info for $col");
43  
44 65 ▶ return $value unless exists $info->{_inflate_info};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $info->{"_inflate_info"} 0 65 65
45  
46 return (
47 $info->{_inflate_info}{inflate}
48 ||
49 65 ▶ $self->throw_exception("No inflator found for '$col'")
Condition33%1/3
$info->{'_inflate_info'}{'inflate'} || $self->throw_exception("No inflator found for '${col}'")
l!l&&r!l&&!r
6500
MC/DC0%0/2
$info->{'_inflate_info'}{'inflate'} || $self->throw_exception("No inflator found for '${col}'")
$info->{'_inflate_info'}{'inflate'} $self->throw_exception("No inflator found for '${col}'")
Truth table33%1/3
A || B
A= $info->{'_inflate_info'}{'inflate'}B= $self->throw_exception("No inflator found for '${col}'")
ABresult
1X1
011
000
50 )->($value, $self);
51 }
52  
53 80 ▶sub _deflated_column {
Subroutine _deflated_column: called CC=6 SCAR=21.4
54 80 my ($self, $col, $value) = @_;
55  
56 ## Deflate any refs except for literals, pass through plain values
57 80 ▶ return $value if (
Branch: 1 branch
BranchTrueFalseTotal
if not length ref $value or &is_literal_value($value) 0 80 80
Condition33%1/3
not length ref $value or &is_literal_value($value)
l!l&&r!l&&!r
0080
MC/DC0%0/2
not length ref $value or &is_literal_value($value)
not length ref $value &is_literal_value($value)
Truth table33%1/3
not(A) or B
A= not length ref $valueB= &is_literal_value($value)
ABresult
1X1
011
000
58 ! length ref $value
59 or
60 is_literal_value($value)
61 );
62  
63 80 ▶ my $info = $self->result_source->column_info($col) or
Branch: 1 branch
BranchTrueFalseTotal
my $info = $self->result_source->column_info($col) or $self->throw_exception("No column info for $col") 80 0 80
64 $self->throw_exception("No column info for $col");
65  
66 80 ▶ return $value unless exists $info->{_inflate_info};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $info->{"_inflate_info"} 0 80 80
67  
68 return (
69 $info->{_inflate_info}{deflate}
70 ||
71 80 ▶ $self->throw_exception("No deflator found for '$col'")
Condition33%1/3
$info->{'_inflate_info'}{'deflate'} || $self->throw_exception("No deflator found for '${col}'")
l!l&&r!l&&!r
8000
MC/DC0%0/2
$info->{'_inflate_info'}{'deflate'} || $self->throw_exception("No deflator found for '${col}'")
$info->{'_inflate_info'}{'deflate'} $self->throw_exception("No deflator found for '${col}'")
Truth table33%1/3
A || B
A= $info->{'_inflate_info'}{'deflate'}B= $self->throw_exception("No deflator found for '${col}'")
ABresult
1X1
011
000
72 )->($value, $self);
73 }
74  
75  
76 75 ▶sub get_inflated_column {
Subroutine get_inflated_column: called CC=3 SCAR=11.0
Pod documented
77 75 my ($self, $col) = @_;
78  
79 $self->throw_exception("$col is not an inflated column")
80 75 ▶ unless exists $self->result_source->column_info($col)->{_inflate_info};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->result_source->column_info($col)->{"_inflate_info"} 0 75 75
81  
82 # we take care of keeping things in sync
83 return $self->{_inflated_column}{$col}
84 75 ▶ if exists $self->{_inflated_column}{$col};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_inflated_column"}{$col} 9 66 75
85  
86 66 my $val = $self->get_column($col);
87  
88 66 return $self->{_inflated_column}{$col} = $self->_inflated_column($col, $val);
89 }
90  
91  
92 16 ▶sub set_inflated_column {
Subroutine set_inflated_column: called CC=3 SCAR=11.0
Pod documented
93 16 my ($self, $col, $value) = @_;
94  
95 # pass through deflated stuff
96 16 ▶ if (! length ref $value or is_literal_value($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not length ref $value or &is_literal_value($value)) { } 3 13 16
Condition66%2/3
not length ref $value or &is_literal_value($value)
l!l&&r!l&&!r
3013
MC/DC50%1/2
not length ref $value or &is_literal_value($value)
not length ref $value &is_literal_value($value)
Truth table66%2/3
not(A) or B
A= not length ref $valueB= &is_literal_value($value)
ABresult
1X1
011
000
97 3 $self->set_column($col, $value);
98 3 delete $self->{_inflated_column}{$col};
99 }
100 # need to call set_column with the deflate cycle so that
101 # relationship caches are nuked if any
102 # also does the compare-for-dirtyness and change tracking dance
103 else {
104 13 $self->set_column($col, $self->_deflated_column($col, $value));
105 8 $self->{_inflated_column}{$col} = $value;
106 }
107  
108 11 return $value;
109 }
110  
111  
112 0 ▶sub store_inflated_column {
Subroutine store_inflated_column: not called CC=3 SCAR=24.8
Pod documented
113 0 my ($self, $col, $value) = @_;
114  
115 0 ▶ if (! length ref $value or is_literal_value($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not length ref $value or &is_literal_value($value)) { } 0 0 0
Condition0%0/3
not length ref $value or &is_literal_value($value)
l!l&&r!l&&!r
000
MC/DC0%0/2
not length ref $value or &is_literal_value($value)
not length ref $value &is_literal_value($value)
Truth table0%0/3
not(A) or B
A= not length ref $valueB= &is_literal_value($value)
ABresult
1X1
011
000
116 0 delete $self->{_inflated_column}{$col};
117 0 $self->store_column($col => $value);
118 }
119 else {
120 0 delete $self->{_column_data}{$col};
121 0 $self->{_inflated_column}{$col} = $value;
122 }
123  
124 0 return $value;
125 }
126  
127  
128 378 1;
129  
130 __END__
« blib/lib/DBIO/Storage/DBI/AccessBroker.pm ↑ Summary blib/lib/DBIO/Replicated/Balancer/Random.pm »