line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::PObject::Iterator; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Iterator.pm,v 1.8 2005/01/26 19:21:58 sherzodr Exp |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
80
|
|
6
|
|
|
|
|
|
|
#use diagnostics; |
7
|
2
|
|
|
2
|
|
11
|
use Carp 'croak'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
124
|
|
8
|
2
|
|
|
2
|
|
11
|
use vars ('$VERSION'); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
854
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '1.01'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
2
|
|
|
2
|
1
|
4
|
my $class = shift; |
14
|
2
|
|
33
|
|
|
20
|
$class = ref($class) || $class; |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
|
|
9
|
my $self = { |
17
|
|
|
|
|
|
|
pobject => $_[0], |
18
|
|
|
|
|
|
|
data_set => $_[1], |
19
|
|
|
|
|
|
|
next_ptr=> 0, |
20
|
2
|
|
|
|
|
4
|
last_ptr => scalar(@{$_[1]})-1 |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
|
|
12
|
bless $self, $class; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
0
|
|
0
|
sub DESTROY { |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub next { |
31
|
10
|
|
|
10
|
1
|
1535
|
my $self = shift; |
32
|
|
|
|
|
|
|
|
33
|
10
|
|
|
|
|
30
|
my $next_id = $self->{data_set}->[ $self->{next_ptr}++ ]; |
34
|
10
|
100
|
|
|
|
39
|
return unless defined $next_id; |
35
|
8
|
|
|
|
|
39
|
return $self->{pobject}->load($next_id) |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub size { |
41
|
2
|
|
|
2
|
1
|
3
|
my $self = shift; |
42
|
2
|
|
|
|
|
17
|
return $self->{last_ptr} - $self->{next_ptr} + 1 |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub reset { |
48
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
4
|
$self->{next_ptr} = 0; |
51
|
2
|
|
|
|
|
3
|
$self->{last_ptr} = scalar( @{ $self->{data_set} } ) - 1 |
|
2
|
|
|
|
|
8
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub push { |
56
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
unless ( @_ ) { |
59
|
0
|
|
|
|
|
|
croak "push() usage error" |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
push @{$self->{data_set}}, $_[0]; |
|
0
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$self->{last_ptr}++ |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub finish { |
67
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->{data_set} = [] |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub dump { |
75
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
require Data::Dumper; |
78
|
0
|
|
|
|
|
|
my $d = new Data::Dumper([$self], [ref $self]); |
79
|
0
|
|
|
|
|
|
return $d->Dump |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
__END__ |