line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ODS::Table; |
2
|
|
|
|
|
|
|
|
3
|
73
|
|
|
73
|
|
373
|
use strict; |
|
73
|
|
|
|
|
139
|
|
|
73
|
|
|
|
|
1816
|
|
4
|
73
|
|
|
73
|
|
257
|
use warnings; |
|
73
|
|
|
|
|
80
|
|
|
73
|
|
|
|
|
1397
|
|
5
|
|
|
|
|
|
|
|
6
|
73
|
|
|
73
|
|
27328
|
use YAOO; |
|
73
|
|
|
|
|
1783776
|
|
|
73
|
|
|
|
|
393
|
|
7
|
|
|
|
|
|
|
|
8
|
73
|
|
|
73
|
|
46723
|
use ODS::Utils qw/clone/; |
|
73
|
|
|
|
|
984
|
|
|
73
|
|
|
|
|
647
|
|
9
|
|
|
|
|
|
|
|
10
|
73
|
|
|
73
|
|
6717
|
use ODS::Utils qw/load build_temp_class/; |
|
73
|
|
|
|
|
1409
|
|
|
73
|
|
|
|
|
343
|
|
11
|
|
|
|
|
|
|
|
12
|
73
|
|
|
73
|
|
2259
|
use Carp qw/croak/; |
|
73
|
|
|
|
|
154
|
|
|
73
|
|
|
|
|
66869
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
auto_build; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has storage_class => isa(string); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has storage => isa(object); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has table_class => isa(string); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has resultset_class => isa(string); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has resultset => isa(object); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has name => isa(string); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has columns => isa(ordered_hash()), default(1); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has row_class => isa(string); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has rows => isa(array); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has options => isa(hash); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has keyfield => isa(string); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub add_column { |
39
|
1104
|
|
|
1104
|
0
|
2816
|
my ($self, @args) = @_; |
40
|
|
|
|
|
|
|
|
41
|
1104
|
|
|
|
|
1525
|
my $name = shift @args; |
42
|
|
|
|
|
|
|
|
43
|
1104
|
100
|
|
|
|
1795
|
if (!$self->keyfield) { |
44
|
86
|
|
|
|
|
1321
|
$self->keyfield($name); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
1104
|
50
|
|
|
|
6704
|
if ($self->columns->{$name}) { |
48
|
0
|
|
|
|
|
0
|
croak sprintf "Column %s is already defined in the %s table", |
49
|
|
|
|
|
|
|
$name, $self->name; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
1104
|
50
|
|
|
|
12808
|
if (scalar @args % 2) { |
53
|
0
|
|
|
|
|
0
|
croak "The column definition for %s does not contain an even number of key/values in the %s table.", |
54
|
|
|
|
|
|
|
$name, $self->name; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
1104
|
|
|
|
|
3607
|
my %column = @args; |
58
|
1104
|
|
|
|
|
1602
|
$column{name} = $name; |
59
|
1104
|
100
|
|
|
|
1777
|
if (! $column{type}) { |
60
|
442
|
|
|
|
|
658
|
$column{type} = 'string'; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
1104
|
100
|
|
|
|
1714
|
if ($column{keyfield}) { |
64
|
82
|
|
|
|
|
168
|
$self->keyfield($name); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
1104
|
|
|
|
|
3673
|
my $module = 'ODS::Table::Column::' . ucfirst($column{type}); |
68
|
|
|
|
|
|
|
|
69
|
1104
|
|
|
|
|
2429
|
load $module; |
70
|
|
|
|
|
|
|
|
71
|
1104
|
|
|
|
|
2800
|
for my $key ( keys %column ) { |
72
|
5505
|
100
|
|
|
|
7993
|
delete $column{$key} if not defined $column{$key}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
1104
|
|
|
|
|
3327
|
my $column = $module->new(\%column); |
76
|
|
|
|
|
|
|
|
77
|
1104
|
|
|
|
|
175053
|
$self->columns->{$name} = $column; |
78
|
|
|
|
|
|
|
|
79
|
1104
|
|
|
|
|
22276
|
return $self; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub add_item { |
83
|
1
|
|
|
1
|
0
|
17
|
my ($self, @args) = @_; |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
|
|
2
|
my $name = 'array_items'; |
86
|
|
|
|
|
|
|
|
87
|
1
|
50
|
|
|
|
3
|
if (!$self->keyfield) { |
88
|
1
|
|
|
|
|
7
|
$self->keyfield($name); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
1
|
50
|
|
|
|
15
|
if ($self->columns->{$name}) { |
92
|
0
|
|
|
|
|
0
|
croak sprintf "Column %s is already defined in the %s table", |
93
|
|
|
|
|
|
|
$name, $self->name; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
1
|
50
|
|
|
|
13
|
if (scalar @args % 2) { |
97
|
0
|
|
|
|
|
0
|
croak "The column definition for %s does not contain an even number of key/values in the %s table.", |
98
|
|
|
|
|
|
|
$name, $self->name; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
3
|
my %column = @args; |
102
|
1
|
|
|
|
|
2
|
$column{name} = $name; |
103
|
1
|
50
|
|
|
|
12
|
if (! $column{type}) { |
104
|
0
|
|
|
|
|
0
|
$column{type} = 'string'; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
4
|
my $module = 'ODS::Table::Column::' . ucfirst($column{type}); |
108
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
3
|
load $module; |
110
|
|
|
|
|
|
|
|
111
|
1
|
|
|
|
|
5
|
my $column = $module->new(\%column); |
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
137
|
$self->columns->{$name} = $column; |
114
|
|
|
|
|
|
|
|
115
|
1
|
|
|
|
|
17
|
return $self; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub connect { |
119
|
142
|
|
|
142
|
0
|
1418
|
my ($self, $package, $storage, $connect) = (shift, shift, shift, shift); |
120
|
|
|
|
|
|
|
|
121
|
142
|
|
|
|
|
1658
|
$self->set_table_resultset_row_class($package); |
122
|
|
|
|
|
|
|
|
123
|
142
|
|
|
|
|
3943
|
my $serialize_class; |
124
|
142
|
100
|
|
|
|
582
|
if ( $connect->{serialize_class} ) { |
125
|
138
|
|
|
|
|
529
|
$serialize_class = 'ODS::Serialize::' . $connect->{serialize_class}; |
126
|
138
|
|
|
|
|
537
|
load $serialize_class; |
127
|
138
|
|
|
|
|
1684
|
$serialize_class = $serialize_class->new; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
142
|
50
|
|
|
|
11969
|
$self->storage_class($storage) if $storage; |
131
|
|
|
|
|
|
|
|
132
|
142
|
|
|
|
|
2638
|
$storage = $self->storage_class; |
133
|
|
|
|
|
|
|
|
134
|
142
|
|
|
|
|
995
|
my $module = 'ODS::Storage::' . $storage; |
135
|
|
|
|
|
|
|
|
136
|
142
|
|
|
|
|
487
|
load $module; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$self->storage( |
139
|
|
|
|
|
|
|
$module->connect( |
140
|
142
|
50
|
|
|
|
405
|
%{$connect || {}}, |
|
142
|
100
|
|
|
|
2730
|
|
141
|
|
|
|
|
|
|
table => $self, |
142
|
|
|
|
|
|
|
($serialize_class ? (serialize_class => $serialize_class) : ()) |
143
|
|
|
|
|
|
|
) |
144
|
|
|
|
|
|
|
); |
145
|
|
|
|
|
|
|
|
146
|
142
|
|
|
|
|
4115
|
return $self->resultset($self->resultset_class->new(table => $self, @_)); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
has parent_column => isa(object); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub instantiate { |
152
|
23
|
|
|
23
|
0
|
53
|
my ($self, $package, $column, $inflated, $data) = @_; |
153
|
|
|
|
|
|
|
|
154
|
23
|
|
|
|
|
53
|
$self->parent_column($column); |
155
|
|
|
|
|
|
|
|
156
|
23
|
|
|
|
|
565
|
$self->set_table_resultset_row_class($package); |
157
|
|
|
|
|
|
|
|
158
|
23
|
|
50
|
|
|
448
|
my $row = $self->row_class->new( |
159
|
|
|
|
|
|
|
table => $self, |
160
|
|
|
|
|
|
|
data => $data, |
161
|
|
|
|
|
|
|
inflated => $inflated || 0, |
162
|
|
|
|
|
|
|
serialize_class => $column->serialize_class |
163
|
|
|
|
|
|
|
); |
164
|
|
|
|
|
|
|
|
165
|
23
|
|
|
|
|
192
|
return $row; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub set_table_resultset_row_class { |
169
|
165
|
|
|
165
|
0
|
543
|
my ($self, $package) = @_; |
170
|
|
|
|
|
|
|
|
171
|
165
|
|
|
|
|
1754
|
$self->table_class($package); |
172
|
|
|
|
|
|
|
|
173
|
165
|
|
|
|
|
9124
|
(my $resultset = $package) =~ s/Table/ResultSet/g; |
174
|
|
|
|
|
|
|
|
175
|
165
|
|
|
|
|
1579
|
eval { |
176
|
165
|
|
|
|
|
1155
|
load $resultset |
177
|
|
|
|
|
|
|
}; |
178
|
|
|
|
|
|
|
|
179
|
165
|
100
|
|
|
|
1730
|
if ($@) { |
180
|
35
|
|
|
|
|
63
|
$resultset = 'ODS::Table::ResultSet'; |
181
|
35
|
|
|
|
|
91
|
load $resultset; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
165
|
|
|
|
|
1172
|
$self->resultset_class($resultset); |
185
|
|
|
|
|
|
|
|
186
|
165
|
|
|
|
|
6589
|
(my $row = $package) =~ s/Table/Row/g; |
187
|
|
|
|
|
|
|
|
188
|
165
|
|
|
|
|
433
|
eval { |
189
|
165
|
|
|
|
|
804
|
load $row |
190
|
|
|
|
|
|
|
}; |
191
|
|
|
|
|
|
|
|
192
|
165
|
100
|
|
|
|
986
|
if ($@) { |
193
|
164
|
|
|
|
|
1110
|
$row = build_temp_class('ODS::Table::Row'); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
165
|
|
|
|
|
1268
|
$self->row_class($row); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
1; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
__END__ |