line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ODS::Table; |
2
|
|
|
|
|
|
|
|
3
|
73
|
|
|
73
|
|
371
|
use strict; |
|
73
|
|
|
|
|
145
|
|
|
73
|
|
|
|
|
1750
|
|
4
|
73
|
|
|
73
|
|
231
|
use warnings; |
|
73
|
|
|
|
|
134
|
|
|
73
|
|
|
|
|
1329
|
|
5
|
|
|
|
|
|
|
|
6
|
73
|
|
|
73
|
|
26706
|
use YAOO; |
|
73
|
|
|
|
|
1848320
|
|
|
73
|
|
|
|
|
381
|
|
7
|
|
|
|
|
|
|
|
8
|
73
|
|
|
73
|
|
46999
|
use ODS::Utils qw/clone/; |
|
73
|
|
|
|
|
214
|
|
|
73
|
|
|
|
|
373
|
|
9
|
|
|
|
|
|
|
|
10
|
73
|
|
|
73
|
|
2854
|
use ODS::Utils qw/load build_temp_class/; |
|
73
|
|
|
|
|
140
|
|
|
73
|
|
|
|
|
278
|
|
11
|
|
|
|
|
|
|
|
12
|
73
|
|
|
73
|
|
2171
|
use Carp qw/croak/; |
|
73
|
|
|
|
|
153
|
|
|
73
|
|
|
|
|
50859
|
|
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
|
1108
|
|
|
1108
|
0
|
2285
|
my ($self, @args) = @_; |
40
|
|
|
|
|
|
|
|
41
|
1108
|
|
|
|
|
1208
|
my $name = shift @args; |
42
|
|
|
|
|
|
|
|
43
|
1108
|
100
|
|
|
|
1718
|
if (!$self->keyfield) { |
44
|
86
|
|
|
|
|
595
|
$self->keyfield($name); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
1108
|
50
|
|
|
|
7154
|
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
|
1108
|
50
|
|
|
|
11661
|
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
|
1108
|
|
|
|
|
3012
|
my %column = @args; |
58
|
1108
|
|
|
|
|
1414
|
$column{name} = $name; |
59
|
1108
|
100
|
|
|
|
1948
|
if (! $column{type}) { |
60
|
450
|
|
|
|
|
658
|
$column{type} = 'string'; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
1108
|
100
|
|
|
|
1832
|
if ($column{keyfield}) { |
64
|
84
|
|
|
|
|
238
|
$self->keyfield($name); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
1108
|
|
|
|
|
3502
|
my $module = 'ODS::Table::Column::' . ucfirst($column{type}); |
68
|
|
|
|
|
|
|
|
69
|
1108
|
|
|
|
|
2175
|
load $module; |
70
|
|
|
|
|
|
|
|
71
|
1108
|
|
|
|
|
3046
|
my $column = $module->new(\%column); |
72
|
|
|
|
|
|
|
|
73
|
1108
|
|
|
|
|
171862
|
$self->columns->{$name} = $column; |
74
|
|
|
|
|
|
|
|
75
|
1108
|
|
|
|
|
21505
|
return $self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub connect { |
79
|
142
|
|
|
142
|
0
|
1013
|
my ($self, $package, $storage, $connect) = (shift, shift, shift, shift); |
80
|
|
|
|
|
|
|
|
81
|
142
|
|
|
|
|
1336
|
$self->set_table_resultset_row_class($package); |
82
|
|
|
|
|
|
|
|
83
|
142
|
|
|
|
|
4329
|
my $serialize_class; |
84
|
142
|
100
|
|
|
|
744
|
if ( $connect->{serialize_class} ) { |
85
|
138
|
|
|
|
|
851
|
$serialize_class = 'ODS::Serialize::' . $connect->{serialize_class}; |
86
|
138
|
|
|
|
|
726
|
load $serialize_class; |
87
|
138
|
|
|
|
|
1465
|
$serialize_class = $serialize_class->new; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
142
|
50
|
|
|
|
14457
|
$self->storage_class($storage) if $storage; |
91
|
|
|
|
|
|
|
|
92
|
142
|
|
|
|
|
3477
|
$storage = $self->storage_class; |
93
|
|
|
|
|
|
|
|
94
|
142
|
|
|
|
|
1160
|
my $module = 'ODS::Storage::' . $storage; |
95
|
|
|
|
|
|
|
|
96
|
142
|
|
|
|
|
623
|
load $module; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$self->storage( |
99
|
|
|
|
|
|
|
$module->connect( |
100
|
142
|
50
|
|
|
|
413
|
%{$connect || {}}, |
|
142
|
100
|
|
|
|
2331
|
|
101
|
|
|
|
|
|
|
table => $self, |
102
|
|
|
|
|
|
|
($serialize_class ? (serialize_class => $serialize_class) : ()) |
103
|
|
|
|
|
|
|
) |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
142
|
|
|
|
|
4447
|
return $self->resultset($self->resultset_class->new(table => $self, @_)); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
has parent_column => isa(object); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub instantiate { |
112
|
8
|
|
|
8
|
0
|
25
|
my ($self, $package, $column, $inflated, $data) = @_; |
113
|
|
|
|
|
|
|
|
114
|
8
|
|
|
|
|
23
|
$self->parent_column($column); |
115
|
|
|
|
|
|
|
|
116
|
8
|
|
|
|
|
205
|
$self->set_table_resultset_row_class($package); |
117
|
|
|
|
|
|
|
|
118
|
8
|
|
50
|
|
|
126
|
my $row = $self->row_class->new( |
119
|
|
|
|
|
|
|
table => $self, |
120
|
|
|
|
|
|
|
data => $data, |
121
|
|
|
|
|
|
|
inflated => $inflated || 0, |
122
|
|
|
|
|
|
|
serialize_class => $column->serialize_class |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
|
125
|
8
|
|
|
|
|
49
|
return $row; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub set_table_resultset_row_class { |
129
|
150
|
|
|
150
|
0
|
681
|
my ($self, $package) = @_; |
130
|
|
|
|
|
|
|
|
131
|
150
|
|
|
|
|
1274
|
$self->table_class($package); |
132
|
|
|
|
|
|
|
|
133
|
150
|
|
|
|
|
7031
|
(my $resultset = $package) =~ s/Table/ResultSet/g; |
134
|
|
|
|
|
|
|
|
135
|
150
|
|
|
|
|
673
|
eval { |
136
|
150
|
|
|
|
|
1227
|
load $resultset |
137
|
|
|
|
|
|
|
}; |
138
|
|
|
|
|
|
|
|
139
|
150
|
100
|
|
|
|
640
|
if ($@) { |
140
|
20
|
|
|
|
|
52
|
$resultset = 'ODS::Table::ResultSet'; |
141
|
20
|
|
|
|
|
64
|
load $resultset; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
150
|
|
|
|
|
1059
|
$self->resultset_class($resultset); |
145
|
|
|
|
|
|
|
|
146
|
150
|
|
|
|
|
4567
|
(my $row = $package) =~ s/Table/Row/g; |
147
|
|
|
|
|
|
|
|
148
|
150
|
|
|
|
|
358
|
eval { |
149
|
150
|
|
|
|
|
376
|
load $row |
150
|
|
|
|
|
|
|
}; |
151
|
|
|
|
|
|
|
|
152
|
150
|
50
|
|
|
|
944
|
if ($@) { |
153
|
150
|
|
|
|
|
1576
|
$row = build_temp_class('ODS::Table::Row'); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
150
|
|
|
|
|
1142
|
$self->row_class($row); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
1; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
__END__ |