Array::Object - Array Object


NAME

Array::Object - Array Object


SYNOPSIS

 # construction
 $array = Array::Object->new(['foo', 'bar', 'baz']); # with a reference

 # decorate
 $array->{foo} = 'bar';
 # treat as ARRAY ref
 push @$array, @things;     # same for pop(), shift(), splice() et al
 $array->[42] = 'boo';
 # operations - modify IN PLACE!
 $array->pop();
 $array->push( @things );
 $array->shift();
 $array->unshift( @things );
 $array->splice( ... );
 $array->sort;
 $array->sort( sub { ... } )

 # visitors - modify IN PLACE!
 $array->map ( CODE )       # new Array::Object
 $array->grep( CODE )       # new Array::Object

 # other methods
 $array->length;
 $array->size;              # same as above
 $array->copy;              # new Array::Object (shallow copy)
 $array->concat([ ... ]);   # new Array::Object (shallow copy)
 $array = $a1 + $2          # same as above
 $array->join(',');


DESCRIPTION

This module implements a simple OO interface to Arrays. The underlying object, however, is a blessed Hash reference, but the overload manpage is used for making the object behave as an Array reference. This allows Array::Object to be decorated and subclassed more easily.

Additionally, when the usual methods which operate on Arrays are called as object methods, then the Array reference which is kept by the object is modified in place. Thus when you want a copy, do this:

 my @sorted = sort $@array;

which is NOT the same as:

 $array->sort;

which sorts in place. Thus the OO methods are not simply syntactic sugar (which would be kinda pointless) but have a useful semantic distinction.


METHODS

See the SYNOPSIS manpage.


AUTHOR

Richard Hundt


LICENSE

This library is free software and may be used under the same terms as Perl itself

 Array::Object - Array Object