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