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

NAME

Farly::Object::Aggregate - Group Farly::Objects with common identity

SYNOPSIS

  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 );

DESCRIPTION

Farly::Object::Aggregate groups Farly::Objects with a common identity (i.e. equal key/value pairs) into Farly::Object::Lists.

METHODS

new()

The constructor. An Farly::Object::List must be provided.

  $aggregate = Farly::Object::Aggregate->new( $list<Farly::Object::List> );

groupby( 'key1', 'key2', 'key3' ... )

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.

matches( $search<Farly::Object> )

Return the Farly::Object::List with the specified identity.

  $set = $aggregate->matches( $identity<Farly::Object> );

update( $search<Farly::Object>, $new_list<Farly::Object::List> )

Search for the identity specified by $search and update the aggregate object with the new Farly::Object::List.

  $set = $aggregate->matches( $identity<Farly::Object> );

iter()

Return an array of aggregate objects.

  @objects = $aggregate->iter();

list_iterator()

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()

id_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()

FUNCTIONS

NEXTVAL()

Advance the iterator to the next object.

  while ( my $list = NEXTVAL($it) ) {
      # do something with $list
  }

COPYRIGHT AND LICENCE

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/>.