|
List::Object - Ordered list of objects with array methods and iterator methods, enforces types of list members. |
List::Object - Ordered list of objects with array methods and iterator methods, enforces types of list members.
List::Object was inspired by several other modules: Array:: for having an object-oriented interface
to perl's array functions. Class::MethodMaker for its auto-generated methods that do that same thing with its object_list functionality (hence the name of this package), as well as the fact that it enforces the declared datatype on its members. And I like the generic Iterator interface for woking with lists.
In a nutshell, List::Object has three main features:
* Object-oriented interface to perl's array methods
* Implements the Iterator interface for the list
* Enforces datatypes of list members.
use List::Object;
$lo = List::Object->new();
[...]
$lo = List::Object->new(type => 'Package::Name',
list => \@array,
allow_undef => 0);
[...]
# Iterator methods $lo->next() $lo->has_next() $lo->peek() $lo->rewind() $lo->get() $lo->set() $lo->add() $lo->remove() $lo->first() $lo->last()
# Perl array functions $lo->shift() $lo->push() $lo->pop() $lo->unshift() $lo->join() $lo->array() $lo->reverse() $lo->sort() $lo->splice()
# Other $lo->sort_by() $lo->allow_undef() $lo->type() $lo->count() $lo->clear()
list: Optional list of elements to initially populate the List::Object list.
allow_undef: Flag to let List::Object know if list items can be undefined. By default this is off, and all items must be defined _and_ of the correct type. By turning it on, List::Object overlooks undefined items when enforcing it type requirement.
Returns a new List::Object object;
next()has_next() to find out ahead of time. Calling next() repeatedly will return a different item each time.
has_next()peek()has_next() to find out ahead of time. Calling peek() repeatedly will return the same item.
rewind()get($index)add($item)remove($index)first()last()shift()push(@list)pop()unshift(@list)unshift function, add the list of items to the beginning of the list;
join($join)array()sort()sort_by($key)sort() method call.
Examples:
$lo = List::Object->new(type => '@' , list => \@list)
$lo->sort_by(2);
# list of array refs have been sorted by the second element
# in their list;
[...]
$lo = List::Object->(type => '%', list => \@list);
$lo->sory_by('last_name)
# list has been sorted by the value of the
# $person->{last_name} key of each hashref in the list;
[...]
$lo = List::Object->(type => 'Person', list \@list);
$lo->sort_by('last_name');
# list has been sorted by the return value of the
# last_name() method of each Person object in the list;
allow_undef()=item type()
Return the type of data permitted in the list, as defined by the 'type' parameter when the List::Object was instantiated. See new().
count()clear()loose(boolean)
None by default.
No known bugs on initial release. Please send reports to author.
Steven Hilton, <mshiltonj@mshiltonj.com>
Copyright (C) 2004 by Steven Hilton
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.
|
List::Object - Ordered list of objects with array methods and iterator methods, enforces types of list members. |