DBIx/Class/FilterColumn.pm

filter: Statementstmt 100% 84 / 84 Branchbran 71.7% 33 / 46 Conditioncond 78.2% 18 / 23 MC/DCmcdc 64.2% 9 / 14 Subroutinesub 100% 17 / 17 Podpod 100% 10 / 10 totaltotal 88.1% 171 / 194 CC 37 SCAR 15.1
CC
37
Cov
88%
filter_column
8.2
_column_from_storage
5.2
new
5.2
CRAP 4.5
« DBIx/Class/Storage/Debug/PrettyTrace.pm ↑ Summary DBIx/Class/CDBICompat/ColumnCase.pm »
1 package DBIx::Class::FilterColumn;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use base 'DBIx::Class::Row';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use SQL::Abstract::Util 'is_literal_value';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶sub filter_column {
Subroutine filter_column: called CC=8 SCAR=21.1
Pod documented
10 6 my ($self, $col, $attrs) = @_;
11  
12 6 my $colinfo = $self->column_info($col);
13  
14 $self->throw_exception("FilterColumn can not be used on a column with a declared InflateColumn inflator")
15 6 ▶ if defined $colinfo->{_inflate_info} and $self->isa('DBIx::Class::InflateColumn');
Branch: 1 branch
BranchTrueFalseTotal
if defined $colinfo->{"_inflate_info"} and $self->isa("DBIx::Class::InflateColumn") 1 5 6
Condition66%2/3
defined $colinfo->{"_inflate_info"} and $self->isa("DBIx::Class::InflateColumn")
!ll&&!rl&&r
501
MC/DC50%1/2
defined $colinfo->{"_inflate_info"} and $self->isa("DBIx::Class::InflateColumn")
defined $colinfo->{"_inflate_info"} $self->isa("DBIx::Class::InflateColumn")
Truth table66%2/3
A and B
A= defined $colinfo->{"_inflate_info"}B= $self->isa("DBIx::Class::InflateColumn")
ABresult
0X0
100
111
16  
17 5 ▶ $self->throw_exception("No such column $col to filter")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_column($col) 0 5 5
18 unless $self->has_column($col);
19  
20 5 ▶ $self->throw_exception('filter_column expects a hashref of filter specifications')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attrs eq "HASH" 0 5 5
21 unless ref $attrs eq 'HASH';
22  
23 $self->throw_exception('An invocation of filter_column() must specify either a filter_from_storage or filter_to_storage')
24 5 ▶ unless $attrs->{filter_from_storage} || $attrs->{filter_to_storage};
Branch: 1 branch
BranchTrueFalseTotal
unless $attrs->{"filter_from_storage"} or $attrs->{"filter_to_storage"} 1 4 5
Condition100%3/3
$attrs->{"filter_from_storage"} or $attrs->{"filter_to_storage"}
l!l&&r!l&&!r
311
MC/DC100%2/2
$attrs->{"filter_from_storage"} or $attrs->{"filter_to_storage"}
$attrs->{"filter_from_storage"} $attrs->{"filter_to_storage"}
Truth table100%3/3
A or B
A= $attrs->{"filter_from_storage"}B= $attrs->{"filter_to_storage"}
ABresult
1X1
011
000
25  
26 4 $colinfo->{_filter_info} = $attrs;
27 4 my $acc = $colinfo->{accessor};
28 4 ▶ $self->mk_group_accessors(filtered_column => [ (defined $acc ? $acc : $col), $col]);
Branch: 1 branch
BranchTrueFalseTotal
defined $acc ? : 0 4 4
29 4 return 1;
30 }
31  
32 14 ▶sub _column_from_storage {
Subroutine _column_from_storage: called CC=5 SCAR=16.6
33 14 my ($self, $col, $value) = @_;
34  
35 14 ▶ return $value if is_literal_value($value);
Branch: 1 branch
BranchTrueFalseTotal
if &is_literal_value($value) 0 14 14
36  
37 14 ▶ 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") 14 0 14
38 or $self->throw_exception("No column info for $col");
39  
40 14 ▶ return $value unless exists $info->{_filter_info};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $info->{"_filter_info"} 0 14 14
41  
42 14 my $filter = $info->{_filter_info}{filter_from_storage};
43  
44 14 ▶ return defined $filter ? $self->$filter($value) : $value;
Branch: 1 branch
BranchTrueFalseTotal
defined $filter ? : 13 1 14
45 }
46  
47 20 ▶sub _column_to_storage {
Subroutine _column_to_storage: called CC=5 SCAR=16.2
48 20 my ($self, $col, $value) = @_;
49  
50 20 ▶ return $value if is_literal_value($value);
Branch: 1 branch
BranchTrueFalseTotal
if &is_literal_value($value) 4 16 20
51  
52 16 ▶ 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") 16 0 16
53 $self->throw_exception("No column info for $col");
54  
55 16 ▶ return $value unless exists $info->{_filter_info};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $info->{"_filter_info"} 0 16 16
56  
57 16 my $unfilter = $info->{_filter_info}{filter_to_storage};
58  
59 16 ▶ return defined $unfilter ? $self->$unfilter($value) : $value;
Branch: 1 branch
BranchTrueFalseTotal
defined $unfilter ? : 13 3 16
60 }
61  
62 33 ▶sub get_filtered_column {
Subroutine get_filtered_column: called CC=3 SCAR=11.0
Pod documented
63 33 my ($self, $col) = @_;
64  
65 $self->throw_exception("$col is not a filtered column")
66 33 ▶ unless exists $self->result_source->column_info($col)->{_filter_info};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->result_source->column_info($col)->{"_filter_info"} 0 33 33
67  
68 return $self->{_filtered_column}{$col}
69 33 ▶ if exists $self->{_filtered_column}{$col};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_filtered_column"}{$col} 19 14 33
70  
71 14 my $val = $self->get_column($col);
72  
73 14 return $self->{_filtered_column}{$col} = $self->_column_from_storage(
74 $col, $val
75 );
76 }
77  
78 65 ▶sub get_column {
Subroutine get_column: called CC=3 SCAR=11.0
Pod documented
79 65 my ($self, $col) = @_;
80  
81 ! exists $self->{_column_data}{$col}
82 and
83 exists $self->{_filtered_column}{$col}
84 and
85 $self->{_column_data}{$col} = $self->_column_to_storage (
86 65 ▶ $col, $self->{_filtered_column}{$col}
Branch: 1 branch
BranchTrueFalseTotal
not exists $self->{"_column_data"}{$col} and exists $self->{"_filtered_column"}{$col} and $self->{"_column_data"}{$col} = $self->_column_to_storage($col, $self->{"_filtered_column"}{$col}) 4 61 65
Condition66%2/3
not exists $self->{"_column_data"}{$col} and exists $self->{"_filtered_column"}{$col}
!ll&&!rl&&r
6104
MC/DC50%1/2
not exists $self->{"_column_data"}{$col} and exists $self->{"_filtered_column"}{$col}
not exists $self->{"_column_data"}{$col} exists $self->{"_filtered_column"}{$col}
Truth table66%2/3
not(A) and B
A= not exists $self->{"_column_data"}{$col}B= exists $self->{"_filtered_column"}{$col}
ABresult
0X0
100
111
87 );
88  
89 65 return $self->next::method ($col);
90 }
91  
92 # sadly a separate codepath in Row.pm ( used by insert() )
93 11 ▶sub get_columns {
Subroutine get_columns: called CC=3 SCAR=11.1
Pod documented
94 11 my $self = shift;
95  
96 $self->{_column_data}{$_} = $self->_column_to_storage (
97 $_, $self->{_filtered_column}{$_}
98 11 ) for grep
99 11 { ! exists $self->{_column_data}{$_} }
100 11 ▶ keys %{$self->{_filtered_column}||{}}
Condition50%1/2
$self->{'_filtered_column'} || {}
l!l
110
MC/DC0%0/1
$self->{'_filtered_column'} || {}
$self->{'_filtered_column'}
Truth table50%1/2
A
A= $self->{'_filtered_column'}
Aresult
11
00
101 ;
102  
103 11 $self->next::method (@_);
104 }
105  
106 # and *another* separate codepath, argh!
107 13 ▶sub get_dirty_columns {
Subroutine get_dirty_columns: called CC=5 SCAR=16.1
Pod documented
108 13 my $self = shift;
109  
110 $self->{_dirty_columns}{$_}
111 and
112 ! exists $self->{_column_data}{$_}
113 and
114 $self->{_column_data}{$_} = $self->_column_to_storage (
115 $_, $self->{_filtered_column}{$_}
116 )
117 13 ▶ for keys %{$self->{_filtered_column}||{}};
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_dirty_columns"}{$_} and not exists $self->{"_column_data"}{$_} and $self->{"_column_data"}{$_} = $self->_column_to_storage($_, $self->{"_filtered_column"}{$_}) 1 12 13
Condition80%4/5
$self->{'_filtered_column'} || {}
l!l
130
$self->{"_dirty_columns"}{$_} and not exists $self->{"_column_data"}{$_}
!ll&&!rl&&r
2101
MC/DC0%0/1
$self->{'_filtered_column'} || {}
$self->{'_filtered_column'}
MC/DC100%2/2
$self->{"_dirty_columns"}{$_} and not exists $self->{"_column_data"}{$_}
$self->{"_dirty_columns"}{$_} not exists $self->{"_column_data"}{$_}
Truth table50%1/2
A
A= $self->{'_filtered_column'}
Aresult
11
00
Truth table100%3/3
A and not(B)
A= $self->{"_dirty_columns"}{$_}B= not exists $self->{"_column_data"}{$_}
ABresult
0X0
100
111
118  
119 13 $self->next::method(@_);
120 }
121  
122 26 ▶sub store_column {
Subroutine store_column: called CC=1 SCAR=0.0
Pod documented
123 26 my ($self, $col) = (shift, @_);
124  
125 # blow cache
126 26 delete $self->{_filtered_column}{$col};
127  
128 26 $self->next::method(@_);
129 }
130  
131 17 ▶sub has_column_loaded {
Subroutine has_column_loaded: called CC=2 SCAR=6.9
Pod documented
132 17 my ($self, $col) = @_;
133 17 ▶ return 1 if exists $self->{_filtered_column}{$col};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_filtered_column"}{$col} 14 3 17
134 3 return $self->next::method($col);
135 }
136  
137 22 ▶sub set_filtered_column {
Subroutine set_filtered_column: called CC=3 SCAR=11.0
Pod documented
138 22 my ($self, $col, $filtered) = @_;
139  
140 # unlike IC, FC does not need to deal with the 'filter' abomination
141 # thus we can short-curcuit filtering entirely and never call set_column
142 # in case this is already a dirty change OR the row never touched storage
143 22 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->in_storage or $self->is_column_changed($col)) { } 10 12 22
Condition100%3/3
not $self->in_storage or $self->is_column_changed($col)
l!l&&r!l&&!r
9112
MC/DC100%2/2
not $self->in_storage or $self->is_column_changed($col)
not $self->in_storage $self->is_column_changed($col)
Truth table100%3/3
not(A) or B
A= not $self->in_storageB= $self->is_column_changed($col)
ABresult
1X1
011
000
144 ! $self->in_storage
145 or
146 $self->is_column_changed($col)
147 ) {
148 10 $self->make_column_dirty($col);
149 10 delete $self->{_column_data}{$col};
150 }
151 else {
152 12 $self->set_column($col, $self->_column_to_storage($col, $filtered));
153 };
154  
155 22 return $self->{_filtered_column}{$col} = $filtered;
156 }
157  
158 9 ▶sub update {
Subroutine update: called CC=5 SCAR=16.2
Pod documented
159 9 my ($self, $data, @rest) = @_;
160  
161 9 my $colinfos = $self->result_source->columns_info;
162  
163 9 ▶ foreach my $col (keys %{$data||{}}) {
Condition100%2/2
$data || {}
l!l
45
MC/DC100%1/1
$data || {}
$data
Truth table100%2/2
A
A= $data
Aresult
11
00
164 4 ▶ if ( exists $colinfos->{$col}{_filter_info} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $colinfos->{$col}{"_filter_info"}) 4 0 4
165 4 $self->set_filtered_column($col, delete $data->{$col});
166  
167 # FIXME update() reaches directly into the object-hash
168 # and we may *not* have a filtered value there - thus
169 # the void-ctx filter-trigger
170 4 ▶ $self->get_column($col) unless exists $self->{_column_data}{$col};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_column_data"}{$col} 0 4 4
171 }
172 }
173  
174 9 return $self->next::method($data, @rest);
175 }
176  
177 7 ▶sub new {
Subroutine new: called CC=5 SCAR=16.5
Pod documented
178 7 my ($class, $data, @rest) = @_;
179  
180 my $rsrc = $data->{-result_source}
181 7 ▶ or $class->throw_exception('Sourceless rows are not supported with DBIx::Class::FilterColumn');
Branch: 1 branch
BranchTrueFalseTotal
my $rsrc = $data->{"-result_source"} or $class->throw_exception("Sourceless rows are not supported with DBIx::Class::FilterColumn") 7 0 7
182  
183 7 my $obj = $class->next::method($data, @rest);
184  
185 7 my $colinfos = $rsrc->columns_info;
186  
187 7 ▶ foreach my $col (keys %{$data||{}}) {
Condition50%1/2
$data || {}
l!l
70
MC/DC0%0/1
$data || {}
$data
Truth table50%1/2
A
A= $data
Aresult
11
00
188 6 ▶ if (exists $colinfos->{$col}{_filter_info} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $colinfos->{$col}{"_filter_info"}) 6 0 6
189 6 $obj->set_filtered_column($col, $data->{$col});
190 }
191 }
192  
193 7 return $obj;
194 }
195  
196 4 1;
197  
198 __END__
« DBIx/Class/Storage/Debug/PrettyTrace.pm ↑ Summary DBIx/Class/CDBICompat/ColumnCase.pm »