The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Template::Iterator - Base iterator class used by the FOREACH directive.

SYNOPSIS

    my $iter = Template::Iterator->new(\@data, \%options);

DESCRIPTION

The Template::Iterator module defines a generic data iterator for use by the FOREACH directive.

It may be used as the base class for custom iterators.

PUBLIC METHODS

new(\@data, \%options)

Constructor method. A reference to a list of values is passed as the first parameter and subsequent first() and next() calls will return each element.

The second optional parameter may be a hash reference containing the following items:

ORDER

A code reference which will be called to pre-sort the data items. A list reference is passed in and should be returned, along with any status code. The ORDER option may also be either of the strings 'sorted' or 'reverse'.

ACTION

A code ref to be called on each iteration. The data item is passed. The modified data should be returned.

get_first()

Returns a ($value, $error) pair for the first item in the iterator set. Returns an error of STATUS_DONE if the list is empty.

get_next()

Returns a ($value, $error) pair for the next item in the iterator set. Returns an error of STATUS_DONE if all items in the list have been visited.

size(), max(), index(), number(), first(), last()

Return the size of the iteration set, the maximum index number (size - 1), the current index number (0..max), the iteration number offset from 1 (index + 1, i.e. 1..size), and boolean values indicating if the current iteration is the first or last in the set, respectively.

AUTHOR

Andy Wardley <cre.canon.co.uk>

REVISION

$Revision: 1.11 $

COPYRIGHT

Copyright (C) 1996-1999 Andy Wardley. All Rights Reserved. Copyright (C) 1998-1999 Canon Research Centre Europe Ltd.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Template