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