line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::CircularList::Iterator; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
79
|
use 5.006; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
169
|
|
4
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
184
|
|
5
|
4
|
|
|
4
|
|
19
|
use warnings FATAL => 'all'; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
183
|
|
6
|
4
|
|
|
4
|
|
18
|
use parent qw/Class::Accessor/; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
17
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/p header rotate rotate_count/); |
8
|
4
|
|
|
4
|
|
270
|
use Scalar::Util qw/blessed/; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
190
|
|
9
|
4
|
|
|
4
|
|
18
|
use Carp; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
1539
|
|
10
|
|
|
|
|
|
|
sub DEBUG() {0}; # {0} when done |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Data::CircularList::Iterator - iterator for Data::CircularList's object. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Version 0.03 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
You can see Data::CircularList module's SYNOPSIS as a example. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 new |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
constructor. reguire one argument (not necessary) as rotate. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
6
|
|
|
6
|
1
|
13
|
my ($class, $circular_list, $rotate) = @_; |
40
|
6
|
100
|
|
|
|
15
|
my $self = { |
41
|
|
|
|
|
|
|
p => $circular_list->header, |
42
|
|
|
|
|
|
|
header => $circular_list->header, |
43
|
|
|
|
|
|
|
rotate => defined $rotate ? $rotate : undef, |
44
|
|
|
|
|
|
|
rotate_count => 0, |
45
|
|
|
|
|
|
|
}; |
46
|
6
|
|
|
|
|
78
|
bless $self => $class; |
47
|
6
|
|
|
|
|
15
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 has_next |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
return boolean value(1 or 0). |
53
|
|
|
|
|
|
|
If the linkedList has next cell, this method return 1. |
54
|
|
|
|
|
|
|
If the linkedList has not next cell, this method return 0. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub has_next { |
59
|
43
|
|
|
43
|
1
|
12943
|
my $self = shift; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# if rotate is not defined, return true eternary. |
62
|
43
|
100
|
|
|
|
93
|
return 1 if (!defined($self->rotate)); |
63
|
|
|
|
|
|
|
|
64
|
19
|
100
|
|
|
|
173
|
if ( ! blessed($self->p->next->data) ) { |
65
|
8
|
|
|
|
|
129
|
$self->rotate_count($self->rotate_count + 1); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# case of the rotate is defined |
69
|
19
|
100
|
|
|
|
296
|
if ( $self->rotate_count < $self->rotate ) { |
70
|
|
|
|
|
|
|
# skip header |
71
|
11
|
|
|
|
|
129
|
return 1; |
72
|
|
|
|
|
|
|
} else { |
73
|
8
|
|
|
|
|
90
|
return 0; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 next |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return next cell(Data::CircularList::Cell) of the CircularList. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head3 caution |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
If next method called, iterator progresses next cell. |
84
|
|
|
|
|
|
|
So you should generally call has_next method and next method alternately each once respectively. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $list = Data::CircularList->new; |
87
|
|
|
|
|
|
|
my $iter = $list->iterator; |
88
|
|
|
|
|
|
|
while ($iter->has_next) { |
89
|
|
|
|
|
|
|
print $iter->next->data . "\n"; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub next { |
95
|
34
|
|
|
34
|
1
|
244
|
my $self = shift; |
96
|
|
|
|
|
|
|
|
97
|
34
|
50
|
|
|
|
59
|
if ( ! defined($self->p->next) ) { |
98
|
0
|
|
|
|
|
0
|
return undef; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
34
|
100
|
|
|
|
390
|
if ( ! blessed($self->p->next->data) ) { |
102
|
|
|
|
|
|
|
# skip header |
103
|
3
|
|
|
|
|
46
|
$self->p($self->p->next->next); |
104
|
|
|
|
|
|
|
} else { |
105
|
31
|
|
|
|
|
471
|
$self->p($self->p->next); |
106
|
|
|
|
|
|
|
} |
107
|
34
|
|
|
|
|
540
|
return $self->p->data; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# free memory of cicular data |
111
|
|
|
|
|
|
|
sub DESTROY { |
112
|
6
|
|
|
6
|
|
2196
|
my $self = shift; |
113
|
6
|
|
|
|
|
20
|
delete $self->{'header'}; |
114
|
6
|
|
|
|
|
13
|
delete $self->{'p'}; |
115
|
6
|
|
|
|
|
42
|
if (DEBUG) { |
116
|
|
|
|
|
|
|
carp "destroying $self\n"; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 AUTHOR |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
shinchit, C<< >> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 BUGS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
127
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
128
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SUPPORT |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
perldoc Data::CircularList::Iterator |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
You can also look for information at: |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over 4 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * CPAN Ratings |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * Search CPAN |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=back |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Copyright 2014 shinchit. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
171
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
172
|
|
|
|
|
|
|
copy of the full license at: |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
177
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
178
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
179
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
182
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
183
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
186
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
189
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
190
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
191
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
192
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
193
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
194
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
195
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
198
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
199
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
200
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
201
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
202
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
203
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
204
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
1; # End of Data::CircularList::Iterator |