line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Tie::Array::Iterable::ForwardIterator; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#============================================================================= |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# $Id: ForwardIterator.pm,v 0.03 2001/11/16 02:27:58 mneylon Exp $ |
8
|
|
|
|
|
|
|
# $Revision: 0.03 $ |
9
|
|
|
|
|
|
|
# $Author: mneylon $ |
10
|
|
|
|
|
|
|
# $Date: 2001/11/16 02:27:58 $ |
11
|
|
|
|
|
|
|
# $Log: ForwardIterator.pm,v $ |
12
|
|
|
|
|
|
|
# Revision 0.03 2001/11/16 02:27:58 mneylon |
13
|
|
|
|
|
|
|
# Fixed packing version variables |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# Revision 0.01.01.2 2001/11/16 02:12:16 mneylon |
16
|
|
|
|
|
|
|
# Added code to clean up iterators after use |
17
|
|
|
|
|
|
|
# clear_iterators() now not needed, simply returns 1; |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# Revision 0.01.01.1 2001/11/15 01:41:21 mneylon |
20
|
|
|
|
|
|
|
# Branch from 0.01 for new features |
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# Revision 0.01 2001/11/11 18:36:14 mneylon |
23
|
|
|
|
|
|
|
# Initial Release |
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
#============================================================================= |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
2
|
|
37
|
use 5.006; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
76
|
|
29
|
2
|
|
|
2
|
|
18
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
88
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $FORWARDID; |
32
|
|
|
|
|
|
|
my %FORWARDITERS; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
BEGIN { |
35
|
2
|
|
|
2
|
|
8
|
use Exporter (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
45
|
|
36
|
2
|
|
|
2
|
|
9
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
350
|
|
37
|
2
|
|
|
2
|
|
13
|
( $VERSION ) = '$Revision: 0.03 $ ' =~ /\$Revision:\s+([^\s]+)/; |
38
|
2
|
|
|
|
|
40
|
@ISA = qw( Exporter ); |
39
|
2
|
|
|
|
|
10
|
@EXPORT = qw( ); |
40
|
2
|
|
|
|
|
4
|
@EXPORT_OK = qw( ); |
41
|
2
|
|
|
|
|
7157
|
%EXPORT_TAGS = ( ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new { |
45
|
1
|
|
|
1
|
0
|
1
|
my $class = shift; |
46
|
1
|
|
|
|
|
8
|
my $iterarray = shift; |
47
|
1
|
|
50
|
|
|
7
|
my $pos = shift || 0; |
48
|
1
|
50
|
|
|
|
5
|
warn "Must be created from a Tie::Array::Iterable" |
49
|
|
|
|
|
|
|
unless ( UNIVERSAL::isa( $iterarray, "Tie::Array::Iterable" ) ); |
50
|
1
|
|
|
|
|
4
|
my %data = ( |
51
|
|
|
|
|
|
|
array => $iterarray, |
52
|
|
|
|
|
|
|
pos => $pos, |
53
|
|
|
|
|
|
|
id => ++$FORWARDID ); |
54
|
1
|
|
|
|
|
3
|
$FORWARDITERS{ $data{ id } } = \%data; |
55
|
1
|
|
|
|
|
4
|
return bless \%data, $class; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub DESTROY { |
59
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
60
|
0
|
|
|
|
|
0
|
$self->{ array }->_remove_forward_iterator( $self->{ id } ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub at_start () { |
64
|
35
|
|
|
35
|
0
|
34
|
my $self = shift; |
65
|
35
|
100
|
|
|
|
103
|
if ( $self->{ pos } <= 0 ) { |
66
|
17
|
|
|
|
|
53
|
return 1; |
67
|
|
|
|
|
|
|
} else { |
68
|
18
|
|
|
|
|
47
|
return 0; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub at_end () { |
73
|
100
|
|
|
100
|
0
|
112
|
my $self = shift; |
74
|
100
|
100
|
|
|
|
131
|
if ( $self->{ pos } >= scalar @{ $self->{ array } } ) { |
|
100
|
|
|
|
|
292
|
|
75
|
23
|
|
|
|
|
58
|
return 1; |
76
|
|
|
|
|
|
|
} else { |
77
|
77
|
|
|
|
|
217
|
return 0; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub to_start () { |
82
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
83
|
1
|
|
|
|
|
3
|
$self->{ pos } = 0; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub to_end () { |
87
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
88
|
2
|
|
|
|
|
3
|
$self->{ pos } = scalar @{ $self->{ array } }; |
|
2
|
|
|
|
|
10
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub value { |
92
|
67
|
|
|
67
|
0
|
139
|
my $self = shift; |
93
|
67
|
100
|
|
|
|
126
|
if ( $self->at_end() ) { return undef }; |
|
7
|
|
|
|
|
48
|
|
94
|
60
|
|
|
|
|
291
|
return $self->{ array }->[ $self->{ pos } ]; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub set_value { |
98
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
99
|
0
|
|
|
|
|
0
|
my $value = shift; |
100
|
0
|
0
|
|
|
|
0
|
if ( $self->at_end() ) { return undef; }; |
|
0
|
|
|
|
|
0
|
|
101
|
0
|
|
|
|
|
0
|
return ( $self->{ array }->[ $self->{ pos } ] = $value ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub index { |
105
|
51
|
|
|
51
|
0
|
101
|
my $self = shift; |
106
|
51
|
|
|
|
|
268
|
return $self->{ pos }; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub set_index { |
110
|
7
|
|
|
7
|
0
|
12
|
my $self = shift; |
111
|
7
|
|
|
|
|
11
|
my $index = shift; |
112
|
7
|
50
|
|
|
|
21
|
if ( $index < 0 ) { $index = 1; } |
|
0
|
|
|
|
|
0
|
|
113
|
7
|
50
|
|
|
|
9
|
if ( $index > scalar @{ $self->{ array } } ) |
|
7
|
|
|
|
|
32
|
|
114
|
0
|
|
|
|
|
0
|
{ $index = scalar @{ $self->{ array } }; } |
|
0
|
|
|
|
|
0
|
|
115
|
7
|
|
|
|
|
32
|
$self->{ pos } = $index; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub next () { |
119
|
29
|
|
|
29
|
0
|
36
|
my $self = shift; |
120
|
29
|
100
|
|
|
|
47
|
if ( $self->at_end() ) { |
121
|
13
|
|
|
|
|
28
|
return undef; |
122
|
|
|
|
|
|
|
} |
123
|
16
|
|
|
|
|
30
|
$self->{ pos }++; |
124
|
16
|
|
|
|
|
29
|
return $self->value(); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub prev () { |
128
|
31
|
|
|
31
|
0
|
32
|
my $self = shift; |
129
|
31
|
100
|
|
|
|
61
|
if ( $self->at_start() ) { |
130
|
14
|
|
|
|
|
33
|
return undef; |
131
|
|
|
|
|
|
|
} |
132
|
17
|
|
|
|
|
26
|
$self->{ pos }--; |
133
|
17
|
|
|
|
|
29
|
return $self->value(); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub forward { |
137
|
4
|
|
|
4
|
0
|
9
|
my $self = shift; |
138
|
4
|
|
|
|
|
9
|
my $steps = shift; |
139
|
4
|
50
|
|
|
|
66
|
die "Number of steps must be non-negative" if $steps < 0; |
140
|
4
|
50
|
33
|
|
|
19
|
$steps = 1 if ( !$steps && $steps ne "0" ); |
141
|
4
|
|
|
|
|
12
|
my $value = $self->value(); |
142
|
4
|
|
|
|
|
22
|
$value = $self->next() for ( 1..$steps ); |
143
|
4
|
|
|
|
|
10
|
return $value; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub backward { |
147
|
3
|
|
|
3
|
0
|
6
|
my $self = shift; |
148
|
3
|
|
|
|
|
5
|
my $steps = shift; |
149
|
3
|
50
|
|
|
|
9
|
die "Number of steps must be non-negative" if $steps < 0; |
150
|
3
|
50
|
33
|
|
|
9
|
$steps = 1 if ( !$steps && $steps ne "0" ); |
151
|
3
|
|
|
|
|
6
|
my $value = $self->value(); |
152
|
3
|
|
|
|
|
13
|
$value = $self->prev() for ( 1..$steps ); |
153
|
3
|
|
|
|
|
6
|
return $value; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub _lookup ($) { |
157
|
16
|
|
|
16
|
|
27
|
my $id = shift; |
158
|
16
|
|
|
|
|
70
|
return $FORWARDITERS{ $id }; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub _id { |
162
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
163
|
1
|
|
|
|
|
7
|
return $self->{ id }; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1; |
167
|
|
|
|
|
|
|
__END__ |