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

NAME

Class::Composite::Container - Collection of Class::Composite::Element

SYNOPSIS

  use Class::Composite::Container;
  my $c = Class::Composite::Container->new();
  $c->nextElement();
  $c->resetPointer();
  $c->nextElement();
  $obj = $c->getElement();
  $list = $c->getElements(2, 5);

DESCRIPTION

Class::Composite::Container acts as a collection of elements.

INHERITANCE

Class::Composite

METHODS

init( %param )

Parameters are 'elements' and 'elempointer' init is useful for inheritance, you don't need to redefine new(), but you can redefined init(). See Base::Class documentation.

elements( ARRAY )

Get/Set elements array

elempointer( integer )

Gets or sets the elements pointer. The pointer is garenteed to be between 0 and the number of elements - 1

addElement( @elements )

The addElement() method adds elements to the collection. Returns the collection if ok.

addElementFlat( @elements )

Same than addElement, but flatten everything before adding. If you add a collection, it will add all elements individually, not the collection. Returns the collection if ok.

checkElement( $elem )

Returns true if $elem can be added to the container. The element must be of the same type than elementType() (see Class::Composite) or is undef. This method is called for each element added to the collection.

getElement( $index )

Returns the element asked. If $index < 0 it backtracks from the last element. If no index is given, returns the current element.

getElements( $start, $end )

Returns an array ref of elements. $start and $end are indexes. $end is optional - if not given all elements after $start are returned. If neither $start and $end are given, returns all elements.

removeElement( $index )

If no $index is given, the current element is removed. Rearrange the collection by shifting to the left the elements > $elem. Returns the element removed if ok.

removeAll()

Reset the collection and returns the collection.

nOfElements()

Returns the number of elements

nextElement()

Returns the current element and increments the internal index. You can use in a while loop such as:

  while ( my $elem = $container->nextElement ) { ... }

previousElement()

Decrements the internal index and returns the element

incrPointer()

Increments the internal index

decrPointer()

Decrements the internal index

resetPointer()

Reset pointer to retrieve the first element again Returns the pointer value before being reset

setPointer( $index )

Set pointer to $index. The internal index will be set to 0 if $index < 0 and will be set to the number of elements - 1 if $index >= number of elements Returns the pointer's former value

SEE ALSO

Class::Composite, Class::Composite::Element

AUTHOR

"Pierre Denis" <pdenis@fotango.com>

COPYRIGHT

Copyright (C) 2002, Fotango Ltd. All rights reserved.

This is free software. This software may be modified and/or distributed under the same terms as Perl itself.