~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/lib/Foswiki/Iterator.pm

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See bottom of file for license and copyright information
 
2
 
 
3
=begin TML
 
4
 
 
5
---+ package Foswiki::Iterator
 
6
 
 
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.
 
10
 
 
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.
 
14
 
 
15
See Foswiki::ListIterator for an example implementation.
 
16
 
 
17
=cut
 
18
 
 
19
package Foswiki::Iterator;
 
20
 
 
21
use strict;
 
22
use Assert;
 
23
 
 
24
=begin TML
 
25
 
 
26
---++ hasNext() -> $boolean
 
27
 
 
28
Returns true if the iterator has more items, or false when the iterator
 
29
is exhausted.
 
30
 
 
31
=cut
 
32
 
 
33
sub hasNext { ASSERT('Pure virtual function called') if DEBUG; }
 
34
 
 
35
=begin TML
 
36
 
 
37
---++ next() -> $data
 
38
 
 
39
Return the next data in the iteration.
 
40
 
 
41
The data may be any type.
 
42
 
 
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
 
45
iterator object:
 
46
 
 
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.
 
52
 
 
53
=cut
 
54
 
 
55
sub next { ASSERT('Pure virtual function called') if DEBUG; }
 
56
1;
 
57
 
 
58
__END__
 
59
# Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/
 
60
#
 
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.
 
64
#
 
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.
 
70
#
 
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.
 
74
#
 
75
# As per the GPL, removal of this notice is prohibited.