blib/lib/DBIx/QuickORM/Role/Row.pm

filter: Statementstmt 95.2% 220 / 231 Branchbran 81.8% 108 / 132 Conditioncond 66.6% 66 / 99 MC/DCmcdc 50.0% 29 / 58 Subroutinesub 94.4% 34 / 36 Podpod 100% 22 / 22 totaltotal 82.8% 479 / 578 CC 188 SCAR 19.8
CC
188
Cov
85%
_fetch_missing
16.1
_fetch_missing
16.1
field
14.9
CRAP 7.3
« blib/lib/DBIx/QuickORM/WhereBuilder/RawSQL.pm ↑ Summary blib/lib/DBIx/QuickORM/WhereBuilder/Simple.pm »
1 package DBIx::QuickORM::Role::Row;
2 303 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 303 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 303 our $VERSION = '0.000032';
6  
7 303 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 303 ▶use Hash::Util::FieldHash qw/fieldhash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 303 ▶use DBIx::QuickORM::LookupTable();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 303 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 303 requires qw/orm table row_data set_row_data/;
15  
16 =pod
17  
18 =encoding UTF-8
19  
20 =head1 NAME
21  
22 DBIx::QuickORM::Role::Row - The logic of a row object.
23  
24 =head1 DESCRIPTION
25  
26 A row object wraps one row's data (a hashref, as the ORM's CRUD operations
27 return it) with the ORM and the table it came from. C<raw_field> gives a value
28 as the database returned it. C<inflated_field>, and C<field>, give it
29 inflated through the field's type. A row in the database changes only through
30 C<update>, C<cas_update>, and C<delete>. There are no setters.
31  
32 A row need not be in the database: one built by the ORM's C<vivify>, one
33 deleted, or one whose insert was rolled back. C<is_in_db> and C<was_deleted>
34 tell. Such a row is changed with C<modify> and written with C<insert>.
35 C<update>, C<cas_update>, C<delete>, and C<refresh> croak on it.
36  
37 Inflated values are cached per field, except for types that inflate on each
38 read. When the row data is replaced (by
39 C<update>, C<refresh>, a field fetch that finds the row changed, or any call
40 of C<set_row_data>), cached values of fields whose raw value is unchanged are
41 kept and the rest are dropped.
42  
43 A read hands out the cached value itself, a fresh inflation, or a copy of the
44 cached value, as the type says (see
45 L<DBIx::QuickORM::Role::Type/"Cached inflated values">), so changing a value
46 read from a row never changes the row or the next read.
47  
48 A field missing from the row data was not fetched: it was omitted, or the row
49 came back from a write without C<RETURNING>. Reading it, in either form,
50 fetches every field asked for with one C<refresh_row>. When that shows the
51 row changed, the row takes the new row data, as C<refresh> would. Reading an
52 omitted field from each row in a loop can run one query per row.
53  
54 A row that is not canon (from a C<no_cache> handle, say) fetches its missing
55 fields without the row cache: they are added to its own row data, nothing the
56 ORM holds changes, and the row stays not canon.
57  
58 A row with no table (a row of a query, or a computed row given a row class)
59 returns the row data's values as they are from every field reader: no field
60 check, no inflation, and no fetch.
61  
62 C<update>, C<cas_update>, and C<refresh> call the ORM's CRUD operations and
63 take the row data they return. C<delete> calls C<delete_row>. Options mean
64 what L<DBIx::QuickORM/"CRUD operations"> says.
65  
66 Any class providing the required methods can consume the role. It keeps
67 nothing in the object. L<DBIx::QuickORM::Row> is the default row class.
68  
69 =head2 Overriding
70  
71 A row class changes what C<field> and C<fields> return by overriding them
72 (say, to give the raw form). It changes the cache policy by overriding
73 C<_inflation_cache> and C<_inflated_value>, the two supported override points.
74 Nothing else about the cache is.
75  
76 =head1 SYNOPSIS
77  
78 package My::Row;
79 use Object::HashBase qw{<orm <table row_data};
80 use Role::Tiny::With qw/with/;
81 with 'DBIx::QuickORM::Role::Row';
82  
83 # Raw values by default, but inflated_field and inflated_fields still inflate.
84 sub field { my $self = shift; $self->raw_field(@_) }
85 sub fields { my $self = shift; $self->raw_fields(@_) }
86  
87 package main;
88  
89 my $orm = DBIx::QuickORM->new(
90 credentials => \%credentials,
91 row_class => 'My::Row',
92 );
93  
94 my $ann = $orm->insert(
95 users => {
96 name => 'Ann',
97 prefs => {theme => 'dark'},
98 },
99 );
100  
101 my $raw = $ann->field('prefs'); # the JSON text
102 my $all = $ann->inflated_field('prefs'); # {theme => 'dark'}
103  
104 =head1 REQUIRED METHODS
105  
106 =over 4
107  
108 =item $orm = $row->orm
109  
110 The L<DBIx::QuickORM> the row came from.
111  
112 =item $table = $row->table
113  
114 The name of the row's table, or undef for a row with no table.
115  
116 =item \%data = $row->row_data
117  
118 The row data the row wraps.
119  
120 =item $row->set_row_data(\%data)
121  
122 Replaces the row data. The role calls it whenever the ORM returns new row
123 data for the row.
124  
125 =back
126  
127 =cut
128  
129 # Inside-out, keyed by row object: {data => the row data the values came from, values => {field => inflated}}.
130 303 fieldhash my %CACHE;
131  
132 =head1 PUBLIC METHODS
133  
134 =over 4
135  
136 =item $value = $row->field($name)
137  
138 =item @values = $row->fields(\@names)
139  
140 =item @values = $row->fields(@names)
141  
142 The inflated form: C<inflated_field> and C<inflated_fields>. Override these
143 to give a row class another default form.
144  
145 A row whose class keeps this role's C<inflated_field> and C<_inflated_value>
146 reads a field it holds without going through C<inflated_field>, which is
147 faster. The value is the same. The class is checked on its first read, as
148 C<fast_bless> is, so methods replaced at run time after that are not seen.
149  
150 =back
151  
152 =cut
153  
154 # Classes whose field() may skip inflated_field: they keep the role's inflated_field and _inflated_value.
155 303 my %DIRECT;
156  
157 33 ▶sub _direct_field {
Subroutine _direct_field: called CC=5 SCAR=23.0
158 0 ▶ my $class = ref($_[0]) || $_[0];
Subroutine _direct_field: not called CC=5 SCAR=23.0
Condition33%2/6
ref $_[0] || $_[0]
l!l&&r!l&&!r
2940
ref $_[0] || $_[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
159 0 ▶ return $DIRECT{$class} //= ($class->can('inflated_field') == \&inflated_field && $class->can('_inflated_value') == \&_inflated_value) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$class->can('inflated_field') == \&DBIx::QuickORM::Role::Row::inflated_field && $class->can('_inflated_value') == \&DBIx::QuickORM::Role::Row::_inflated_value ? : 29 4 33
$class->can('inflated_field') == \&DBIx::QuickORM::Role::Row::inflated_field && $class->can('_inflated_value') == \&DBIx::QuickORM::Role::Row::_inflated_value ? : 0 0 0
Condition40%4/10
$DIRECT{$class} //= $class->can("inflated_field") == \&DBIx::QuickORM::Role::Row::inflated_field && $class->can("_inflated_value") == \&DBIx::QuickORM::Role::Row::_inflated_value ? 1 : 0
l!l
033
$class->can("inflated_field") == \&DBIx::QuickORM::Role::Row::inflated_field and $class->can("_inflated_value") == \&DBIx::QuickORM::Role::Row::_inflated_value
!ll&&!rl&&r
2229
$DIRECT{$class} //= $class->can("inflated_field") == \&DBIx::QuickORM::Role::Row::inflated_field && $class->can("_inflated_value") == \&DBIx::QuickORM::Role::Row::_inflated_value ? 1 : 0
l!l
00
$class->can("inflated_field") == \&DBIx::QuickORM::Role::Row::inflated_field and $class->can("_inflated_value") == \&DBIx::QuickORM::Role::Row::_inflated_value
!ll&&!rl&&r
000
MC/DC0%0/1
$DIRECT{$class} //= $class->can("inflated_field") == \&DBIx::QuickORM::Role::Row::inflated_field && $class->can("_inflated_value") == \&DBIx::QuickORM::Role::Row::_inflated_value ? 1 : 0
$DIRECT{$class}
MC/DC0%0/1
$DIRECT{$class} //= $class->can("inflated_field") == \&DBIx::QuickORM::Role::Row::inflated_field && $class->can("_inflated_value") == \&DBIx::QuickORM::Role::Row::_inflated_value ? 1 : 0
$DIRECT{$class}
Truth table50%1/2
A
A= $DIRECT{$class}
Aresult
11
00
Truth table0%0/2
A
A= $DIRECT{$class}
Aresult
11
00
160 }
161  
162 # A present field is read from the row data, through _inflated_value only when typed. Anything else (no table, an
163 # unknown or missing field) goes through inflated_field.
164 275 ▶sub field {
Subroutine field: called CC=7 SCAR=27.0
Pod documented
165 0 ▶ my $self = shift;
Subroutine field: not called CC=7 SCAR=27.0
Pod documented
166 0 ▶ return $self->inflated_field(@_) unless $DIRECT{ref $self} // $self->_direct_field;
Branch: 2 branches
BranchTrueFalseTotal
unless $DIRECT{ref $self} // $self->_direct_field 4 271 275
unless $DIRECT{ref $self} // $self->_direct_field 0 0 0
Condition33%2/6
$DIRECT{ref $self} // $self->_direct_field
l!l&&r!l&&!r
246290
$DIRECT{ref $self} // $self->_direct_field
l!l&&r!l&&!r
000
MC/DC0%0/2
$DIRECT{ref $self} // $self->_direct_field
$DIRECT{ref $self} $self->_direct_field
MC/DC0%0/2
$DIRECT{ref $self} // $self->_direct_field
$DIRECT{ref $self} $self->_direct_field
Truth table66%2/3
A // B
A= $DIRECT{ref $self}B= $self->_direct_field
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $DIRECT{ref $self}B= $self->_direct_field
ABresult
1X1
011
000
167  
168 0 my ($name) = @_;
169 0 my $table = $self->table;
170 0 my $data = $self->row_data;
171 0 ▶ return $self->inflated_field($name) unless defined $table && exists $data->{$name};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $table and exists $data->{$name} 21 250 271
unless defined $table and exists $data->{$name} 0 0 0
Condition50%3/6
defined $table and exists $data->{$name}
!ll&&!rl&&r
516250
defined $table and exists $data->{$name}
!ll&&!rl&&r
000
MC/DC100%2/2
defined $table and exists $data->{$name}
defined $table exists $data->{$name}
MC/DC0%0/2
defined $table and exists $data->{$name}
defined $table exists $data->{$name}
Truth table100%3/3
A and B
A= defined $tableB= exists $data->{$name}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $tableB= exists $data->{$name}
ABresult
0X0
100
111
172 0 ▶ my $field = $self->orm->_table_fields($table)->{$name} or return $self->inflated_field($name);
Branch: 2 branches
BranchTrueFalseTotal
my $field = $self->orm->_table_fields($table)->{$name} or return $self->inflated_field($name) 250 0 250
my $field = $self->orm->_table_fields($table)->{$name} or return $self->inflated_field($name) 0 0 0
173  
174 0 ▶ return $data->{$name} unless $field->{orm_type};
Branch: 2 branches
BranchTrueFalseTotal
unless $field->{"orm_type"} 194 56 250
unless $field->{"orm_type"} 0 0 0
175 0 return $self->_inflated_value($name, $field);
176 }
177  
178 10 ▶sub fields { my $self = shift; $self->inflated_fields(@_) }
Subroutine fields: called CC=1 SCAR=0.0
Pod documented
179  
180 =pod
181  
182 =over 4
183  
184 =item $value = $row->inflated_field($name)
185  
186 =item @values = $row->inflated_fields(\@names)
187  
188 =item @values = $row->inflated_fields(@names)
189  
190 Values inflated through each field's type: the cached value, a fresh
191 inflation, or a copy of the cached value, as the type says (see
192 L</DESCRIPTION>). The raw value for an untyped field,
193 undef for NULL, and undef for an undef inflated value (a JSON C<null>).
194 Missing fields are fetched with one C<refresh_row> (one C<no_cache> read for a
195 row that is not canon). A row built by C<vivify>
196 returns undef for a field it was not given. So does a row whose insert
197 was rolled back.
198  
199 Croaks for a field the table does not have, and for a missing field that
200 cannot be fetched (no primary key, or the row is deleted or no longer in the
201 database).
202  
203 =back
204  
205 =cut
206  
207 # One field-record lookup. It calls _fetch_missing (which croaks for an unknown field) only when a field is unknown or missing.
208 38 ▶sub inflated_field {
Subroutine inflated_field: called CC=4 SCAR=13.9
Pod documented
209 38 my $self = shift;
210 38 my ($name) = @_;
211  
212 38 my $table = $self->table;
213 38 ▶ return $self->row_data->{$name} unless defined $table;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table 5 33 38
214  
215 33 my $field = $self->orm->_table_fields($table)->{$name};
216 33 ▶ $self->_fetch_missing($name) unless $field && exists $self->row_data->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $field and exists $self->row_data->{$name} 19 14 33
Condition100%3/3
$field and exists $self->row_data->{$name}
!ll&&!rl&&r
31614
MC/DC100%2/2
$field and exists $self->row_data->{$name}
$field exists $self->row_data->{$name}
Truth table100%3/3
A and B
A= $fieldB= exists $self->row_data->{$name}
ABresult
0X0
100
111
217 27 return $self->_inflated_value($name, $field);
218 }
219  
220 13 ▶sub inflated_fields {
Subroutine inflated_fields: called CC=5 SCAR=16.1
Pod documented
221 13 my $self = shift;
222 13 ▶ my @names = ref($_[0]) eq 'ARRAY' ? @{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 2 11 13
223  
224 13 my $table = $self->table;
225 13 ▶ return @{$self->row_data}{@names} unless defined $table;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table 2 11 13
226  
227 11 my $fields = $self->orm->_table_fields($table);
228 11 my $data = $self->row_data;
229 11 ▶ $self->_fetch_missing(@names) if grep { !$fields->{$_} || !exists $data->{$_} } @names;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $fields->{$_} && exists $data->{$_};} @names 4 7 11
Condition100%3/3
$fields->{$_} && exists $data->{$_}
!ll&&!rl&&r
1616
MC/DC100%2/2
$fields->{$_} && exists $data->{$_}
$fields->{$_} exists $data->{$_}
Truth table100%3/3
A && B
A= $fields->{$_}B= exists $data->{$_}
ABresult
0X0
100
111
230 10 return map { $self->_inflated_value($_, $fields->{$_}) } @names;
231 }
232  
233 =pod
234  
235 =over 4
236  
237 =item $raw = $row->raw_field($name)
238  
239 =item @raw = $row->raw_fields(\@names)
240  
241 =item @raw = $row->raw_fields(@names)
242  
243 Values as the database returned them, never inflated. Missing fields are
244 fetched and unknown ones croak, as for C<inflated_fields>.
245  
246 =back
247  
248 =cut
249  
250 18 ▶sub raw_field {
Subroutine raw_field: called CC=1 SCAR=0.0
Pod documented
251 18 my $self = shift;
252 18 my ($name) = @_;
253 18 return ($self->raw_fields($name))[0];
254 }
255  
256 # Like inflated_fields, it calls _fetch_missing (which croaks for an unknown field) only when a field is unknown or missing.
257 20 ▶sub raw_fields {
Subroutine raw_fields: called CC=5 SCAR=16.1
Pod documented
258 20 my $self = shift;
259 20 ▶ my @names = ref($_[0]) eq 'ARRAY' ? @{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 1 19 20
260  
261 20 my $table = $self->table;
262 20 ▶ if (defined $table) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $table) 19 1 20
263 19 my $fields = $self->orm->_table_fields($table);
264 19 my $data = $self->row_data;
265 19 ▶ $self->_fetch_missing(@names) if grep { !$fields->{$_} || !exists $data->{$_} } @names;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $fields->{$_} && exists $data->{$_};} @names 6 13 19
Condition100%3/3
$fields->{$_} && exists $data->{$_}
!ll&&!rl&&r
2617
MC/DC100%2/2
$fields->{$_} && exists $data->{$_}
$fields->{$_} exists $data->{$_}
Truth table100%3/3
A && B
A= $fields->{$_}B= exists $data->{$_}
ABresult
0X0
100
111
266 }
267 18 return @{$self->row_data}{@names};
268 }
269  
270 =pod
271  
272 =over 4
273  
274 =item \%pk = $row->pk
275  
276 The primary key fields and their values from the row data. Undef when the row
277 has no table or the table has no primary key.
278  
279 =back
280  
281 =cut
282  
283 199 ▶sub pk {
Subroutine pk: called CC=3 SCAR=11.0
Pod documented
284 199 my $self = shift;
285 199 ▶ my $table = $self->table // return undef;
Condition100%2/2
$self->table // (return undef)
l!l
18613
MC/DC100%1/1
$self->table // (return undef)
$self->table
Truth table100%2/2
A
A= $self->table
Aresult
11
00
286 186 ▶ my $pk = $self->orm->db_map->pk($table) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $pk = $self->orm->db_map->pk($table) or return undef 177 9 186
287 177 my $data = $self->row_data;
288 177 return {map { $_ => $data->{$_} } @$pk};
289 }
290  
291 =pod
292  
293 =over 4
294  
295 =item $row = $row->update(\%changes, %update_row_options)
296  
297 Writes the changes with C<update_row> and takes the new row data. Returns the
298 row, or undef when no row matched (a compare-and-swap failed, or the row is
299 gone), leaving the row as it was.
300  
301 Each change is deflated through its field's type. The options are those of
302 C<update_row>: C<enforce_canon>, C<cas>, C<auto_cas>. A row that is not
303 canonical croaks under C<enforce_canon>. C<cas_update> writes one safely.
304  
305 Croaks when the changes are not a hashref, when given C<data> (it always
306 returns the row), when the row is not in the database, or when it has no
307 usable primary key.
308  
309 =back
310  
311 =cut
312  
313 52 ▶sub update {
Subroutine update: called CC=7 SCAR=19.5
Pod documented
314 52 my $self = shift;
315 52 my ($changes, %params) = @_;
316 52 ▶ croak "update() needs a hashref of changes" unless ref($changes) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $changes eq "HASH" 1 51 52
317 51 ▶ croak "update() always returns the row; use the ORM's update_row() for row data" if exists $params{data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"data"} 1 50 51
318 50 ▶ croak "update() always returns the row itself, so it takes no row_class" if exists $params{row_class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"row_class"} 1 49 50
319  
320 49 $self->_require_in_db('update');
321 47 my $table = $self->_require_pk('update');
322 43 my $orm = $self->orm;
323 43 ▶ my $lookup = $orm->debug && $orm->connection->lookup;
Condition66%2/3
$orm->debug && $orm->connection->lookup
!ll&&!rl&&r
3607
MC/DC50%1/2
$orm->debug && $orm->connection->lookup
$orm->debug $orm->connection->lookup
Truth table66%2/3
A && B
A= $orm->debugB= $orm->connection->lookup
ABresult
0X0
100
111
324 43 ▶ local $lookup->{caller} = [(caller(0))[0 .. 3]] if $lookup && !$lookup->{caller};
Branch: 1 branch
BranchTrueFalseTotal
if $lookup and not $lookup->{"caller"} 6 37 43
Condition100%3/3
$lookup and not $lookup->{"caller"}
!ll&&!rl&&r
3616
MC/DC100%2/2
$lookup and not $lookup->{"caller"}
$lookup not $lookup->{"caller"}
Truth table100%3/3
A and not(B)
A= $lookupB= not $lookup->{"caller"}
ABresult
0X0
100
111
325 43 return $orm->update_row($table, $self, $orm->connection->deflate($table, $changes), %params, raw => 1);
326 }
327  
328 =pod
329  
330 =over 4
331  
332 =item $row = $row->cas_update(\%changes)
333  
334 =item $row = $row->cas_update(\%changes, cas => \@fields)
335  
336 Writes the changes only if the database still holds the row's values for the
337 changed fields (or the C<cas> fields). Returns the row with the new data, or
338 undef on a conflict, leaving the row as it was.
339  
340 The row need not be canonical, even inside a transaction, so this is how
341 to write a row read before the transaction began. The changes are deflated as
342 C<update> deflates them.
343  
344 It compares the changed fields with C<=>, which does not suit floats,
345 PostgreSQL C<json>, or MySQL C<JSON>: pass C<cas> to compare other fields. On
346 MySQL and MariaDB a successful update leaves only the primary key in the row
347 data, so another C<cas_update> croaks until the row is refreshed (or the
348 compared fields are read again).
349  
350 Croaks when the changes are not a hashref of at least one change, on any
351 option but C<cas>, on an empty C<cas> list (an unconditional write), when the
352 row is not in the database, when it has no usable primary key, or when it does
353 not hold a field it compares.
354  
355 It calls the ORM's C<cas_update> (L<DBIx::QuickORM/"CRUD operations">), which
356 does the same for row data, a C<bare> hashref included.
357  
358 A field left out of the row's select (C<omit>, C<default_fields>, or
359 C<auto_omit>) must be read first (C<< $row->field($name) >>), or selected
360 with C<fields>, before C<cas_update> compares it.
361  
362 =back
363  
364 =cut
365  
366 17 ▶sub cas_update {
Subroutine cas_update: called CC=7 SCAR=19.9
Pod documented
367 17 my $self = shift;
368 17 my ($changes, @args) = @_;
369 17 ▶ croak "cas_update() needs a hashref of changes" unless ref($changes) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $changes eq "HASH" 1 16 17
370 16 ▶ croak "Odd number of options to cas_update()" if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 1 15 16
371 15 my %params = @args;
372 15 ▶ croak "cas_update() takes only the 'cas' option" if grep { $_ ne 'cas' } keys %params;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ ne "cas";} keys %params 1 14 15
373  
374 14 $self->_require_in_db('cas_update');
375 13 my $table = $self->_require_pk('cas_update');
376 12 my $orm = $self->orm;
377 12 ▶ my $lookup = $orm->debug && $orm->connection->lookup;
Condition33%1/3
$orm->debug && $orm->connection->lookup
!ll&&!rl&&r
1200
MC/DC0%0/2
$orm->debug && $orm->connection->lookup
$orm->debug $orm->connection->lookup
Truth table33%1/3
A && B
A= $orm->debugB= $orm->connection->lookup
ABresult
0X0
100
111
378 12 ▶ local $lookup->{caller} = [(caller(0))[0 .. 3]] if $lookup && !$lookup->{caller};
Branch: 1 branch
BranchTrueFalseTotal
if $lookup and not $lookup->{"caller"} 0 12 12
Condition33%1/3
$lookup and not $lookup->{"caller"}
!ll&&!rl&&r
1200
MC/DC0%0/2
$lookup and not $lookup->{"caller"}
$lookup not $lookup->{"caller"}
Truth table33%1/3
A and not(B)
A= $lookupB= not $lookup->{"caller"}
ABresult
0X0
100
111
379 12 return $orm->cas_update($table, $self, $changes, %params);
380 }
381  
382 =pod
383  
384 =over 4
385  
386 =item $count = $row->delete(%delete_row_options)
387  
388 Deletes the row with C<delete_row> and returns how many rows went. The row,
389 and every row holding the same row data, is then marked deleted.
390  
391 A delete that matches no row also marks it deleted (it is not in the
392 database) and returns 0.
393  
394 Croaks when the row is not in the database or has no usable primary key.
395  
396 =back
397  
398 =cut
399  
400 27 ▶sub delete {
Subroutine delete: called CC=4 SCAR=14.0
Pod documented
401 27 my $self = shift;
402 27 my (%params) = @_;
403 27 $self->_require_in_db('delete');
404 26 my $table = $self->_require_pk('delete');
405 22 ▶ my $lookup = $self->orm->debug && $self->orm->connection->lookup;
Condition66%2/3
$self->orm->debug && $self->orm->connection->lookup
!ll&&!rl&&r
2101
MC/DC50%1/2
$self->orm->debug && $self->orm->connection->lookup
$self->orm->debug $self->orm->connection->lookup
Truth table66%2/3
A && B
A= $self->orm->debugB= $self->orm->connection->lookup
ABresult
0X0
100
111
406 22 ▶ local $lookup->{caller} = [(caller(0))[0 .. 3]] if $lookup && !$lookup->{caller};
Branch: 1 branch
BranchTrueFalseTotal
if $lookup and not $lookup->{"caller"} 1 21 22
Condition66%2/3
$lookup and not $lookup->{"caller"}
!ll&&!rl&&r
2101
MC/DC50%1/2
$lookup and not $lookup->{"caller"}
$lookup not $lookup->{"caller"}
Truth table66%2/3
A and not(B)
A= $lookupB= not $lookup->{"caller"}
ABresult
0X0
100
111
407 22 return $self->orm->connection->delete_row($table, $self->row_data, %params, raw => 1);
408 }
409  
410 =pod
411  
412 =over 4
413  
414 =item $row = $row->refresh
415  
416 Reads the row from the database and takes the new row data. Takes no
417 arguments.
418  
419 Croaks when given any, when the row is not in the database (as this ORM last
420 saw it), or has no usable primary key. Croaks too when the row is no longer
421 there, marking it deleted.
422  
423 =back
424  
425 =cut
426  
427 36 ▶sub refresh {
Subroutine refresh: called CC=6 SCAR=18.0
Pod documented
428 36 my $self = shift;
429 36 ▶ croak "refresh() takes no arguments" if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 35 36
430  
431 35 $self->_require_in_db('refresh');
432 32 my $table = $self->_require_pk('refresh');
433 26 ▶ my $lookup = $self->orm->debug && $self->orm->connection->lookup;
Condition66%2/3
$self->orm->debug && $self->orm->connection->lookup
!ll&&!rl&&r
2501
MC/DC50%1/2
$self->orm->debug && $self->orm->connection->lookup
$self->orm->debug $self->orm->connection->lookup
Truth table66%2/3
A && B
A= $self->orm->debugB= $self->orm->connection->lookup
ABresult
0X0
100
111
434 26 ▶ local $lookup->{caller} = [(caller(0))[0 .. 3]] if $lookup && !$lookup->{caller};
Branch: 1 branch
BranchTrueFalseTotal
if $lookup and not $lookup->{"caller"} 1 25 26
Condition66%2/3
$lookup and not $lookup->{"caller"}
!ll&&!rl&&r
2501
MC/DC50%1/2
$lookup and not $lookup->{"caller"}
$lookup not $lookup->{"caller"}
Truth table66%2/3
A and not(B)
A= $lookupB= not $lookup->{"caller"}
ABresult
0X0
100
111
435 26 ▶ return $self->orm->refresh_row($table, $self, cache => 0, raw => 1) // croak "The row is no longer in the table '$table'";
Condition100%2/2
$self->orm->refresh_row($table, $self, "cache", 0, "raw", 1) // croak("The row is no longer in the table '${table}'")
l!l
233
MC/DC0%0/1
$self->orm->refresh_row($table, $self, "cache", 0, "raw", 1) // croak("The row is no longer in the table '${table}'")
$self->orm->refresh_row($table, $self, "cache", 0, "raw", 1)
Truth table50%1/2
A
A= $self->orm->refresh_row($table, $self, "cache", 0, "raw", 1)
Aresult
11
00
436 }
437  
438 =pod
439  
440 =over 4
441  
442 =item $bool = $row->is_canon
443  
444 True when the row data is the ORM's canonical copy of the row. False for a row
445 not in the database, even one without its key (the ORM's C<is_canon> croaks
446 for that). Croaks when a row in the database has no usable primary key.
447  
448 =back
449  
450 =cut
451  
452 47 ▶sub is_canon {
Subroutine is_canon: called CC=2 SCAR=6.9
Pod documented
453 47 my $self = shift;
454 47 ▶ return 0 unless $self->is_in_db;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_in_db 3 44 47
455 44 my $table = $self->_require_pk('is_canon');
456 41 return $self->orm->connection->is_canon($table, $self->row_data);
457 }
458  
459 =over 4
460  
461 =item $status = $row->canon_status
462  
463 Undef while the row is canonical. Otherwise a hashref saying why not: its
464 C<cause>, and the call behind it (C<by>, or C<last_clear>) when the ORM was
465 built with C<< debug => 1 >>. This is the ORM's C<canon_status> for the row,
466 which lists the causes.
467  
468 my $why = $row->canon_status; # {cause => 'replaced', by => [$pkg, $file, $line, $sub]}
469  
470 Croaks for a row with no table, and as C<is_canon> does for a row in the
471 database without a usable primary key.
472  
473 =back
474  
475 =cut
476  
477 19 ▶sub canon_status {
Subroutine canon_status: called CC=1 SCAR=0.0
Pod documented
478 19 my $self = shift;
479 19 return $self->orm->canon_status($self->_require_table('canon_status'), $self);
480 }
481  
482 =over 4
483  
484 =item $bool = $row->is_in_db
485  
486 True unless the row was built by C<vivify> and not yet inserted, or was
487 marked deleted (see C<was_deleted>). This is what this ORM last saw, not a
488 check of the database.
489  
490 C<insert> sets it. A rollback of the inserting transaction or savepoint
491 clears it again, so the row can be inserted again.
492  
493 An update or refresh of that row in the same transaction carries this along.
494 A plain re-read that gives the row changed data does not: after a rollback
495 such a row may still report C<is_in_db>, so C<refresh> it to check.
496  
497 =item $bool = $row->was_deleted
498  
499 True when the row was marked deleted. Three things mark it: a row
500 C<delete>, a C<delete_row>, and a C<refresh> or C<find> that finds nothing in
501 the database.
502 A vivified row is neither in the database nor deleted.
503  
504 A bulk C<delete> on a handle marks nothing unless given
505 C<< mark_deleted => 1 >>. Otherwise rows already held keep C<is_in_db> true,
506 so refresh them to check.
507  
508 A delete inside a transaction or savepoint that rolls back is undone here too.
509  
510 =back
511  
512 =cut
513  
514 244 ▶sub is_in_db { DBIx::QuickORM::LookupTable->row_state($_[0]->row_data) ? 0 : 1 }
Subroutine is_in_db: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
'DBIx::QuickORM::LookupTable'->row_state($_[0]->row_data) ? : 47 197 244
515  
516 29 ▶sub was_deleted {
Subroutine was_deleted: called CC=3 SCAR=11.0
Pod documented
517 29 ▶ my $state = DBIx::QuickORM::LookupTable->row_state($_[0]->row_data) // '';
Condition100%2/2
"DBIx::QuickORM::LookupTable"->row_state($_[0]->row_data) // ""
l!l
236
MC/DC100%1/1
"DBIx::QuickORM::LookupTable"->row_state($_[0]->row_data) // ""
"DBIx::QuickORM::LookupTable"->row_state($_[0]->row_data)
Truth table100%2/2
A
A= "DBIx::QuickORM::LookupTable"->row_state($_[0]->row_data)
Aresult
11
00
518 29 ▶ return $state eq 'deleted' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$state eq 'deleted' ? : 20 9 29
519 }
520  
521 =pod
522  
523 =over 4
524  
525 =item $row = $row->insert
526  
527 Inserts a row that is not in the database, with the ORM's C<insert>, and takes
528 the new row data. The row is then in the database, and canonical when the
529 table has a primary key. Returns the row.
530  
531 Croaks when given arguments, for a row with no table, and for a row already
532 in the database.
533  
534 =back
535  
536 =cut
537  
538 6 ▶sub insert {
Subroutine insert: called CC=6 SCAR=19.4
Pod documented
539 6 my $self = shift;
540 6 ▶ croak "insert() takes no arguments" if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 6 6
541 6 my $table = $self->_require_table('insert');
542 6 ▶ croak "Cannot insert a row that is already in the database (table '$table')" if $self->is_in_db;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_in_db 1 5 6
543 5 ▶ my $lookup = $self->orm->debug && $self->orm->connection->lookup;
Condition33%1/3
$self->orm->debug && $self->orm->connection->lookup
!ll&&!rl&&r
500
MC/DC0%0/2
$self->orm->debug && $self->orm->connection->lookup
$self->orm->debug $self->orm->connection->lookup
Truth table33%1/3
A && B
A= $self->orm->debugB= $self->orm->connection->lookup
ABresult
0X0
100
111
544 5 ▶ local $lookup->{caller} = [(caller(0))[0 .. 3]] if $lookup && !$lookup->{caller};
Branch: 1 branch
BranchTrueFalseTotal
if $lookup and not $lookup->{"caller"} 0 5 5
Condition33%1/3
$lookup and not $lookup->{"caller"}
!ll&&!rl&&r
500
MC/DC0%0/2
$lookup and not $lookup->{"caller"}
$lookup not $lookup->{"caller"}
Truth table33%1/3
A and not(B)
A= $lookupB= not $lookup->{"caller"}
ABresult
0X0
100
111
545 5 $self->set_row_data($self->orm->insert($table => $self->row_data, data => 1, raw => 1));
546 5 return $self;
547 }
548  
549 =pod
550  
551 =over 4
552  
553 =item $row = $row->modify(\%changes)
554  
555 Changes the fields of a row that is not in the database, before its
556 C<insert>. Nothing is written. Returns the row.
557  
558 The changes are deflated as C<update> deflates them. The row takes a changed
559 copy of its row data, so other rows holding the old row data are untouched.
560  
561 Croaks when the changes are not a hashref, for a row with no table, for a
562 field the table does not have, and for a row in the database: use C<update>.
563  
564 =back
565  
566 =cut
567  
568 8 ▶sub modify {
Subroutine modify: called CC=3 SCAR=11.0
Pod documented
569 8 my $self = shift;
570 8 my ($changes) = @_;
571 8 ▶ croak "modify() needs a hashref of changes" unless ref($changes) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $changes eq "HASH" 0 8 8
572 8 my $table = $self->_require_table('modify');
573 8 ▶ croak "Cannot modify a row that is in the database; use update()" if $self->is_in_db;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_in_db 1 7 8
574  
575 7 my $old = $self->row_data;
576 7 my $new = {%$old, %{$self->orm->connection->deflate($table, $changes)}};
577 6 DBIx::QuickORM::LookupTable->copy_row_state($old, $new);
578 6 $self->set_row_data($new);
579 6 return $self;
580 }
581  
582 =pod
583  
584 =over 4
585  
586 =item $h = $row->follow_fk($other_table, link => \%link)
587  
588 =item $h = $row->follow_fk($other_table, via => \%via)
589  
590 The ORM's C<follow_fk> from this row: a handle on the rows it links to.
591 Croaks for a row with no table.
592  
593 =back
594  
595 =cut
596  
597 27 ▶sub follow_fk {
Subroutine follow_fk: called CC=3 SCAR=11.0
Pod documented
598 27 my $self = shift;
599 27 my ($other, %params) = @_;
600 27 my $table = $self->table;
601 27 ▶ croak "Cannot follow a foreign key from a row with no table" unless defined $table;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table 1 26 27
602 26 ▶ return $self->orm->_follow_fk($self->orm->debug ? [(caller(0))[0 .. 3]] : [caller], $table, $self, $other, %params);
Branch: 1 branch
BranchTrueFalseTotal
$self->orm->debug ? : 0 26 26
603 }
604  
605 =pod
606  
607 =over 4
608  
609 =item $new = $row->insert_fk($other_table, %opts, \%fields)
610  
611 =item \@new = $row->insert_many_fk($other_table, %opts, @fields)
612  
613 The ORM's C<insert_fk> and C<insert_many_fk> from this row: insert rows that
614 point at it.
615  
616 my $post = $alice->insert_fk('posts', {title => 'One'});
617 my $posts = $alice->insert_many_fk('posts', link => {id => 'user_id'}, {title => 'A'}, {title => 'B'});
618  
619 Croaks for a row with no table.
620  
621 =back
622  
623 =cut
624  
625 21 ▶sub insert_fk {
Subroutine insert_fk: called CC=3 SCAR=11.4
Pod documented
626 21 my $self = shift;
627 21 my $table = $self->table;
628 21 ▶ croak "Cannot insert rows linked to a row with no table" unless defined $table;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table 0 21 21
629 21 ▶ return $self->orm->_insert_fk($self->orm->debug ? [(caller(0))[0 .. 3]] : [caller], insert => $table, $self, @_);
Branch: 1 branch
BranchTrueFalseTotal
$self->orm->debug ? : 0 21 21
630 }
631  
632 8 ▶sub insert_many_fk {
Subroutine insert_many_fk: called CC=3 SCAR=11.4
Pod documented
633 8 my $self = shift;
634 8 my $table = $self->table;
635 8 ▶ croak "Cannot insert rows linked to a row with no table" unless defined $table;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table 0 8 8
636 8 ▶ return $self->orm->_insert_fk($self->orm->debug ? [(caller(0))[0 .. 3]] : [caller], insert_many => $table, $self, @_);
Branch: 1 branch
BranchTrueFalseTotal
$self->orm->debug ? : 0 8 8
637 }
638  
639 =pod
640  
641 =over 4
642  
643 =item $bool = $class->fast_bless
644  
645 True when the ORM may build rows of the class by blessing
646 C<< {orm => $orm, table => $table, row_data => \%data} >> directly, skipping
647 C<new>. False here. L<DBIx::QuickORM::Row> says when it is true.
648  
649 The ORM takes the answer once per row class per ORM, not once per row.
650  
651 =back
652  
653 =cut
654  
655 7 ▶sub fast_bless { 0 }
Subroutine fast_bless: called CC=1 SCAR=0.0
Pod documented
656  
657 =head1 PRIVATE METHODS
658  
659 =over 4
660  
661 =item $table = $row->_require_pk($action)
662  
663 The row's table. Croaks naming the action unless the table has a primary key
664 and the row data holds all of it.
665  
666 =back
667  
668 =cut
669  
670 181 ▶sub _require_pk {
Subroutine _require_pk: called CC=4 SCAR=13.9
671 181 my $self = shift;
672 181 my ($action) = @_;
673  
674 181 my $table = $self->table;
675 181 my $pk = $self->pk;
676 181 ▶ my $ok = $pk && !grep { !defined } values %$pk;
Condition100%3/3
$pk && !grep({not defined $_;} values %$pk)
!ll&&!rl&&r
172162
MC/DC100%2/2
$pk && !grep({not defined $_;} values %$pk)
$pk !grep({not defined $_;} values %$pk)
Truth table100%3/3
A && not(B)
A= $pkB= !grep({not defined $_;} values %$pk)
ABresult
0X0
100
111
677 181 ▶ croak "Cannot $action a row without a primary key" . (defined($table) ? " (table '$table')" : '') unless $ok;
Branch: 2 branches
BranchTrueFalseTotal
unless $ok 19 162 181
defined $table ? : 10 9 19
678  
679 162 return $table;
680 }
681  
682 =pod
683  
684 =over 4
685  
686 =item $row->_require_in_db($action)
687  
688 Croaks naming the action unless the row is in the database.
689  
690 =item $table = $row->_require_table($action)
691  
692 The row's table. Croaks naming the action for a row with no table.
693  
694 =back
695  
696 =cut
697  
698 145 ▶sub _require_in_db {
Subroutine _require_in_db: called CC=2 SCAR=6.9
699 145 my $self = shift;
700 145 my ($action) = @_;
701 145 ▶ croak "Cannot $action a row that is not in the database; insert it first" unless $self->is_in_db;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_in_db 8 137 145
702 }
703  
704 33 ▶sub _require_table {
Subroutine _require_table: called CC=2 SCAR=7.0
705 33 my $self = shift;
706 33 my ($action) = @_;
707 33 my $table = $self->table;
708 33 ▶ croak "Cannot $action a row with no table" unless defined $table;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table 0 33 33
709 33 return $table;
710 }
711  
712 =pod
713  
714 =over 4
715  
716 =item $row->_fetch_missing(@names)
717  
718 Fetches the missing fields, all of them with one C<refresh_row> that also
719 asks for the fields already present, and takes the row data it returns. A vivified row fetches nothing: its missing fields
720 read as undef. Croaks for a field the table does not have, and for a deleted
721 row.
722  
723 A row that is not canon reads just the missing fields through a C<no_cache>
724 handle and adds them to its own row data: the row cache is not touched, and
725 the row stays not canon.
726  
727 =back
728  
729 =cut
730  
731 29 ▶sub _fetch_missing {
Subroutine _fetch_missing: called CC=16 SCAR=27.8
732 29 my $self = shift;
733 29 my (@names) = @_;
734  
735 29 my $table = $self->table;
736 29 my $fields = $self->orm->_table_fields($table);
737 29 for my $name (@names) {
738 39 ▶ croak "The table '$table' has no field '$name'" unless $fields->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $fields->{$name} 6 33 39
739 }
740  
741 23 my $data = $self->row_data;
742 23 ▶ return unless grep { !exists $data->{$_} } @names;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {not exists $data->{$_};} @names 0 23 23
743 23 ▶ return if (DBIx::QuickORM::LookupTable->row_state($data) // '') eq 'vivified';
Branch: 1 branch
BranchTrueFalseTotal
if ("DBIx::QuickORM::LookupTable"->row_state($data) // "") eq "vivified" 3 20 23
Condition100%2/2
"DBIx::QuickORM::LookupTable"->row_state($data) // ""
l!l
419
MC/DC100%1/1
"DBIx::QuickORM::LookupTable"->row_state($data) // ""
"DBIx::QuickORM::LookupTable"->row_state($data)
Truth table100%2/2
A
A= "DBIx::QuickORM::LookupTable"->row_state($data)
Aresult
11
00
744 20 $self->_require_in_db('fetch missing fields of');
745  
746 19 $self->_require_pk('fetch missing fields of');
747  
748 # The reader that called this is the public call, one frame up. When it was called through another reader of
749 # this role (field() through inflated_field()), that frame is ours, so none is recorded.
750 18 ▶ my $lookup = $self->orm->debug && $self->orm->connection->lookup;
Condition66%2/3
$self->orm->debug && $self->orm->connection->lookup
!ll&&!rl&&r
1602
MC/DC50%1/2
$self->orm->debug && $self->orm->connection->lookup
$self->orm->debug $self->orm->connection->lookup
Truth table66%2/3
A && B
A= $self->orm->debugB= $self->orm->connection->lookup
ABresult
0X0
100
111
751 18 ▶ my @frame = $lookup ? (caller(1))[0 .. 3] : ();
Branch: 1 branch
BranchTrueFalseTotal
$lookup ? : 2 16 18
752 18 ▶ local $lookup->{caller} = ($frame[0] eq __PACKAGE__ ? undef : \@frame) if $lookup && !$lookup->{caller};
Branch: 2 branches
BranchTrueFalseTotal
if $lookup and not $lookup->{"caller"} 2 16 18
$frame[0] eq __PACKAGE__ ? : 1 1 2
Condition66%2/3
$lookup and not $lookup->{"caller"}
!ll&&!rl&&r
1602
MC/DC50%1/2
$lookup and not $lookup->{"caller"}
$lookup not $lookup->{"caller"}
Truth table66%2/3
A and not(B)
A= $lookupB= not $lookup->{"caller"}
ABresult
0X0
100
111
753  
754 # A row that is not canon reads around the row cache and keeps its own data.
755 18 ▶ unless ($self->is_canon) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_canon) 10 8 18
756 10 my @missing = grep { !exists $data->{$_} } @names;
757 10 ▶ my $got = $self->orm->handle($table)->no_cache->fields(\@missing)->where($self->pk)->data_only->first or croak "Cannot fetch missing fields: the row is no longer in the table '$table'";
Branch: 1 branch
BranchTrueFalseTotal
my $got = $self->orm->handle($table)->no_cache->fields(\@missing)->where($self->pk)->data_only->first or croak("Cannot fetch missing fields: the row is no longer in the table '${table}'") 10 0 10
758 10 $data->{$_} = $got->{$_} for @missing;
759 10 return;
760 }
761  
762 # The present fields are asked for too, so a changed row's new data holds them as well.
763 8 my @want = ((grep { $fields->{$_} } keys %$data), @names);
764 8 ▶ my $new = $self->orm->connection->refresh_row($table, $data, fields => \@want, raw => 1) or croak "Cannot fetch missing fields: the row is no longer in the table '$table'";
Branch: 1 branch
BranchTrueFalseTotal
my $new = $self->orm->connection->refresh_row($table, $data, "fields", \@want, "raw", 1) or croak("Cannot fetch missing fields: the row is no longer in the table '${table}'") 7 1 8
765 7 ▶ $self->set_row_data($new) unless $new == $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $new == $data 3 4 7
766 }
767  
768 =pod
769  
770 =over 4
771  
772 =item \%values = $row->_inflation_cache
773  
774 The cache of inflated values (field name to value) for the current row data.
775 A supported override point.
776  
777 When the row data has been replaced since the cache was built, a new cache is
778 started, keeping the values of fields present in both whose raw values do not
779 differ by C<< DBIx::QuickORM::LookupTable->differ >>.
780  
781 =back
782  
783 =cut
784  
785 47 ▶sub _inflation_cache {
Subroutine _inflation_cache: called CC=7 SCAR=19.5
786 47 my $self = shift;
787 47 my $data = $self->row_data;
788 47 my $old = $CACHE{$self};
789 47 ▶ return $old->{values} if $old && $old->{data} == $data;
Branch: 1 branch
BranchTrueFalseTotal
if $old and $old->{"data"} == $data 20 27 47
Condition100%3/3
$old and $old->{"data"} == $data
!ll&&!rl&&r
22520
MC/DC100%2/2
$old and $old->{"data"} == $data
$old $old->{"data"} == $data
Truth table100%3/3
A and B
A= $oldB= $old->{"data"} == $data
ABresult
0X0
100
111
790  
791 27 my %keep;
792 27 ▶ if ($old) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old) 5 22 27
793 5 my $was = $old->{data};
794 5 for my $name (keys %{$old->{values}}) {
795 3 ▶ next unless exists $data->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $data->{$name} 0 3 3
796 3 ▶ next if DBIx::QuickORM::LookupTable->differ($was->{$name}, $data->{$name});
Branch: 1 branch
BranchTrueFalseTotal
if "DBIx::QuickORM::LookupTable"->differ($was->{$name}, $data->{$name}) 2 1 3
797 1 $keep{$name} = $old->{values}->{$name};
798 }
799 }
800  
801 27 $CACHE{$self} = {data => $data, values => \%keep};
802 27 return \%keep;
803 }
804  
805 =pod
806  
807 =over 4
808  
809 =item $value = $row->_inflated_value($name, \%field)
810  
811 The value to hand out for a present field. A supported override point.
812  
813 The raw value when it is NULL, the field is untyped, or the field is
814 C<passthrough> (its type would return it unchanged). Otherwise, by the type:
815  
816 =over 4
817  
818 =item *
819  
820 C<inflated_is_immutable_for_cache> true: the value cached by
821 C<_inflation_cache>, inflated on first read, handed out as it is.
822  
823 =item *
824  
825 Else C<inflate_on_each_read> true: the raw value inflated again for this read,
826 with nothing cached.
827  
828 =item *
829  
830 Else: the cached value, copied by C<clone_inflated>.
831  
832 =back
833  
834 =back
835  
836 =cut
837  
838 130 ▶sub _inflated_value {
Subroutine _inflated_value: called CC=9 SCAR=22.0
839 130 my $self = shift;
840 130 my ($name, $field) = @_;
841  
842 130 my $raw = $self->row_data->{$name};
843 130 my $type = $field->{orm_type};
844 130 ▶ return $raw unless defined($raw) && $type && !$field->{passthrough};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw and $type and not $field->{"passthrough"} 47 83 130
Condition100%6/6
defined $raw and $type and not $field->{"passthrough"}
!ll&&!rl&&r
40783
defined $raw and $type
!ll&&!rl&&r
103090
MC/DC100%3/3
defined $raw and $type and not $field->{"passthrough"}
defined $raw $type not $field->{"passthrough"}
Truth table100%4/4
A and B and not(C)
A= defined $rawB= $typeC= not $field->{"passthrough"}
ABCresult
0XX0
10X0
1100
1111
845  
846 83 my $immutable = $type->inflated_is_immutable_for_cache;
847 83 ▶ return scalar $type->inflate($raw, $field, $self->orm->connection) if !$immutable && $type->can('inflate_on_each_read') && $type->inflate_on_each_read;
Branch: 1 branch
BranchTrueFalseTotal
if not $immutable and $type->can("inflate_on_each_read") and $type->inflate_on_each_read 38 45 83
Condition83%5/6
not $immutable and $type->can("inflate_on_each_read") and $type->inflate_on_each_read
!ll&&!rl&&r
40538
not $immutable and $type->can("inflate_on_each_read")
!ll&&!rl&&r
40043
MC/DC66%2/3
not $immutable and $type->can("inflate_on_each_read") and $type->inflate_on_each_read
not $immutable $type->can("inflate_on_each_read") $type->inflate_on_each_read
Truth table75%3/4
not(A) and B and C
A= not $immutableB= $type->can("inflate_on_each_read")C= $type->inflate_on_each_read
ABCresult
0XX0
10X0
1100
1111
848  
849 45 my $cache = $self->_inflation_cache;
850 45 ▶ $cache->{$name} = $type->inflate($raw, $field, $self->orm->connection) unless exists $cache->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $cache->{$name} 26 19 45
851 45 ▶ return $immutable ? $cache->{$name} : $type->clone_inflated($cache->{$name});
Branch: 1 branch
BranchTrueFalseTotal
$immutable ? : 40 5 45
852 }
853  
854 303 1;
855  
856 __END__
« blib/lib/DBIx/QuickORM/WhereBuilder/RawSQL.pm ↑ Summary blib/lib/DBIx/QuickORM/WhereBuilder/Simple.pm »