1
# See bottom of file for license and copyright information
5
---+ package Foswiki::Iterator
7
This class cannot be instantiated on its own - it is an interface
8
specification for iterators. See http://en.wikipedia.org/wiki/Iterator_Pattern
9
for more information on the iterator pattern.
11
The interface only supports forward iteration. Subclasses should use this
12
as their base class (so that =$it->isa("Foswiki::Iterator")= returns true),
13
and must implement =hasNext= and =next= per the specification below.
15
See Foswiki::ListIterator for an example implementation.
19
package Foswiki::Iterator;
26
---++ hasNext() -> $boolean
28
Returns true if the iterator has more items, or false when the iterator
33
sub hasNext { ASSERT('Pure virtual function called') if DEBUG; }
39
Return the next data in the iteration.
41
The data may be any type.
43
The iterator object can be customised to pre- and post-process entries from
44
the list before returning them. This is done by setting two fields in the
47
* ={filter}= can be defined to be a sub that filters each entry. The entry
48
will be ignored (next() will not return it) if the filter returns false.
49
* ={process}= can be defined to be a sub to process each entry before it
50
is returned by next. The value returned from next is the value returned
51
by the process function.
55
sub next { ASSERT('Pure virtual function called') if DEBUG; }
59
# Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/
61
# Copyright (C) 2009 Foswiki Contributors. All Rights Reserved.
62
# Foswiki Contributors are listed in the AUTHORS file in the root
63
# of this distribution. NOTE: Please extend that file, not this notice.
65
# This program is free software; you can redistribute it and/or
66
# modify it under the terms of the GNU General Public License
67
# as published by the Free Software Foundation; either version 2
68
# of the License, or (at your option) any later version. For
69
# more details read LICENSE in the root of this distribution.
71
# This program is distributed in the hope that it will be useful,
72
# but WITHOUT ANY WARRANTY; without even the implied warranty of
73
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
75
# As per the GPL, removal of this notice is prohibited.