Class::Iterator - Iterator class
use Class::Iterator; my $it = Class::Iterator->new(\&closure_generator); while (my $v = $it->next) { print "value : $v\n" } # use map like my $it2 = imap { ...some code with $_...} $it while (my $v = $it->next) { print "value : $v\n" } # use grep like my $it3 = igrep { ...some code with $_...} $it while (my $v = $it->next) { print "value : $v\n" }
Class::Iterator is a generic iterator object class. It use a closure an wrap into an object interface.
This is the constructor. The argument is a sub which look like sub closure_generator { my $private_data; return sub { # do something with $private_data # and return it return $private_data } }
calling this method make one iteration.
This a creator. It create a new iterator from an existant iterator in the manner of map.
This a creator. It create a new iterator from an existant iterator in the manner of grep.
Marc Jason Dominius's YAPC::EU 2003 classes. Ken Olstad
Robert Silve <robert@silve.net>
To install Class::Iterator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Iterator
CPAN shell
perl -MCPAN -e shell install Class::Iterator
For more information on module installation, please visit the detailed CPAN module installation guide.