Farly::Object::Aggregate - Group Farly::Objects with common identity
use Farly::Object; my $list = Farly::Object::List->new(); my $object1 = Farly::Object->new(); my $object2 = Farly::Object->new(); $object1->set( 'id', Farly::Value::String->new('id1234') ); $object2->set( 'id', Farly::Value::String->new('id1234') ); . . . More $object attributes $list->add($object1); $list->add($object2); my $aggregate = Farly::Object::Aggregate->new( $list ); $aggregate->groupby( 'id' ); my $id = Farly::Object->new(); $id->set( 'id', Farly::Value::String->new('id1234') ); my $list = $aggregate->matches( $id );
Farly::Object::Aggregate groups Farly::Objects with a common identity (i.e. equal key/value pairs) into Farly::Object::Lists.
The constructor. An Farly::Object::List must be provided.
$aggregate = Farly::Object::Aggregate->new( $list<Farly::Object::List> );
All objects in the supplied list of keys, with equal value objects for the specified keys, will be grouped into a Farly::Object::List.
$aggregate->groupby( 'key1', 'key2', 'key3' );
Farly::Objects without the specified property/key will be skipped.
Return the Farly::Object::List with the specified identity.
$set = $aggregate->matches( $identity<Farly::Object> );
Search for the identity specified by $search and update the aggregate object with the new Farly::Object::List.
Return an array of aggregate objects.
@objects = $aggregate->iter();
Return an iterator code reference to an iterator function which iterates over all aggregate objects defined in the Farly::Object::Aggregate. Each aggregate contains objects with the same identity as defined by the 'groupby' method.
use Farly::Object::Aggregate qw(NEXTVAL); $it = $aggregate->list_iterator()
Return a code reference to an iterator function which iterates over all identities defined in the aggregate. The identities are Farly::Objects with the identity as defined by the 'groupby' method.
use Farly::Object::Aggregate qw(NEXTVAL); $it = $aggregate->id_iterator()
Advance the iterator to the next object.
while ( my $list = NEXTVAL($it) ) { # do something with $list }
Farly::Object::Aggregate Copyright (C) 2013 Trystan Johnson
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
To install Farly, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Farly
CPAN shell
perl -MCPAN -e shell install Farly
For more information on module installation, please visit the detailed CPAN module installation guide.