line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::CircularList::Iterator; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
59
|
use 5.006; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
136
|
|
4
|
4
|
|
|
4
|
|
19
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
138
|
|
5
|
4
|
|
|
4
|
|
15
|
use warnings FATAL => 'all'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
128
|
|
6
|
4
|
|
|
4
|
|
13
|
use parent qw/Class::Accessor/; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
16
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/p header rotate rotate_count/); |
8
|
4
|
|
|
4
|
|
217
|
use Scalar::Util qw/blessed/; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
156
|
|
9
|
4
|
|
|
4
|
|
16
|
use Carp; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
1398
|
|
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.01 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
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
|
10
|
my ($class, $circular_list, $rotate) = @_; |
40
|
6
|
100
|
|
|
|
18
|
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
|
|
|
|
|
95
|
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
|
15577
|
my $self = shift; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# if rotate is not defined, return true eternary. |
62
|
43
|
100
|
|
|
|
135
|
return 1 if (!defined($self->rotate)); |
63
|
|
|
|
|
|
|
|
64
|
19
|
100
|
|
|
|
202
|
if ( ! blessed($self->p->next->data) ) { |
65
|
8
|
|
|
|
|
142
|
$self->rotate_count($self->rotate_count + 1); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# case of the rotate is defined |
69
|
19
|
100
|
|
|
|
315
|
if ( $self->rotate_count < $self->rotate ) { |
70
|
|
|
|
|
|
|
# skip header |
71
|
11
|
|
|
|
|
130
|
return 1; |
72
|
|
|
|
|
|
|
} else { |
73
|
8
|
|
|
|
|
94
|
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
|
230
|
my $self = shift; |
96
|
|
|
|
|
|
|
|
97
|
34
|
50
|
|
|
|
59
|
if ( ! defined($self->p->next) ) { |
98
|
0
|
|
|
|
|
0
|
return undef; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
34
|
100
|
|
|
|
391
|
if ( ! blessed($self->p->next->data) ) { |
102
|
|
|
|
|
|
|
# skip header |
103
|
3
|
|
|
|
|
44
|
$self->p($self->p->next->next); |
104
|
|
|
|
|
|
|
} else { |
105
|
31
|
|
|
|
|
467
|
$self->p($self->p->next); |
106
|
|
|
|
|
|
|
} |
107
|
34
|
|
|
|
|
523
|
return $self->p->data; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 DESTROY |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
destructor. |
113
|
|
|
|
|
|
|
Don't you need to use this method directory. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub DESTROY { |
118
|
6
|
|
|
6
|
|
2791
|
my $self = shift; |
119
|
6
|
|
|
|
|
19
|
delete $self->{'header'}; |
120
|
6
|
|
|
|
|
9
|
delete $self->{'p'}; |
121
|
6
|
|
|
|
|
37
|
if (DEBUG) { |
122
|
|
|
|
|
|
|
carp "destroying $self\n"; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
shinchit, C<< >> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 BUGS |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
133
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
134
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 SUPPORT |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
perldoc Data::CircularList::Iterator |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
You can also look for information at: |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=over 4 |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
L |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
L |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * CPAN Ratings |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * Search CPAN |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=back |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Copyright 2014 shinchit. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
177
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
178
|
|
|
|
|
|
|
copy of the full license at: |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
L |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
183
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
184
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
185
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
188
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
189
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
192
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
195
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
196
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
197
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
198
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
199
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
200
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
201
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
204
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
205
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
206
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
207
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
208
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
209
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
210
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=cut |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
1; # End of Data::CircularList::Iterator |