blib/lib/DBIx/Class/FrozenColumns.pm

filter: Statementstmt 93.5% 160 / 171 Branchbran 80.4% 37 / 46 Conditioncond 45.2% 19 / 42 MC/DCmcdc 8.0% 2 / 25 Subroutinesub 86.0% 37 / 43 Podpod 100% 16 / 16 totaltotal 79.0% 271 / 343 CC 44 SCAR 15.4
CC
44
Cov
83%
recover
20.0
add_frozen_columns
10.5
set_column
6.2
CRAP 4.6
↑ Summary
1 package DBIx::Class::FrozenColumns;
2 3 ▶use base qw/DBIx::Class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = 1.0;
8  
9 3 __PACKAGE__->mk_group_accessors(inherited => qw/_frozen_columns _dirty_frozen_columns/);
10 3 __PACKAGE__->_frozen_columns({});
11  
12 =head1 NAME
13  
14 DBIx::Class::FrozenColumns - Store virtual columns inside another column.
15  
16 =head1 SYNOPSIS
17  
18 package Artist;
19 __PACKAGE__->load_components(qw/FrozenColumns Core/);
20 __PACKAGE__->add_columns(qw/name description frozen/);
21 __PACKAGE__->add_frozen_columns(
22 frozen => qw/biography url img50x50 img100x100/
23 );
24  
25 $artist->url('http://cpan.org');
26 $artist->get_column('url');
27 $artist->get_dirty_columns; # 'url' and 'frozen' are dirty
28 $artist->update; #updates column 'frozen' (using Storable::freeze)
29  
30 $artistRS->create({
31 name => 'theodor bastard',
32 img50x50 => '50x50.gif',
33 }); #that's ok. 'img50x50' will be stored in 'frozen'
34  
35 my @artists = $artistRS->search({
36 name => '.....',
37 url => 'http://cpan.org',
38 }); # Error! no such column 'url'
39  
40 package Artist;
41 __PACKAGE__->add_frozen_columns(
42 biography => qw/childhood adolescence youth present/,
43 );
44  
45 $artist->childhood('bla-bla-bla');
46 $artist->update; #Updates column 'frozen'.
47  
48 =head1 DESCRIPTION
49  
50 This module allows you to store multiple columns in one. This is useful when
51 you want to store dynamic number of columns in database or you just don't know
52 what columns will be stored there. Or when you can't (or don't want) to alter
53 your tables in database.
54  
55 Module allows you to transparently use this columns as if they were normal
56 columns in your table. With one obvious restriction: you cannot search rows in a
57 table and therefore you cannot add relationships using these columns (search is
58 needed to build reverse relationship).
59  
60 Module handles its own dirty column management and will not update the parent
61 field unless any columns is changed.
62  
63 Note: The component needs to be loaded before Core and plugin 'Ordered'.
64 If you get an error like 'no such column: <frozencolumn>' while updating a row
65 then try to move this module more closer to the start of the load_components
66 list.
67  
68 Also note that frozen column IS NOT a real column of your result class.
69 This impose some restrictions on use of this columns such as searching, adding
70 relationships, has_column, get_columns, etc.
71 See L</EXTENDED METHODS> for the list of method that will work with frozen
72 columns (as will methods that use it).
73  
74 Module unpacks frozen columns only once when you first accessing it and packs
75 when you call update.
76  
77 You can also create frozen columns in another frozen column any level deep.
78 The only restriction is that they all use the same storing mechanism.
79  
80 =head1 METHODS
81  
82 =head2 add_frozen_columns
83  
84 __PACKAGE__->add_frozen_columns ($data_column, @columns)
85 __PACKAGE__->add_frozen_columns ($hashref)
86  
87 Adds frozen @columns to your result source class. These columns will be stored in
88 $data_column using Storable freeze/thaw algorithm.
89 If $hashref is specified instead, then below params is expected in it:
90 data_column - same as $data_column
91 columns - same as @columns
92 type - class with custom mechanism of storing/restoring frozen cols
93 See below for more information about L</Custom frozen class>.
94  
95 =head2 add_dumped_columns ($data_column, @columns)
96  
97 Same as L</add_frozen_columns> but uses Data::Dumper mechanism.
98  
99 =head2 add_json_columns ($data_column, @columns)
100  
101 Same as L</add_frozen_columns> but uses JSON::XS mechanism.
102  
103 =cut
104  
105 12 ▶sub add_frozen_columns {
Subroutine add_frozen_columns: called CC=10 SCAR=23.5
Pod documented
106 12 my $this = shift;
107 12 my ($type, $data_column, @frozen_columns);
108  
109 12 ▶ if(ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 6 6 12
110 6 my $params = shift;
111 6 $type = $params->{type};
112 6 $data_column = $params->{data_column};
113 6 ▶ @frozen_columns = @{$params->{columns}||[]};
Condition50%1/2
$params->{'columns'} || []
l!l
60
MC/DC0%0/1
$params->{'columns'} || []
$params->{'columns'}
Truth table50%1/2
A
A= $params->{'columns'}
Aresult
11
00
114 }
115 else {
116 6 $type = 'DBIx::Class::FrozenColumns::Frozen';
117 6 ($data_column, @frozen_columns) = @_;
118 }
119  
120 $this->throw_exception('Cannot store frozen columns inside another frozen column of different type')
121 if exists $this->_frozen_columns->{$data_column}
122 12 ▶ and $this->_frozen_columns->{$data_column}{type} ne $type;
Branch: 1 branch
BranchTrueFalseTotal
if exists $this->_frozen_columns->{$data_column} and $this->_frozen_columns->{$data_column}{"type"} ne $type 0 12 12
Condition66%2/3
exists $this->_frozen_columns->{$data_column} and $this->_frozen_columns->{$data_column}{"type"} ne $type
!ll&&!rl&&r
480
MC/DC0%0/2
exists $this->_frozen_columns->{$data_column} and $this->_frozen_columns->{$data_column}{"type"} ne $type
exists $this->_frozen_columns->{$data_column} $this->_frozen_columns->{$data_column}{"type"} ne $type
Truth table66%2/3
A and B
A= exists $this->_frozen_columns->{$data_column}B= $this->_frozen_columns->{$data_column}{"type"} ne $type
ABresult
0X0
100
111
123  
124 $this->add_column($data_column)
125 12 ▶ unless $this->has_column($data_column) or $this->_frozen_columns->{$data_column};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->has_column($data_column) or $this->_frozen_columns->{$data_column} 0 12 12
Condition66%2/3
$this->has_column($data_column) or $this->_frozen_columns->{$data_column}
l!l&&r!l&&!r
480
MC/DC0%0/2
$this->has_column($data_column) or $this->_frozen_columns->{$data_column}
$this->has_column($data_column) $this->_frozen_columns->{$data_column}
Truth table66%2/3
A or B
A= $this->has_column($data_column)B= $this->_frozen_columns->{$data_column}
ABresult
1X1
011
000
126  
127 12 my %frozen_columns = %{$this->_frozen_columns};
128 12 foreach my $f_column (@frozen_columns) {
129 $this->throw_exception('Cannot override existing column with frozen one')
130 20 ▶ if $this->has_column($f_column) or $this->_frozen_columns->{$f_column};
Branch: 1 branch
BranchTrueFalseTotal
if $this->has_column($f_column) or $this->_frozen_columns->{$f_column} 0 20 20
Condition33%1/3
$this->has_column($f_column) or $this->_frozen_columns->{$f_column}
l!l&&r!l&&!r
0020
MC/DC0%0/2
$this->has_column($f_column) or $this->_frozen_columns->{$f_column}
$this->has_column($f_column) $this->_frozen_columns->{$f_column}
Truth table33%1/3
A or B
A= $this->has_column($f_column)B= $this->_frozen_columns->{$f_column}
ABresult
1X1
011
000
131  
132 20 $frozen_columns{$f_column} = {
133 column => $data_column,
134 type => $type,
135 };
136  
137 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
138 20 ▶ *{"${this}::$f_column"} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
139 8 my $self = shift;
140 8 ▶ return $self->get_column($f_column) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 4 4 8
141 4 $self->set_column($f_column, shift);
142 20 };
143 }
144  
145 12 $this->_frozen_columns(\%frozen_columns);
146 }
147  
148 6 ▶sub add_dumped_columns {
Subroutine add_dumped_columns: called CC=1 SCAR=0.0
Pod documented
149 shift->add_frozen_columns({
150 6 type => 'DBIx::Class::FrozenColumns::Dumped',
151 data_column => shift,
152 columns => [@_],
153 });
154 }
155  
156 0 ▶sub add_json_columns {
Subroutine add_json_columns: not called CC=1 SCAR=6.9
Pod documented
157 shift->add_frozen_columns({
158 0 type => 'DBIx::Class::FrozenColumns::JSON',
159 data_column => shift,
160 columns => [@_],
161 });
162 }
163  
164 =head2 frozen_columns
165  
166 Returns hash of frozen columns where keys are the names of fcolumns and values
167 are hashes with the following properties:
168  
169 'type' - type of fcolumn (frozen or dumped or some custom).
170 'column' - parent column where fcolumn is stored.
171  
172 =cut
173  
174 0 ▶sub frozen_columns {$_[0]->_frozen_columns}
Subroutine frozen_columns: not called CC=1 SCAR=6.9
Pod documented
175  
176 =head2 frozen_columns_list
177  
178 Returns list of names of all frozen columns registered with the result source.
179  
180 =cut
181  
182 0 ▶sub frozen_columns_list {keys %{$_[0]->_frozen_columns}}
Subroutine frozen_columns_list: not called CC=1 SCAR=6.9
Pod documented
183  
184 =head1 EXTENDED METHODS
185  
186 =head2 new
187  
188 Accepts initial values for frozen columns.
189  
190 $artistRS->new({img50x50 => '50x50.gif'});
191  
192 =cut
193  
194 4 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
195 4 my $self = shift;
196 4 my ($attrs) = @_;
197 4 my %fattrs;
198  
199 4 foreach my $attr (keys %$attrs) {
200 12 ▶ next unless exists $self->_frozen_columns->{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->_frozen_columns->{$attr} 8 4 12
201 4 $fattrs{$attr} = delete $attrs->{$attr};
202 }
203  
204 4 my $ret = $self->next::method(@_);
205 4 ▶ while ( my($k,$v) = each %fattrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %fattrs) 4 4 8
206 4 $ret->store_column($k, $v);
207 }
208 4 return $ret;
209 }
210  
211  
212 =head2 get_column
213  
214 =cut
215  
216 630 ▶sub get_column {
Subroutine get_column: called CC=2 SCAR=6.9
Pod documented
217 630 my ($self, $column) = @_;
218  
219 630 ▶ if (my $frozen_info = $self->_frozen_columns->{$column}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $frozen_info = $self->_frozen_columns->{$column}) 238 392 630
220 238 $self->_ensure_column_unpacked( $frozen_info->{column}, $frozen_info->{type} );
221 238 return $self->get_column( $frozen_info->{column} )->{$column};
222 }
223  
224 392 return $self->next::method($column);
225 }
226  
227 =head2 get_columns
228  
229 Returns DBIC's get_columns with frozen columns hash.
230 IMPORTANT: until $row is not in storage this method will return basic get_columns
231 result without frozen columns. This is needed for correct work of insert method.
232  
233 =cut
234  
235 8 ▶sub get_columns {
Subroutine get_columns: called CC=3 SCAR=11.0
Pod documented
236 8 my $self = shift;
237 8 ▶ return $self->next::method(@_) unless $self->in_storage;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->in_storage 4 4 8
238 4 my %data = $self->next::method(@_);
239 4 foreach my $f_column ( keys %{$self->_frozen_columns} ) {
240 40 $data{$f_column} = $self->get_column($f_column);
241 }
242 4 return %data;
243 }
244  
245 =head2 store_column
246  
247 =cut
248  
249 62 ▶sub store_column {
Subroutine store_column: called CC=2 SCAR=6.9
Pod documented
250 62 my ($self, $column, $value) = @_;
251  
252 62 ▶ if (my $frozen_info = $self->_frozen_columns->{$column}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $frozen_info = $self->_frozen_columns->{$column}) 30 32 62
253 30 $self->_ensure_column_unpacked( $frozen_info->{column}, $frozen_info->{type} );
254 30 return $self->get_column( $frozen_info->{column} )->{$column} = $value;
255 }
256  
257 32 return $self->next::method($column, $value);
258 }
259  
260 =head2 set_column
261  
262 =cut
263  
264 20 ▶sub set_column {
Subroutine set_column: called CC=6 SCAR=18.2
Pod documented
265 20 my ($self, $column, $value) = @_;
266  
267 20 ▶ if (my $frozen_info = $self->_frozen_columns->{$column}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $frozen_info = $self->_frozen_columns->{$column}) 12 8 20
268 12 my $data_column = $frozen_info->{column};
269 12 my $old = $self->get_column($column);
270 12 my $ret = $self->store_column($column, $value);
271  
272 12 ▶ if(defined $old ^ defined $ret or (defined $old && $old ne $ret)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old ^ defined $ret or defined $old and $old ne $ret) 12 0 12
Condition50%3/6
defined $old ^ defined $ret or defined $old and $old ne $ret
l!l&&r!l&&!r
660
defined $old and $old ne $ret
!ll&&!rl&&r
006
MC/DC0%0/3
defined $old ^ defined $ret or defined $old and $old ne $ret
defined $old ^ defined $ret defined $old $old ne $ret
Truth table50%2/4
A or B and C
A= defined $old ^ defined $retB= defined $oldC= $old ne $ret
ABCresult
1XX1
0111
00X0
0100
273 12 $self->set_column( $data_column, $self->get_column($data_column) );
274 12 ▶ my $frozen_dirty = $self->_dirty_frozen_columns || {};
Condition100%2/2
$self->_dirty_frozen_columns || {}
l!l
84
MC/DC100%1/1
$self->_dirty_frozen_columns || {}
$self->_dirty_frozen_columns
Truth table100%2/2
A
A= $self->_dirty_frozen_columns
Aresult
11
00
275 12 $frozen_dirty->{$column} = 1;
276 12 $self->_dirty_frozen_columns($frozen_dirty);
277 }
278  
279 12 return $ret;
280  
281 }
282  
283 8 return $self->next::method($column, $value);
284 }
285  
286 =head2 get_dirty_columns
287  
288 Returns real and frozen dirty columns.
289 Note that changing frozen column will result in marking at least 2 columns as
290 dirty.
291  
292 =cut
293  
294 11 ▶sub get_dirty_columns {
Subroutine get_dirty_columns: called CC=3 SCAR=11.0
Pod documented
295 11 my $self = shift;
296 11 ▶ return $self->next::method(@_) unless $self->_dirty_frozen_columns;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_dirty_frozen_columns 9 2 11
297 2 my %data = $self->next::method(@_);
298 2 foreach my $f_column ( keys %{$self->_dirty_frozen_columns} ) {
299 2 $data{$f_column} = $self->get_column($f_column);
300 }
301 2 return %data;
302 }
303  
304 268 ▶sub _ensure_column_unpacked {
Subroutine _ensure_column_unpacked: called CC=2 SCAR=6.9
305 268 my ($self, $column, $type) = @_;
306 268 ▶ unless ( ref (my $packed = $self->get_column($column)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref(my $packed = $self->get_column($column))) 28 240 268
307 28 $self->store_column($column, $type->recover(\$packed));
308 }
309 }
310  
311 =head2 has_column_loaded
312  
313 Returns true if data_column of frozen column has loaded.
314  
315 =cut
316  
317 38 ▶sub has_column_loaded {
Subroutine has_column_loaded: called CC=2 SCAR=6.9
Pod documented
318 38 my ($self, $column) = @_;
319  
320 38 ▶ if (my $frozen_info = $self->_frozen_columns->{$column}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $frozen_info = $self->_frozen_columns->{$column}) 16 22 38
321 16 return $self->has_column_loaded( $frozen_info->{column} );
322 }
323  
324 22 $self->next::method($column);
325 }
326  
327 =head2 is_column_changed
328  
329 =cut
330  
331 4 ▶sub is_column_changed {
Subroutine is_column_changed: called CC=3 SCAR=11.2
Pod documented
332 4 my ($self, $column) = @_;
333  
334 4 ▶ if ($self->_frozen_columns->{$column}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_frozen_columns->{$column}) 2 2 4
335 2 my $frozen_dirty = $self->_dirty_frozen_columns;
336 2 ▶ return $frozen_dirty && exists $frozen_dirty->{$column};
Condition33%1/3
$frozen_dirty && exists $frozen_dirty->{$column}
!ll&&!rl&&r
002
MC/DC0%0/2
$frozen_dirty && exists $frozen_dirty->{$column}
$frozen_dirty exists $frozen_dirty->{$column}
Truth table33%1/3
A && B
A= $frozen_dirtyB= exists $frozen_dirty->{$column}
ABresult
0X0
100
111
337 }
338  
339 2 $self->next::method($column);
340 }
341  
342 =head2 is_changed
343  
344 =cut
345  
346 4 ▶sub is_changed {
Subroutine is_changed: called CC=6 SCAR=18.2
Pod documented
347 4 my $self = shift;
348  
349 4 ▶ if(wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 2 2 4
350 2 my @columns = $self->next::method(@_);
351 2 my $frozen_dirty = $self->_dirty_frozen_columns;
352 2 ▶ push @columns, keys %$frozen_dirty if $frozen_dirty;
Branch: 1 branch
BranchTrueFalseTotal
if $frozen_dirty 2 0 2
353 2 return @columns;
354 }
355  
356 2 ▶ return 1 if $self->next::method(@_) or keys %{$self->_dirty_frozen_columns||{}};
Branch: 1 branch
BranchTrueFalseTotal
if $self->next::method(@_) or keys %{$self->_dirty_frozen_columns or {};} 1 1 2
Condition60%3/5
$self->next::method(@_) or keys %{$self->_dirty_frozen_columns or {};}
l!l&&r!l&&!r
101
$self->_dirty_frozen_columns || {}
l!l
01
MC/DC50%1/2
$self->next::method(@_) or keys %{$self->_dirty_frozen_columns or {};}
$self->next::method(@_) keys %{$self->_dirty_frozen_columns or {};}
MC/DC0%0/1
$self->_dirty_frozen_columns || {}
$self->_dirty_frozen_columns
Truth table66%2/3
A or B
A= $self->next::method(@_)B= keys %{$self->_dirty_frozen_columns or {};}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $self->_dirty_frozen_columns
Aresult
11
00
357 }
358  
359 =head2 update
360  
361 =cut
362  
363 5 ▶sub update {
Subroutine update: called CC=1 SCAR=0.0
Pod documented
364 5 my $self = shift;
365 5 $self->_dirty_frozen_columns(undef);
366 5 $self->next::method(@_);
367 }
368  
369  
370 =head2 insert
371  
372 =cut
373  
374 4 ▶sub insert {
Subroutine insert: called CC=1 SCAR=0.0
Pod documented
375 4 my $self = shift;
376 4 $self->_dirty_frozen_columns(undef);
377 4 $self->next::method(@_);
378 }
379  
380 =head1 Custom frozen class
381  
382 Such a class must be derived from 'DBIx::Class::FrozenColumns::Base' and is
383 responsible for fetching and storing frozen columns to/from a real database column.
384 The corresponding methods are 'recover' and 'stringify'.
385  
386 The best explanation is an expamle:
387  
388 package DBIx::Class::FrozenColumns::Frozen;
389 use base qw/DBIx::Class::FrozenColumns::Base/;
390  
391 use strict;
392 use Storable qw/freeze thaw/;
393  
394 sub stringify {
395 freeze(shift);
396 }
397  
398 sub recover {
399 my ($this, $dataref) = @_;
400 my $data = defined $$dataref ? eval {thaw($$dataref)} || {} : {};
401 bless ($data, ref $this || $this);
402 }
403  
404 Information actually stored in database can be used by any other programs as a simple
405 hash (possibly containing another hashes like itself).
406  
407 =cut
408  
409 package DBIx::Class::FrozenColumns::Base;
410 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
411 0 ▶use overload '.' => sub {$_[0]->stringify},
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=6.9
412 20 ▶ '""' => sub {$_[0]->stringify},
Subroutine __ANON__: called CC=1 SCAR=0.0
413 8 ▶ 'ne' => sub{1},
Subroutine __ANON__: called CC=1 SCAR=0.0
414 6 ▶ 'eq' => sub{undef},
Subroutine __ANON__: called CC=1 SCAR=0.0
415 3 fallback => 1;
416  
417 package DBIx::Class::FrozenColumns::Frozen;
418 3 ▶use base qw/DBIx::Class::FrozenColumns::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
419  
420 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
421 3 ▶use Storable qw/freeze thaw/;
Subroutine BEGIN: called CC=1 SCAR=0.0
422  
423 10 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
424 10 freeze(shift);
425 }
426  
427 14 ▶sub recover {
Subroutine recover: called CC=4 SCAR=14.6
428 14 my ($this, $dataref) = @_;
429 14 ▶ my $data = defined $$dataref ? eval {thaw($$dataref)} || {} : {};
Branch: 1 branch
BranchTrueFalseTotal
defined $$dataref ? : 4 10 14
Condition50%1/2
eval { do { thaw($$dataref) } } or {}
l!l
40
MC/DC0%0/1
eval { do { thaw($$dataref) } } or {}
eval { do { thaw($$dataref) } }
Truth table50%1/2
A
A= eval { do { thaw($$dataref) } }
Aresult
11
00
430 14 ▶ bless ($data, ref $this || $this);
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0140
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
431 }
432  
433  
434 package DBIx::Class::FrozenColumns::Dumped;
435 3 ▶use base qw/DBIx::Class::FrozenColumns::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
436  
437 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
438 3 ▶use Data::Dumper qw/Dumper/;
Subroutine BEGIN: called CC=1 SCAR=0.0
439  
440 10 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
441 10 local $Data::Dumper::Indent = 0;
442 10 Dumper(shift);
443 }
444  
445 14 ▶sub recover {
Subroutine recover: called CC=4 SCAR=14.6
446 14 my ($this, $dataref) = @_;
447 14 our $VAR1;
448 14 ▶ my $data = defined $$dataref ? eval "$$dataref" || {} : {};
Branch: 1 branch
BranchTrueFalseTotal
defined $$dataref ? : 4 10 14
Condition50%1/2
eval "$$dataref" or {}
l!l
40
MC/DC0%0/1
eval "$$dataref" or {}
eval "$$dataref"
Truth table50%1/2
A
A= eval "$$dataref"
Aresult
11
00
449 14 ▶ bless ($data, ref $this || $this);
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0140
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
450 }
451  
452  
453 package DBIx::Class::FrozenColumns::JSON;
454 3 ▶use base qw/DBIx::Class::FrozenColumns::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
455  
456 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
457 3 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
458 3 my $json = JSON::XS->new; #utf8 will be handled automatically (<dbtype>_enable_utf8 required)
459  
460 0 ▶sub stringify {ref $_[0] ? $json->encode({%{$_[0]}}) : undef}
Subroutine stringify: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
461 0 ▶sub recover {
Subroutine recover: not called CC=4 SCAR=30.0
462 0 my ($this, $dataref) = @_;
463 0 ▶ my $data = defined $$dataref ? eval {$json->decode($$dataref)} || {} : {};
Branch: 1 branch
BranchTrueFalseTotal
defined $$dataref ? : 0 0 0
Condition0%0/2
eval { do { $json->decode($$dataref) } } or {}
l!l
00
MC/DC0%0/1
eval { do { $json->decode($$dataref) } } or {}
eval { do { $json->decode($$dataref) } }
Truth table0%0/2
A
A= eval { do { $json->decode($$dataref) } }
Aresult
11
00
464 0 ▶ bless $data, ref $this || $this;
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
465 }
466  
467  
468 =head1 CAVEATS
469  
470 =over
471  
472 =item *
473  
474 You cannot search rows in a table using frozen columns
475  
476 =item *
477  
478 You cannot add relationships using frozen columns
479  
480 =back
481  
482 =head1 SEE ALSO
483  
484 L<Storable>, L<Data::Dumper>.
485  
486 =head1 AUTHOR
487  
488 Pronin Oleg <syber@cpan.org>
489  
490 =head1 LICENSE
491  
492 You may distribute this code under the same terms as Perl itself.
493  
494 =cut
495  
496 3 1;
↑ Summary