8.215. Tie::Array, Tie::StdArray
Provides methods for array-tying
classes. (See the perltie manpage for the
functions needed for tying an array to a package.) The basic
Tie::Array package provides stub DELETE and EXTEND methods and
implements PUSH, POP, SHIFT, UNSHIFT, SPLICE, and CLEAR in terms of
basic FETCH, STORE, FETCHSIZE, and STORESIZE.
Tie::StdArray inherits from Tie::Array and provides the methods
needed for tied arrays implemented as blessed references to an
"inner" Perl array. It causes tied
arrays to behave like standard arrays, allowing for selective method
overloading.
See the perltie manpage for more detailed
information and for examples. To write your own tied arrays, use the
following required methods.
Constructor. This method is invoked by the command
TIEARRAY classname, list
tie @array ,
classname. Associates an array instance
with the specified class. list represents
additional arguments needed to complete the association. Should
return an object of a class that provides the remaining methods.
Clears all values from the tied array associated with object
CLEAR this
this.
Normal object destructor.
DESTROY this
Doesn't need to do anything. Provides information
EXTEND this, count
that the array will likely grow to have
count entries.
Retrieves the data item in index for the
FETCH this, index
tied array associated with object this.
Returns the number of items in the tied array associated with object
FETCHSIZE this
this.
Removes the last element from the array and returns it.
POP this
Appends elements of list to the array.
PUSH this, list
Removes and returns the first element of the array, shifting the
SHIFT this
remaining elements down.
Performs the equivalent of a splice on the
SPLICE this, offset, length, list
array. Returns a list of the original
length elements at the specified offset.
The arguments are:
- offset
Optional. Defaults to 0; if negative, counts back
from the end of the array.- length
Optional. Defaults to the rest of the array.- list
May be empty.
Stores value of a data item into index for
STORE this, index, value
the tied array associated with object
this. If the resulting array is larger
than the class's mapping for the array,
undef should be returned for new positions.
Sets the total number of items in the tied array associated with
STORESIZE this, count
object this to
count. If this makes the array larger than
the class's mapping for the array, then
undef should be returned for new positions. If it
makes the array smaller than the mapping, then entries beyond
count should be deleted.
Inserts list elements at the beginning of
UNSHIFT this, list
the array, moving existing elements up to make room.