Iterator version 0.02 ===================== 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.