| 1 | package DBomb::Value::Column; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | DBomb::Value::Column - The value in a single colummn. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =cut | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | our $VERSION = '$Revision: 1.7 $'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Carp::Assert; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Carp qw(carp croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use base qw(DBomb::Value); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | use Class::MethodMaker | ||||||||||||||||||||||||||||
| 18 | 1 | ▶ | 'new_with_init' => 'new', | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 'get_set' => [ qw(column_info), ## column_info object | ||||||||||||||||||||||||||||
| 20 | ], | ||||||||||||||||||||||||||||
| 21 | 'boolean' => [ qw(has_value), ## so we can tell between undef and NULL | ||||||||||||||||||||||||||||
| 22 | qw(is_modified), ## local value is logically different than database value | ||||||||||||||||||||||||||||
| 23 | ], | ||||||||||||||||||||||||||||
| 24 | 1 | ; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | ## init($column_info) | ||||||||||||||||||||||||||||
| 27 | ## init($column_info,$value) | ||||||||||||||||||||||||||||
| 28 | sub init | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | assert(UNIVERSAL::isa($_[0],'DBomb::Meta::ColumnInfo'), __PACKAGE__ .' requires column info object'); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | $self->column_info(shift); | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | $self->value(shift) if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | ## accessor | ||||||||||||||||||||||||||||
| 39 | sub value | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
value: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | if (@_){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | $self->is_modified(1); | |||||||||||||||||||||||||||
| 44 | 0 | $self->{'value'} = shift; | |||||||||||||||||||||||||||
| 45 | 0 | $self->has_value(1); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 0 | $self->{'value'}; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | sub clear | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 53 | 0 | $self->value(undef); | |||||||||||||||||||||||||||
| 54 | 0 | $self->has_value(0); | |||||||||||||||||||||||||||
| 55 | 0 | $self->is_modified(0); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | ## set_value_from_select($value) | ||||||||||||||||||||||||||||
| 59 | sub set_value_from_select | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_value_from_select: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | 0 | assert(@_ == 1, 'value_for_select has 1 argument'); | |||||||||||||||||||||||||||
| 63 | 0 | my $v = shift; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | my $cinfo = $self->column_info; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if (not defined $v){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | my $swn = $cinfo->select_when_null; | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | $v = $swn->[0] if scalar @$swn; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if (defined $v && $cinfo->select_trim){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $v and $cinfo->select_trim
MC/DC0%0/2
defined $v and $cinfo->select_trim
defined $v
$cinfo->select_trim
Truth table0%0/3
A and B
A= defined $vB= $cinfo->select_trim
| |||||||||||||||||||||||||||||
| 73 | 0 | $v =~ s/^\s+//; | |||||||||||||||||||||||||||
| 74 | 0 | $v =~ s/\s+$//; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | #TODO: trigger | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | $self->value($v); | |||||||||||||||||||||||||||
| 80 | 0 | $self->is_modified(0); | |||||||||||||||||||||||||||
| 81 | 0 | return $self->value; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | ## get_value_for_update() | ||||||||||||||||||||||||||||
| 85 | sub get_value_for_update | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_value_for_update: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 88 | 0 | assert(@_ == 0, 'value_for_update has no arguments'); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return undef unless $self->has_value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | my $v = $self->value; | |||||||||||||||||||||||||||
| 92 | 0 | my $cinfo = $self->column_info; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | ## process the value | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if (defined $v){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if ($cinfo->update_trim){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | $v =~ s/^\s+//; | |||||||||||||||||||||||||||
| 98 | 0 | $v =~ s/\s+$//; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (0 == length $v){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | my $uwe = $cinfo->update_when_empty; | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | $v = $uwe->[0] if scalar @$uwe; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | #TODO: trigger | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | return $v; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | 1; | |||||||||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||||||||||