NAME
Mail::Builder::List - Helper module for handling various lists
SYNOPSIS
use Mail::Builder;
# Create a list that accepts Mail::Builder::Address objects
my $list = Mail::Builder::List->new('Mail::Builder::Address');
# Add aMail::Builder::Address object
$list->add($address_object);
# Add an email (Unrecognized values will be passed to the constructor of
# the type class - Mail::Builder::Address)
$list->add('sasha.nein@psychonauts.org');
# Add one more email (Unrecognized values will be passed to the constructor of
# the type class - Mail::Builder::Address)
$list->add({ email => 'raz.aquato@psychonauts.org', name => 'Razputin'} );
# Remove email from list
$list->remove('raz.aquato@psychonauts.org');
# Remove first element in list
$list->remove(1);
# Reset list
$list->reset;
# Add email
$list->add('milla.vodello@psychonauts.org','Milla Vodello');
# Serialize email list
print $list->join(',');
DESCRIPTION
This is a helper module for handling various lists (e.g. recipient, attachment lists). The class contains convinient array/list handling functions.
METHODS
Constructor
new
my $list = Mail::Builder::List->new(Class name);
OR
my $list = Mail::Builder::List->new({
type => Class name,
[ list => ArrayRef, ]
});
This constructor takes the class name of the objects it should hold. It is only possible to add objects of the given type. It is not possible to change the assigned type later.
convert
my $list = Mail::Builder::List->convert(ArrayRef);
Constructor that converts an array reference into a Mail::Builder::List object. The list type is defined by the first element of the array.
Public Methods
length
Returns the number of items in the list.
add
$obj->add(Object);
OR
$obj->add(Anything)
Pushes a new item into the list. The methods either accepts an object or any values. Values will be passed to the new
method in the list type class.
push
Synonym for add
remove
$obj->remove(Object)
OR
$obj->remove(Index)
OR
$obj->remove(Anything)
OR
$obj->remove()
Removes the given element from the list. If no parameter is passed to the method the last element from the list will be removed instead.
reset
Removes all elements from the list, leaving an empty list.
item
my $list_item = $obj->item(Index)
Returns the list item with the given index.
join
my $list = $obj->join(String)
Serializes all items in the list and joins them using the given string.
contains
$obj->contains(Object)
or
$obj->contains(Anything)
Returns true if the given object is in the list. You can either pass an object or scalar value. Uses the compare method from the list type class.
Accessors
type
Returns the class name which was initially passed to the constructor.
list
Raw list as list or array reference.
AUTHOR
Maroš Kollár
CPAN ID: MAROS
maros [at] k-1.com
http://www.k-1.com