| 1 | package ObjectDB::InflateColumn; | ||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 3 | our $VERSION = '0.01'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
| |||||||||||||||||||||
| 8 | 3 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 3 | ▶ | use Module::Util qw(); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 3 | ▶ | unless (Module::Util::module_is_loaded('ObjectDB')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 11 | 0 | croak __PACKAGE__." can't be loaded before ObjectDB" | |||||||||||||||||||
| 12 | } | ||||||||||||||||||||
| 13 | # ok, lets go | ||||||||||||||||||||
| 14 | } | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 3 | ▶ | use Sub::Install; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 3 | my $imported = 0; | |||||||||||||||||||
| 19 | 3 | ▶ | sub import { | ||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=15.0
| |||||||||||||||||||||
| 20 | 3 | my $class = shift; | |||||||||||||||||||
| 21 | 3 | ▶ | return if $imported; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | # extend ObjectDB::Schema | ||||||||||||||||||||
| 24 | Sub::Install::install_sub({ | ||||||||||||||||||||
| 25 | 0 | ▶ | code => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||
| 26 | 0 | my $self = shift; | |||||||||||||||||||
| 27 | 0 | my $field = shift; | |||||||||||||||||||
| 28 | 0 | ▶ | unless ($field) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 0 | ▶ | return $self->{_inflate_columns_info} ||= {}; | ||||||||||||||||||
|
Condition0%0/2
$self->{"_inflate_columns_info"} ||= {}
MC/DC0%0/1
$self->{"_inflate_columns_info"} ||= {}
$self->{"_inflate_columns_info"}
Truth table0%0/2
A
A= $self->{"_inflate_columns_info"}
| |||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||
| 31 | 0 | ▶ | my $param = ref $_[0] eq 'HASH' ? $_[0] : {@_}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 0 | ▶ | $param->{inflate} ||= sub {$_[0]}; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$param->{"inflate"} ||= sub {
$_[0];
}
MC/DC0%0/2
$param->{"inflate"} ||= sub {
$_[0];
}
$param->{"inflate"}
sub {
$_[0];
}
Truth table0%0/3
A ||= B
A= $param->{"inflate"}B= sub {
$_[0];
}
| |||||||||||||||||||||
| 33 | 0 | ▶ | $param->{deflate} ||= sub {$_[0]}; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$param->{"deflate"} ||= sub {
$_[0];
}
MC/DC0%0/2
$param->{"deflate"} ||= sub {
$_[0];
}
$param->{"deflate"}
sub {
$_[0];
}
Truth table0%0/3
A ||= B
A= $param->{"deflate"}B= sub {
$_[0];
}
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | $self->{_inflate_columns_info}->{$field} = $param; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | return 1; | |||||||||||||||||||
| 38 | }, | ||||||||||||||||||||
| 39 | 3 | into => 'ObjectDB::Schema', | |||||||||||||||||||
| 40 | as => 'inflate_column' | ||||||||||||||||||||
| 41 | }); | ||||||||||||||||||||
| 42 | # method 'inflate_column' has been added | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | Sub::Install::install_sub({ | ||||||||||||||||||||
| 45 | 0 | ▶ | code => sub {$_[0]->{_inflate_columns_info} ||= {}}, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]{"_inflate_columns_info"} ||= {}
MC/DC0%0/1
$_[0]{"_inflate_columns_info"} ||= {}
$_[0]{"_inflate_columns_info"}
Truth table0%0/2
A
A= $_[0]{"_inflate_columns_info"}
| |||||||||||||||||||||
| 46 | 3 | into => 'ObjectDB::Schema', | |||||||||||||||||||
| 47 | as => '_inflate_columns_info' | ||||||||||||||||||||
| 48 | }); | ||||||||||||||||||||
| 49 | # method '_inflate_columns_info' has been added (access to field {_inflate_columns_info}) | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | # extend ObjectDB | ||||||||||||||||||||
| 52 | Sub::Install::install_sub({ | ||||||||||||||||||||
| 53 | 0 | ▶ | code => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 54 | 0 | my $self = shift; | |||||||||||||||||||
| 55 | 0 | my $inflate_info = $self->schema->_inflate_columns_info; | |||||||||||||||||||
| 56 | 0 | ▶ | if (exists $inflate_info->{$_[0]}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 0 | ▶ | if (@_==1) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 58 | 0 | return $inflate_info->{$_[0]}->{deflate}->($self->column($_[0])); | |||||||||||||||||||
| 59 | } elsif (@_==2) { | ||||||||||||||||||||
| 60 | 0 | return $self->column($_[0], $inflate_info->{$_[0]}->{inflate}->($_[1])); | |||||||||||||||||||
| 61 | }; | ||||||||||||||||||||
| 62 | }; | ||||||||||||||||||||
| 63 | 0 | return $self->column(@_); | |||||||||||||||||||
| 64 | }, | ||||||||||||||||||||
| 65 | 3 | into => 'ObjectDB', | |||||||||||||||||||
| 66 | as => 'inflate_column' | ||||||||||||||||||||
| 67 | }); | ||||||||||||||||||||
| 68 | # method 'inflate_column' has been added | ||||||||||||||||||||
| 69 | 3 | $imported++; | |||||||||||||||||||
| 70 | }; | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 3 | 1; | |||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||