The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Handel::Iterator::Results - Iterator class used for collection looping storage iterators

SYNOPSIS

    my $iterator = $storage->search;
    
    my $results = Handel::Iterator::Results->new({
        data         => $iterator,
        result_class => 'MyCart'
    });
    
    while (my $cart = $results->next) {
        print $cart->id;
    };

DESCRIPTION

Handel::Iterator::Results is a used to iterate through result iterators returned by storage search/search_items operations. The only different between this, and Handel::Iterator::DBIC and Handel::Iterator::List is that it inflates results into the interface classes rather than into storage results.

CONSTRUCTOR

new

Arguments: \%options

Creates a new iterator object. The following options are available:

    my $iterator = $storage->search;
    
    my $results = Handel::Iterator::Results->new({
        data         => $iterator,
        result_class => 'MyCart'
    });

    my $cart = $results->first;
    print ref $cart; # MyCart
data

The data to be iterated through. This should be an iterator returns by storage.

result_class

The name of the class that each result should be inflated into.

METHODS

all

Returns all results from current iterator.

    foreach my $result ($iterator->all) {
        print $result->method;
    };

count

Returns the number of results in the current iterator.

    my $count = $iterator->count;

create_result

Arguments: $result

Returns a new result class object based on the specified result objects.

This method is used by methods like first and next to to create result class objects. There is probably no good reason to use this method directly.

first

Returns the first result or undef if there are no results.

    my $first = $iterator->first;

last

Returns the last result or undef if there are no results.

    my $last = $iterator->last;

next

Returns the next result or undef if there are no results.

    while (my $result = $iterator->next) {
        print $result->method;
    };

reset

Resets the current result position back to the first result.

    while (my $result = $iterator->next) {
        print $result->method;
    };
    
    $iterator->reset;
    
    while (my $result = $iterator->next) {
        print $result->method;
    };

SEE ALSO

Handel::Iterator::List, Handel::Iterator::DBIC

AUTHOR

    Christopher H. Laco
    CPAN ID: CLACO
    claco@chrislaco.com
    http://today.icantfocus.com/blog/