1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  
     | 
    
      Iterator version 0.03
=====================
This module is meant to be the definitive implementation of iterators,
as popularized by Mark Jason Dominus's lectures and recent book
(_Higher Order Perl_, Morgan Kauffman, 2005).
An "iterator" is an object, represented as a code block that generates
the "next value" of a sequence, and generally implemented as a
closure.  Iterator.pm provides a class that simplifies creation and
use of these iterator objects.
EXAMPLES
Synopsis:
    $it = Iterator->new( sub { some code } );
Simple "upto" counter (Dominus, p. 121):
    sub upto
    {
        my ($m, $n) = @_;
        return Iterator->new( sub {
            return $m++  if $m <= $n;
            Iterator::X::Am_Now_Exhausted->throw();
        });
    }
    my $it = upto (3, 5);
    $i = $it->value;     #  returns 3
    $i = $it->value;     #  returns 4
    $i = $it->value;     #  returns 5
    $i = $it->value;     #  throws an Iterator::X::Exhausted exception.
    $another_it = upto (7, 10);
    while ($another_it->isnt_exhausted)
    {
        print $another_it->value, "\n";
    }
    # The above prints 7, 8, 9, 10 and throws no exceptions.
    # Another call to $another_it->value would throw an exception.
DEVELOPMENT STATE
This is a brand-new module.  It has a decent test suite, but has
not been extensively field-tested.  Therefore, it should be considered
"beta" software, and used with care.
If you find any bugs, or if any behavior of Iterator surprises you,
I would be grateful if you could send me an email message about it.
Thanks.
INSTALLATION
To install this module, do the standard Perl module four-step:
   perl Makefile.PL    or    perl Makefile.pl LIB='my/install/path'
   make
   make test
   make install
DEPENDENCIES
This module requires these other modules and libraries:
  Exception::Class
  Test::Simple
COPYRIGHT AND LICENSE
Eric J. Roode, roode@cpan.org
To avoid my spam filter, please include "Perl", "module", or this
module's name in the message's subject line, and/or GPG-sign your
message.
Copyright (c) 2005 by Eric J. Roode. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
 
     |