line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ODS::Iterator; |
2
|
|
|
|
|
|
|
|
3
|
72
|
|
|
72
|
|
431
|
use YAOO; |
|
72
|
|
|
|
|
140
|
|
|
72
|
|
|
|
|
360
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
auto_build; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has table => isa(object); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has next_index => isa(integer(0)); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has prev_index => isa(integer(0)); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use overload |
14
|
72
|
|
|
72
|
|
27281
|
'@{}' => sub { $_[0]->all }; |
|
72
|
|
|
120
|
|
554
|
|
|
72
|
|
|
|
|
640
|
|
|
120
|
|
|
|
|
11906
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# The following sub routines only manipulate the data that is in "memory" |
17
|
|
|
|
|
|
|
# to query a larger dataset you should use the storage api/sub routines. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub all { |
20
|
120
|
|
|
120
|
0
|
314
|
return $_[0]->table->rows; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub first { |
24
|
4
|
|
|
4
|
0
|
3465
|
return $_[0]->table->rows->[0]; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub last { |
28
|
4
|
|
|
4
|
0
|
1899
|
return $_[0]->table->rows->[-1]; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub next { |
32
|
16
|
|
|
16
|
0
|
8072
|
my $next = $_[0]->table->rows->[$_[0]->next_index]; |
33
|
16
|
|
|
|
|
246
|
$_[0]->next_index($_[0]->next_index + 1); |
34
|
16
|
100
|
50
|
|
|
429
|
return $next ? $next : $_[0]->next_index(0) && 0; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub prev { |
38
|
16
|
50
|
|
16
|
0
|
5987
|
if (not defined $_[0]->prev_index ) { |
39
|
0
|
|
|
|
|
0
|
$_[0]->prev_index(scalar @{ $_[0] }); |
|
0
|
|
|
|
|
0
|
|
40
|
|
|
|
|
|
|
} |
41
|
16
|
|
|
|
|
168
|
my $prev = $_[0]->table->rows->[$_[0]->prev_index]; |
42
|
16
|
|
|
|
|
194
|
$_[0]->prev_index($_[0]->prev_index + 1); |
43
|
16
|
100
|
50
|
|
|
428
|
return $prev ? $prev : $_[0]->prev_index(scalar @{$_[0]}) && 0; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub flat { |
47
|
0
|
|
|
0
|
0
|
0
|
my ($self, $keyfield) = @_; |
48
|
0
|
|
|
|
|
0
|
my @array; |
49
|
0
|
|
|
|
|
0
|
for my $row (@{ $self }) { |
|
0
|
|
|
|
|
0
|
|
50
|
0
|
|
|
|
|
0
|
push @array, {%{$row}}; |
|
0
|
|
|
|
|
0
|
|
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
0
|
return \@array; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub array_to_hash { |
56
|
3
|
|
|
3
|
0
|
29
|
my ($self, $keyfield) = @_; |
57
|
3
|
|
33
|
|
|
37
|
$keyfield ||= $self->table->keyfield; |
58
|
3
|
|
|
|
|
38
|
my %hash; |
59
|
3
|
|
|
|
|
6
|
for my $row (@{ $self }) { |
|
3
|
|
|
|
|
5
|
|
60
|
9
|
|
|
|
|
35
|
$hash{$row->{$keyfield}} = {%{$row}}; |
|
9
|
|
|
|
|
23
|
|
61
|
|
|
|
|
|
|
} |
62
|
3
|
|
|
|
|
9
|
return \%hash; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub foreach { |
66
|
3
|
|
|
3
|
0
|
125
|
my ($self, $cb) = @_; |
67
|
3
|
|
|
|
|
34
|
my @results; |
68
|
3
|
|
|
|
|
7
|
foreach my $row ( @{ $self }) { |
|
3
|
|
|
|
|
11
|
|
69
|
9
|
|
|
|
|
75
|
push @results, $cb->($row); |
70
|
|
|
|
|
|
|
} |
71
|
3
|
50
|
|
|
|
15
|
return wantarray ? @results : \@results; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub find { |
75
|
11
|
|
|
11
|
0
|
3277
|
my ($self, $cb) = @_; |
76
|
11
|
|
|
|
|
20
|
my $result; |
77
|
11
|
|
|
|
|
18
|
foreach my $row ( @{ $self }) { |
|
11
|
|
|
|
|
26
|
|
78
|
33
|
|
|
|
|
139
|
my $valid = $cb->({%{$row}}); |
|
33
|
|
|
|
|
63
|
|
79
|
33
|
100
|
50
|
|
|
121
|
do { $result = $row } and last if $valid; |
|
9
|
|
|
|
|
31
|
|
80
|
|
|
|
|
|
|
} |
81
|
11
|
|
|
|
|
26
|
return $result; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub find_index { |
85
|
8
|
|
|
8
|
0
|
779
|
my ($self, $cb) = @_; |
86
|
8
|
|
|
|
|
17
|
my $i; |
87
|
8
|
|
|
|
|
13
|
my @rows = @{ $self }; |
|
8
|
|
|
|
|
23
|
|
88
|
8
|
|
|
|
|
119
|
for ($i = 0; $i < scalar @rows; $i++) { |
89
|
24
|
|
|
|
|
46
|
my $row = $rows[$i]; |
90
|
24
|
|
|
|
|
34
|
my $valid = $cb->({%{$row}}); |
|
24
|
|
|
|
|
57
|
|
91
|
24
|
100
|
|
|
|
236
|
last if $valid; |
92
|
|
|
|
|
|
|
} |
93
|
8
|
|
|
|
|
27
|
return $i; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub reverse { |
97
|
6
|
|
|
6
|
0
|
2805
|
my $self = shift; |
98
|
6
|
|
|
|
|
17
|
@{$self} = reverse @{$self}; |
|
6
|
|
|
|
|
69
|
|
|
6
|
|
|
|
|
14
|
|
99
|
6
|
|
|
|
|
52
|
return [@{$self}]; |
|
6
|
|
|
|
|
8
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub filter { |
103
|
6
|
|
|
6
|
0
|
62
|
my ($self, $cb) = @_; |
104
|
|
|
|
|
|
|
my @results = grep { |
105
|
12
|
100
|
|
|
|
67
|
$cb->({%{$_}}) && $_ |
|
12
|
|
|
|
|
26
|
|
106
|
6
|
|
|
|
|
10
|
} @{ $self }; |
|
6
|
|
|
|
|
13
|
|
107
|
6
|
100
|
|
|
|
48
|
return wantarray ? @results : \@results; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub sort { |
111
|
1
|
|
|
1
|
0
|
420
|
my ($self, $cb) = @_; |
112
|
1
|
|
|
|
|
8
|
@{ $self } = sort { $cb->($a, $b) } @{ $self }; |
|
1
|
|
|
|
|
16
|
|
|
28
|
|
|
|
|
323
|
|
|
1
|
|
|
|
|
5
|
|
113
|
1
|
|
|
|
|
20
|
$self; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub shift { |
117
|
0
|
|
|
0
|
0
|
0
|
CORE::shift @{ $_[0] }; |
|
0
|
|
|
|
|
0
|
|
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub pop { |
121
|
0
|
|
|
0
|
0
|
0
|
CORE::pop @{ $_[0] }; |
|
0
|
|
|
|
|
0
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub splice { |
125
|
5
|
|
|
5
|
0
|
26
|
my ($self, @params) = @_; |
126
|
|
|
|
|
|
|
|
127
|
5
|
|
|
|
|
8
|
return splice( @{$self}, CORE::shift @params, CORE::shift @params); |
|
5
|
|
|
|
|
12
|
|
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |