home *** CD-ROM | disk | FTP | other *** search
Wrap
<HTML> <HEAD> <TITLE>Tie::Array - base class for tied arrays</TITLE> <LINK REL="stylesheet" HREF="../../Active.css" TYPE="text/css"> <LINK REV="made" HREF="mailto:"> </HEAD> <BODY> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%> <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc"> <STRONG><P CLASS=block> Tie::Array - base class for tied arrays</P></STRONG> </TD></TR> </TABLE> <A NAME="__index__"></A> <!-- INDEX BEGIN --> <UL> <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI> <LI><A HREF="#synopsis">SYNOPSIS</A></LI> <LI><A HREF="#description">DESCRIPTION</A></LI> <LI><A HREF="#caveats">CAVEATS</A></LI> <LI><A HREF="#author">AUTHOR</A></LI> </UL> <!-- INDEX END --> <HR> <P> <H1><A NAME="name">NAME</A></H1> <P>Tie::Array - base class for tied arrays</P> <P> <HR> <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1> <UL> <LI>Linux</LI> <LI>Solaris</LI> <LI>Windows</LI> </UL> <HR> <H1><A NAME="synopsis">SYNOPSIS</A></H1> <PRE> package NewArray; use Tie::Array; @ISA = ('Tie::Array');</PRE> <PRE> # mandatory methods sub TIEARRAY { ... } sub FETCH { ... } sub FETCHSIZE { ... }</PRE> <PRE> sub STORE { ... } # mandatory if elements writeable sub STORESIZE { ... } # mandatory if elements can be added/deleted sub EXISTS { ... } # mandatory if exists() expected to work sub DELETE { ... } # mandatory if delete() expected to work</PRE> <PRE> # optional methods - for efficiency sub CLEAR { ... } sub PUSH { ... } sub POP { ... } sub SHIFT { ... } sub UNSHIFT { ... } sub SPLICE { ... } sub EXTEND { ... } sub DESTROY { ... }</PRE> <PRE> package NewStdArray; use Tie::Array;</PRE> <PRE> @ISA = ('Tie::StdArray');</PRE> <PRE> # all methods provided by default</PRE> <PRE> package main;</PRE> <PRE> $object = tie @somearray,Tie::NewArray; $object = tie @somearray,Tie::StdArray; $object = tie @somearray,Tie::NewStdArray;</PRE> <P> <HR> <H1><A NAME="description">DESCRIPTION</A></H1> <P>This module provides methods for array-tying classes. See <A HREF="../../lib/Pod/perltie.html">the perltie manpage</A> for a list of the functions required in order to tie an array to a package. The basic <STRONG>Tie::Array</STRONG> package provides stub <CODE>DESTROY</CODE>, and <CODE>EXTEND</CODE> methods that do nothing, stub <CODE>DELETE</CODE> and <CODE>EXISTS</CODE> methods that <CODE>croak()</CODE> if the <A HREF="../../lib/Pod/perlfunc.html#item_delete"><CODE>delete()</CODE></A> or <A HREF="../../lib/Pod/perlfunc.html#item_exists"><CODE>exists()</CODE></A> builtins are ever called on the tied array, and implementations of <CODE>PUSH</CODE>, <CODE>POP</CODE>, <CODE>SHIFT</CODE>, <CODE>UNSHIFT</CODE>, <CODE>SPLICE</CODE> and <CODE>CLEAR</CODE> in terms of basic <CODE>FETCH</CODE>, <CODE>STORE</CODE>, <CODE>FETCHSIZE</CODE>, <CODE>STORESIZE</CODE>.</P> <P>The <STRONG>Tie::StdArray</STRONG> package provides efficient methods required for tied arrays which are implemented as blessed references to an ``inner'' perl array. It inherits from <STRONG>Tie::Array</STRONG>, and should cause tied arrays to behave exactly like standard arrays, allowing for selective overloading of methods.</P> <P>For developers wishing to write their own tied arrays, the required methods are briefly defined below. See the <A HREF="../../lib/Pod/perltie.html">the perltie manpage</A> section for more detailed descriptive, as well as example code:</P> <DL> <DT><STRONG><A NAME="item_TIEARRAY_classname%2C_LIST">TIEARRAY classname, LIST</A></STRONG><BR> <DD> The class method is invoked by the command <CODE>tie @array, classname</CODE>. Associates an array instance with the specified class. <CODE>LIST</CODE> would represent additional arguments (along the lines of <A HREF="../../lib/AnyDBM_File.html">the AnyDBM_File manpage</A> and compatriots) needed to complete the association. The method should return an object of a class which provides the methods below. <P></P> <DT><STRONG><A NAME="item_STORE_this%2C_index%2C_value">STORE this, index, value</A></STRONG><BR> <DD> Store datum <EM>value</EM> into <EM>index</EM> for the tied array associated with object <EM>this</EM>. If this makes the array larger then class's mapping of <A HREF="../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> should be returned for new positions. <P></P> <DT><STRONG><A NAME="item_FETCH_this%2C_index">FETCH this, index</A></STRONG><BR> <DD> Retrieve the datum in <EM>index</EM> for the tied array associated with object <EM>this</EM>. <P></P> <DT><STRONG><A NAME="item_FETCHSIZE_this">FETCHSIZE this</A></STRONG><BR> <DD> Returns the total number of items in the tied array associated with object <EM>this</EM>. (Equivalent to <A HREF="../../lib/Pod/perlfunc.html#item_scalar"><CODE>scalar(@array)</CODE></A>). <P></P> <DT><STRONG><A NAME="item_STORESIZE_this%2C_count">STORESIZE this, count</A></STRONG><BR> <DD> Sets the total number of items in the tied array associated with object <EM>this</EM> to be <EM>count</EM>. If this makes the array larger then class's mapping of <A HREF="../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> should be returned for new positions. If the array becomes smaller then entries beyond count should be deleted. <P></P> <DT><STRONG><A NAME="item_EXTEND_this%2C_count">EXTEND this, count</A></STRONG><BR> <DD> Informative call that array is likely to grow to have <EM>count</EM> entries. Can be used to optimize allocation. This method need do nothing. <P></P> <DT><STRONG><A NAME="item_EXISTS_this%2C_key">EXISTS this, key</A></STRONG><BR> <DD> Verify that the element at index <EM>key</EM> exists in the tied array <EM>this</EM>. <P>The <STRONG>Tie::Array</STRONG> implementation is a stub that simply croaks.</P> <P></P> <DT><STRONG><A NAME="item_DELETE_this%2C_key">DELETE this, key</A></STRONG><BR> <DD> Delete the element at index <EM>key</EM> from the tied array <EM>this</EM>. <P>The <STRONG>Tie::Array</STRONG> implementation is a stub that simply croaks.</P> <P></P> <DT><STRONG><A NAME="item_CLEAR_this">CLEAR this</A></STRONG><BR> <DD> Clear (remove, delete, ...) all values from the tied array associated with object <EM>this</EM>. <P></P> <DT><STRONG><A NAME="item_DESTROY_this">DESTROY this</A></STRONG><BR> <DD> Normal object destructor method. <P></P> <DT><STRONG><A NAME="item_PUSH_this%2C_LIST">PUSH this, LIST</A></STRONG><BR> <DD> Append elements of LIST to the array. <P></P> <DT><STRONG><A NAME="item_POP_this">POP this</A></STRONG><BR> <DD> Remove last element of the array and return it. <P></P> <DT><STRONG><A NAME="item_SHIFT_this">SHIFT this</A></STRONG><BR> <DD> Remove the first element of the array (shifting other elements down) and return it. <P></P> <DT><STRONG><A NAME="item_UNSHIFT_this%2C_LIST">UNSHIFT this, LIST</A></STRONG><BR> <DD> Insert LIST elements at the beginning of the array, moving existing elements up to make room. <P></P> <DT><STRONG><A NAME="item_SPLICE_this%2C_offset%2C_length%2C_LIST">SPLICE this, offset, length, LIST</A></STRONG><BR> <DD> Perform the equivalent of <A HREF="../../lib/Pod/perlfunc.html#item_splice"><CODE>splice</CODE></A> on the array. <P><EM>offset</EM> is optional and defaults to zero, negative values count back from the end of the array.</P> <P><EM>length</EM> is optional and defaults to rest of the array.</P> <P><EM>LIST</EM> may be empty.</P> <P>Returns a list of the original <EM>length</EM> elements at <EM>offset</EM>.</P> <P></P></DL> <P> <HR> <H1><A NAME="caveats">CAVEATS</A></H1> <P>There is no support at present for tied @ISA. There is a potential conflict between magic entries needed to notice setting of @ISA, and those needed to implement 'tie'.</P> <P>Very little consideration has been given to the behaviour of tied arrays when <CODE>$[</CODE> is not default value of zero.</P> <P> <HR> <H1><A NAME="author">AUTHOR</A></H1> <P>Nick Ing-Simmons <<A HREF="mailto:nik@tiuk.ti.com">nik@tiuk.ti.com</A>></P> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%> <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc"> <STRONG><P CLASS=block> Tie::Array - base class for tied arrays</P></STRONG> </TD></TR> </TABLE> </BODY> </HTML>