| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
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
|
|
|
1
|
|
2447
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
44
|
|
|
11
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
52
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '$Revision: 1.7 $'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use Carp::Assert; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
10
|
|
|
15
|
1
|
|
|
1
|
|
177
|
use Carp qw(carp croak); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
72
|
|
|
16
|
1
|
|
|
1
|
|
94
|
use base qw(DBomb::Value); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
451
|
|
|
17
|
|
|
|
|
|
|
use Class::MethodMaker |
|
18
|
1
|
|
|
|
|
24
|
'new_with_init' => 'new', |
|
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
|
|
|
1
|
|
14
|
; |
|
|
1
|
|
|
|
|
353
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
## init($column_info) |
|
27
|
|
|
|
|
|
|
## init($column_info,$value) |
|
28
|
|
|
|
|
|
|
sub init |
|
29
|
|
|
|
|
|
|
{ |
|
30
|
0
|
|
|
0
|
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
|
0
|
|
|
|
|
$self->value(shift) if @_; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
## accessor |
|
39
|
|
|
|
|
|
|
sub value |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
42
|
0
|
0
|
|
|
|
|
if (@_){ |
|
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
|
|
|
|
|
|
|
{ |
|
52
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
{ |
|
61
|
0
|
|
|
0
|
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
|
0
|
|
|
|
|
if (not defined $v){ |
|
68
|
0
|
|
|
|
|
|
my $swn = $cinfo->select_when_null; |
|
69
|
0
|
0
|
|
|
|
|
$v = $swn->[0] if scalar @$swn; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
0
|
0
|
|
|
|
if (defined $v && $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
|
|
|
|
|
|
|
{ |
|
87
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
88
|
0
|
|
|
|
|
|
assert(@_ == 0, 'value_for_update has no arguments'); |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
return undef unless $self->has_value; |
|
91
|
0
|
|
|
|
|
|
my $v = $self->value; |
|
92
|
0
|
|
|
|
|
|
my $cinfo = $self->column_info; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
## process the value |
|
95
|
0
|
0
|
|
|
|
|
if (defined $v){ |
|
96
|
0
|
0
|
|
|
|
|
if ($cinfo->update_trim){ |
|
97
|
0
|
|
|
|
|
|
$v =~ s/^\s+//; |
|
98
|
0
|
|
|
|
|
|
$v =~ s/\s+$//; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
if (0 == length $v){ |
|
102
|
0
|
|
|
|
|
|
my $uwe = $cinfo->update_when_empty; |
|
103
|
0
|
0
|
|
|
|
|
$v = $uwe->[0] if scalar @$uwe; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
#TODO: trigger |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return $v; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
|
113
|
|
|
|
|
|
|
__END__ |