Fey::Object::Iterator::FromArray - An iterator which iterates over an array of objects
version 0.45
use Fey::Object::Iterator::FromArray; my $iter = Fey::Object::Iterator::FromArray->new( classes => 'MyApp::User', objects => \@users, ); my $iter2 = Fey::Object::Iterator::FromArray->new( classes => [ 'MyApp::User', 'MyApp::Group' ], objects => [ [ $user1, $group1 ], [ $user2, $group1 ] ], ); print $iter->index(); # 0 while ( my $user = $iter->next() ) { print $iter->index(); # 1, 2, 3, ... print $user->username(); } # will return cached objects now $iter->reset();
This class provides an object which does the Fey::ORM::Role::Iterator role, but gets its data from an array reference. This lets you provide a single API that accepts data from Fey::ORM-created iterators, or existing data sets.
Fey::ORM::Role::Iterator
This class provides the following methods:
The constructor requires two parameters, classes and objects. The classes parameter can be a single class name, or an array reference of names.
classes
objects
The objects parameter should be an array reference. That reference can contain a list of objects, or an a list of array references, each of which contains objects.
In either case, the objects must be subclasses of Fey::Object::Table.
Resets the iterator so that the next call to $iterator->next() returns the first object(s).
$iterator->next()
This class does the Fey::ORM::Role::Iterator role.
Dave Rolsky <autarch@urth.org>
This software is copyright (c) 2011 by Dave Rolsky.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Fey::ORM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Fey::ORM
CPAN shell
perl -MCPAN -e shell install Fey::ORM
For more information on module installation, please visit the detailed CPAN module installation guide.