| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Class::DBI::Lite::Iterator; |
|
3
|
|
|
|
|
|
|
|
|
4
|
17
|
|
|
17
|
|
107
|
use strict; |
|
|
17
|
|
|
|
|
32
|
|
|
|
17
|
|
|
|
|
524
|
|
|
5
|
17
|
|
|
17
|
|
85
|
use warnings 'all'; |
|
|
17
|
|
|
|
|
32
|
|
|
|
17
|
|
|
|
|
3255
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new |
|
9
|
|
|
|
|
|
|
{ |
|
10
|
76
|
|
|
76
|
0
|
195
|
my ($class, $data) = @_; |
|
11
|
|
|
|
|
|
|
|
|
12
|
76
|
|
|
|
|
405
|
my $s = bless { |
|
13
|
|
|
|
|
|
|
data => $data, |
|
14
|
|
|
|
|
|
|
count => scalar(@$data), |
|
15
|
|
|
|
|
|
|
idx => 0 |
|
16
|
|
|
|
|
|
|
}, $class; |
|
17
|
76
|
|
|
|
|
253
|
$s->init(); |
|
18
|
|
|
|
|
|
|
|
|
19
|
76
|
|
|
|
|
202
|
return $s; |
|
20
|
|
|
|
|
|
|
}# end new() |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
76
|
0
|
|
sub init { } |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub first |
|
27
|
|
|
|
|
|
|
{ |
|
28
|
14
|
50
|
|
14
|
0
|
233
|
return unless $_[0]->{data}->[0]; |
|
29
|
14
|
|
|
|
|
61
|
$_[0]->{data}->[0]; |
|
30
|
|
|
|
|
|
|
}# end first() |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub next |
|
34
|
|
|
|
|
|
|
{ |
|
35
|
119
|
|
|
119
|
1
|
1448
|
my $s = shift; |
|
36
|
119
|
100
|
|
|
|
317
|
return unless $s->{idx} < $s->{count}; |
|
37
|
114
|
|
|
|
|
282
|
$s->{data}->[ $s->{idx}++ ]; |
|
38
|
|
|
|
|
|
|
}# end next() |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub count |
|
42
|
|
|
|
|
|
|
{ |
|
43
|
17
|
|
|
17
|
1
|
2420
|
$_[0]->{count}; |
|
44
|
|
|
|
|
|
|
}# end count() |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub reset |
|
48
|
|
|
|
|
|
|
{ |
|
49
|
1
|
|
|
1
|
1
|
1145
|
$_[0]->{idx} = 0; |
|
50
|
|
|
|
|
|
|
}# end reset() |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1;# return true: |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=pod |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 NAME |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Class::DBI::Lite::Iterator - Simple iterator for Class::DBI::Lite |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Get an iterator somehow: |
|
64
|
|
|
|
|
|
|
my $iter = app::artist->retrieve_all; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $artist = $iter->first; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $record_count = $iter->count; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
while( my $artist = $iter->next ) |
|
71
|
|
|
|
|
|
|
{ |
|
72
|
|
|
|
|
|
|
... |
|
73
|
|
|
|
|
|
|
}# end while() |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# We can reset the iterator to go back to the beginning: |
|
76
|
|
|
|
|
|
|
$iter->reset; |
|
77
|
|
|
|
|
|
|
print $_->id . "\n" while $_ = $iter->next; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Provides a simple iterator-based approach to Class::DBI::Lite resultsets. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 PUBLIC PROPERTIES |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 count |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Returns the number of records in the Iterator. |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 PUBLIC METHODS |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 next |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Returns the next object in the series, or undef. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Moves the internal cursor to the next object if one exists. |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 reset |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Resets the internal cursor to the first object if one exists. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 AUTHOR |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
John Drago . |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Copyright 2008 John Drago . All rights reserved. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This software is Free software and may be used and distributed under the same |
|
114
|
|
|
|
|
|
|
terms as perl itself. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
|
117
|
|
|
|
|
|
|
|