blib/lib/DBIO/Row.pm

filter: Statementstmt 90.1% 756 / 839 Branchbran 75.3% 324 / 430 Conditioncond 67.5% 202 / 299 MC/DCmcdc 47.5% 79 / 166 Subroutinesub 93.3% 113 / 121 Podpod 97.9% 48 / 49 totaltotal 79.9% 1522 / 1904 CC 361 SCAR 25.9
CC
361
Cov
82%
get_inflated_columns
47.8
new
38.7
insert
37.6
CRAP 13.4
« blib/lib/DBIO/Storage/PoolBase.pm ↑ Summary blib/lib/DBIO/Introspect/DBI.pm »
1 package DBIO::Row;
2 # ABSTRACT: Basic row methods
3  
4 379 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 379 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 378 our $VERSION = '0.900007';
8  
9 379 ▶use base qw/DBIO::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 379 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 379 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 379 ▶use Sub::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 379 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 379 ▶use DBIO::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 379 ▶use DBIO::Util qw(is_literal_value assert_column_value);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 ###
19 ### Internal method
20 ### Do not use
21 ###
22 379 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.6
23 *MULTICREATE_DEBUG =
24 $ENV{DBIO_MULTICREATE_DEBUG}
25 ? sub () { 1 }
26 379 ▶ : sub () { 0 };
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'DBIO_MULTICREATE_DEBUG'} ? : 0 379 379
27 }
28  
29 379 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 378 __PACKAGE__->mk_group_accessors ( simple => [ in_storage => '_in_storage' ] );
32  
33  
34 ## It needs to store the new objects somewhere, and call insert on that list later when insert is called on this object. We may need an accessor for these so the user can retrieve them, if just doing ->new().
35 ## This only works because DBIO doesn't yet care to check whether the new_related objects have been passed all their mandatory columns
36 ## When doing the later insert, we need to make sure the PKs are set.
37 ## using _relationship_data in new and funky ways..
38 ## check Relationship::CascadeActions and Relationship::Codegen for compat
39 ## tests!
40  
41 39 ▶sub __new_related_find_or_new_helper {
Subroutine __new_related_find_or_new_helper: called CC=6 SCAR=18.6
42 39 my ($self, $rel_name, $values) = @_;
43  
44 39 my $rsrc = $self->result_source;
45  
46 # create a mock-object so all new/set_column component overrides will run:
47 39 my $rel_rs = $rsrc->related_source($rel_name)->resultset;
48 39 my $new_rel_obj = $rel_rs->new_result($values);
49 37 my $proc_data = { $new_rel_obj->get_columns };
50  
51 37 ▶ if ($self->__their_pk_needs_us($rel_name)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->__their_pk_needs_us($rel_name)) { } 18 19 37
elsif ($rsrc->_pk_depends_on($rel_name, $proc_data)) { } 19 0 19
52 18 MULTICREATE_DEBUG and print STDERR "MC $self constructing $rel_name via new_result\n";
53 18 return $new_rel_obj;
54 }
55 elsif ($rsrc->_pk_depends_on($rel_name, $proc_data )) {
56 19 ▶ if (! keys %$proc_data) {
Branch: 1 branch
BranchTrueFalseTotal
if (not keys %$proc_data) { } 0 19 19
57 # there is nothing to search for - blind create
58 0 MULTICREATE_DEBUG and print STDERR "MC $self constructing default-insert $rel_name\n";
59 }
60 else {
61 19 MULTICREATE_DEBUG and print STDERR "MC $self constructing $rel_name via find_or_new\n";
62 # this is not *really* find or new, as we don't want to double-new the
63 # data (thus potentially double encoding or whatever)
64 # only a belongs_to row that the data identifies is looked up, every
65 # other related row is created (ADR 0071)
66 19 ▶ my $exists = $rsrc->_relationship_depends_on($rel_name)
Condition66%2/3
$rsrc->_relationship_depends_on($rel_name) && $rel_rs->_find_identified($proc_data)
!ll&&!rl&&r
0154
MC/DC50%1/2
$rsrc->_relationship_depends_on($rel_name) && $rel_rs->_find_identified($proc_data)
$rsrc->_relationship_depends_on($rel_name) $rel_rs->_find_identified($proc_data)
Truth table66%2/3
A && B
A= $rsrc->_relationship_depends_on($rel_name)B= $rel_rs->_find_identified($proc_data)
ABresult
0X0
100
111
67 && $rel_rs->_find_identified($proc_data);
68 19 ▶ return $exists if $exists;
Branch: 1 branch
BranchTrueFalseTotal
if $exists 4 15 19
69 }
70 15 return $new_rel_obj;
71 }
72 else {
73 0 my $us = $rsrc->source_name;
74 0 $self->throw_exception (
75 "Unable to determine relationship '$rel_name' direction from '$us', "
76 . "possibly due to a missing reverse-relationship on '$rel_name' to '$us'."
77 );
78 }
79 }
80  
81 # Mass assignment (ADR 0071). Called for every key of the hash the caller gave
82 # to new before anything is stored: a column marked is_guarded takes no value,
83 # a guarded relationship takes no hash of data, and a relationship that holds
84 # this row's foreign key (belongs_to) may not set a guarded foreign key column.
85 # Relationship values that only resolve to columns later (a row created along)
86 # are checked at the point they are set, see __set_from_related_by_caller.
87 6526 ▶sub __assert_caller_assignment {
Subroutine __assert_caller_assignment: called CC=7 SCAR=19.5
88 6526 my ($self, $key, $value) = @_;
89  
90 6526 my $rsrc = $self->result_source;
91  
92 6526 ▶ if (ref $value and ! is_literal_value($value) and $rsrc->relationship_info($key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and not &is_literal_value($value) and $rsrc->relationship_info($key)) { } 66 6460 6526
Condition100%6/6
ref $value and not &is_literal_value($value) and $rsrc->relationship_info($key)
!ll&&!rl&&r
64105066
ref $value and not &is_literal_value($value)
!ll&&!rl&&r
639614116
MC/DC100%3/3
ref $value and not &is_literal_value($value) and $rsrc->relationship_info($key)
ref $value not &is_literal_value($value) $rsrc->relationship_info($key)
Truth table100%4/4
A and not(B) and C
A= ref $valueB= not &is_literal_value($value)C= $rsrc->relationship_info($key)
ABCresult
0XX0
10X0
1100
1111
93 66 ▶ $rsrc->_assert_relationship_not_guarded($key)
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "HASH" or ref $value eq "ARRAY" 42 24 66
Condition100%3/3
ref $value eq "HASH" or ref $value eq "ARRAY"
l!l&&r!l&&!r
251724
MC/DC100%2/2
ref $value eq "HASH" or ref $value eq "ARRAY"
ref $value eq "HASH" ref $value eq "ARRAY"
Truth table100%3/3
A or B
A= ref $value eq "HASH"B= ref $value eq "ARRAY"
ABresult
1X1
011
000
94 if ref $value eq 'HASH' or ref $value eq 'ARRAY';
95  
96 63 ▶ $rsrc->_assert_columns_not_guarded($rsrc->_relationship_self_columns($key))
Branch: 1 branch
BranchTrueFalseTotal
if $rsrc->_relationship_depends_on($key) 46 17 63
97 if $rsrc->_relationship_depends_on($key);
98 }
99 else {
100 6460 $rsrc->_assert_columns_not_guarded($key);
101 }
102  
103 6509 return;
104 }
105  
106 # The columns a value the caller gave for a relationship resolves to may not be
107 # guarded and may not contradict the equalities of the resultset's condition
108 58 ▶sub __assert_resolved_assignable {
Subroutine __assert_resolved_assignable: called CC=2 SCAR=6.9
109 58 my ($self, $cols) = @_;
110  
111 58 my $rsrc = $self->result_source;
112  
113 58 $rsrc->_assert_columns_not_guarded(sort keys %$cols);
114 56 ▶ $rsrc->_assert_scope_agrees($cols, $self->{_scope_values}) if $self->{_scope_values};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_scope_values"} 6 50 56
115  
116 52 return;
117 }
118  
119 # set_from_related for a relationship value the caller gave to new
120 35 ▶sub __set_from_related_by_caller {
Subroutine __set_from_related_by_caller: called CC=1 SCAR=0.0
121 35 my ($self, $rel_name, $rel_obj) = @_;
122  
123 35 $self->__assert_resolved_assignable($self->_inferred_from_related($rel_name, $rel_obj));
124  
125 32 return $self->set_from_related($rel_name, $rel_obj);
126 }
127  
128 # update(\%hash) assigns what the caller gives: guarded columns take no value,
129 # and neither does a relationship value that resolves to one
130 113 ▶sub __assert_update_assignable {
Subroutine __assert_update_assignable: called CC=11 SCAR=24.4
131 113 my ($self, $upd) = @_;
132  
133 113 ▶ my $rsrc = $self->result_source or return;
Branch: 1 branch
BranchTrueFalseTotal
my $rsrc = $self->result_source or return 113 0 113
134  
135 113 for my $key (sort keys %$upd) {
136 161 my $value = $upd->{$key};
137 161 ▶ my $info = ( ! defined $value or ( ref $value and ! is_literal_value($value) ) )
Branch: 1 branch
BranchTrueFalseTotal
!defined($value) || ref $value && !&is_literal_value($value) ? : 17 144 161
Condition66%4/6
not defined $value or ref $value and not &is_literal_value($value)
l!l&&r!l&&!r
017144
ref $value and not &is_literal_value($value)
!ll&&!rl&&r
144017
MC/DC33%1/3
not defined $value or ref $value and not &is_literal_value($value)
not defined $value ref $value not &is_literal_value($value)
Truth table50%2/4
not(A) or B and not(C)
A= not defined $valueB= ref $valueC= not &is_literal_value($value)
ABCresult
1XX1
0111
00X0
0100
138 ? $rsrc->relationship_info($key)
139 : undef
140 ;
141  
142 161 ▶ my $acc_type = $info ? $info->{attrs}{accessor} || '' : '';
Branch: 1 branch
BranchTrueFalseTotal
$info ? : 15 146 161
Condition50%1/2
$info->{"attrs"}{"accessor"} or ""
l!l
150
MC/DC0%0/1
$info->{"attrs"}{"accessor"} or ""
$info->{"attrs"}{"accessor"}
Truth table50%1/2
A
A= $info->{"attrs"}{"accessor"}
Aresult
11
00
143  
144 161 ▶ if ($acc_type eq 'single' or $acc_type eq 'filter') {
Branch: 2 branches
BranchTrueFalseTotal
if ($acc_type eq 'single' or $acc_type eq 'filter') { } 15 146 161
elsif (not $info) { } 146 0 146
Condition100%3/3
$acc_type eq "single" or $acc_type eq "filter"
l!l&&r!l&&!r
132146
MC/DC100%2/2
$acc_type eq "single" or $acc_type eq "filter"
$acc_type eq "single" $acc_type eq "filter"
Truth table100%3/3
A or B
A= $acc_type eq "single"B= $acc_type eq "filter"
ABresult
1X1
011
000
145 15 $self->__assert_resolved_assignable($self->_inferred_from_related($key, $value));
146 }
147 elsif (! $info) {
148 146 $rsrc->_assert_columns_not_guarded($key);
149 }
150 }
151  
152 102 return;
153 }
154  
155 49 ▶sub __their_pk_needs_us { # this should maybe be in resultsource.
Subroutine __their_pk_needs_us: called CC=3 SCAR=11.0
156 49 my ($self, $rel_name) = @_;
157 49 my $rsrc = $self->result_source;
158 49 my $reverse = $rsrc->reverse_relationship_info($rel_name);
159 49 my $rel_source = $rsrc->related_source($rel_name);
160 49 my $us = { $self->get_columns };
161 49 foreach my $key (keys %$reverse) {
162 # if their primary key depends on us, then we have to
163 # just create a result and we'll fill it out afterwards
164 74 ▶ return 1 if $rel_source->_pk_depends_on($key, $us);
Branch: 1 branch
BranchTrueFalseTotal
if $rel_source->_pk_depends_on($key, $us) 30 44 74
165 }
166 19 return 0;
167 }
168  
169 3606 ▶sub new {
Subroutine new: called CC=35 SCAR=36.6
Pod documented
170 3606 my ($class, $attrs) = @_;
171 3606 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 3606 3606
172  
173 3606 my $new = bless { _column_data => {}, _in_storage => 0 }, $class;
174  
175 3606 ▶ if ($attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs) 3606 0 3606
176 3606 ▶ $new->throw_exception("attrs must be a hashref")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attrs eq "HASH" 1 3605 3606
177 unless ref($attrs) eq 'HASH';
178  
179 3605 my $rsrc = delete $attrs->{-result_source};
180  
181 3605 ▶ $new->result_source($rsrc) if $rsrc;
Branch: 1 branch
BranchTrueFalseTotal
if $rsrc 3605 0 3605
182  
183 3605 ▶ if (my $col_from_rel = delete $attrs->{-cols_from_relations}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $col_from_rel = delete $attrs->{"-cols_from_relations"}) 0 3605 3605
184 0 @{$new->{_ignore_at_insert}={}}{@$col_from_rel} = ();
185 }
186  
187 # ADR 0071: which keys are the caller's assignment (all of them, unless
188 # the resultset names them) and the equalities of the resultset's condition
189 # a value of the caller may not contradict
190 3605 my $caller_keys = delete $attrs->{-caller_keys};
191 3605 my $scope_values = delete $attrs->{-scope_values};
192 3605 ▶ my %caller = map { $_ => 1 } ( $caller_keys ? @$caller_keys : keys %$attrs );
Branch: 1 branch
BranchTrueFalseTotal
$caller_keys ? : 3605 0 3605
193  
194 3605 ▶ $new->{_scope_values} = $scope_values if $scope_values and %$scope_values;
Branch: 1 branch
BranchTrueFalseTotal
if $scope_values and %$scope_values 1506 2099 3605
Condition66%2/3
$scope_values and %$scope_values
!ll&&!rl&&r
209901506
MC/DC50%1/2
$scope_values and %$scope_values
$scope_values %$scope_values
Truth table66%2/3
A and B
A= $scope_valuesB= %$scope_values
ABresult
0X0
100
111
195  
196 3605 ▶ if ($rsrc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rsrc) 3605 0 3605
197 3605 $new->__assert_caller_assignment($_, $attrs->{$_}) for sort grep { $caller{$_} } keys %$attrs;
198 }
199  
200 3588 my ($related,$inflated);
201  
202 3588 foreach my $key (keys %$attrs) {
203 7985 ▶ if (ref $attrs->{$key} and ! is_literal_value($attrs->{$key}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attrs->{$key} and not &is_literal_value($attrs->{$key})) 109 7876 7985
Condition100%3/3
ref $attrs->{$key} and not &is_literal_value($attrs->{$key})
!ll&&!rl&&r
786214109
MC/DC100%2/2
ref $attrs->{$key} and not &is_literal_value($attrs->{$key})
ref $attrs->{$key} not &is_literal_value($attrs->{$key})
Truth table100%3/3
A and not(B)
A= ref $attrs->{$key}B= not &is_literal_value($attrs->{$key})
ABresult
0X0
100
111
204 ## Can we extract this lot to use with update(_or .. ) ?
205 109 ▶ $new->throw_exception("Can't do multi-create without result source")
Branch: 1 branch
BranchTrueFalseTotal
unless $rsrc 0 109 109
206 unless $rsrc;
207 109 my $info = $rsrc->relationship_info($key);
208 109 ▶ my $acc_type = $info->{attrs}{accessor} || '';
Condition100%2/2
$info->{'attrs'}{'accessor'} || ''
l!l
5950
MC/DC100%1/1
$info->{'attrs'}{'accessor'} || ''
$info->{'attrs'}{'accessor'}
Truth table100%2/2
A
A= $info->{'attrs'}{'accessor'}
Aresult
11
00
209 109 ▶ if ($acc_type eq 'single') {
Branch: 4 branches
BranchTrueFalseTotal
if ($acc_type eq 'single') { } 17 92 109
elsif ($acc_type eq 'multi' and ref $attrs->{$key} eq 'ARRAY') { } 16 76 92
elsif ($acc_type eq 'filter') { } 26 50 76
elsif ($rsrc->has_column($key) and $rsrc->column_info($key)->{'_inflate_info'}) { } 45 5 50
210 17 my $rel_obj = delete $attrs->{$key};
211 17 ▶ if(!blessed $rel_obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($rel_obj)) 7 10 17
212 7 $rel_obj = $new->__new_related_find_or_new_helper($key, $rel_obj);
213 }
214  
215 17 ▶ $new->{_caller_rels}{$key} = 1 if $caller{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $caller{$key} 17 0 17
216  
217 17 ▶ if ($rel_obj->in_storage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rel_obj->in_storage) { } 12 5 17
218 12 $new->{_rel_in_storage}{$key} = 1;
219 12 ▶ $caller{$key}
Branch: 1 branch
BranchTrueFalseTotal
$caller{$key} ? : 12 0 12
220 ? $new->__set_from_related_by_caller($key, $rel_obj)
221 : $new->set_from_related($key, $rel_obj)
222 ;
223 } else {
224 5 MULTICREATE_DEBUG and print STDERR "MC $new uninserted $key $rel_obj\n";
225 }
226  
227 15 $related->{$key} = $rel_obj;
228 15 next;
229 }
230 ▶ elsif ($acc_type eq 'multi' && ref $attrs->{$key} eq 'ARRAY' ) {
Condition66%2/3
$acc_type eq "multi" and ref $attrs->{$key} eq "ARRAY"
!ll&&!rl&&r
76016
MC/DC50%1/2
$acc_type eq "multi" and ref $attrs->{$key} eq "ARRAY"
$acc_type eq "multi" ref $attrs->{$key} eq "ARRAY"
Truth table66%2/3
A and B
A= $acc_type eq "multi"B= ref $attrs->{$key} eq "ARRAY"
ABresult
0X0
100
111
231 16 my $others = delete $attrs->{$key};
232 16 my $total = @$others;
233 16 my @objects;
234 16 foreach my $idx (0 .. $#$others) {
235 18 my $rel_obj = $others->[$idx];
236 18 ▶ if(!blessed $rel_obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($rel_obj)) 18 0 18
237 18 $rel_obj = $new->__new_related_find_or_new_helper($key, $rel_obj);
238 }
239  
240 17 ▶ if ($rel_obj->in_storage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rel_obj->in_storage) { } 0 17 17
241 0 $rel_obj->throw_exception ('A multi relationship can not be pre-existing when doing multicreate. Something went wrong');
242 } else {
243 17 MULTICREATE_DEBUG and
244 print STDERR "MC $new uninserted $key $rel_obj (${\($idx+1)} of $total)\n";
245 }
246 17 push(@objects, $rel_obj);
247 }
248 15 $related->{$key} = \@objects;
249 15 next;
250 }
251 elsif ($acc_type eq 'filter') {
252 ## 'filter' should disappear and get merged in with 'single' above!
253 26 my $rel_obj = delete $attrs->{$key};
254 26 ▶ if(!blessed $rel_obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($rel_obj)) 14 12 26
255 14 $rel_obj = $new->__new_related_find_or_new_helper($key, $rel_obj);
256 }
257 25 ▶ $new->{_caller_rels}{$key} = 1 if $caller{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $caller{$key} 25 0 25
258  
259 25 ▶ if ($rel_obj->in_storage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rel_obj->in_storage) { } 12 13 25
260 12 $new->{_rel_in_storage}{$key} = 1;
261  
262 # its key is set when the row is inserted, say now if it may not be
263 $new->__assert_resolved_assignable($new->_inferred_from_related($key, $rel_obj))
264 12 ▶ if $caller{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $caller{$key} 12 0 12
265 }
266 else {
267 13 MULTICREATE_DEBUG and print STDERR "MC $new uninserted $key $rel_obj\n";
268 }
269 24 $inflated->{$key} = $rel_obj;
270 24 next;
271 }
272 ▶ elsif (
Condition66%2/3
$rsrc->has_column($key) and $rsrc->column_info($key)->{"_inflate_info"}
!ll&&!rl&&r
0545
MC/DC50%1/2
$rsrc->has_column($key) and $rsrc->column_info($key)->{"_inflate_info"}
$rsrc->has_column($key) $rsrc->column_info($key)->{"_inflate_info"}
Truth table66%2/3
A and B
A= $rsrc->has_column($key)B= $rsrc->column_info($key)->{"_inflate_info"}
ABresult
0X0
100
111
273 $rsrc->has_column($key)
274 and
275 $rsrc->column_info($key)->{_inflate_info}
276 ) {
277 45 $inflated->{$key} = $attrs->{$key};
278 45 next;
279 }
280 }
281 7881 $new->store_column($key => $attrs->{$key});
282 }
283  
284 3579 ▶ $new->{_relationship_data} = $related if $related;
Branch: 1 branch
BranchTrueFalseTotal
if $related 30 3549 3579
285 3579 ▶ $new->{_inflated_column} = $inflated if $inflated;
Branch: 1 branch
BranchTrueFalseTotal
if $inflated 63 3516 3579
286 }
287  
288 # StorageValues (integrated helper): per-row snapshot slot.
289 # Zero-cost when no column declares keep_storage_value.
290 3579 $new->_storage_values({});
291  
292 3579 return $new;
293 }
294  
295  
296 3177 ▶sub insert {
Subroutine insert: called CC=32 SCAR=36.3
Pod documented
297 3177 my ($self) = @_;
298 3177 ▶ return $self if $self->in_storage;
Branch: 1 branch
BranchTrueFalseTotal
if $self->in_storage 1 3176 3177
299 3176 my $rsrc = $self->result_source;
300 3176 ▶ $self->throw_exception("No result_source set on this object; can't insert")
Branch: 1 branch
BranchTrueFalseTotal
unless $rsrc 0 3176 3176
301 unless $rsrc;
302  
303 3176 my $storage = $rsrc->storage;
304  
305 # whatever a component has to do before this row is written
306 3176 $self->prepare_insert;
307  
308 3176 my $rollback_guard;
309  
310 # Check if we stored uninserted relobjs here in new()
311 3176 ▶ my %related_stuff = (%{$self->{_relationship_data} || {}},
Condition100%2/2
$self->{'_relationship_data'} || {}
l!l
293147
MC/DC100%1/1
$self->{'_relationship_data'} || {}
$self->{'_relationship_data'}
Truth table100%2/2
A
A= $self->{'_relationship_data'}
Aresult
11
00
312 3176 ▶ %{$self->{_inflated_column} || {}});
Condition100%2/2
$self->{'_inflated_column'} || {}
l!l
1093067
MC/DC100%1/1
$self->{'_inflated_column'} || {}
$self->{'_inflated_column'}
Truth table100%2/2
A
A= $self->{'_inflated_column'}
Aresult
11
00
313  
314 # insert what needs to be inserted before us
315 3176 my %pre_insert;
316 3176 for my $rel_name (keys %related_stuff) {
317 74 my $rel_obj = $related_stuff{$rel_name};
318  
319 74 ▶ if (! $self->{_rel_in_storage}{$rel_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_rel_in_storage"}{$rel_name}) 65 9 74
320 65 ▶ next unless (blessed $rel_obj && $rel_obj->isa('DBIO::Row'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($rel_obj) and $rel_obj->isa("DBIO::Row") 50 15 65
Condition100%3/3
builtin::blessed($rel_obj) and $rel_obj->isa("DBIO::Row")
!ll&&!rl&&r
123815
MC/DC100%2/2
builtin::blessed($rel_obj) and $rel_obj->isa("DBIO::Row")
builtin::blessed($rel_obj) $rel_obj->isa("DBIO::Row")
Truth table100%3/3
A and B
A= builtin::blessed($rel_obj)B= $rel_obj->isa("DBIO::Row")
ABresult
0X0
100
111
321  
322 15 ▶ next unless $rsrc->_pk_depends_on(
Branch: 1 branch
BranchTrueFalseTotal
unless $rsrc->_pk_depends_on($rel_name, {$rel_obj->get_columns}) 0 15 15
323 $rel_name, { $rel_obj->get_columns }
324 );
325  
326 # The guard will save us if we blow out of this scope via die
327 15 ▶ $rollback_guard ||= $storage->txn_scope_guard;
Condition66%2/3
$rollback_guard ||= $storage->txn_scope_guard
l!l&&r!l&&!r
1140
MC/DC0%0/2
$rollback_guard ||= $storage->txn_scope_guard
$rollback_guard $storage->txn_scope_guard
Truth table66%2/3
A ||= B
A= $rollback_guardB= $storage->txn_scope_guard
ABresult
1X1
011
000
328  
329 15 MULTICREATE_DEBUG and print STDERR "MC $self pre-reconstructing $rel_name $rel_obj\n";
330  
331 15 ▶ my $them = { %{$rel_obj->{_relationship_data} || {} }, $rel_obj->get_columns };
Condition100%2/2
$rel_obj->{'_relationship_data'} || {}
l!l
114
MC/DC100%1/1
$rel_obj->{'_relationship_data'} || {}
$rel_obj->{'_relationship_data'}
Truth table100%2/2
A
A= $rel_obj->{'_relationship_data'}
Aresult
11
00
332 15 my $existing;
333  
334 # a belongs_to row that the data identifies is the row to link to; any
335 # other related row is created (ADR 0071)
336 15 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($rsrc->_relationship_depends_on($rel_name) and keys %$them and $existing = $rsrc->related_source($rel_name)->resultset->_find_identified($them)) { } 0 15 15
Condition66%4/6
$rsrc->_relationship_depends_on($rel_name) and keys %$them and $existing = $rsrc->related_source($rel_name)->resultset->_find_identified($them)
!ll&&!rl&&r
1140
$rsrc->_relationship_depends_on($rel_name) and keys %$them
!ll&&!rl&&r
1014
MC/DC0%0/3
$rsrc->_relationship_depends_on($rel_name) and keys %$them and $existing = $rsrc->related_source($rel_name)->resultset->_find_identified($them)
$rsrc->_relationship_depends_on($rel_name) keys %$them $existing = $rsrc->related_source($rel_name)->resultset->_find_identified($them)
Truth table50%2/4
A and B and C
A= $rsrc->_relationship_depends_on($rel_name)B= keys %$themC= $existing = $rsrc->related_source($rel_name)->resultset->_find_identified($them)
ABCresult
0XX0
10X0
1100
1111
337 $rsrc->_relationship_depends_on($rel_name)
338 and
339 keys %$them
340 and
341 $existing = $rsrc->related_source($rel_name)->resultset->_find_identified($them)
342 ) {
343 0 %{$rel_obj} = %{$existing};
344 }
345 else {
346 15 $rel_obj->insert;
347 }
348  
349 15 $self->{_rel_in_storage}{$rel_name} = 1;
350 }
351  
352 24 ▶ $self->{_caller_rels}{$rel_name}
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_caller_rels'}{$rel_name} ? : 23 1 24
353 ? $self->__set_from_related_by_caller($rel_name, $rel_obj)
354 : $self->set_from_related($rel_name, $rel_obj)
355 ;
356 23 delete $related_stuff{$rel_name};
357 }
358  
359 # start a transaction here if not started yet and there is more stuff
360 # to insert after us. What is left in %related_stuff is not enough to say
361 # so: an object waiting in _inflated_column for its column's deflation is
362 # in there as well and writes nothing (karr k331). The pre-insert loop
363 # above flagged what it handled as _rel_in_storage, so the reason is asked
364 # only about what insert() still has to write after this row.
365 3175 ▶ if (keys %related_stuff and $self->_insert_cascade_reason) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %related_stuff and $self->_insert_cascade_reason) 11 3164 3175
Condition100%3/3
keys %related_stuff and $self->_insert_cascade_reason
!ll&&!rl&&r
31263811
MC/DC100%2/2
keys %related_stuff and $self->_insert_cascade_reason
keys %related_stuff $self->_insert_cascade_reason
Truth table100%3/3
A and B
A= keys %related_stuffB= $self->_insert_cascade_reason
ABresult
0X0
100
111
366 11 ▶ $rollback_guard ||= $storage->txn_scope_guard
Condition66%2/3
$rollback_guard ||= $storage->txn_scope_guard
l!l&&r!l&&!r
560
MC/DC0%0/2
$rollback_guard ||= $storage->txn_scope_guard
$rollback_guard $storage->txn_scope_guard
Truth table66%2/3
A ||= B
A= $rollback_guardB= $storage->txn_scope_guard
ABresult
1X1
011
000
367 }
368  
369 3175 MULTICREATE_DEBUG and do {
370 379 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
371 print STDERR "MC $self inserting (".join(', ', $self->get_columns).")\n";
372 };
373  
374 # perform the insert - the storage will return everything it is asked to
375 # (autoinc primary columns and any retrieve_on_insert columns)
376 3175 my %current_rowdata = $self->get_columns;
377 3175 assert_column_value($_, $current_rowdata{$_}) for sort keys %current_rowdata;
378 3174 my $returned_cols = $storage->insert(
379 $rsrc,
380 { %current_rowdata }, # what to insert, copy because the storage *will* change it
381 );
382  
383 3157 $self->_store_inserted_columns(\%current_rowdata, $returned_cols);
384  
385 3157 foreach my $rel_name (keys %related_stuff) {
386 50 ▶ next unless $rsrc->has_relationship ($rel_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $rsrc->has_relationship($rel_name) 39 11 50
387  
388 my @cands = ref $related_stuff{$rel_name} eq 'ARRAY'
389 11 ? @{$related_stuff{$rel_name}}
390 11 ▶ : $related_stuff{$rel_name}
Branch: 1 branch
BranchTrueFalseTotal
ref $related_stuff{$rel_name} eq 'ARRAY' ? : 11 0 11
391 ;
392  
393 11 ▶ if (@cands && blessed $cands[0] && $cands[0]->isa('DBIO::Row')
Branch: 1 branch
BranchTrueFalseTotal
if (@cands and builtin::blessed($cands[0]) and $cands[0]->isa("DBIO::Row")) 11 0 11
Condition33%2/6
@cands and builtin::blessed($cands[0]) and $cands[0]->isa("DBIO::Row")
!ll&&!rl&&r
0011
@cands and builtin::blessed($cands[0])
!ll&&!rl&&r
0011
MC/DC0%0/3
@cands and builtin::blessed($cands[0]) and $cands[0]->isa("DBIO::Row")
@cands builtin::blessed($cands[0]) $cands[0]->isa("DBIO::Row")
Truth table25%1/4
A and B and C
A= @candsB= builtin::blessed($cands[0])C= $cands[0]->isa("DBIO::Row")
ABCresult
0XX0
10X0
1100
1111
394 ) {
395 11 my $reverse = $rsrc->reverse_relationship_info($rel_name);
396 11 foreach my $obj (@cands) {
397 12 $obj->set_from_related($_, $self) for keys %$reverse;
398 12 ▶ if ($self->__their_pk_needs_us($rel_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__their_pk_needs_us($rel_name)) { } 12 0 12
399 12 ▶ if (exists $self->{_ignore_at_insert}{$rel_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_ignore_at_insert'}{$rel_name}) { } 0 12 12
400 0 MULTICREATE_DEBUG and print STDERR "MC $self skipping post-insert on $rel_name\n";
401 }
402 else {
403 12 MULTICREATE_DEBUG and print STDERR "MC $self inserting $rel_name $obj\n";
404 12 $obj->insert;
405 }
406 } else {
407 0 MULTICREATE_DEBUG and print STDERR "MC $self post-inserting $obj\n";
408 0 $obj->insert();
409 }
410 }
411 }
412 }
413  
414 3157 delete $self->{_ignore_at_insert};
415  
416 3157 ▶ $rollback_guard->commit if $rollback_guard;
Branch: 1 branch
BranchTrueFalseTotal
if $rollback_guard 19 3138 3157
417  
418 # StorageValues (integrated helper): snapshot the now-stored values.
419 3157 ▶ $self->store_storage_values if @{$self->storage_value_columns};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->storage_value_columns;} 6 3151 3157
420  
421 3157 return $self;
422 }
423  
424 # Fold the columns the storage returned from an insert (autoinc PKs and any
425 # retrieve_on_insert columns) back into the object, mark it stored and clean.
426 # Shared by the synchronous insert() and the async insert_async() so both build
427 # the now-stored object identically.
428 3238 ▶sub _store_inserted_columns {
Subroutine _store_inserted_columns: called CC=7 SCAR=19.6
429 3238 my ($self, $current_rowdata, $returned_cols) = @_;
430  
431 3238 for (keys %$returned_cols) {
432 $self->store_column($_, $returned_cols->{$_})
433 # this ensures we fire store_column only once
434 # (some asshats like overriding it)
435 if (
436 (!exists $current_rowdata->{$_})
437 or
438 (defined $current_rowdata->{$_} xor defined $returned_cols->{$_})
439 or
440 9626 ▶ (defined $current_rowdata->{$_} and $current_rowdata->{$_} ne $returned_cols->{$_})
Branch: 1 branch
BranchTrueFalseTotal
if not exists $current_rowdata->{$_} or (defined $current_rowdata->{$_} xor defined $returned_cols->{$_}) or defined $current_rowdata->{$_} and $current_rowdata->{$_} ne $returned_cols->{$_} 2376 7250 9626
Condition76%10/13
not exists $current_rowdata->{$_} or (defined $current_rowdata->{$_} xor defined $returned_cols->{$_}) or defined $current_rowdata->{$_} and $current_rowdata->{$_} ne $returned_cols->{$_}
l!l&&r!l&&!r
237427250
not exists $current_rowdata->{$_} or (defined $current_rowdata->{$_} xor defined $returned_cols->{$_})
l!l&&r!l&&!r
237407252
defined $current_rowdata->{$_} xor defined $returned_cols->{$_}
l&&rl&&!r!l&&r!l&&!r
72090043
defined $current_rowdata->{$_} and $current_rowdata->{$_} ne $returned_cols->{$_}
!ll&&!rl&&r
4372072
MC/DC40%2/5
not exists $current_rowdata->{$_} or (defined $current_rowdata->{$_} xor defined $returned_cols->{$_}) or defined $current_rowdata->{$_} and $current_rowdata->{$_} ne $returned_cols->{$_}
not exists $current_rowdata->{$_} defined $current_rowdata->{$_} defined $returned_cols->{$_} defined $current_rowdata->{$_} $current_rowdata->{$_} ne $returned_cols->{$_}
Truth table44%4/9
not(A) or B xor C or D and E
A= not exists $current_rowdata->{$_}B= defined $current_rowdata->{$_}C= defined $returned_cols->{$_}D= defined $current_rowdata->{$_}E= $current_rowdata->{$_} ne $returned_cols->{$_}
ABCDEresult
1XXXX1
010XX1
001XX1
011111
000111
0110X0
011100
0000X0
000100
441 );
442 }
443  
444 3238 delete $self->{_column_data_in_storage};
445 3238 $self->in_storage(1);
446  
447 3238 $self->{_dirty_columns} = {};
448 3238 $self->{related_resultsets} = {};
449  
450 3238 return $self;
451 }
452  
453 # Row-level mirror of DBIO::ResultSet::_rs_run_async (ADR 0030/0031): route to a
454 # live embedded backend, degrade synchronously in the 'immediate' mode, or croak
455 # on a sync instance.
456 231 ▶sub _row_run_async {
Subroutine _row_run_async: called CC=6 SCAR=17.9
457 231 my ($self, $name, $backend_build, $sync_run) = @_;
458  
459 231 my $storage = $self->result_source->storage;
460 231 my $fc = $storage->future_class;
461  
462 # A pinned context inherited from a context-bound resultset (or bound
463 # directly via ->with_context) wins over the pooled backend, so this row's
464 # insert/update/delete_async runs on the pinned txn/pipeline connection. A
465 # terminal pipeline or transaction context refuses loudly rather than dropping
466 # to the pool. No context => historical path below, unchanged.
467 231 ▶ if (my $ctx = $self->_async_context) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ctx = $self->_async_context) 103 128 231
468 103 $self->_assert_async_context_active($ctx, $name);
469 92 $storage->_assert_async_context_owner($ctx);
470 91 return $backend_build->($ctx, $fc);
471 }
472  
473 128 ▶ if (my $backend = $storage->_async_storage) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $backend = $storage->_async_storage) 114 14 128
474 # A Future derived from the storage's own is reported to the pool (k397).
475 return $backend->can('_note_pooled_derivation')
476 114 ▶ ? $backend->_note_pooled_derivation(sub { $backend_build->($backend, $fc) })
Subroutine __ANON__: called CC=1 SCAR=0.0
477 114 ▶ : $backend_build->($backend, $fc);
Branch: 1 branch
BranchTrueFalseTotal
$backend->can('_note_pooled_derivation') ? : 114 0 114
478 }
479  
480 $self->throw_exception(
481 14 ▶ "not an async connection -- connect with { async => ... } to use ${name}_async"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $storage->_async_mode 6 8 14
482 ) unless defined $storage->_async_mode;
483  
484 8 my @r = eval { $sync_run->() };
485 8 ▶ if (my $error = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 2 6 8
486 # Inside an immediate txn_do_async this is a statement of the transaction
487 # like any other: its failure fails it, awaited or not (karr k331).
488 2 $storage->_note_immediate_failure($error);
489 2 return $fc->fail($error);
490 }
491 6 return $fc->done(@r);
492 }
493  
494 # ADR 0045: the pinned async context bound to this row (undef if unbound) and
495 # active-context / sync-punt guards. Kept in step with the same-named helpers on
496 # DBIO::ResultSet -- a row derived from a context-bound resultset inherits its
497 # context (see DBIO::ResultSet::_construct_results / new_result) so that a chain
498 # like $rs->with_context($ctx)->first_async->then(sub { $_[0]->update_async })
499 # writes back on the pinned connection instead of the pool.
500 296 ▶sub _async_context { $_[0]->{_async_context} }
Subroutine _async_context: called CC=1 SCAR=0.0
501  
502 # ADR 0045 / karr k195: stamp a pinned async context onto this row and cascade it
503 # into any eagerly-prefetched children -- the related resultsets cached on the
504 # row and the child rows in their caches -- so a child fetched off a
505 # context-bound parent stays on the pinned connection instead of a sibling pool
506 # connection outside the transaction/pipeline. Called by
507 # DBIO::ResultSet::_construct_results on each top-level row built from a
508 # context-bound resultset, and by with_context on a pre-filled cache. The
509 # prefetch tree is finite and acyclic (built to the prefetch spec's depth), so
510 # the recursion terminates without a visited-set.
511 42 ▶sub _bind_async_context {
Subroutine _bind_async_context: called CC=8 SCAR=21.8
512 42 my ($self, $ctx) = @_;
513 42 $self->{_async_context} = $ctx;
514 42 ▶ for my $rrs (values %{ $self->{related_resultsets} || {} }) {
Condition100%2/2
$self->{'related_resultsets'} || {}
l!l
141
MC/DC100%1/1
$self->{'related_resultsets'} || {}
$self->{'related_resultsets'}
Truth table100%2/2
A
A= $self->{'related_resultsets'}
Aresult
11
00
515 1 ▶ next unless blessed $rrs;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($rrs) 0 1 1
516 1 $rrs->{_async_context} = $ctx;
517 1 ▶ my $cache = $rrs->get_cache or next;
Branch: 1 branch
BranchTrueFalseTotal
my $cache = $rrs->get_cache or next 1 0 1
518 1 for my $child (@$cache) {
519 1 ▶ $child->_bind_async_context($ctx)
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($child) and $child->can("_bind_async_context") 1 0 1
Condition33%1/3
builtin::blessed($child) and $child->can("_bind_async_context")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($child) and $child->can("_bind_async_context")
builtin::blessed($child) $child->can("_bind_async_context")
Truth table33%1/3
A and B
A= builtin::blessed($child)B= $child->can("_bind_async_context")
ABresult
0X0
100
111
520 if blessed $child and $child->can('_bind_async_context');
521 }
522 }
523 42 return $self;
524 }
525  
526  
527 77 ▶sub with_context {
Subroutine with_context: called CC=7 SCAR=21.3
Pod documented
528 77 my ($self, $ctx) = @_;
529 77 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ctx and builtin::blessed($ctx) and $ctx->can("select_async") 0 77 77
Condition33%2/6
defined $ctx and builtin::blessed($ctx) and $ctx->can("select_async")
!ll&&!rl&&r
0077
defined $ctx and builtin::blessed($ctx)
!ll&&!rl&&r
0077
MC/DC0%0/3
defined $ctx and builtin::blessed($ctx) and $ctx->can("select_async")
defined $ctx builtin::blessed($ctx) $ctx->can("select_async")
Truth table25%1/4
A and B and C
A= defined $ctxB= builtin::blessed($ctx)C= $ctx->can("select_async")
ABCresult
0XX0
10X0
1100
1111
530 'with_context requires an async context object (the one passed to a '
531 . 'txn_do_async / pipeline coderef)'
532 ) unless defined $ctx and blessed($ctx) and $ctx->can('select_async');
533 77 my $storage = $self->result_source->storage;
534 77 $storage->_assert_async_context_owner($ctx);
535 74 my $clone = bless { %$self }, ref $self;
536 74 $clone->{_async_context} = $ctx;
537  
538 # ADR 0045 / karr k203: if this row carries eagerly-prefetched children
539 # (cached related resultsets), the pin must cascade THROUGH them -- a
540 # grandchild fetched off the bound clone has to stay on the pinned connection.
541 # But the shallow clone above shares the source's {related_resultsets} hashref,
542 # so binding those in place would mutate the unbound source (and its shared
543 # child rows). Rebuild the map on the clone from bound clones instead:
544 # ResultSet::with_context clones each child rs (search_rs) and rebinds its cache
545 # into a fresh cache of bound row clones, recursing back through here for the
546 # grandchildren -- non-mutating all the way down. This is the clone-and-rebind
547 # sibling of _construct_results' in-place _bind_async_context, which is correct
548 # there because those rows are freshly built and owned by the query.
549 74 ▶ if (my $rrs_map = $self->{related_resultsets}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rrs_map = $self->{"related_resultsets"}) 1 73 74
550 $clone->{related_resultsets} = {
551 map {
552 1 my $rrs = $rrs_map->{$_};
553 1 ▶ ( blessed $rrs and $rrs->can('with_context') )
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($rrs) && $rrs->can('with_context') ? : 1 0 1
Condition33%1/3
builtin::blessed($rrs) and $rrs->can("with_context")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($rrs) and $rrs->can("with_context")
builtin::blessed($rrs) $rrs->can("with_context")
Truth table33%1/3
A and B
A= builtin::blessed($rrs)B= $rrs->can("with_context")
ABresult
0X0
100
111
554 ? ( $_ => $rrs->with_context($ctx) )
555 : ( $_ => $rrs );
556 } keys %$rrs_map
557 };
558 }
559  
560 74 return $clone;
561 }
562  
563 103 ▶sub _assert_async_context_active {
Subroutine _assert_async_context_active: called CC=3 SCAR=11.0
564 103 my ($self, $ctx, $name) = @_;
565 103 ▶ return if !$ctx->can('_context_active') || $ctx->_context_active;
Branch: 1 branch
BranchTrueFalseTotal
if not $ctx->can("_context_active") or $ctx->_context_active 92 11 103
Condition66%2/3
not $ctx->can("_context_active") or $ctx->_context_active
l!l&&r!l&&!r
09211
MC/DC50%1/2
not $ctx->can("_context_active") or $ctx->_context_active
not $ctx->can("_context_active") $ctx->_context_active
Truth table66%2/3
not(A) or B
A= not $ctx->can("_context_active")B= $ctx->_context_active
ABresult
1X1
011
000
566 11 $self->throw_exception(
567 "the async context bound to this result is no longer active; ${name}_async "
568 . "cannot be routed onto it. Pipeline contexts stop accepting work when their "
569 . "synchronous batch coderef returns; transaction contexts stop on their "
570 . "terminal BEGIN / COMMIT / ROLLBACK path. Issue the async work while its "
571 . "owning context remains active, not from a row held past it."
572 );
573 }
574  
575 # A row write that is not a single pinned async statement (related
576 # multi-create, OnColumnChange/cascade_update, cascade-delete) must not silently
577 # run the synchronous fallback while a pinned context is bound -- that would
578 # execute outside the pinned transaction/pipeline (consequence 4). Refuse,
579 # named. Without a context this is the historical sync-and-resolve punt.
580 #
581 # In the 'immediate' mode the context is the storage itself (ADR 0055), and
582 # the fallback would run inside the transaction. The refusal stands there too,
583 # so that a bound row behaves the same in every async mode; only the reason
584 # given is the one that is true there (karr k282).
585 #
586 # $lead, if given, is what the refusal says in place of "it is not expressible
587 # as a single pinned statement ($why)" -- the override gate (see
588 # _async_override_gap), whose reason is not the shape of the statement.
589 62 ▶sub _async_ctx_or_sync_punt {
Subroutine _async_ctx_or_sync_punt: called CC=7 SCAR=19.9
590 62 my ($self, $fc, $op, $why, $sync_cref, $lead) = @_;
591 62 ▶ if (my $ctx = $self->_async_context) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ctx = $self->_async_context) 33 29 62
592 33 ▶ $lead //= "it is not expressible as a single pinned statement ($why)";
Condition100%2/2
$lead //= "it is not expressible as a single pinned statement ($why)"
l!l
249
MC/DC100%1/1
$lead //= "it is not expressible as a single pinned statement ($why)"
$lead
Truth table100%2/2
A
A= $lead
Aresult
11
00
593 33 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
if $ctx == $self->result_source->storage 13 20 33
594 "${op}_async cannot run on a bound async context: $lead. "
595 . "In the 'immediate' mode the "
596 . "synchronous fallback would run inside the transaction, but a bound "
597 . "object refuses it in every async mode alike. Restructure so this runs "
598 . "unbound -- in this mode that is still inside the transaction."
599 ) if $ctx == $self->result_source->storage;
600  
601 20 ▶ my $where = $ctx->can('in_txn') && $ctx->in_txn ? 'transaction' : 'pipeline';
Branch: 1 branch
BranchTrueFalseTotal
$ctx->can('in_txn') && $ctx->in_txn ? : 20 0 20
Condition33%1/3
$ctx->can("in_txn") and $ctx->in_txn
!ll&&!rl&&r
0020
MC/DC0%0/2
$ctx->can("in_txn") and $ctx->in_txn
$ctx->can("in_txn") $ctx->in_txn
Truth table33%1/3
A and B
A= $ctx->can("in_txn")B= $ctx->in_txn
ABresult
0X0
100
111
602 20 $self->throw_exception(
603 "${op}_async cannot run on a bound async context: $lead, and the "
604 . "synchronous fallback would run outside the pinned $where. Restructure "
605 . "so this runs outside the "
606 . "context."
607 );
608 }
609 29 my $r = eval { $sync_cref->() };
610 29 ▶ return $@ ? $fc->fail($@) : $fc->done($r);
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 29 29
611 }
612  
613 # The override gate (karr k331). insert_async / update_async / delete_async
614 # send their statement through the backend and are a new method name beside
615 # insert / update / delete, so an override of the synchronous method higher
616 # up the class's MRO -- a component's, the user class's, a Moo `around` -- is
617 # not on their way. This answers: which package before DBIO::Row defines
618 # $op itself without defining ${op}_async in that same package? undef if there
619 # is none. The caller then takes the full synchronous method instead (see
620 # _async_ctx_or_sync_punt): unbound, that is the old synchronous-and-settled
621 # answer; bound, it is refused, as the statement would run outside the pinned
622 # context.
623 #
624 # DBIO::Relationship::CascadeActions is exempt: it overrides update and delete
625 # and is covered by their own, finer predicates (_has_cascade_update_relateds,
626 # _has_cascade_delete_relateds), which punt only where it would cascade -- the
627 # gate would punt every row of every class, as it is in every result class.
628 # The list is closed on purpose: a component that does its work BEFORE the
629 # write uses the prepare_* hooks and defines no insert / update / delete.
630 #
631 # Not cached: the walk is a handful of stash lookups per call, and a
632 # load_components or a Moo around after the first call would make a cache lie.
633 378 my %ASYNC_GATE_EXEMPT = (
634 'DBIO::Relationship::CascadeActions' => 1,
635 );
636  
637 176 ▶sub _async_override_gap {
Subroutine _async_override_gap: called CC=6 SCAR=17.9
638 176 my ($self, $op) = @_;
639  
640 379 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
641 176 for my $pkg (@{ mro::get_linear_isa(ref $self) }) {
642 2634 ▶ last if $pkg eq 'DBIO::Row';
Branch: 1 branch
BranchTrueFalseTotal
if $pkg eq "DBIO::Row" 140 2494 2634
643 2494 ▶ next if $ASYNC_GATE_EXEMPT{$pkg};
Branch: 1 branch
BranchTrueFalseTotal
if $ASYNC_GATE_EXEMPT{$pkg} 140 2354 2494
644 2354 ▶ next unless defined &{"${pkg}::${op}"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${pkg}::$op";} 2317 37 2354
645 37 ▶ return $pkg unless defined &{"${pkg}::${op}_async"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${pkg}::${op}_async";} 36 1 37
646 }
647 140 return undef;
648 }
649  
650 36 ▶sub _async_override_gap_lead {
Subroutine _async_override_gap_lead: called CC=1 SCAR=0.0
651 36 my ($self, $pkg, $op) = @_;
652 36 return "class $pkg overrides $op and has no ${op}_async sibling in that "
653 . "class, so ${op}_async would run past the override (implement "
654 . "${op}_async beside it, or move the work done before the write into "
655 . "prepare_$op, see DBIO::Manual::Component)";
656 }
657  
658  
659 90 ▶sub insert_async {
Subroutine insert_async: called CC=1 SCAR=0.0
Pod documented
660 90 my $self = shift;
661  
662 return $self->_row_run_async('insert',
663 89 ▶ sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
664 89 my ($backend, $fc) = @_;
665  
666 89 my $rsrc = $self->result_source;
667 89 ▶ $self->throw_exception("No result_source set on this object; can't insert")
Branch: 1 branch
BranchTrueFalseTotal
unless $rsrc 0 89 89
668 unless $rsrc;
669  
670 89 ▶ return $fc->done($self) if $self->in_storage;
Branch: 1 branch
BranchTrueFalseTotal
if $self->in_storage 1 88 89
671  
672 # An override of insert() the backend would run past: see
673 # _async_override_gap.
674 88 ▶ if (my $pkg = $self->_async_override_gap('insert')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pkg = $self->_async_override_gap("insert")) 12 76 88
675 return $self->_async_ctx_or_sync_punt($fc, 'insert',
676 4 ▶ 'an override of insert', sub { $self->insert },
Subroutine __ANON__: called CC=1 SCAR=0.0
677 12 $self->_async_override_gap_lead($pkg, 'insert'));
678 }
679  
680 # Related-object multi-create is a multi-statement (and transactional)
681 # cascade, not a single insert_async; run it synchronously and resolve.
682 76 ▶ if (my $cascade = $self->_insert_cascade_reason) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cascade = $self->_insert_cascade_reason) 14 62 76
683 return $self->_async_ctx_or_sync_punt($fc, 'insert',
684 "related-object multi-create is a transactional cascade: $cascade",
685 14 ▶ sub { $self->insert });
Subroutine __ANON__: called CC=1 SCAR=0.0
686 }
687  
688 # insert() calls it at this point as well; the punts above run the full
689 # insert(), which calls it itself.
690 62 $self->prepare_insert;
691  
692 # What is left in the two slots writes nothing of its own. A related row
693 # that was in storage when the row was built gives its key to ours, as
694 # insert() has it do at this point; an inflated value is deflated by the
695 # get_columns below, as it is there.
696 62 ▶ my %related_stuff = (%{$self->{_relationship_data} || {}},
Condition100%2/2
$self->{'_relationship_data'} || {}
l!l
656
MC/DC100%1/1
$self->{'_relationship_data'} || {}
$self->{'_relationship_data'}
Truth table100%2/2
A
A= $self->{'_relationship_data'}
Aresult
11
00
697 62 ▶ %{$self->{_inflated_column} || {}});
Condition100%2/2
$self->{'_inflated_column'} || {}
l!l
2636
MC/DC100%1/1
$self->{'_inflated_column'} || {}
$self->{'_inflated_column'}
Truth table100%2/2
A
A= $self->{'_inflated_column'}
Aresult
11
00
698 $self->set_from_related($_, $related_stuff{$_})
699 62 for grep { $self->{_rel_in_storage}{$_} } keys %related_stuff;
700  
701 62 my %current_rowdata = $self->get_columns;
702 55 ▶ return $backend->insert_async( $rsrc, { %current_rowdata } )->then(sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
703 55 my ($returned_cols) = @_;
704 55 $self->_store_inserted_columns(\%current_rowdata, $returned_cols);
705 55 ▶ $self->store_storage_values if @{$self->storage_value_columns};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->storage_value_columns;} 0 55 55
706 55 return $self;
707 62 });
708 },
709 1 ▶ sub { $self->insert },
Subroutine __ANON__: called CC=1 SCAR=0.0
710 90 );
711 }
712  
713 # Why insert() would send more than the one INSERT for THIS row, or undef if
714 # it would not -- mirrors what insert()'s own two loops over
715 # _relationship_data and _inflated_column do, entry by entry, rather than the
716 # coarser "is anything in those slots at all" (karr k282). Both slots hold
717 # more than multi-create data: _inflated_column is where an object for a
718 # column with an inflator sits until get_columns deflates it, and a related
719 # row that was in storage when the row was built is flagged _rel_in_storage
720 # and only lends its key. Neither writes a statement of its own, and a row
721 # carrying only those is a plain single-row insert.
722 #
723 # What does write, and so makes the insert a cascade:
724 # - a related row our foreign key depends on that is not flagged: insert()
725 # looks it up, and inserts it if it is not there, BEFORE this row;
726 # - related rows whose foreign key depends on us (a has_many's arrayref, a
727 # has_one / might_have object): insert() inserts them AFTER this row.
728 125 ▶sub _insert_cascade_reason {
Subroutine _insert_cascade_reason: called CC=13 SCAR=26.4
729 125 my $self = shift;
730 125 my $rsrc = $self->result_source;
731  
732 125 ▶ my %related_stuff = (%{$self->{_relationship_data} || {}},
Condition100%2/2
$self->{'_relationship_data'} || {}
l!l
2996
MC/DC100%1/1
$self->{'_relationship_data'} || {}
$self->{'_relationship_data'}
Truth table100%2/2
A
A= $self->{'_relationship_data'}
Aresult
11
00
733 125 ▶ %{$self->{_inflated_column} || {}});
Condition100%2/2
$self->{'_inflated_column'} || {}
l!l
6659
MC/DC100%1/1
$self->{'_inflated_column'} || {}
$self->{'_inflated_column'}
Truth table100%2/2
A
A= $self->{'_inflated_column'}
Aresult
11
00
734  
735 125 for my $rel_name (sort keys %related_stuff) {
736 83 ▶ next if $self->{_rel_in_storage}{$rel_name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_rel_in_storage"}{$rel_name} 12 71 83
737  
738 71 my $rel_obj = $related_stuff{$rel_name};
739  
740 71 ▶ return "the row for '$rel_name' is looked up or inserted before this one"
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($rel_obj) and $rel_obj->isa("DBIO::Row") and $rsrc->_pk_depends_on($rel_name, {$rel_obj->get_columns}) 8 63 71
Condition83%5/6
builtin::blessed($rel_obj) and $rel_obj->isa("DBIO::Row") and $rsrc->_pk_depends_on($rel_name, {$rel_obj->get_columns})
!ll&&!rl&&r
6308
builtin::blessed($rel_obj) and $rel_obj->isa("DBIO::Row")
!ll&&!rl&&r
18458
MC/DC66%2/3
builtin::blessed($rel_obj) and $rel_obj->isa("DBIO::Row") and $rsrc->_pk_depends_on($rel_name, {$rel_obj->get_columns})
builtin::blessed($rel_obj) $rel_obj->isa("DBIO::Row") $rsrc->_pk_depends_on($rel_name, {$rel_obj->get_columns})
Truth table75%3/4
A and B and C
A= builtin::blessed($rel_obj)B= $rel_obj->isa("DBIO::Row")C= $rsrc->_pk_depends_on($rel_name, {$rel_obj->get_columns})
ABCresult
0XX0
10X0
1100
1111
741 if blessed $rel_obj
742 and $rel_obj->isa('DBIO::Row')
743 and $rsrc->_pk_depends_on($rel_name, { $rel_obj->get_columns });
744  
745 63 ▶ next unless $rsrc->has_relationship($rel_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $rsrc->has_relationship($rel_name) 46 17 63
746  
747 17 ▶ my @cands = ref $rel_obj eq 'ARRAY' ? @$rel_obj : $rel_obj;
Branch: 1 branch
BranchTrueFalseTotal
ref $rel_obj eq 'ARRAY' ? : 17 0 17
748 17 ▶ return "the rows for '$rel_name' are linked and inserted after this one"
Branch: 1 branch
BranchTrueFalseTotal
if @cands and builtin::blessed($cands[0]) and $cands[0]->isa("DBIO::Row") 17 0 17
Condition33%2/6
@cands and builtin::blessed($cands[0]) and $cands[0]->isa("DBIO::Row")
!ll&&!rl&&r
0017
@cands and builtin::blessed($cands[0])
!ll&&!rl&&r
0017
MC/DC0%0/3
@cands and builtin::blessed($cands[0]) and $cands[0]->isa("DBIO::Row")
@cands builtin::blessed($cands[0]) $cands[0]->isa("DBIO::Row")
Truth table25%1/4
A and B and C
A= @candsB= builtin::blessed($cands[0])C= $cands[0]->isa("DBIO::Row")
ABCresult
0XX0
10X0
1100
1111
749 if @cands && blessed $cands[0] && $cands[0]->isa('DBIO::Row');
750 }
751  
752 100 return undef;
753 }
754  
755 # True if this row's class has any OnColumnChange before/around/after
756 # callback registered -- mirrors update()'s own $has_change_cbs gate
757 # (Row.pm's `update`, above).
758 49 ▶sub _has_on_column_change_cbs {
Subroutine _has_on_column_change_cbs: called CC=3 SCAR=11.4
759 49 my $self = shift;
760 49 ▶ return !! ( $self->_before_change || $self->_around_change || $self->_after_change );
Condition66%4/6
$self->_before_change || $self->_around_change || $self->_after_change
l!l&&r!l&&!r
1048
$self->_before_change or $self->_around_change
l!l&&r!l&&!r
1048
MC/DC33%1/3
$self->_before_change || $self->_around_change || $self->_after_change
$self->_before_change $self->_around_change $self->_after_change
Truth table50%2/4
A or B || C
A= $self->_before_changeB= $self->_around_changeC= $self->_after_change
ABCresult
1XX1
01X1
0011
0000
761 }
762  
763 # True if update()'s CascadeActions wrap would actually attempt a cascade for
764 # THIS row instance, once $upd (if any) has been applied -- mirrors its
765 # per-relationship skip condition exactly (Relationship::CascadeActions::
766 # update's own `next if $accessor eq 'single' && !exists
767 # $self->{_relationship_data}{$rel}`), rather than the coarser "does a
768 # cascade_update relationship exist on the source at all" question.
769 #
770 # A 'single'-accessor relationship (has_one/might_have, the cascade_update
771 # default) only cascades if its accessor has already been touched on this
772 # instance: explicitly assigned, or fetched at least once as a getter --
773 # either way, that's what populates _relationship_data (see
774 # Relationship::Codegen's 'single' accessor codegen). A freshly-loaded row
775 # that never touched the accessor has _relationship_data{$rel} unset, so
776 # CascadeActions itself would skip it -- nothing to cascade, and update_async
777 # must not punt over it either, or a plain one-column update on any class
778 # with a has_one/might_have relationship would never be truly async.
779 #
780 # $upd is checked too, and must be: set_inflated_columns (called from
781 # update()'s own body) populates _relationship_data for a 'single'-accessor
782 # key found in $upd as it processes it -- but that happens AFTER this gate
783 # would otherwise already have decided not to punt, since update_async calls
784 # this predicate before ever calling set_inflated_columns on the fast path.
785 # Without this check, assigning a cascade_update relationship via the update
786 # hashref itself (update_async({ rel => $obj })), rather than via a prior
787 # separate accessor call, would silently dispatch truly async and skip the
788 # cascade sync performs for the exact same call shape.
789 #
790 # Both checks are pure hash-key tests -- no accessor call, no I/O, no second
791 # invocation of set_inflated_columns -- calling the accessor itself to check
792 # would trigger the very query this predicate exists to let update_async
793 # avoid.
794 #
795 # A cascade_update relationship whose accessor attr is not 'single' (only
796 # possible via manual configuration; has_one/might_have always use 'single')
797 # is not skippable in CascadeActions's own logic, so it is always treated as
798 # cascading here too, matching CascadeActions's unconditional proceed for
799 # that case.
800 48 ▶sub _has_cascade_update_relateds {
Subroutine _has_cascade_update_relateds: called CC=9 SCAR=22.4
801 48 my ($self, $upd) = @_;
802 48 my $source = $self->result_source;
803 48 my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
804  
805 48 for my $rel (grep { $rels{$_}{attrs}{cascade_update} } keys %rels) {
806 25 ▶ my $accessor = $rels{$rel}{attrs}{accessor} || '';
Condition50%1/2
$rels{$rel}{'attrs'}{'accessor'} || ''
l!l
250
MC/DC0%0/1
$rels{$rel}{'attrs'}{'accessor'} || ''
$rels{$rel}{'attrs'}{'accessor'}
Truth table50%1/2
A
A= $rels{$rel}{'attrs'}{'accessor'}
Aresult
11
00
807 25 ▶ if ($accessor eq 'single') {
Branch: 1 branch
BranchTrueFalseTotal
if ($accessor eq "single") 25 0 25
808 next unless exists $self->{_relationship_data}{$rel}
809 25 ▶ or ($upd and exists $upd->{$rel} and (!defined $upd->{$rel} or ref $upd->{$rel}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_relationship_data"}{$rel} or $upd and exists $upd->{$rel} and !defined($upd->{$rel}) || ref $upd->{$rel} 23 2 25
Condition75%9/12
exists $self->{"_relationship_data"}{$rel} or $upd and exists $upd->{$rel} and !defined($upd->{$rel}) || ref $upd->{$rel}
l!l&&r!l&&!r
1123
$upd and exists $upd->{$rel} and !defined($upd->{$rel}) || ref $upd->{$rel}
!ll&&!rl&&r
2301
$upd and exists $upd->{$rel}
!ll&&!rl&&r
5181
not defined $upd->{$rel} or ref $upd->{$rel}
l!l&&r!l&&!r
010
MC/DC60%3/5
exists $self->{"_relationship_data"}{$rel} or $upd and exists $upd->{$rel} and !defined($upd->{$rel}) || ref $upd->{$rel}
exists $self->{"_relationship_data"}{$rel} $upd exists $upd->{$rel} not defined $upd->{$rel} ref $upd->{$rel}
Truth table66%4/6
A or B and C and not(D) or E
A= exists $self->{"_relationship_data"}{$rel}B= $updC= exists $upd->{$rel}D= not defined $upd->{$rel}E= ref $upd->{$rel}
ABCDEresult
1XXXX1
0111X1
011011
00XXX0
010XX0
011000
810 }
811 2 return 1;
812 }
813 46 return 0;
814 }
815  
816  
817 74 ▶sub update_async {
Subroutine update_async: called CC=1 SCAR=0.0
Pod documented
818 74 my ($self, $upd) = @_;
819  
820 return $self->_row_run_async('update',
821 61 ▶ sub {
Subroutine __ANON__: called CC=10 SCAR=23.3
822 61 my ($backend, $fc) = @_;
823  
824 # ADR 0071: the hash is an assignment of the caller's
825 61 ▶ $self->__assert_update_assignable($upd) if $upd;
Branch: 1 branch
BranchTrueFalseTotal
if $upd 53 8 61
826  
827 61 ▶ if (my $pkg = $self->_async_override_gap('update')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pkg = $self->_async_override_gap("update")) 12 49 61
828 return $self->_async_ctx_or_sync_punt($fc, 'update',
829 4 ▶ 'an override of update', sub { $self->update($upd) },
Subroutine __ANON__: called CC=1 SCAR=0.0
830 12 $self->_async_override_gap_lead($pkg, 'update'));
831 }
832  
833 49 ▶ if ($self->_has_on_column_change_cbs or $self->_has_cascade_update_relateds($upd)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_on_column_change_cbs or $self->_has_cascade_update_relateds($upd)) 3 46 49
Condition100%3/3
$self->_has_on_column_change_cbs or $self->_has_cascade_update_relateds($upd)
l!l&&r!l&&!r
1246
MC/DC100%2/2
$self->_has_on_column_change_cbs or $self->_has_cascade_update_relateds($upd)
$self->_has_on_column_change_cbs $self->_has_cascade_update_relateds($upd)
Truth table100%3/3
A or B
A= $self->_has_on_column_change_cbsB= $self->_has_cascade_update_relateds($upd)
ABresult
1X1
011
000
834 return $self->_async_ctx_or_sync_punt($fc, 'update',
835 'an OnColumnChange callback or cascade_update relationship wraps update()',
836 3 ▶ sub { $self->update($upd) });
Subroutine __ANON__: called CC=1 SCAR=0.0
837 }
838  
839 # update() calls it first as well; the punts above run the full
840 # update(), which calls it itself. It may take keys out of $upd.
841 46 $self->prepare_update($upd);
842  
843 46 ▶ $self->{_dirty_columns} ||= {};
Condition100%2/2
$self->{"_dirty_columns"} ||= {}
l!l
2026
MC/DC100%1/1
$self->{"_dirty_columns"} ||= {}
$self->{"_dirty_columns"}
Truth table100%2/2
A
A= $self->{"_dirty_columns"}
Aresult
11
00
844 46 ▶ delete local @{$self->{_dirty_columns}}{@{$self->_proxy_slots||[]}};
Condition50%1/2
$self->_proxy_slots || []
l!l
046
MC/DC0%0/1
$self->_proxy_slots || []
$self->_proxy_slots
Truth table50%1/2
A
A= $self->_proxy_slots
Aresult
11
00
845  
846 46 ▶ $self->set_inflated_columns($upd) if $upd;
Branch: 1 branch
BranchTrueFalseTotal
if $upd 40 6 46
847  
848 46 my %to_update = $self->get_dirty_columns;
849 46 ▶ return $fc->done($self) unless %to_update;
Branch: 1 branch
BranchTrueFalseTotal
unless %to_update 0 46 46
850  
851 46 ▶ $self->throw_exception( "Not in database" ) unless $self->in_storage;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in_storage 0 46 46
852  
853 46 my $rsrc = $self->result_source;
854 46 my $ident_cond = $self->_storage_ident_condition;
855  
856 46 ▶ return $backend->update_async($rsrc, \%to_update, $ident_cond)->then(sub {
Subroutine __ANON__: called CC=4 SCAR=15.0
857 46 my ($rows) = @_;
858 46 ▶ if ($rows == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rows == 0) { } 0 46 46
elsif ($rows > 1) { } 0 46 46
859 0 $self->throw_exception( "Can't update ${self}: row not found" );
860 } elsif ($rows > 1) {
861 0 $self->throw_exception("Can't update ${self}: updated more than one row");
862 }
863 46 $self->{_dirty_columns} = {};
864 46 $self->{related_resultsets} = {};
865 46 delete $self->{_column_data_in_storage};
866 46 ▶ $self->store_storage_values if @{$self->storage_value_columns};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->storage_value_columns;} 0 46 46
867 46 return $self;
868 46 });
869 },
870 3 ▶ sub { $self->update($upd) },
Subroutine __ANON__: called CC=1 SCAR=0.0
871 74 );
872 }
873  
874  
875 93 ▶sub update {
Subroutine update: called CC=18 SCAR=30.5
Pod documented
876 93 my ($self, $upd) = @_;
877  
878 # ADR 0071: the hash is an assignment of the caller's
879 93 ▶ $self->__assert_update_assignable($upd) if $upd;
Branch: 1 branch
BranchTrueFalseTotal
if $upd 60 33 93
880  
881 # whatever a component has to do before the columns are set and written;
882 # it may take keys out of $upd
883 82 $self->prepare_update($upd);
884  
885 # ProxyResultSetMethod (integrated helper): strip proxy slots from the
886 # dirty-column set so UPDATE statements never include them. "delete
887 # local" localises the deletion for the scope of this sub, so the
888 # original dirty flags are restored when update returns.
889 82 ▶ $self->{_dirty_columns} ||= {};
Condition100%2/2
$self->{"_dirty_columns"} ||= {}
l!l
4438
MC/DC100%1/1
$self->{"_dirty_columns"} ||= {}
$self->{"_dirty_columns"}
Truth table100%2/2
A
A= $self->{"_dirty_columns"}
Aresult
11
00
890 82 ▶ delete local @{$self->{_dirty_columns}}{@{$self->_proxy_slots||[]}};
Condition100%2/2
$self->_proxy_slots || []
l!l
181
MC/DC100%1/1
$self->_proxy_slots || []
$self->_proxy_slots
Truth table100%2/2
A
A= $self->_proxy_slots
Aresult
11
00
891  
892 # OnColumnChange (integrated helper): short-circuit when nothing is
893 # registered. When callbacks exist, build the before/around/after
894 # chain, then delegate to _update_body via around-wrapper; the whole
895 # orchestration is a no-op if none of the registered columns are dirty.
896 82 ▶ my $has_change_cbs =
Condition66%4/6
$self->_before_change || $self->_around_change || $self->_after_change
l!l&&r!l&&!r
3079
$self->_before_change or $self->_around_change
l!l&&r!l&&!r
3079
MC/DC33%1/3
$self->_before_change || $self->_around_change || $self->_after_change
$self->_before_change $self->_around_change $self->_after_change
Truth table50%2/4
A or B || C
A= $self->_before_changeB= $self->_around_changeC= $self->_after_change
ABCresult
1XX1
01X1
0011
0000
897 $self->_before_change
898 || $self->_around_change
899 || $self->_after_change;
900  
901 82 ▶ if ($has_change_cbs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_change_cbs) 3 79 82
902 3 ▶ $self->set_inflated_columns($upd) if $upd;
Branch: 1 branch
BranchTrueFalseTotal
if $upd 0 3 3
903  
904 3 ▶ my %dirty = $self->get_dirty_columns
Branch: 1 branch
BranchTrueFalseTotal
my(%dirty) = $self->get_dirty_columns or return $self 3 0 3
905 or return $self;
906  
907 3 ▶ my @all_before = @{$self->_before_change || []};
Condition50%1/2
$self->_before_change || []
l!l
30
MC/DC0%0/1
$self->_before_change || []
$self->_before_change
Truth table50%1/2
A
A= $self->_before_change
Aresult
11
00
908 3 ▶ my @all_around = @{$self->_around_change || []};
Condition50%1/2
$self->_around_change || []
l!l
03
MC/DC0%0/1
$self->_around_change || []
$self->_around_change
Truth table50%1/2
A
A= $self->_around_change
Aresult
11
00
909 3 ▶ my @all_after = @{$self->_after_change || []};
Condition50%1/2
$self->_after_change || []
l!l
30
MC/DC0%0/1
$self->_after_change || []
$self->_after_change
Truth table50%1/2
A
A= $self->_after_change
Aresult
11
00
910  
911 3 my @before = grep { defined $dirty{$_->{column}} } @all_before;
912 0 my @around = grep { defined $dirty{$_->{column}} } @all_around;
913 3 my @after = grep { defined $dirty{$_->{column}} } @all_after;
914  
915 3 my $allow_override = $self->on_column_change_allow_override_args;
916 my $final = $allow_override
917 0 ▶ ? sub { $self->_update_body }
Subroutine __ANON__: not called CC=1 SCAR=6.9
918 3 ▶ : sub { $self->_update_body($upd) };
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
$allow_override ? : 0 3 3
919  
920 3 for (reverse @around) {
921 0 my $fn = $_->{method};
922 0 my $old = $self->get_storage_value($_->{column});
923 0 my $new = $dirty{$_->{column}};
924 0 my $old_final = $final;
925 0 ▶ $final = sub { $self->$fn($old_final, $old, $new) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
926 }
927  
928 6 ▶ my $txn_wrap = List::Util::first {
Subroutine __ANON__: called CC=2 SCAR=6.9
929 defined $dirty{$_->{column}} && $_->{txn_wrap}
930 3 ▶ } @all_before, @all_around, @all_after;
Branch: 1 branch
BranchTrueFalseTotal
defined $dirty{$_->{"column"}} and $_->{"txn_wrap"} 4 2 6
931  
932 3 my $guard;
933 3 ▶ $guard = $self->result_source->schema->txn_scope_guard if $txn_wrap;
Branch: 1 branch
BranchTrueFalseTotal
if $txn_wrap 0 3 3
934  
935 3 for (@before) {
936 2 my $fn = $_->{method};
937 2 my $old = $self->get_storage_value($_->{column});
938 2 my $new = $dirty{$_->{column}};
939 2 $self->$fn($old, $new);
940 }
941  
942 3 my $ret = $final->();
943  
944 3 for (@after) {
945 2 my $fn = $_->{method};
946 2 my $old = $self->get_storage_value($_->{column});
947 2 my $new = $dirty{$_->{column}};
948 2 $self->$fn($old, $new);
949 }
950  
951 3 ▶ $guard->commit if $txn_wrap;
Branch: 1 branch
BranchTrueFalseTotal
if $txn_wrap 0 3 3
952  
953 3 return $ret;
954 }
955  
956 79 return $self->_update_body($upd);
957 }
958  
959 # Core update logic, extracted so OnColumnChange (above) can wrap it
960 # with before/around/after callbacks without mutual recursion.
961 82 ▶sub _update_body {
Subroutine _update_body: called CC=8 SCAR=21.1
962 82 my ($self, $upd) = @_;
963  
964 82 ▶ $self->set_inflated_columns($upd) if $upd;
Branch: 1 branch
BranchTrueFalseTotal
if $upd 49 33 82
965  
966 80 ▶ my %to_update = $self->get_dirty_columns
Branch: 1 branch
BranchTrueFalseTotal
my(%to_update) = $self->get_dirty_columns or return $self 78 2 80
967 or return $self;
968  
969 78 ▶ $self->throw_exception( "Not in database" ) unless $self->in_storage;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in_storage 1 77 78
970  
971 77 assert_column_value($_, $to_update{$_}) for sort keys %to_update;
972  
973 77 my $rows = $self->result_source->storage->update(
974 $self->result_source, \%to_update, $self->_storage_ident_condition
975 );
976 76 ▶ if ($rows == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rows == 0) { } 0 76 76
elsif ($rows > 1) { } 0 76 76
977 0 $self->throw_exception( "Can't update ${self}: row not found" );
978 } elsif ($rows > 1) {
979 0 $self->throw_exception("Can't update ${self}: updated more than one row");
980 }
981 76 $self->{_dirty_columns} = {};
982 76 $self->{related_resultsets} = {};
983 76 delete $self->{_column_data_in_storage};
984  
985 # StorageValues (integrated helper): refresh snapshot post-UPDATE.
986 76 ▶ $self->store_storage_values if @{$self->storage_value_columns};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->storage_value_columns;} 6 70 76
987  
988 76 return $self;
989 }
990  
991  
992 133 ▶sub delete {
Subroutine delete: called CC=7 SCAR=19.9
Pod documented
993 133 my $self = shift;
994 133 ▶ if (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 131 2 133
995 131 ▶ $self->throw_exception( "Not in database" ) unless $self->in_storage;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in_storage 1 130 131
996  
997 130 $self->prepare_delete;
998  
999 130 $self->result_source->storage->delete(
1000 $self->result_source, $self->_storage_ident_condition
1001 );
1002  
1003 130 delete $self->{_column_data_in_storage};
1004 130 $self->in_storage(0);
1005 }
1006 else {
1007 2 ▶ my $rsrc = try { $self->result_source_instance }
Subroutine __ANON__: called CC=1 SCAR=0.0
1008 2 ▶ or $self->throw_exception("Can't do class delete without a ResultSource instance");
Branch: 1 branch
BranchTrueFalseTotal
my $rsrc = &try(sub { $self->result_source_instance; } ) or $self->throw_exception("Can't do class delete without a ResultSource instance") 2 0 2
1009  
1010 0 ▶ my $attrs = @_ > 1 && ref $_[$#_] eq 'HASH' ? { %{pop(@_)} } : {};
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 && ref $_[$#_] eq 'HASH' ? : 0 2 2
Condition33%1/3
@_ > 1 and ref $_[$#_] eq "HASH"
!ll&&!rl&&r
200
MC/DC0%0/2
@_ > 1 and ref $_[$#_] eq "HASH"
@_ > 1 ref $_[$#_] eq "HASH"
Truth table33%1/3
A and B
A= @_ > 1B= ref $_[$#_] eq "HASH"
ABresult
0X0
100
111
1011 2 ▶ my $query = ref $_[0] eq 'HASH' ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 1 1 2
1012 2 $rsrc->resultset->search(@_)->delete;
1013 }
1014 131 return $self;
1015 }
1016  
1017 # True if any relationship on this row's source has cascade_delete set --
1018 # mirrors DBIO::Relationship::CascadeActions::delete's own gate. Shared by
1019 # delete_async's punt check, below.
1020 15 ▶sub _has_cascade_delete_relateds {
Subroutine _has_cascade_delete_relateds: called CC=1 SCAR=0.0
1021 15 my $self = shift;
1022 15 my $source = $self->result_source;
1023 15 my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
1024 15 return !! grep { $rels{$_}{attrs}{cascade_delete} } keys %rels;
1025 }
1026  
1027  
1028 29 ▶sub delete_async {
Subroutine delete_async: called CC=1 SCAR=0.0
Pod documented
1029 29 my $self = shift;
1030  
1031 return $self->_row_run_async('delete',
1032 27 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
1033 27 my ($backend, $fc) = @_;
1034  
1035 27 ▶ $self->throw_exception( "Not in database" ) unless $self->in_storage;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in_storage 0 27 27
1036  
1037 27 ▶ if (my $pkg = $self->_async_override_gap('delete')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pkg = $self->_async_override_gap("delete")) 12 15 27
1038 return $self->_async_ctx_or_sync_punt($fc, 'delete',
1039 4 ▶ 'an override of delete', sub { $self->delete },
Subroutine __ANON__: called CC=1 SCAR=0.0
1040 12 $self->_async_override_gap_lead($pkg, 'delete'));
1041 }
1042  
1043 15 ▶ if ($self->_has_cascade_delete_relateds) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_cascade_delete_relateds) 7 8 15
1044 return $self->_async_ctx_or_sync_punt($fc, 'delete',
1045 'a cascade_delete relationship makes this a multi-statement delete',
1046 7 ▶ sub { $self->delete });
Subroutine __ANON__: called CC=1 SCAR=0.0
1047 }
1048  
1049 # delete() calls it at this point as well; the punts above run the
1050 # full delete(), which calls it itself.
1051 8 $self->prepare_delete;
1052  
1053 8 my $rsrc = $self->result_source;
1054 8 ▶ return $backend->delete_async($rsrc, $self->_storage_ident_condition)->then(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1055 8 delete $self->{_column_data_in_storage};
1056 8 $self->in_storage(0);
1057 8 return $self;
1058 8 });
1059 },
1060 1 ▶ sub { $self->delete },
Subroutine __ANON__: called CC=1 SCAR=0.0
1061 29 );
1062 }
1063  
1064  
1065 3238 ▶sub prepare_insert { }
Subroutine prepare_insert: called CC=1 SCAR=0.0
Pod documented
1066 128 ▶sub prepare_update { }
Subroutine prepare_update: called CC=1 SCAR=0.0
Pod documented
1067 138 ▶sub prepare_delete { }
Subroutine prepare_delete: called CC=1 SCAR=0.0
Pod documented
1068  
1069  
1070 7674 ▶sub get_column {
Subroutine get_column: called CC=5 SCAR=16.2
Pod documented
1071 7674 my ($self, $column) = @_;
1072 7674 ▶ $self->throw_exception( "Can't fetch data as class method" ) unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 7674 7674
1073  
1074 return $self->{_column_data}{$column}
1075 7674 ▶ if exists $self->{_column_data}{$column};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_column_data"}{$column} 7559 115 7674
1076  
1077 115 ▶ if (exists $self->{_inflated_column}{$column}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_inflated_column"}{$column}) 21 94 115
1078 # deflate+return cycle
1079 return $self->store_column($column, $self->_deflated_column(
1080 21 $column, $self->{_inflated_column}{$column}
1081 ));
1082 }
1083  
1084 94 ▶ $self->throw_exception( "No such column '${column}' on " . ref $self )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->result_source->has_column($column) 0 94 94
1085 unless $self->result_source->has_column($column);
1086  
1087 94 return undef;
1088 }
1089  
1090  
1091 5484 ▶sub has_column_loaded {
Subroutine has_column_loaded: called CC=4 SCAR=13.9
Pod documented
1092 5484 my ($self, $column) = @_;
1093 5484 ▶ $self->throw_exception( "Can't call has_column data as class method" ) unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 5484 5484
1094  
1095 return (
1096 exists $self->{_inflated_column}{$column}
1097 or
1098 5484 ▶ exists $self->{_column_data}{$column}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'_inflated_column'}{$column} || exists $self->{'_column_data'}{$column} ? : 5419 65 5484
Condition100%3/3
exists $self->{"_inflated_column"}{$column} or exists $self->{"_column_data"}{$column}
l!l&&r!l&&!r
26539365
MC/DC100%2/2
exists $self->{"_inflated_column"}{$column} or exists $self->{"_column_data"}{$column}
exists $self->{"_inflated_column"}{$column} exists $self->{"_column_data"}{$column}
Truth table100%3/3
A or B
A= exists $self->{"_inflated_column"}{$column}B= exists $self->{"_column_data"}{$column}
ABresult
1X1
011
000
1099 ) ? 1 : 0;
1100 }
1101  
1102  
1103 3799 ▶sub get_columns {
Subroutine get_columns: called CC=7 SCAR=20.4
Pod documented
1104 3799 my $self = shift;
1105 3799 ▶ if (exists $self->{_inflated_column}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_inflated_column"}) 283 3516 3799
1106 # deflate cycle for each inflation, including filter rels
1107 283 foreach my $col (keys %{$self->{_inflated_column}}) {
1108 68 ▶ unless (exists $self->{_column_data}{$col}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_column_data"}{$col}) 46 22 68
1109  
1110 # if cached related_resultset is present assume this was a prefetch
1111 carp_unique(
1112 "Returning primary keys of prefetched 'filter' rels as part of get_columns() is deprecated and will "
1113 . 'eventually be removed entirely (set DBIO_COLUMNS_INCLUDE_FILTER_RELS to disable this warning)'
1114 ) if (
1115 ! $ENV{DBIO_COLUMNS_INCLUDE_FILTER_RELS}
1116 and
1117 defined $self->{related_resultsets}{$col}
1118 and
1119 46 ▶ defined $self->{related_resultsets}{$col}->get_cache
Branch: 1 branch
BranchTrueFalseTotal
if not $ENV{"DBIO_COLUMNS_INCLUDE_FILTER_RELS"} and defined $self->{"related_resultsets"}{$col} and defined $self->{"related_resultsets"}{$col}->get_cache 0 46 46
Condition33%2/6
not $ENV{"DBIO_COLUMNS_INCLUDE_FILTER_RELS"} and defined $self->{"related_resultsets"}{$col} and defined $self->{"related_resultsets"}{$col}->get_cache
!ll&&!rl&&r
4600
not $ENV{"DBIO_COLUMNS_INCLUDE_FILTER_RELS"} and defined $self->{"related_resultsets"}{$col}
!ll&&!rl&&r
0460
MC/DC0%0/3
not $ENV{"DBIO_COLUMNS_INCLUDE_FILTER_RELS"} and defined $self->{"related_resultsets"}{$col} and defined $self->{"related_resultsets"}{$col}->get_cache
not $ENV{"DBIO_COLUMNS_INCLUDE_FILTER_RELS"} defined $self->{"related_resultsets"}{$col} defined $self->{"related_resultsets"}{$col}->get_cache
Truth table25%1/4
not(A) and B and C
A= not $ENV{"DBIO_COLUMNS_INCLUDE_FILTER_RELS"}B= defined $self->{"related_resultsets"}{$col}C= defined $self->{"related_resultsets"}{$col}->get_cache
ABCresult
0XX0
10X0
1100
1111
1120 );
1121  
1122 46 $self->store_column($col, $self->_deflated_column($col, $self->{_inflated_column}{$col}));
1123 }
1124 }
1125 }
1126 3799 return %{$self->{_column_data}};
1127 }
1128  
1129  
1130 201 ▶sub get_dirty_columns {
Subroutine get_dirty_columns: called CC=1 SCAR=0.0
Pod documented
1131 201 my $self = shift;
1132 160 return map { $_ => $self->{_column_data}{$_} }
1133 201 keys %{$self->{_dirty_columns}};
1134 }
1135  
1136  
1137 23 ▶sub make_column_dirty {
Subroutine make_column_dirty: called CC=5 SCAR=17.0
Pod documented
1138 23 my ($self, $column) = @_;
1139  
1140 $self->throw_exception( "No such column '${column}' on " . ref $self )
1141 23 ▶ unless exists $self->{_column_data}{$column} || $self->result_source->has_column($column);
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_column_data"}{$column} or $self->result_source->has_column($column) 0 23 23
Condition66%2/3
exists $self->{"_column_data"}{$column} or $self->result_source->has_column($column)
l!l&&r!l&&!r
2210
MC/DC0%0/2
exists $self->{"_column_data"}{$column} or $self->result_source->has_column($column)
exists $self->{"_column_data"}{$column} $self->result_source->has_column($column)
Truth table66%2/3
A or B
A= exists $self->{"_column_data"}{$column}B= $self->result_source->has_column($column)
ABresult
1X1
011
000
1142  
1143 # the entire clean/dirty code relies on exists, not on true/false
1144 23 ▶ return 1 if exists $self->{_dirty_columns}{$column};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_dirty_columns"}{$column} 2 21 23
1145  
1146 21 $self->{_dirty_columns}{$column} = 1;
1147  
1148 # if we are just now making the column dirty, and if there is an inflated
1149 # value, force it over the deflated one
1150 21 ▶ if (exists $self->{_inflated_column}{$column}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_inflated_column"}{$column}) 0 21 21
1151 $self->store_column($column,
1152 $self->_deflated_column(
1153 0 $column, $self->{_inflated_column}{$column}
1154 )
1155 );
1156 }
1157 }
1158  
1159  
1160 1 ▶sub get_inflated_columns {
Subroutine get_inflated_columns: called CC=12 SCAR=38.7
Pod documented
1161 1 my $self = shift;
1162  
1163 1 my $loaded_colinfo = $self->result_source->columns_info;
1164 $self->has_column_loaded($_) or delete $loaded_colinfo->{$_}
1165 1 ▶ for keys %$loaded_colinfo;
Branch: 1 branch
BranchTrueFalseTotal
$self->has_column_loaded($_) or delete $loaded_colinfo->{$_} 0 6 6
1166  
1167 1 my %cols_to_return = ( %{$self->{_column_data}}, %$loaded_colinfo );
1168  
1169 1 ▶ unless ($ENV{DBIO_COLUMNS_INCLUDE_FILTER_RELS}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"DBIO_COLUMNS_INCLUDE_FILTER_RELS"}) 1 0 1
1170 1 for (keys %$loaded_colinfo) {
1171 # if cached related_resultset is present assume this was a prefetch
1172 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($loaded_colinfo->{$_}{"_inflate_info"} and defined $self->{"related_resultsets"}{$_} and defined $self->{"related_resultsets"}{$_}->get_cache) 0 0 0
Condition0%0/6
$loaded_colinfo->{$_}{"_inflate_info"} and defined $self->{"related_resultsets"}{$_} and defined $self->{"related_resultsets"}{$_}->get_cache
!ll&&!rl&&r
000
$loaded_colinfo->{$_}{"_inflate_info"} and defined $self->{"related_resultsets"}{$_}
!ll&&!rl&&r
000
MC/DC0%0/3
$loaded_colinfo->{$_}{"_inflate_info"} and defined $self->{"related_resultsets"}{$_} and defined $self->{"related_resultsets"}{$_}->get_cache
$loaded_colinfo->{$_}{"_inflate_info"} defined $self->{"related_resultsets"}{$_} defined $self->{"related_resultsets"}{$_}->get_cache
Truth table0%0/4
A and B and C
A= $loaded_colinfo->{$_}{"_inflate_info"}B= defined $self->{"related_resultsets"}{$_}C= defined $self->{"related_resultsets"}{$_}->get_cache
ABCresult
0XX0
10X0
1100
1111
1173 $loaded_colinfo->{$_}{_inflate_info}
1174 and
1175 defined $self->{related_resultsets}{$_}
1176 and
1177 defined $self->{related_resultsets}{$_}->get_cache
1178 ) {
1179 0 carp_unique(
1180 "Returning prefetched 'filter' rels as part of get_inflated_columns() is deprecated and will "
1181 . 'eventually be removed entirely (set DBIO_COLUMNS_INCLUDE_FILTER_RELS to disable this warning)'
1182 );
1183 0 last;
1184 }
1185 }
1186 }
1187  
1188 1 map { $_ => (
1189 (
1190 ! exists $loaded_colinfo->{$_}
1191 or
1192 (
1193 exists $loaded_colinfo->{$_}{accessor}
1194 and
1195 ! defined $loaded_colinfo->{$_}{accessor}
1196 )
1197 ) ? $self->get_column($_)
1198 1 ▶ : $self->${ \(
Branch: 1 branch
BranchTrueFalseTotal
!exists $loaded_colinfo->{$_} || exists $loaded_colinfo->{$_}{'accessor'} && !defined($loaded_colinfo->{$_}{'accessor'}) ? : 1 0 1
Condition16%1/6
not exists $loaded_colinfo->{$_} or exists $loaded_colinfo->{$_}{"accessor"} and not defined $loaded_colinfo->{$_}{"accessor"}
l!l&&r!l&&!r
100
exists $loaded_colinfo->{$_}{"accessor"} and not defined $loaded_colinfo->{$_}{"accessor"}
!ll&&!rl&&r
000
MC/DC0%0/3
not exists $loaded_colinfo->{$_} or exists $loaded_colinfo->{$_}{"accessor"} and not defined $loaded_colinfo->{$_}{"accessor"}
not exists $loaded_colinfo->{$_} exists $loaded_colinfo->{$_}{"accessor"} not defined $loaded_colinfo->{$_}{"accessor"}
Truth table25%1/4
not(A) or B and not(C)
A= not exists $loaded_colinfo->{$_}B= exists $loaded_colinfo->{$_}{"accessor"}C= not defined $loaded_colinfo->{$_}{"accessor"}
ABCresult
1XX1
0111
00X0
0100
1199 defined $loaded_colinfo->{$_}{accessor}
1200 ? $loaded_colinfo->{$_}{accessor}
1201 0 ▶ : $_
Branch: 1 branch
BranchTrueFalseTotal
defined $loaded_colinfo->{$_}{'accessor'} ? : 0 0 0
1202 )}
1203 )} keys %cols_to_return;
1204 }
1205  
1206 157 ▶sub _is_column_numeric {
Subroutine _is_column_numeric: called CC=5 SCAR=16.1
1207 157 my ($self, $column) = @_;
1208  
1209 157 ▶ return undef unless $self->result_source->has_column($column);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->result_source->has_column($column) 0 157 157
1210  
1211 157 my $colinfo = $self->result_source->column_info ($column);
1212  
1213 # cache for speed (the object may *not* have a resultsource instance)
1214 157 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $colinfo->{"is_numeric"} and my $storage = &try(sub { $self->result_source->schema->storage; } )) 58 99 157
Condition100%3/3
not defined $colinfo->{"is_numeric"} and my $storage = &try(sub { $self->result_source->schema->storage; } )
!ll&&!rl&&r
98158
MC/DC100%2/2
not defined $colinfo->{"is_numeric"} and my $storage = &try(sub { $self->result_source->schema->storage; } )
not defined $colinfo->{"is_numeric"} my $storage = &try(sub { $self->result_source->schema->storage; } )
Truth table100%3/3
not(A) and B
A= not defined $colinfo->{"is_numeric"}B= my $storage = &try(sub { $self->result_source->schema->storage; } )
ABresult
0X0
100
111
1215 ! defined $colinfo->{is_numeric}
1216 and
1217 59 ▶ my $storage = try { $self->result_source->schema->storage }
Subroutine __ANON__: called CC=1 SCAR=0.0
1218 ) {
1219 $colinfo->{is_numeric} =
1220 $storage->is_datatype_numeric ($colinfo->{data_type})
1221 58 ▶ ? 1
Branch: 1 branch
BranchTrueFalseTotal
$storage->is_datatype_numeric($colinfo->{'data_type'}) ? : 10 48 58
1222 : 0
1223 ;
1224 }
1225  
1226 157 return $colinfo->{is_numeric};
1227 }
1228  
1229  
1230 351 ▶sub set_column {
Subroutine set_column: called CC=14 SCAR=26.4
Pod documented
1231 351 my ($self, $column, $new_value) = @_;
1232  
1233 351 my $had_value = $self->has_column_loaded($column);
1234 351 my $old_value = $self->get_column($column);
1235  
1236 351 $new_value = $self->store_column($column, $new_value);
1237  
1238 my $dirty =
1239 342 ▶ $self->{_dirty_columns}{$column}
Branch: 1 branch
BranchTrueFalseTotal
$self->in_storage ? : 195 114 309
Condition100%3/3
$self->{'_dirty_columns'}{$column} || ($self->in_storage ? !$self->_eq_column_values($column, $old_value, $new_value) : 1)
l!l&&r!l&&!r
3327435
MC/DC100%2/2
$self->{'_dirty_columns'}{$column} || ($self->in_storage ? !$self->_eq_column_values($column, $old_value, $new_value) : 1)
$self->{'_dirty_columns'}{$column} ($self->in_storage ? !$self->_eq_column_values($column, $old_value, $new_value) : 1)
Truth table100%3/3
A || B
A= $self->{'_dirty_columns'}{$column}B= ($self->in_storage ? !$self->_eq_column_values($column, $old_value, $new_value) : 1)
ABresult
1X1
011
000
1240 ||
1241 ( $self->in_storage # no point tracking dirtyness on uninserted data
1242 ? ! $self->_eq_column_values ($column, $old_value, $new_value)
1243 : 1
1244 )
1245 ;
1246  
1247 342 ▶ if ($dirty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirty) 307 35 342
1248 # FIXME sadly the update code just checks for keys, not for their value
1249 307 $self->{_dirty_columns}{$column} = 1;
1250  
1251 # Clear out the relation/inflation cache related to this column
1252 #
1253 # FIXME - this is a quick *largely incorrect* hack, pending a more
1254 # serious rework during the merge of single and filter rels
1255 307 my $rel_names = $self->result_source->{_relationships};
1256 307 for my $rel_name (keys %$rel_names) {
1257  
1258 2083 ▶ my $acc = $rel_names->{$rel_name}{attrs}{accessor} || '';
Condition50%1/2
$rel_names->{$rel_name}{'attrs'}{'accessor'} || ''
l!l
20830
MC/DC0%0/1
$rel_names->{$rel_name}{'attrs'}{'accessor'} || ''
$rel_names->{$rel_name}{'attrs'}{'accessor'}
Truth table50%1/2
A
A= $rel_names->{$rel_name}{'attrs'}{'accessor'}
Aresult
11
00
1259  
1260 2083 ▶ if ( $acc eq 'single' and $rel_names->{$rel_name}{attrs}{fk_columns}{$column} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($acc eq 'single' and $rel_names->{$rel_name}{'attrs'}{'fk_columns'}{$column}) { } 165 1918 2083
elsif ($acc eq 'filter' and $rel_name eq $column) { } 95 3504 3599
Condition100%3/3
$acc eq "single" and $rel_names->{$rel_name}{"attrs"}{"fk_columns"}{$column}
!ll&&!rl&&r
1140778165
MC/DC100%2/2
$acc eq "single" and $rel_names->{$rel_name}{"attrs"}{"fk_columns"}{$column}
$acc eq "single" $rel_names->{$rel_name}{"attrs"}{"fk_columns"}{$column}
Truth table100%3/3
A and B
A= $acc eq "single"B= $rel_names->{$rel_name}{"attrs"}{"fk_columns"}{$column}
ABresult
0X0
100
111
1261 165 delete $self->{related_resultsets}{$rel_name};
1262 165 delete $self->{_relationship_data}{$rel_name};
1263 #delete $self->{_inflated_column}{$rel_name};
1264 }
1265 ▶ elsif ( $acc eq 'filter' and $rel_name eq $column) {
Condition100%3/3
$acc eq "filter" and $rel_name eq $column
!ll&&!rl&&r
168114295
MC/DC100%2/2
$acc eq "filter" and $rel_name eq $column
$acc eq "filter" $rel_name eq $column
Truth table100%3/3
A and B
A= $acc eq "filter"B= $rel_name eq $column
ABresult
0X0
100
111
1266 95 delete $self->{related_resultsets}{$rel_name};
1267 #delete $self->{_relationship_data}{$rel_name};
1268 95 delete $self->{_inflated_column}{$rel_name};
1269 }
1270 }
1271 307 delete $self->{_inflated_column}{$column};
1272  
1273 307 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($had_value and $self->in_storage and not exists $self->{"_column_data_in_storage"}{$column} and $self->_track_storage_value($column)) 5 302 307
Condition100%9/9
$had_value and $self->in_storage and not exists $self->{"_column_data_in_storage"}{$column} and $self->_track_storage_value($column)
!ll&&!rl&&r
1601425
$had_value and $self->in_storage and not exists $self->{"_column_data_in_storage"}{$column}
!ll&&!rl&&r
14713147
$had_value and $self->in_storage
!ll&&!rl&&r
5790160
MC/DC100%4/4
$had_value and $self->in_storage and not exists $self->{"_column_data_in_storage"}{$column} and $self->_track_storage_value($column)
$had_value $self->in_storage not exists $self->{"_column_data_in_storage"}{$column} $self->_track_storage_value($column)
Truth table100%5/5
A and B and not(C) and D
A= $had_valueB= $self->in_storageC= not exists $self->{"_column_data_in_storage"}{$column}D= $self->_track_storage_value($column)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1274 # value change from something (even if NULL)
1275 $had_value
1276 and
1277 # no storage - no storage-value
1278 $self->in_storage
1279 and
1280 # no value already stored (multiple changes before commit to storage)
1281 ! exists $self->{_column_data_in_storage}{$column}
1282 and
1283 $self->_track_storage_value($column)
1284 ) {
1285 5 $self->{_column_data_in_storage}{$column} = $old_value;
1286 }
1287 }
1288  
1289 342 return $new_value;
1290 }
1291  
1292 195 ▶sub _eq_column_values {
Subroutine _eq_column_values: called CC=8 SCAR=22.4
1293 195 my ($self, $col, $old, $new) = @_;
1294  
1295 195 ▶ if (defined $old xor defined $new) {
Branch: 5 branches
BranchTrueFalseTotal
if (defined $old xor defined $new) { } 3 192 195
elsif (not defined $old) { } 0 192 192
elsif (&is_literal_value($old) or &is_literal_value($new)) { } 0 192 192
elsif ($old eq $new) { } 35 157 192
elsif ($self->_is_column_numeric($col)) { } 46 111 157
Condition75%3/4
defined $old xor defined $new
l&&rl&&!r!l&&r!l&&!r
192120
MC/DC100%2/2
defined $old xor defined $new
defined $old defined $new
Truth table75%3/4
A xor B
A= defined $oldB= defined $new
ABresult
110
101
011
000
1296 3 return 0;
1297 }
1298 elsif (not defined $old) { # both undef
1299 0 return 1;
1300 }
1301 ▶ elsif (
Condition33%1/3
&is_literal_value($old) or &is_literal_value($new)
l!l&&r!l&&!r
00192
MC/DC0%0/2
&is_literal_value($old) or &is_literal_value($new)
&is_literal_value($old) &is_literal_value($new)
Truth table33%1/3
A or B
A= &is_literal_value($old)B= &is_literal_value($new)
ABresult
1X1
011
000
1302 is_literal_value $old
1303 or
1304 is_literal_value $new
1305 ) {
1306 0 return 0;
1307 }
1308 elsif ($old eq $new) {
1309 35 return 1;
1310 }
1311 elsif ($self->_is_column_numeric($col)) { # do a numeric comparison if datatype allows it
1312 46 return $old == $new;
1313 }
1314 else {
1315 111 return 0;
1316 }
1317 }
1318  
1319 # returns a boolean indicating if the passed column should have its original
1320 # value tracked between column changes and commitment to storage
1321 147 ▶sub _track_storage_value {
Subroutine _track_storage_value: called CC=2 SCAR=6.9
1322 147 my ($self, $col) = @_;
1323  
1324 147 my @pri = $self->result_source->primary_columns;
1325  
1326 # Without a primary key the row's identity is whatever get_from_storage's
1327 # fallback builds it from, and that is *every* loaded column: find()'s
1328 # heuristics narrow down to a unique constraint when one matches, but a
1329 # source declaring none at all ends up in _non_unique_find_fallback, which
1330 # uses the lot. Tracking only the unique-constraint columns would therefore
1331 # leave exactly those sources unable to identify a dirty row, so track
1332 # everything -- the map still only ever holds columns that actually changed.
1333 147 ▶ return 1 unless @pri;
Branch: 1 branch
BranchTrueFalseTotal
unless @pri 1 146 147
1334  
1335 146 return scalar grep { $col eq $_ } @pri;
1336 }
1337  
1338  
1339 270 ▶sub set_columns {
Subroutine set_columns: called CC=2 SCAR=6.9
Pod documented
1340 270 my ($self, $values) = @_;
1341 270 $self->set_column( $_, $values->{$_} ) for keys %$values;
1342 266 return $self;
1343 }
1344  
1345  
1346 147 ▶sub set_inflated_columns {
Subroutine set_inflated_columns: called CC=13 SCAR=25.9
Pod documented
1347 147 my ( $self, $upd ) = @_;
1348 147 my $rsrc;
1349 147 foreach my $key (keys %$upd) {
1350 178 ▶ if (!defined $upd->{$key} || ref $upd->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $upd->{$key} or ref $upd->{$key}) 31 147 178
Condition100%3/3
not defined $upd->{$key} or ref $upd->{$key}
l!l&&r!l&&!r
328147
MC/DC100%2/2
not defined $upd->{$key} or ref $upd->{$key}
not defined $upd->{$key} ref $upd->{$key}
Truth table100%3/3
not(A) or B
A= not defined $upd->{$key}B= ref $upd->{$key}
ABresult
1X1
011
000
1351 31 ▶ $rsrc ||= $self->result_source;
Condition33%1/3
$rsrc ||= $self->result_source
l!l&&r!l&&!r
0310
MC/DC0%0/2
$rsrc ||= $self->result_source
$rsrc $self->result_source
Truth table33%1/3
A ||= B
A= $rsrcB= $self->result_source
ABresult
1X1
011
000
1352 31 my $info = $rsrc->relationship_info($key);
1353 31 ▶ my $acc_type = $info->{attrs}{accessor} || '';
Condition100%2/2
$info->{'attrs'}{'accessor'} || ''
l!l
256
MC/DC100%1/1
$info->{'attrs'}{'accessor'} || ''
$info->{'attrs'}{'accessor'}
Truth table100%2/2
A
A= $info->{'attrs'}{'accessor'}
Aresult
11
00
1354  
1355 # A plain hashref for a to-one relationship is column values of the
1356 # related row, not a related object: set_from_related reduces it to
1357 # this row's own columns or refuses it (ADR 0034), whichever accessor
1358 # the relationship has. There is no object in it to deflate or to keep
1359 # -- what the row held for the relationship goes or stays with those
1360 # columns, as for any other set_column.
1361 31 ▶ if (
Branch: 4 branches
BranchTrueFalseTotal
if (ref $upd->{$key} eq 'HASH' and $acc_type eq 'single' || $acc_type eq 'filter') { } 17 14 31
elsif ($acc_type eq 'single') { } 6 8 14
elsif ($acc_type eq 'multi') { } 0 8 8
elsif ($rsrc->has_column($key) and exists $rsrc->column_info($key)->{'_inflate_info'}) { } 3 5 8
Condition100%6/6
ref $upd->{$key} eq "HASH" and $acc_type eq "single" || $acc_type eq "filter"
!ll&&!rl&&r
11317
$acc_type eq "single" or $acc_type eq "filter"
l!l&&r!l&&!r
1343
MC/DC100%3/3
ref $upd->{$key} eq "HASH" and $acc_type eq "single" || $acc_type eq "filter"
ref $upd->{$key} eq "HASH" $acc_type eq "single" $acc_type eq "filter"
Truth table100%4/4
A and B or C
A= ref $upd->{$key} eq "HASH"B= $acc_type eq "single"C= $acc_type eq "filter"
ABCresult
0XX0
1000
11X1
1011
1362 ref $upd->{$key} eq 'HASH'
1363 and
1364 ( $acc_type eq 'single' or $acc_type eq 'filter' )
1365 ) {
1366 17 $self->set_from_related($key => delete $upd->{$key});
1367 }
1368 elsif ($acc_type eq 'single') {
1369 6 my $rel_obj = delete $upd->{$key};
1370 6 $self->set_from_related($key => $rel_obj);
1371 6 $self->{_relationship_data}{$key} = $rel_obj;
1372 }
1373 elsif ($acc_type eq 'multi') {
1374 0 $self->throw_exception(
1375 "Recursive update is not supported over relationships of type '$acc_type' ($key)"
1376 );
1377 }
1378 ▶ elsif (
Condition66%2/3
$rsrc->has_column($key) and exists $rsrc->column_info($key)->{"_inflate_info"}
!ll&&!rl&&r
053
MC/DC50%1/2
$rsrc->has_column($key) and exists $rsrc->column_info($key)->{"_inflate_info"}
$rsrc->has_column($key) exists $rsrc->column_info($key)->{"_inflate_info"}
Truth table66%2/3
A and B
A= $rsrc->has_column($key)B= exists $rsrc->column_info($key)->{"_inflate_info"}
ABresult
0X0
100
111
1379 $rsrc->has_column($key)
1380 and
1381 exists $rsrc->column_info($key)->{_inflate_info}
1382 ) {
1383 3 $self->set_inflated_column($key, delete $upd->{$key});
1384 }
1385 }
1386 }
1387 143 $self->set_columns($upd);
1388 }
1389  
1390  
1391 11 ▶sub copy {
Subroutine copy: called CC=12 SCAR=25.0
Pod documented
1392 11 my ($self, $changes) = @_;
1393  
1394 # ProxyResultSetMethod (integrated helper): proxied values are not
1395 # real columns and must not be carried into the copy.
1396 11 ▶ delete local @{$self->{_column_data}}{@{$self->_proxy_slots||[]}};
Condition100%2/2
$self->_proxy_slots || []
l!l
110
MC/DC100%1/1
$self->_proxy_slots || []
$self->_proxy_slots
Truth table100%2/2
A
A= $self->_proxy_slots
Aresult
11
00
1397  
1398 11 ▶ $changes ||= {};
Condition100%2/2
$changes ||= {}
l!l
92
MC/DC100%1/1
$changes ||= {}
$changes
Truth table100%2/2
A
A= $changes
Aresult
11
00
1399 11 my $col_data = { $self->get_columns };
1400  
1401 11 my $rsrc = $self->result_source;
1402  
1403 11 my $colinfo = $rsrc->columns_info;
1404 11 foreach my $col (keys %$col_data) {
1405 delete $col_data->{$col}
1406 26 ▶ if ( ! $colinfo->{$col} or $colinfo->{$col}{is_auto_increment} );
Branch: 1 branch
BranchTrueFalseTotal
if not $colinfo->{$col} or $colinfo->{$col}{"is_auto_increment"} 11 15 26
Condition66%2/3
not $colinfo->{$col} or $colinfo->{$col}{"is_auto_increment"}
l!l&&r!l&&!r
01115
MC/DC50%1/2
not $colinfo->{$col} or $colinfo->{$col}{"is_auto_increment"}
not $colinfo->{$col} $colinfo->{$col}{"is_auto_increment"}
Truth table66%2/3
not(A) or B
A= not $colinfo->{$col}B= $colinfo->{$col}{"is_auto_increment"}
ABresult
1X1
011
000
1407 }
1408  
1409 11 my $new = { _column_data => $col_data };
1410 11 bless $new, ref $self;
1411  
1412 11 $new->result_source($rsrc);
1413 11 $new->set_inflated_columns($changes);
1414  
1415 # ADR 0045 / karr k325: the copy of a context-bound row keeps the pin, as the
1416 # one copy_async builds does. The insert below is synchronous and does not
1417 # read it.
1418 11 ▶ $new->{_async_context} = $self->{_async_context} if $self->{_async_context};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_async_context"} 2 9 11
1419  
1420 11 $new->insert;
1421  
1422 # Its possible we'll have 2 relations to the same Source. We need to make
1423 # sure we don't try to insert the same row twice else we'll violate unique
1424 # constraints
1425 11 my $rel_names_copied = {};
1426  
1427 11 foreach my $rel_name ($rsrc->relationships) {
1428 12 my $rel_info = $rsrc->relationship_info($rel_name);
1429  
1430 12 ▶ next unless $rel_info->{attrs}{cascade_copy};
Branch: 1 branch
BranchTrueFalseTotal
unless $rel_info->{"attrs"}{"cascade_copy"} 6 6 12
1431  
1432 my $resolved = $rsrc->_resolve_condition(
1433 6 $rel_info->{cond}, $rel_name, $new, $rel_name
1434 );
1435  
1436 6 ▶ my $copied = $rel_names_copied->{ $rel_info->{source} } ||= {};
Condition100%2/2
$$rel_names_copied{$rel_info->{"source"}} ||= {}
l!l
24
MC/DC100%1/1
$$rel_names_copied{$rel_info->{"source"}} ||= {}
$$rel_names_copied{$rel_info->{"source"}}
Truth table100%2/2
A
A= $$rel_names_copied{$rel_info->{"source"}}
Aresult
11
00
1437 6 foreach my $related ($self->search_related($rel_name)->all) {
1438 $related->copy($resolved)
1439 0 ▶ unless $copied->{$related->ID}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $$copied{$related->ID}++ 0 0 0
1440 }
1441  
1442 }
1443 11 return $new;
1444 }
1445  
1446 # True if any relationship on this row's source has cascade_copy set --
1447 # mirrors copy()'s own gate (`next unless $rel_info->{attrs}{cascade_copy}`,
1448 # above). Shared by copy_async's punt check, below.
1449 7 ▶sub _has_cascade_copy_relateds {
Subroutine _has_cascade_copy_relateds: called CC=1 SCAR=0.0
1450 7 my $self = shift;
1451 7 my $source = $self->result_source;
1452 7 my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
1453 7 return !! grep { $rels{$_}{attrs}{cascade_copy} } keys %rels;
1454 }
1455  
1456  
1457 9 ▶sub copy_async {
Subroutine copy_async: called CC=1 SCAR=0.0
Pod documented
1458 9 my ($self, $changes) = @_;
1459  
1460 return $self->_row_run_async('copy',
1461 7 ▶ sub {
Subroutine __ANON__: called CC=8 SCAR=20.9
1462 7 my ($backend, $fc) = @_;
1463  
1464 7 ▶ if ($self->_has_cascade_copy_relateds) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_cascade_copy_relateds) 2 5 7
1465 return $self->_async_ctx_or_sync_punt($fc, 'copy',
1466 'copy with a cascade_copy relationship is a multi-row cascade',
1467 2 ▶ sub { $self->copy($changes) });
Subroutine __ANON__: called CC=1 SCAR=0.0
1468 }
1469  
1470 # ProxyResultSetMethod (integrated helper): proxied values are not
1471 # real columns and must not be carried into the copy.
1472 5 ▶ delete local @{$self->{_column_data}}{@{$self->_proxy_slots||[]}};
Condition50%1/2
$self->_proxy_slots || []
l!l
05
MC/DC0%0/1
$self->_proxy_slots || []
$self->_proxy_slots
Truth table50%1/2
A
A= $self->_proxy_slots
Aresult
11
00
1473  
1474 5 ▶ my $applied_changes = $changes || {};
Condition50%1/2
$changes || {}
l!l
50
MC/DC0%0/1
$changes || {}
$changes
Truth table50%1/2
A
A= $changes
Aresult
11
00
1475 5 my $col_data = { $self->get_columns };
1476  
1477 5 my $rsrc = $self->result_source;
1478  
1479 5 my $colinfo = $rsrc->columns_info;
1480 5 foreach my $col (keys %$col_data) {
1481 delete $col_data->{$col}
1482 14 ▶ if ( ! $colinfo->{$col} or $colinfo->{$col}{is_auto_increment} );
Branch: 1 branch
BranchTrueFalseTotal
if not $colinfo->{$col} or $colinfo->{$col}{"is_auto_increment"} 5 9 14
Condition66%2/3
not $colinfo->{$col} or $colinfo->{$col}{"is_auto_increment"}
l!l&&r!l&&!r
059
MC/DC50%1/2
not $colinfo->{$col} or $colinfo->{$col}{"is_auto_increment"}
not $colinfo->{$col} $colinfo->{$col}{"is_auto_increment"}
Truth table66%2/3
not(A) or B
A= not $colinfo->{$col}B= $colinfo->{$col}{"is_auto_increment"}
ABresult
1X1
011
000
1483 }
1484  
1485 5 my $new = { _column_data => $col_data };
1486 5 bless $new, ref $self;
1487  
1488 5 $new->result_source($rsrc);
1489 5 $new->set_inflated_columns($applied_changes);
1490  
1491 # ADR 0045 / karr k195: the copy inherits the pin so its insert runs on the
1492 # pinned connection instead of a sibling pool connection outside the txn.
1493 5 ▶ $new->{_async_context} = $self->{_async_context} if $self->{_async_context};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_async_context"} 1 4 5
1494  
1495 5 return $new->insert_async;
1496 },
1497 1 ▶ sub { $self->copy($changes) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1498 9 );
1499 }
1500  
1501  
1502 10753 ▶sub store_column {
Subroutine store_column: called CC=4 SCAR=13.9
Pod documented
1503 10753 my ($self, $column, $value) = @_;
1504 $self->throw_exception( "No such column '${column}' on " . ref $self )
1505 10753 ▶ unless exists $self->{_column_data}{$column} || $self->result_source->has_column($column);
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_column_data"}{$column} or $self->result_source->has_column($column) 2 10751 10753
Condition100%3/3
exists $self->{"_column_data"}{$column} or $self->result_source->has_column($column)
l!l&&r!l&&!r
347104042
MC/DC100%2/2
exists $self->{"_column_data"}{$column} or $self->result_source->has_column($column)
exists $self->{"_column_data"}{$column} $self->result_source->has_column($column)
Truth table100%3/3
A or B
A= exists $self->{"_column_data"}{$column}B= $self->result_source->has_column($column)
ABresult
1X1
011
000
1506 10751 ▶ $self->throw_exception( "set_column called for ${column} without value" )
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 10751 10751
1507 if @_ < 3;
1508 # a raw value, or the value a deflate / filter / encode handed on
1509 10751 assert_column_value($column, $value);
1510 10740 return $self->{_column_data}{$column} = $value;
1511 }
1512  
1513  
1514 730 ▶sub inflate_result {
Subroutine inflate_result: called CC=15 SCAR=30.3
Pod documented
1515 730 my ($class, $rsrc, $me, $prefetch) = @_;
1516  
1517 730 ▶ my $new = bless
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
07300
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
1518 { _column_data => $me, _result_source => $rsrc },
1519 ref $class || $class
1520 ;
1521  
1522 730 ▶ if ($prefetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefetch) 18 712 730
1523 18 for my $rel_name ( keys %$prefetch ) {
1524  
1525 18 ▶ my $relinfo = $rsrc->relationship_info($rel_name) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $relinfo = $rsrc->relationship_info($rel_name) or do { my $err = sprintf("Inflation into non-existent relationship '%s' of '%s' requested", $rel_name, $rsrc->source_name); if (my($colname) = (sort {length $a <=> length $b;} keys %{$prefetch->{$rel_name}[0] or {};})) { $err .= sprintf(q[, check the inflation specification (columns/as) ending in '...%s.%s'], $rel_name, $colname); } ; $rsrc->throw_exception($err) } 18 0 18
1526 0 my $err = sprintf
1527 "Inflation into non-existent relationship '%s' of '%s' requested",
1528 $rel_name,
1529 $rsrc->source_name,
1530 ;
1531 0 ▶ if (my ($colname) = sort { length($a) <=> length ($b) } keys %{$prefetch->{$rel_name}[0] || {}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($colname) = (sort {length $a <=> length $b;} keys %{$prefetch->{$rel_name}[0] or {};})) 0 0 0
Condition0%0/2
$prefetch->{$rel_name}[0] || {}
l!l
00
MC/DC0%0/1
$prefetch->{$rel_name}[0] || {}
$prefetch->{$rel_name}[0]
Truth table0%0/2
A
A= $prefetch->{$rel_name}[0]
Aresult
11
00
1532 0 $err .= sprintf ", check the inflation specification (columns/as) ending in '...%s.%s'",
1533 $rel_name,
1534 $colname,
1535 }
1536  
1537 0 $rsrc->throw_exception($err);
1538 };
1539  
1540 $class->throw_exception("No accessor type declared for prefetched relationship '$rel_name'")
1541 18 ▶ unless $relinfo->{attrs}{accessor};
Branch: 1 branch
BranchTrueFalseTotal
unless $relinfo->{"attrs"}{"accessor"} 0 18 18
1542  
1543 18 my $rel_rs = $new->related_resultset($rel_name);
1544  
1545 18 my @rel_objects;
1546 18 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (@{$prefetch->{$rel_name} or [];} and ref $prefetch->{$rel_name} ne $DBIO::ResultSource::RowParser::Util::null_branch_class) 15 3 18
Condition66%2/3
@{$prefetch->{$rel_name} or [];} and ref $prefetch->{$rel_name} ne $DBIO::ResultSource::RowParser::Util::null_branch_class
!ll&&!rl&&r
3015
MC/DC50%1/2
@{$prefetch->{$rel_name} or [];} and ref $prefetch->{$rel_name} ne $DBIO::ResultSource::RowParser::Util::null_branch_class
@{$prefetch->{$rel_name} or [];} ref $prefetch->{$rel_name} ne $DBIO::ResultSource::RowParser::Util::null_branch_class
Truth table66%2/3
A and B
A= @{$prefetch->{$rel_name} or [];}B= ref $prefetch->{$rel_name} ne $DBIO::ResultSource::RowParser::Util::null_branch_class
ABresult
0X0
100
111
1547 18 ▶ @{ $prefetch->{$rel_name} || [] }
Condition100%2/2
$prefetch->{$rel_name} || []
l!l
153
MC/DC100%1/1
$prefetch->{$rel_name} || []
$prefetch->{$rel_name}
Truth table100%2/2
A
A= $prefetch->{$rel_name}
Aresult
11
00
1548 and
1549 ref($prefetch->{$rel_name}) ne $DBIO::ResultSource::RowParser::Util::null_branch_class
1550 ) {
1551  
1552 15 ▶ if (ref $prefetch->{$rel_name}[0] eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $prefetch->{$rel_name}[0] eq 'ARRAY') { } 15 0 15
1553 15 my $rel_rsrc = $rel_rs->result_source;
1554 15 my $rel_class = $rel_rs->result_class;
1555 15 my $rel_inflator = $rel_class->can('inflate_result');
1556 @rel_objects = map
1557 21 { $rel_class->$rel_inflator ( $rel_rsrc, @$_ ) }
1558 15 @{$prefetch->{$rel_name}}
1559 ;
1560 }
1561 else {
1562 @rel_objects = $rel_rs->result_class->inflate_result(
1563 0 $rel_rs->result_source, @{$prefetch->{$rel_name}}
1564 );
1565 }
1566 }
1567  
1568 18 ▶ if ($relinfo->{attrs}{accessor} eq 'single') {
Branch: 2 branches
BranchTrueFalseTotal
if ($relinfo->{'attrs'}{'accessor'} eq 'single') { } 1 17 18
elsif ($relinfo->{'attrs'}{'accessor'} eq 'filter') { } 2 15 17
1569 1 $new->{_relationship_data}{$rel_name} = $rel_objects[0];
1570 }
1571 elsif ($relinfo->{attrs}{accessor} eq 'filter') {
1572 2 $new->{_inflated_column}{$rel_name} = $rel_objects[0];
1573 }
1574  
1575 18 $rel_rs->set_cache(\@rel_objects);
1576 }
1577 }
1578  
1579 730 $new->in_storage (1);
1580  
1581 # StorageValues (integrated helper): snapshot freshly-inflated values.
1582 730 ▶ $new->store_storage_values if @{$new->storage_value_columns};
Branch: 1 branch
BranchTrueFalseTotal
if @{$new->storage_value_columns;} 1 729 730
1583  
1584 730 return $new;
1585 }
1586  
1587  
1588 0 ▶sub insert_or_update { shift->update_or_insert(@_) }
Subroutine insert_or_update: not called CC=1 SCAR=6.9
Pod documented
1589  
1590 4 ▶sub update_or_insert {
Subroutine update_or_insert: called CC=2 SCAR=6.9
Pod documented
1591 4 my $self = shift;
1592 4 ▶ return ($self->in_storage ? $self->update : $self->insert);
Branch: 1 branch
BranchTrueFalseTotal
$self->in_storage ? : 1 3 4
1593 }
1594  
1595  
1596 1 ▶sub insert_or_update_async { shift->update_or_insert_async(@_) }
Subroutine insert_or_update_async: called CC=1 SCAR=0.0
Pod documented
1597  
1598  
1599 9 ▶sub update_or_insert_async {
Subroutine update_or_insert_async: called CC=2 SCAR=6.9
Pod documented
1600 9 my $self = shift;
1601 9 ▶ return ($self->in_storage ? $self->update_async : $self->insert_async);
Branch: 1 branch
BranchTrueFalseTotal
$self->in_storage ? : 5 4 9
1602 }
1603  
1604  
1605 9 ▶sub is_changed {
Subroutine is_changed: called CC=2 SCAR=6.9
Pod documented
1606 9 ▶ return keys %{shift->{_dirty_columns} || {}};
Condition100%2/2
+(shift())->{'_dirty_columns'} || {}
l!l
72
MC/DC100%1/1
+(shift())->{'_dirty_columns'} || {}
+(shift())->{'_dirty_columns'}
Truth table100%2/2
A
A= +(shift())->{'_dirty_columns'}
Aresult
11
00
1607 }
1608  
1609  
1610 19 ▶sub is_column_changed {
Subroutine is_column_changed: called CC=1 SCAR=0.0
Pod documented
1611 19 my( $self, $col ) = @_;
1612 19 return exists $self->{_dirty_columns}->{$col};
1613 }
1614  
1615  
1616 40564 ▶sub result_source {
Subroutine result_source: called CC=5 SCAR=21.9
Pod documented
1617 40564 ▶ $_[0]->throw_exception( 'result_source can be called on instances only' )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 0 40564 40564
1618 unless ref $_[0];
1619  
1620 @_ > 1
1621 ? $_[0]->{_result_source} = $_[1]
1622  
1623 # note this is a || not a ||=, the difference is important
1624 40564 ▶ : $_[0]->{_result_source} || do {
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 3621 36943 40564
Condition33%1/3
$_[0]{"_result_source"} or do { my $class = ref $_[0]; $_[0]->can("result_source_instance") ? $_[0]->result_source_instance : $_[0]->throw_exception("No result source instance registered for $class, did you forget to call $class->table(...) ?") }
l!l&&r!l&&!r
3694300
MC/DC0%0/2
$_[0]{"_result_source"} or do { my $class = ref $_[0]; $_[0]->can("result_source_instance") ? $_[0]->result_source_instance : $_[0]->throw_exception("No result source instance registered for $class, did you forget to call $class->table(...) ?") }
$_[0]{"_result_source"} do { my $class = ref $_[0]; $_[0]->can("result_source_instance") ? $_[0]->result_source_instance : $_[0]->throw_exception("No result source instance registered for $class, did you forget to call $class->table(...) ?") }
Truth table33%1/3
A or B
A= $_[0]{"_result_source"}B= do { my $class = ref $_[0]; $_[0]->can("result_source_instance") ? $_[0]->result_source_instance : $_[0]->throw_exception("No result source instance registered for $class, did you forget to call $class->table(...) ?") }
ABresult
1X1
011
000
1625 0 my $class = ref $_[0];
1626 0 ▶ $_[0]->can('result_source_instance')
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->can('result_source_instance') ? : 0 0 0
1627 ? $_[0]->result_source_instance
1628 : $_[0]->throw_exception(
1629 "No result source instance registered for $class, did you forget to call $class->table(...) ?"
1630 )
1631 }
1632 ;
1633 }
1634  
1635  
1636 37230 ▶sub register_column {
Subroutine register_column: called CC=3 SCAR=11.0
Pod documented
1637 37230 my ($class, $col, $info) = @_;
1638 37230 my $acc = $col;
1639 37230 ▶ if (exists $info->{accessor}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{"accessor"}) 779 36451 37230
1640 779 ▶ return unless defined $info->{accessor};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $info->{"accessor"} 256 523 779
1641 523 $acc = [ $info->{accessor}, $col ];
1642 }
1643 36974 $class->mk_group_accessors('column' => $acc);
1644 }
1645  
1646  
1647 33 ▶sub get_from_storage {
Subroutine get_from_storage: called CC=8 SCAR=20.8
Pod documented
1648 33 my $self = shift @_;
1649 33 my $attrs = shift @_;
1650 33 my $resultset = $self->result_source->resultset;
1651  
1652 33 ▶ if(defined $attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attrs) 23 10 33
1653 23 $resultset = $resultset->search(undef, $attrs);
1654 }
1655  
1656 # ADR 0045 / karr k325: the lookup itself is synchronous and never reads
1657 # the pin, but the row it returns is derived from this one and keeps it --
1658 # and so does this row when discard_changes refreshes it from that copy.
1659 $resultset->{_async_context} = $self->{_async_context}
1660 33 ▶ if $self->{_async_context};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_async_context"} 4 29 33
1661  
1662 33 ▶ if ($self->result_source->primary_columns) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->result_source->primary_columns) 27 6 33
1663 27 return $resultset->find($self->_storage_ident_condition, { key => 'primary' });
1664 }
1665  
1666 # No primary key defined — fall back to heuristics mode using all loaded
1667 # column values so find() can match against any available unique constraint.
1668 # Values follow the same precedence as DBIO::PK/_ident_values does for the
1669 # PK path: the last known in-storage value wins over a dirty in-memory one,
1670 # so we look the row up as it currently is in the database.
1671 6 my %cond;
1672 6 for my $col ($self->result_source->columns) {
1673 18 ▶ next unless $self->has_column_loaded($col);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_column_loaded($col) 2 16 18
1674 $cond{$col} = exists $self->{_column_data_in_storage}{$col}
1675 16 ▶ ? $self->{_column_data_in_storage}{$col}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'_column_data_in_storage'}{$col} ? : 14 2 16
1676 : $self->get_column($col)
1677 ;
1678 }
1679  
1680 # all loaded columns describe the row; a unique constraint among them
1681 # makes that a find, otherwise it is a plain search for that row
1682 6 ▶ return $resultset->find(\%cond)
Branch: 1 branch
BranchTrueFalseTotal
if $resultset->_covered_constraints(($resultset->_merge_with_rscond(\%cond))[0]) 5 1 6
1683 if $resultset->_covered_constraints(($resultset->_merge_with_rscond(\%cond))[0]);
1684  
1685 1 return $resultset->search(
1686 $resultset->_qualify_cond_columns(\%cond, $resultset->current_source_alias)
1687 )->single;
1688 }
1689  
1690  
1691 21 ▶sub get_from_storage_async {
Subroutine get_from_storage_async: called CC=8 SCAR=27.7
Pod documented
1692 21 my $self = shift @_;
1693 21 my $attrs = shift @_;
1694 21 my $resultset = $self->result_source->resultset;
1695  
1696 21 ▶ if(defined $attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attrs) 14 7 21
1697 14 $resultset = $resultset->search(undef, $attrs);
1698 }
1699  
1700 # ADR 0045 / karr k195: a refetch off a context-bound row (directly or via
1701 # discard_changes_async) stays on the pinned connection. find_async's own
1702 # _rs_run_async then dispatches the lookup through the pinned context.
1703 $resultset->{_async_context} = $self->{_async_context}
1704 21 ▶ if $self->{_async_context};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_async_context"} 6 15 21
1705  
1706 21 ▶ if ($self->result_source->primary_columns) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->result_source->primary_columns) 21 0 21
1707 21 return $resultset->find_async($self->_storage_ident_condition, { key => 'primary' });
1708 }
1709  
1710 # No primary key defined — fall back to heuristics mode using all loaded
1711 # column values so find_async() can match against available unique constraints.
1712 # Same value precedence as the sync L</get_from_storage> path: in-storage
1713 # state wins over a dirty in-memory value.
1714 0 my %cond;
1715 0 for my $col ($self->result_source->columns) {
1716 0 ▶ next unless $self->has_column_loaded($col);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_column_loaded($col) 0 0 0
1717 $cond{$col} = exists $self->{_column_data_in_storage}{$col}
1718 0 ▶ ? $self->{_column_data_in_storage}{$col}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'_column_data_in_storage'}{$col} ? : 0 0 0
1719 : $self->get_column($col)
1720 ;
1721 }
1722  
1723 0 ▶ return $resultset->find_async(\%cond)
Branch: 1 branch
BranchTrueFalseTotal
if $resultset->_covered_constraints(($resultset->_merge_with_rscond(\%cond))[0]) 0 0 0
1724 if $resultset->_covered_constraints(($resultset->_merge_with_rscond(\%cond))[0]);
1725  
1726 0 return $resultset->search(
1727 $resultset->_qualify_cond_columns(\%cond, $resultset->current_source_alias)
1728 )->single_async;
1729 }
1730  
1731  
1732 23 ▶sub discard_changes {
Subroutine discard_changes: called CC=4 SCAR=13.9
Pod documented
1733 23 my ($self, $attrs) = @_;
1734 23 ▶ return unless $self->in_storage; # Don't reload if we aren't real!
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in_storage 0 23 23
1735  
1736 # add a replication default to read from the master only
1737 23 ▶ $attrs = { force_pool => 'master', %{$attrs||{}} };
Condition50%1/2
$attrs || {}
l!l
023
MC/DC0%0/1
$attrs || {}
$attrs
Truth table50%1/2
A
A= $attrs
Aresult
11
00
1738  
1739 23 ▶ if( my $current_storage = $self->get_from_storage($attrs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $current_storage = $self->get_from_storage($attrs)) { } 14 8 22
1740  
1741 # Set $self to the current.
1742 14 %$self = %$current_storage;
1743  
1744 # Avoid a possible infinite loop with
1745 # sub DESTROY { $_[0]->discard_changes }
1746 14 bless $current_storage, 'Do::Not::Exist';
1747  
1748 14 return $self;
1749 }
1750 else {
1751 8 $self->in_storage(0);
1752 8 return $self;
1753 }
1754 }
1755  
1756  
1757 21 ▶sub discard_changes_async {
Subroutine discard_changes_async: called CC=1 SCAR=0.0
Pod documented
1758 21 my ($self, $attrs) = @_;
1759  
1760 return $self->_row_run_async('discard_changes',
1761 15 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
1762 15 my ($backend, $fc) = @_;
1763 15 ▶ return $fc->done(undef) unless $self->in_storage; # Don't reload if we aren't real!
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in_storage 1 14 15
1764  
1765 # add a replication default to read from the master only
1766 14 ▶ my $merged_attrs = { force_pool => 'master', %{$attrs||{}} };
Condition50%1/2
$attrs || {}
l!l
014
MC/DC0%0/1
$attrs || {}
$attrs
Truth table50%1/2
A
A= $attrs
Aresult
11
00
1767  
1768 14 ▶ return $self->get_from_storage_async($merged_attrs)->then(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1769 14 my ($current_storage) = @_;
1770  
1771 14 ▶ if ($current_storage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_storage) { } 13 1 14
1772 # Set $self to the current.
1773 13 %$self = %$current_storage;
1774  
1775 # Avoid a possible infinite loop with
1776 # sub DESTROY { $_[0]->discard_changes }
1777 13 bless $current_storage, 'Do::Not::Exist';
1778  
1779 13 return $self;
1780 }
1781 else {
1782 1 $self->in_storage(0);
1783 1 return $self;
1784 }
1785 14 });
1786 },
1787 1 ▶ sub { $self->discard_changes($attrs) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1788 21 );
1789 }
1790  
1791  
1792 97 ▶sub throw_exception {
Subroutine throw_exception: called CC=3 SCAR=11.0
Pod documented
1793 97 my $self=shift;
1794  
1795 97 ▶ if (ref $self && ref (my $rsrc = try { $self->result_source_instance } ) ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and ref(my $rsrc = &try(sub { $self->result_source_instance; } ))) { } 82 15 97
Condition100%3/3
ref $self and ref(my $rsrc = &try(sub { $self->result_source_instance; } ))
!ll&&!rl&&r
14182
MC/DC100%2/2
ref $self and ref(my $rsrc = &try(sub { $self->result_source_instance; } ))
ref $self ref(my $rsrc = &try(sub { $self->result_source_instance; } ))
Truth table100%3/3
A and B
A= ref $selfB= ref(my $rsrc = &try(sub { $self->result_source_instance; } ))
ABresult
0X0
100
111
1796 82 $rsrc->throw_exception(@_)
1797 }
1798 else {
1799 15 DBIO::Exception->throw(@_);
1800 }
1801 }
1802  
1803  
1804 # ============================================================
1805 # Integrated helper methods (from DBIx::Class::Helpers by FREW)
1806 # ============================================================
1807  
1808  
1809 {
1810 378 my $dont_serialize = { text => 1, ntext => 1, blob => 1 };
1811  
1812 0 ▶ sub _is_column_serializable {
Subroutine _is_column_serializable: not called CC=4 SCAR=30.0
1813 0 my ($self, $column) = @_;
1814 0 my $info = $self->column_info($column);
1815 0 ▶ if (!defined $info->{is_serializable}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $info->{"is_serializable"}) 0 0 0
1816 0 ▶ if (defined $info->{data_type} && $dont_serialize->{lc $info->{data_type}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{'data_type'} and $$dont_serialize{lc $info->{'data_type'}}) { } 0 0 0
Condition0%0/3
defined $info->{"data_type"} and $$dont_serialize{lc $info->{"data_type"}}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $info->{"data_type"} and $$dont_serialize{lc $info->{"data_type"}}
defined $info->{"data_type"} $$dont_serialize{lc $info->{"data_type"}}
Truth table0%0/3
A and B
A= defined $info->{"data_type"}B= $$dont_serialize{lc $info->{"data_type"}}
ABresult
0X0
100
111
1817 0 $info->{is_serializable} = 0;
1818 } else {
1819 0 $info->{is_serializable} = 1;
1820 }
1821 }
1822 0 return $info->{is_serializable};
1823 }
1824 }
1825  
1826 378 ▶sub serializable_columns {
Subroutine serializable_columns: not called CC=1 SCAR=3.5
Pod undocumented
1827 0 my $self = shift;
1828 return [
1829 0 grep { $self->_is_column_serializable($_) }
1830 $self->result_source->columns
1831 ];
1832 }
1833  
1834 0 ▶sub TO_JSON {
Subroutine TO_JSON: not called CC=4 SCAR=30.0
Pod documented
1835 0 my $self = shift;
1836 0 my %all_cols = $self->get_columns;
1837 0 my @ser_cols = grep { exists $all_cols{$_} }
1838 0 @{ $self->serializable_columns };
1839  
1840 0 my %data;
1841 0 for my $col (@ser_cols) {
1842 0 my $val = $all_cols{$col};
1843 # numify numeric columns for correct JSON encoding
1844 0 ▶ if (defined $val && $self->_is_column_numeric($col)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $self->_is_column_numeric($col)) 0 0 0
Condition0%0/3
defined $val and $self->_is_column_numeric($col)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $self->_is_column_numeric($col)
defined $val $self->_is_column_numeric($col)
Truth table0%0/3
A and B
A= defined $valB= $self->_is_column_numeric($col)
ABresult
0X0
100
111
1845 0 $val += 0;
1846 }
1847 0 $data{$col} = $val;
1848 }
1849 0 return \%data;
1850 }
1851  
1852  
1853 3 ▶sub self_rs {
Subroutine self_rs: called CC=2 SCAR=6.9
Pod documented
1854 3 my ($self) = @_;
1855 3 my $rs = $self->result_source->resultset;
1856 # ADR 0045 / karr k325: the resultset of a context-bound row keeps the pin
1857 # (the ->search_rs below passes it on to the returned clone).
1858 3 ▶ $rs->{_async_context} = $self->{_async_context} if $self->{_async_context};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_async_context"} 2 1 3
1859 3 return $rs->search_rs($self->ident_condition($rs->current_source_alias));
1860 }
1861  
1862  
1863 # --- clean_rs: get unfiltered ResultSet for this row's source ---
1864 3 ▶sub clean_rs {
Subroutine clean_rs: called CC=2 SCAR=6.9
Pod documented
1865 3 my ($self) = @_;
1866 3 my $rs = $self->result_source->resultset;
1867 # ADR 0045 / karr k325: unfiltered, but still derived from this row -- the
1868 # pin of a context-bound row stays.
1869 3 ▶ $rs->{_async_context} = $self->{_async_context} if $self->{_async_context};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_async_context"} 2 1 3
1870 3 return $rs;
1871 }
1872  
1873 # ------------------------------------------------------------
1874 # StorageValues
1875 # ------------------------------------------------------------
1876  
1877  
1878 378 __PACKAGE__->mk_group_accessors(inherited => '_storage_value_columns');
1879 378 __PACKAGE__->mk_group_accessors(inherited => '_storage_values');
1880  
1881  
1882 17523 ▶sub _has_storage_value { $_[0]->column_info($_[1])->{keep_storage_value} }
Subroutine _has_storage_value: called CC=1 SCAR=0.0
1883  
1884  
1885 4078 ▶sub storage_value_columns {
Subroutine storage_value_columns: called CC=2 SCAR=6.9
Pod documented
1886 4078 my $self = shift;
1887 4078 ▶ if (!$self->_storage_value_columns) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_storage_value_columns) 3970 108 4078
1888 3970 $self->_storage_value_columns([
1889 grep $self->_has_storage_value($_),
1890 $self->result_source->columns
1891 ]);
1892 }
1893 4078 return $self->_storage_value_columns;
1894 }
1895  
1896  
1897 13 ▶sub store_storage_values {
Subroutine store_storage_values: called CC=2 SCAR=7.1
Pod documented
1898 13 my $self = shift;
1899 $self->_storage_values({
1900 map {
1901 15 ▶ my $acc = ($self->column_info($_)->{accessor} || $_);
Condition33%1/3
$self->column_info($_)->{'accessor'} || $_
l!l&&r!l&&!r
0150
MC/DC0%0/2
$self->column_info($_)->{'accessor'} || $_
$self->column_info($_)->{'accessor'} $_
Truth table33%1/3
A || B
A= $self->column_info($_)->{'accessor'}B= $_
ABresult
1X1
011
000
1902 15 $_ => _clone_for_storage($self->$acc)
1903 13 } @{$self->storage_value_columns}
1904 });
1905 13 $self->_storage_values;
1906 }
1907  
1908 # Clone a value for storage snapshot. DateTime objects are cloned so
1909 # later mutations don't corrupt the snapshot. Plain scalars/objects
1910 # without clone are stored as-is (acceptable for numbers, strings,
1911 # and DBIO Row objects which are inherently snapshot-like).
1912 29 ▶sub _clone_for_storage {
Subroutine _clone_for_storage: called CC=4 SCAR=14.0
1913 29 my ($val) = @_;
1914 29 ▶ return $val unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 29 29
1915 29 ▶ if (blessed($val) && $val->can('clone')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($val) and $val->can("clone")) 4 25 29
Condition66%2/3
builtin::blessed($val) and $val->can("clone")
!ll&&!rl&&r
2504
MC/DC50%1/2
builtin::blessed($val) and $val->can("clone")
builtin::blessed($val) $val->can("clone")
Truth table66%2/3
A and B
A= builtin::blessed($val)B= $val->can("clone")
ABresult
0X0
100
111
1916 4 return $val->clone;
1917 }
1918 25 return $val;
1919 }
1920  
1921  
1922 14 ▶sub get_storage_value {
Subroutine get_storage_value: called CC=1 SCAR=0.0
Pod documented
1923 14 my ($self, $col) = @_;
1924 14 return DBIO::Row::_clone_for_storage($self->_storage_values->{$col});
1925 }
1926  
1927 # ------------------------------------------------------------
1928 # OnColumnChange
1929 # ------------------------------------------------------------
1930  
1931  
1932 __PACKAGE__->mk_group_accessors(inherited => $_)
1933 378 for qw(_before_change _around_change _after_change);
1934  
1935 4 ▶sub _register_column_change {
Subroutine _register_column_change: called CC=4 SCAR=13.9
1936 4 my ($self, $slot, $prepend, $column, $args) = @_;
1937 $self->throw_exception('method is a required parameter')
1938 4 ▶ unless $args->{method};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"method"} 0 4 4
1939 4 $args->{column} = $column;
1940 4 $args->{txn_wrap} = !!$args->{txn_wrap};
1941 4 ▶ $self->$slot([]) unless $self->$slot;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->$slot 4 0 4
1942 4 ▶ if ($prepend) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prepend) { } 2 2 4
1943 2 unshift @{$self->$slot}, $args;
1944 } else {
1945 2 push @{$self->$slot}, $args;
1946 }
1947 4 return;
1948 }
1949  
1950  
1951 2 ▶sub before_column_change {
Subroutine before_column_change: called CC=2 SCAR=7.1
Pod documented
1952 2 ▶ $_[0]->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 2 2
1953 'Invalid number of arguments. One $column => $args pair at a time.'
1954 ) unless @_ == 3;
1955 2 my ($self, $column, $args) = @_;
1956 2 $self->_register_column_change('_before_change', 0, $column, $args);
1957 }
1958  
1959  
1960 0 ▶sub around_column_change {
Subroutine around_column_change: not called CC=2 SCAR=17.9
Pod documented
1961 0 ▶ $_[0]->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
1962 'Invalid number of arguments. One $column => $args pair at a time.'
1963 ) unless @_ == 3;
1964 0 my ($self, $column, $args) = @_;
1965 0 $self->_register_column_change('_around_change', 0, $column, $args);
1966 }
1967  
1968  
1969 2 ▶sub after_column_change {
Subroutine after_column_change: called CC=2 SCAR=7.1
Pod documented
1970 2 ▶ $_[0]->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 2 2
1971 'Invalid number of arguments. One $column => $args pair at a time.'
1972 ) unless @_ == 3;
1973 2 my ($self, $column, $args) = @_;
1974 2 $self->_register_column_change('_after_change', 1, $column, $args);
1975 }
1976  
1977  
1978 3 ▶sub on_column_change_allow_override_args { 0 }
Subroutine on_column_change_allow_override_args: called CC=1 SCAR=0.0
Pod documented
1979  
1980 # ------------------------------------------------------------
1981 # ProxyResultSetMethod
1982 # ------------------------------------------------------------
1983  
1984  
1985 378 __PACKAGE__->mk_group_accessors(inherited => '_proxy_slots');
1986  
1987  
1988 1 ▶sub proxy_resultset_method {
Subroutine proxy_resultset_method: called CC=5 SCAR=18.8
Pod documented
1989 1 my ($self, $name, $attr) = @_;
1990 1 ▶ $attr ||= {};
Condition50%1/2
$attr ||= {}
l!l
01
MC/DC0%0/1
$attr ||= {}
$attr
Truth table50%1/2
A
A= $attr
Aresult
11
00
1991  
1992 1 ▶ my $rs_method = $attr->{resultset_method} || "with_$name";
Condition50%1/2
$attr->{'resultset_method'} || "with_$name"
l!l
01
MC/DC0%0/1
$attr->{'resultset_method'} || "with_$name"
$attr->{'resultset_method'}
Truth table50%1/2
A
A= $attr->{'resultset_method'}
Aresult
11
00
1993 1 ▶ my $slot = $attr->{slot} || $name;
Condition33%1/3
$attr->{'slot'} || $name
l!l&&r!l&&!r
010
MC/DC0%0/2
$attr->{'slot'} || $name
$attr->{'slot'} $name
Truth table33%1/3
A || B
A= $attr->{'slot'}B= $name
ABresult
1X1
011
000
1994  
1995 1 ▶ $self->_proxy_slots([]) unless $self->_proxy_slots;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_proxy_slots 1 0 1
1996 1 push @{$self->_proxy_slots}, $slot;
1997  
1998 1 my $fq = $self . '::' . $name;
1999 0 ▶ my $body = sub {
Subroutine __ANON__: not called CC=2 SCAR=12.4
Subroutine score: called CC=2 SCAR=12.4
2000 0 my ($row) = @_;
2001 0 ▶ unless ($row->has_column_loaded($slot)) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($row->has_column_loaded($slot)) 0 0 0
unless ($row->has_column_loaded($slot)) 0 1 1
2002 0 $row->{_column_data}{$slot} = undef;
2003 0 $row->set_column(
2004 $slot,
2005 $row->self_rs
2006 ->search(undef, { columns => [] })
2007 ->$rs_method
2008 ->get_column($slot)
2009 ->next,
2010 );
2011 }
2012 0 return $row->get_column($slot);
2013 1 };
2014  
2015 379 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2016 1 *{$fq} = Sub::Util::set_subname($fq, $body);
2017 1 return;
2018 }
2019  
2020  
2021 378 1;
2022  
2023 __END__
« blib/lib/DBIO/Storage/PoolBase.pm ↑ Summary blib/lib/DBIO/Introspect/DBI.pm »