Class::Composite::Container - Collection of Class::Composite::Element
use Class::Composite::Container; my $c = Class::Composite::Container->new(); $c->nextElement(); $c->resetPointer(); $c->nextElement(); $obj = $c->getElement(); $list = $c->getElements(2, 5);
Class::Composite::Container acts as a collection of elements.
Class::Composite
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.
Get/Set elements array
Gets or sets the elements pointer. The pointer is garenteed to be between 0 and the number of elements - 1
The addElement() method adds elements to the collection. Returns the collection if ok.
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.
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.
Returns the element asked. If $index < 0 it backtracks from the last element. If no index is given, returns the current element.
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.
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.
Reset the collection and returns the collection.
Returns the number of elements
Returns the current element and increments the internal index. You can use in a while loop such as:
while ( my $elem = $container->nextElement ) { ... }
Decrements the internal index and returns the element
Increments the internal index
Decrements the internal index
Reset pointer to retrieve the first element again Returns the pointer value before being reset
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
Class::Composite, Class::Composite::Element
"Pierre Denis" <pdenis@fotango.com>
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.
To install Class::Composite, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Composite
CPAN shell
perl -MCPAN -e shell install Class::Composite
For more information on module installation, please visit the detailed CPAN module installation guide.