line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBomb::Meta::ColumnInfo; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
DBomb::Meta::ColumnInfo - Meta data about a column. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
1612
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
12
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
13
|
|
|
|
|
|
|
our $VERSION = '$Revision: 1.15 $'; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
5
|
use Carp qw(carp croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
16
|
1
|
|
|
1
|
|
5
|
use Carp::Assert; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
17
|
|
|
|
|
|
|
use Class::MethodMaker |
18
|
1
|
|
|
|
|
12
|
'new_with_init' => 'new_internal', |
19
|
|
|
|
|
|
|
'get_set' => [qw(table_info), # table_info |
20
|
|
|
|
|
|
|
qw(name), # column name |
21
|
|
|
|
|
|
|
qw(fq_name), # fully qualified -- read only |
22
|
|
|
|
|
|
|
qw(accessor), # accessor name |
23
|
|
|
|
|
|
|
qw(attr), # attribute name |
24
|
|
|
|
|
|
|
qw(select_when_null), # list of 1 element. promote NULLs to this value. default: [] |
25
|
|
|
|
|
|
|
qw(update_when_empty), # list of 1 element. promote empty string to this value. default: [] |
26
|
|
|
|
|
|
|
], |
27
|
|
|
|
|
|
|
'boolean' => [qw(is_resolved), |
28
|
|
|
|
|
|
|
qw(is_expr), # Is an expression column (not a real column) |
29
|
|
|
|
|
|
|
qw(is_generated), # database generates it (auto_increment, etc.) |
30
|
|
|
|
|
|
|
qw(select_trim), # trim whitespace |
31
|
|
|
|
|
|
|
qw(update_trim), # trim whitespace |
32
|
|
|
|
|
|
|
qw(recurse_on_copy), # deep copy |
33
|
|
|
|
|
|
|
], |
34
|
1
|
|
|
1
|
|
197
|
; |
|
1
|
|
|
|
|
3
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
## new ColumnInfo($table_info, $name, $opts) |
37
|
|
|
|
|
|
|
sub new |
38
|
|
|
|
|
|
|
{ |
39
|
|
|
|
|
|
|
## This new() is actually a class factory, following a parameterized singleton pattern |
40
|
|
|
|
|
|
|
## The real new() is new_internal(). |
41
|
0
|
0
|
|
0
|
0
|
|
my $class = ref($_[0]) ? ref(shift) : shift; |
42
|
0
|
|
|
|
|
|
my ($table_info,$name,$opts) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
assert(defined $table_info); |
45
|
0
|
|
|
|
|
|
assert(defined $name); |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $cols = DBomb->tables->{$table_info->name}->columns; |
48
|
0
|
0
|
|
|
|
|
if (exists $cols->{$name}){ |
49
|
0
|
|
|
|
|
|
croak "duplicate column name '$name' for table " . $table_info->name; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else{ |
52
|
0
|
|
|
|
|
|
$table_info->add_column($class->new_internal($table_info, $name, $opts)); |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
|
return $cols->{$name}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub init |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
|
|
0
|
0
|
|
my ($self, $table_info, $name, $opts) = @_; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
assert(defined($table_info), "table_info defined"); |
62
|
0
|
|
|
|
|
|
assert(defined($name), "column name defined"); |
63
|
0
|
|
|
|
|
|
assert(defined($opts), "options defined"); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$self->table_info($table_info); |
66
|
0
|
|
|
|
|
|
$self->name($name); |
67
|
0
|
|
|
|
|
|
$self->fq_name($self->table_info->name .".". $self->name); |
68
|
0
|
|
|
|
|
|
$self->is_resolved(1); ## nothing to resolve |
69
|
0
|
|
|
|
|
|
$self->select_trim(0); |
70
|
0
|
|
|
|
|
|
$self->update_trim(0); |
71
|
0
|
|
|
|
|
|
$self->recurse_on_copy(0); |
72
|
0
|
|
|
|
|
|
$self->select_when_null([]); |
73
|
0
|
|
|
|
|
|
$self->update_when_empty([]); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
## defaults |
76
|
0
|
|
|
|
|
|
$self->accessor($name); |
77
|
0
|
|
|
|
|
|
$self->attr("__dbo_column: $name"); |
78
|
0
|
0
|
|
|
|
|
$self->enable_string_mangle if $opts->{'string_mangle'}; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
for (keys %$opts) { |
81
|
0
|
|
|
|
|
|
my $v = $opts->{$_}; |
82
|
0
|
0
|
|
|
|
|
/^column$/ && do{ $self->name($v); next}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
/^accessor$/ && do{ $self->accessor($v); next}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
/^attr$/ && do{ $self->attr($v); next}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
/^expr(?:ession)?$/ && do{ $self->name($v); $self->fq_name($v); $self->is_expr(1); next}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
/^is_generated|auto_increment$/ && do{ $self->is_generated($v); next}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
/^select_trim$/ && do{ $self->select_trim($v); next}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
/^update_trim$/ && do{ $self->update_trim($v); next}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
/^recurse_on_copy$/ && do{ $self->recurse_on_copy($v); next}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
/^select_when_null$/ && do{ $self->select_when_null->[0] = $v; next}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
/^update_when_empty$/ && do{ $self->update_when_empty->[0] = $v; next}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
/^string_mangle$/ && do { next; }; # handled above. |
|
0
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
croak "unrecognized option '$_'"; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub is_in_primary_key |
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
100
|
0
|
|
|
|
|
|
assert(@_ == 0); |
101
|
0
|
|
|
|
|
|
exists $self->table_info->primary_key->columns->{$self->name}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub enable_string_mangle |
105
|
|
|
|
|
|
|
{ |
106
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
107
|
0
|
|
|
|
|
|
$self->select_trim(1); |
108
|
0
|
|
|
|
|
|
$self->update_trim(1); |
109
|
0
|
|
|
|
|
|
$self->select_when_null->[0] = ''; |
110
|
0
|
|
|
|
|
|
$self->update_when_empty->[0] = undef; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
0
|
0
|
|
sub resolve { 1 } |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
__END__ |