NAME

Handel::Iterator - Iterator class used for collection looping

SYNOPSIS

use Handel::Cart;

my $cart = Handel::Cart->new({
    shopper => 'D597DEED-5B9F-11D1-8DD2-00AA004ABD5E'
});

my $iterator = $cart->items;
while (my $item = $iterator->next) {
    print $item->sku;
    print $item->price;
    print $item->total;
};

DESCRIPTION

Handel::Iterator is used internally by Handel::Cart/Order/Item to iterate through collections of objects and items. At this point, there should be no reason to use it directly.

METHODS

all

Returns all results from the resultset as a list.

my $it = Handel::Cart->load({
    shopper => '11111111-1111-1111-1111-111111111111'
});

my @carts = $it->all;

create_iterator

Arguments: $iterator, $result_class

Returns a new iterator object that iterates through the supplied iterator and calls create_instance on each result_class for each result.

my $results_it = $storage->search;
my $carts_it = $storage->iterator_class->create_iterator($results_it, 'Handel::Cart');

This is used by the interface classes to wrap results returned by the storage layer.

first

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

my $it = Handel::Cart->load({
    shopper => '11111111-1111-1111-1111-111111111111'
});

my $carts = $it->first;

next

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

my $it = Handel::Cart->load({
    shopper => '11111111-1111-1111-1111-111111111111'
});

while ($cart = $it->next) {
    print $cart->name;
};

count

Returns the number of results.

my $it = Handel::Cart->load({
    shopper => '11111111-1111-1111-1111-111111111111'
});

my $cart_count = $it->count;

reset

Resets the current result position back to the first result.

my $it = Handel::Cart->load({
    shopper => '11111111-1111-1111-1111-111111111111'
});

while (my $cart = $it->next) {
    print $cart->name;
};

$it->reset;

while (my $cart = $it->next) {
    print $cart->name;
};

SEE ALSO

Handel::Cart, Handel::Order

AUTHOR

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