line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ODS::Iterator; |
2
|
|
|
|
|
|
|
|
3
|
72
|
|
|
72
|
|
493
|
use YAOO; |
|
72
|
|
|
|
|
147
|
|
|
72
|
|
|
|
|
423
|
|
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
|
|
26382
|
'@{}' => sub { $_[0]->all }; |
|
72
|
|
|
120
|
|
149
|
|
|
72
|
|
|
|
|
777
|
|
|
120
|
|
|
|
|
31139
|
|
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
|
430
|
return $_[0]->table->rows; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub first { |
24
|
4
|
|
|
4
|
0
|
4025
|
return $_[0]->table->rows->[0]; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub last { |
28
|
4
|
|
|
4
|
0
|
1889
|
return $_[0]->table->rows->[-1]; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub next { |
32
|
16
|
|
|
16
|
0
|
8063
|
my $next = $_[0]->table->rows->[$_[0]->next_index]; |
33
|
16
|
|
|
|
|
247
|
$_[0]->next_index($_[0]->next_index + 1); |
34
|
16
|
100
|
50
|
|
|
455
|
return $next ? $next : $_[0]->next_index(0) && 0; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub prev { |
38
|
16
|
50
|
|
16
|
0
|
5859
|
if (not defined $_[0]->prev_index ) { |
39
|
0
|
|
|
|
|
0
|
$_[0]->prev_index(scalar @{ $_[0] }); |
|
0
|
|
|
|
|
0
|
|
40
|
|
|
|
|
|
|
} |
41
|
16
|
|
|
|
|
205
|
my $prev = $_[0]->table->rows->[$_[0]->prev_index]; |
42
|
16
|
|
|
|
|
240
|
$_[0]->prev_index($_[0]->prev_index + 1); |
43
|
16
|
100
|
50
|
|
|
412
|
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
|
27
|
my ($self, $keyfield) = @_; |
57
|
3
|
|
33
|
|
|
64
|
$keyfield ||= $self->table->keyfield; |
58
|
3
|
|
|
|
|
44
|
my %hash; |
59
|
3
|
|
|
|
|
6
|
for my $row (@{ $self }) { |
|
3
|
|
|
|
|
6
|
|
60
|
9
|
|
|
|
|
40
|
$hash{$row->{$keyfield}} = {%{$row}}; |
|
9
|
|
|
|
|
20
|
|
61
|
|
|
|
|
|
|
} |
62
|
3
|
|
|
|
|
12
|
return \%hash; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub foreach { |
66
|
3
|
|
|
3
|
0
|
128
|
my ($self, $cb) = @_; |
67
|
3
|
|
|
|
|
82
|
my @results; |
68
|
3
|
|
|
|
|
44
|
foreach my $row ( @{ $self }) { |
|
3
|
|
|
|
|
9
|
|
69
|
9
|
|
|
|
|
67
|
push @results, $cb->($row); |
70
|
|
|
|
|
|
|
} |
71
|
3
|
50
|
|
|
|
21
|
return wantarray ? @results : \@results; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub find { |
75
|
11
|
|
|
11
|
0
|
3479
|
my ($self, $cb) = @_; |
76
|
11
|
|
|
|
|
21
|
my $result; |
77
|
11
|
|
|
|
|
19
|
foreach my $row ( @{ $self }) { |
|
11
|
|
|
|
|
34
|
|
78
|
33
|
|
|
|
|
158
|
my $valid = $cb->({%{$row}}); |
|
33
|
|
|
|
|
101
|
|
79
|
33
|
100
|
50
|
|
|
121
|
do { $result = $row } and last if $valid; |
|
9
|
|
|
|
|
39
|
|
80
|
|
|
|
|
|
|
} |
81
|
11
|
|
|
|
|
26
|
return $result; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub find_index { |
85
|
8
|
|
|
8
|
0
|
954
|
my ($self, $cb) = @_; |
86
|
8
|
|
|
|
|
21
|
my $i; |
87
|
8
|
|
|
|
|
17
|
my @rows = @{ $self }; |
|
8
|
|
|
|
|
47
|
|
88
|
8
|
|
|
|
|
119
|
for ($i = 0; $i < scalar @rows; $i++) { |
89
|
24
|
|
|
|
|
37
|
my $row = $rows[$i]; |
90
|
24
|
|
|
|
|
33
|
my $valid = $cb->({%{$row}}); |
|
24
|
|
|
|
|
50
|
|
91
|
24
|
100
|
|
|
|
243
|
last if $valid; |
92
|
|
|
|
|
|
|
} |
93
|
8
|
|
|
|
|
20
|
return $i; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub reverse { |
97
|
6
|
|
|
6
|
0
|
3405
|
my $self = shift; |
98
|
6
|
|
|
|
|
14
|
@{$self} = reverse @{$self}; |
|
6
|
|
|
|
|
62
|
|
|
6
|
|
|
|
|
15
|
|
99
|
6
|
|
|
|
|
52
|
return [@{$self}]; |
|
6
|
|
|
|
|
10
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub filter { |
103
|
6
|
|
|
6
|
0
|
68
|
my ($self, $cb) = @_; |
104
|
|
|
|
|
|
|
my @results = grep { |
105
|
12
|
100
|
|
|
|
86
|
$cb->({%{$_}}) && $_ |
|
12
|
|
|
|
|
30
|
|
106
|
6
|
|
|
|
|
13
|
} @{ $self }; |
|
6
|
|
|
|
|
15
|
|
107
|
6
|
100
|
|
|
|
37
|
return wantarray ? @results : \@results; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub sort { |
111
|
1
|
|
|
1
|
0
|
711
|
my ($self, $cb) = @_; |
112
|
1
|
|
|
|
|
4
|
@{ $self } = sort { $cb->($a, $b) } @{ $self }; |
|
1
|
|
|
|
|
21
|
|
|
28
|
|
|
|
|
362
|
|
|
1
|
|
|
|
|
7
|
|
113
|
1
|
|
|
|
|
17
|
$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
|
16
|
my ($self, @params) = @_; |
126
|
|
|
|
|
|
|
|
127
|
5
|
|
|
|
|
9
|
return splice( @{$self}, CORE::shift @params, CORE::shift @params); |
|
5
|
|
|
|
|
10
|
|
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |