File Coverage

blib/lib/DataStructure/LinkedList/Iterator.pm
Criterion Covered Total %
statement 12 23 52.1
branch 0 2 0.0
condition n/a
subroutine 4 7 57.1
pod 3 3 100.0
total 19 35 54.2


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