line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (C) 2003-2007, G. Allen Morris III, all rights reserved |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
46
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
448
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package |
6
|
|
|
|
|
|
|
Data::Tabular::Table::Group; |
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
40
|
use base 'Data::Tabular::Table'; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
606
|
|
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
18694
|
use Data::Tabular::Group::Interface; |
|
7
|
|
|
|
|
23
|
|
|
7
|
|
|
|
|
5773
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new |
13
|
|
|
|
|
|
|
{ |
14
|
56
|
|
|
56
|
1
|
79
|
my $class = shift; |
15
|
56
|
|
|
|
|
377
|
bless { @_ }, $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _row_count |
19
|
|
|
|
|
|
|
{ |
20
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
0
|
die; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub sum_list |
26
|
|
|
|
|
|
|
{ |
27
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
28
|
0
|
|
|
|
|
0
|
$self->group->sum_list; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub column_sum |
32
|
|
|
|
|
|
|
{ |
33
|
89
|
|
|
89
|
0
|
3702
|
my $self = shift; |
34
|
89
|
|
|
|
|
737
|
my $column_name = shift; |
35
|
89
|
|
|
|
|
103
|
my $ret; |
36
|
89
|
50
|
|
|
|
1206
|
if ($ret = $self->{memo}->{$column_name}) { |
37
|
0
|
|
|
|
|
0
|
return $ret; |
38
|
|
|
|
|
|
|
} |
39
|
89
|
|
|
|
|
129
|
my $formula = '=SUM('; |
40
|
89
|
|
|
|
|
144
|
my $sum = 0; |
41
|
89
|
|
|
|
|
113
|
my @rows; |
42
|
89
|
|
|
|
|
434
|
for my $row ($self->raw_rows) { |
43
|
355
|
|
|
|
|
22161
|
push(@rows, $row->id()); |
44
|
355
|
|
|
|
|
1012
|
my $next = $row->get($column_name); |
45
|
355
|
50
|
|
|
|
6031
|
if (UNIVERSAL::isa($next, 'Data::Tabular::Formula')) { |
46
|
0
|
|
|
|
|
0
|
die; |
47
|
0
|
|
|
|
|
0
|
$next = $next->{html}; |
48
|
|
|
|
|
|
|
} |
49
|
355
|
|
|
|
|
1130
|
$sum += $next; |
50
|
|
|
|
|
|
|
} |
51
|
89
|
|
|
|
|
2454
|
require Data::Tabular::Type::Formula; |
52
|
|
|
|
|
|
|
|
53
|
89
|
|
|
|
|
833
|
$ret = Data::Tabular::Type::Formula->new( |
54
|
|
|
|
|
|
|
data => $sum, |
55
|
|
|
|
|
|
|
type => 'sum', |
56
|
|
|
|
|
|
|
column => $column_name, |
57
|
|
|
|
|
|
|
rows => \@rows, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
89
|
|
|
|
|
465
|
$self->{memo}->{$column_name} = $ret; |
61
|
89
|
|
|
|
|
377
|
$ret; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub column_average |
65
|
|
|
|
|
|
|
{ |
66
|
5
|
|
|
5
|
0
|
8
|
my $self = shift; |
67
|
5
|
|
|
|
|
8
|
my $column_name = shift; |
68
|
5
|
|
|
|
|
5
|
my $ret; |
69
|
5
|
50
|
|
|
|
16
|
if ($ret = $self->{memoa}->{$column_name}) { |
70
|
0
|
|
|
|
|
0
|
return $ret; |
71
|
|
|
|
|
|
|
} |
72
|
5
|
|
|
|
|
7
|
my $formula = '=SUM('; |
73
|
5
|
|
|
|
|
8
|
my $sum = 0; |
74
|
5
|
|
|
|
|
6
|
my @rows; |
75
|
5
|
|
|
|
|
6
|
my $count = 0; |
76
|
5
|
|
|
|
|
12
|
for my $row ($self->raw_rows) { |
77
|
55
|
|
|
|
|
149
|
push(@rows, $row->id()); |
78
|
55
|
|
|
|
|
144
|
my $next = $row->get($column_name); |
79
|
55
|
50
|
|
|
|
281
|
if (UNIVERSAL::isa($next, 'Data::Tabular::Formula')) { |
80
|
0
|
|
|
|
|
0
|
die; |
81
|
0
|
|
|
|
|
0
|
$next = $next->{html}; |
82
|
|
|
|
|
|
|
} |
83
|
55
|
|
|
|
|
143
|
$sum += $next; |
84
|
55
|
|
|
|
|
139
|
$count++; |
85
|
|
|
|
|
|
|
} |
86
|
5
|
|
|
|
|
31
|
require Data::Tabular::Type::Formula; |
87
|
|
|
|
|
|
|
|
88
|
5
|
|
|
|
|
25
|
$ret = Data::Tabular::Type::Formula->new( |
89
|
|
|
|
|
|
|
data => $sum / $count, |
90
|
|
|
|
|
|
|
count => $count, |
91
|
|
|
|
|
|
|
type => 'avg', |
92
|
|
|
|
|
|
|
column => $column_name, |
93
|
|
|
|
|
|
|
rows => \@rows, |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
5
|
|
|
|
|
14
|
$self->{memoa}->{$column_name} = $ret; |
97
|
5
|
|
|
|
|
15
|
$ret; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub group |
101
|
|
|
|
|
|
|
{ |
102
|
256
|
|
|
256
|
0
|
319
|
my $self = shift; |
103
|
256
|
|
|
|
|
964
|
$self->{group}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub headers |
107
|
|
|
|
|
|
|
{ |
108
|
256
|
|
|
256
|
1
|
364
|
my $self = shift; |
109
|
256
|
|
|
|
|
580
|
$self->group->headers; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub all_headers |
113
|
|
|
|
|
|
|
{ |
114
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
0
|
$self->group->headers; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub raw_rows |
120
|
|
|
|
|
|
|
{ |
121
|
362
|
|
|
362
|
0
|
441
|
my $self = shift; |
122
|
362
|
|
|
|
|
897
|
my @ret = (); |
123
|
|
|
|
|
|
|
|
124
|
362
|
|
|
|
|
387
|
for my $value (@{$self->{data}}) { |
|
362
|
|
|
|
|
2699
|
|
125
|
678
|
50
|
|
|
|
1861
|
next unless $value; |
126
|
678
|
100
|
|
|
|
3518
|
if ($value->isa(__PACKAGE__)) { |
127
|
268
|
|
|
|
|
523
|
push(@ret, $value->raw_rows); |
128
|
|
|
|
|
|
|
} else { |
129
|
410
|
|
|
|
|
909
|
push(@ret, $value); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
362
|
|
|
|
|
1489
|
@ret; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub level |
136
|
|
|
|
|
|
|
{ |
137
|
112
|
|
|
112
|
0
|
523
|
shift->{level}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub groups |
141
|
|
|
|
|
|
|
{ |
142
|
112
|
|
|
112
|
0
|
161
|
my $self = shift; |
143
|
112
|
|
|
|
|
399
|
$self->{group}->{groups}; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub get_column |
147
|
|
|
|
|
|
|
{ |
148
|
32
|
|
|
32
|
0
|
42
|
my $self = shift; |
149
|
32
|
|
|
|
|
70
|
$self->get(@_); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub get |
153
|
|
|
|
|
|
|
{ |
154
|
76
|
|
|
76
|
0
|
88
|
my $self = shift; |
155
|
76
|
|
|
|
|
100
|
my $key = shift; |
156
|
|
|
|
|
|
|
|
157
|
76
|
|
|
|
|
239
|
my $ret = $self->{data}->[0]->get_column($key); |
158
|
76
|
|
|
|
|
250
|
my $ret1 = $self->{data}->[-1]->get_column($key); |
159
|
76
|
50
|
|
|
|
239
|
unless ($ret->{data} eq $ret1->{data}) { |
160
|
7
|
|
|
7
|
|
63
|
use Data::Dumper; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
4840
|
|
161
|
0
|
|
|
|
|
0
|
die Dumper $ret, $ret1; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
76
|
|
|
|
|
408
|
$ret; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub get_all |
168
|
|
|
|
|
|
|
{ |
169
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
170
|
0
|
|
|
|
|
0
|
my $key = shift; |
171
|
0
|
|
|
|
|
0
|
my $temp = {}; |
172
|
0
|
|
|
|
|
0
|
my @ret; |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
0
|
for my $value (@{$self->{data}}) { |
|
0
|
|
|
|
|
0
|
|
175
|
0
|
0
|
|
|
|
0
|
next unless $value; |
176
|
0
|
|
|
|
|
0
|
my $item = $value->get_column($key); |
177
|
0
|
0
|
|
|
|
0
|
unless ($temp->{$item}++) { |
178
|
0
|
|
|
|
|
0
|
push(@ret, $item); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
0
|
\@ret; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub rows |
186
|
|
|
|
|
|
|
{ |
187
|
56
|
|
|
56
|
1
|
97
|
my $self = shift; |
188
|
56
|
|
|
|
|
294
|
my $info = { |
189
|
|
|
|
|
|
|
@_, |
190
|
|
|
|
|
|
|
row => 0, |
191
|
|
|
|
|
|
|
pre_once => 0, |
192
|
|
|
|
|
|
|
x => 'ok' |
193
|
|
|
|
|
|
|
}; |
194
|
56
|
50
|
|
|
|
223
|
return $self->{rows} if $self->{rows}; |
195
|
|
|
|
|
|
|
|
196
|
56
|
50
|
|
|
|
149
|
return unless $self->{data}; |
197
|
56
|
50
|
|
|
|
194
|
return unless $self->{data}->[0]; |
198
|
|
|
|
|
|
|
|
199
|
56
|
|
|
|
|
98
|
my $rid = 1; |
200
|
56
|
|
|
|
|
97
|
my @ret = (); |
201
|
56
|
50
|
|
|
|
175
|
if (my $action = $self->groups->[$self->level]->{pre}) { |
202
|
56
|
|
|
|
|
277
|
my $grouper = Data::Tabular::Group::Interface->new( |
203
|
|
|
|
|
|
|
group => $self, |
204
|
|
|
|
|
|
|
); |
205
|
56
|
|
|
|
|
186
|
my @data = $action->($grouper); |
206
|
56
|
|
|
|
|
112
|
eval { |
207
|
56
|
|
|
|
|
115
|
push(@ret, map({ $_->{row_id} = $rid++; $_->{output} = $info->{output}; $_ } @data)); |
|
60
|
|
|
|
|
162
|
|
|
60
|
|
|
|
|
139
|
|
|
60
|
|
|
|
|
181
|
|
208
|
|
|
|
|
|
|
}; |
209
|
56
|
50
|
|
|
|
249
|
if ($@) { warn $@; } |
|
0
|
|
|
|
|
0
|
|
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
56
|
|
|
|
|
92
|
for my $value (@{$self->{data}}) { |
|
56
|
|
|
|
|
147
|
|
213
|
141
|
100
|
|
|
|
823
|
if (my $x = $value->isa(__PACKAGE__)) { |
214
|
44
|
|
|
|
|
206
|
push(@ret, map({ $_->{row_id} = $rid++; $_->{output} = $info->{output}; $_ } ($value->rows(%$info)))); |
|
223
|
|
|
|
|
350
|
|
|
223
|
|
|
|
|
365
|
|
|
223
|
|
|
|
|
509
|
|
215
|
|
|
|
|
|
|
} else { |
216
|
97
|
|
|
|
|
143
|
push(@ret, map({ $_->{row_id} = $rid++; $_->{output} = $info->{output}; $_ } ($value))); |
|
97
|
|
|
|
|
177
|
|
|
97
|
|
|
|
|
174
|
|
|
97
|
|
|
|
|
266
|
|
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
56
|
|
|
|
|
131
|
$info->{x} = 'ok'; |
221
|
56
|
100
|
|
|
|
140
|
if (my $action = $self->groups->[$self->level]->{post}) { |
222
|
48
|
|
|
|
|
191
|
my $grouper = Data::Tabular::Group::Interface->new( |
223
|
|
|
|
|
|
|
group => $self, |
224
|
|
|
|
|
|
|
table => $self, |
225
|
|
|
|
|
|
|
); |
226
|
48
|
|
|
|
|
139
|
my @data = $action->($grouper); |
227
|
48
|
|
|
|
|
118
|
push(@ret, map({ $_->{row_id} = $rid++; $_->{output} = $info->{output}; $_ } @data)); |
|
52
|
|
|
|
|
120
|
|
|
52
|
|
|
|
|
106
|
|
|
52
|
|
|
|
|
192
|
|
228
|
|
|
|
|
|
|
} |
229
|
56
|
|
|
|
|
133
|
$self->{rows} = \@ret; |
230
|
56
|
|
|
|
|
80
|
@{$self->{rows}}; |
|
56
|
|
|
|
|
316
|
|
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
1; |
234
|
|
|
|
|
|
|
__END__ |