perlfunc
root
<P>
Tie::Handle - base class definitions for tied handles
<P>
<HR>
<P>
<PRE> package NewHandle;
require Tie::Handle;
@ISA = (Tie::Handle);
sub READ { ... } # Provide a needed method
sub TIEHANDLE { ... } # Overrides inherited method
package main;
<P>
This module provides some skeletal methods for handle-tying classes. See
[perlman:perltie|perltie] for a list of the functions required in tying a handle to a package. The
basic <STRONG>Tie::Handle</STRONG> package provides a <CODE>new</CODE> method, as well as methods
<CODE>TIESCALAR</CODE>, <CODE>FETCH</CODE> and <CODE>STORE</CODE>. The <CODE>new</CODE> method is provided as a means of grandfathering, for classes that forget to
provide their own <CODE>TIESCALAR</CODE>
method.
<P>
For developers wishing to write their own tied-handle classes, the methods
are summarized below. The [perlman:perltie|perltie] section not only documents these, but has sample code as well:
<DL>
<DT><STRONG><A NAME="item_TIEHANDLE">TIEHANDLE classname, LIST</A></STRONG><P>
<DD>
The method invoked by the command <CODE>tie *glob, classname</CODE>. Associates a new glob instance with the specified class. <CODE>LIST</CODE> would represent additional arguments (along the lines of [perlman:lib:AnyDBM_File|AnyDBM_File] and compatriots) needed to complete the association.
<P><DT><STRONG><A NAME="item_WRITE">WRITE this, scalar, length, offset</A></STRONG><P>
<DD>
Write <EM>length</EM> bytes of data from <EM>scalar</EM> starting at <EM>offset</EM>.
<P><DT><STRONG><A NAME="item_PRINT">PRINT this, LIST</A></STRONG><P>
<DD>
Print the values in <EM>LIST</EM>
<P><DT><STRONG><A NAME="item_PRINTF">PRINTF this, format, LIST</A></STRONG><P>
<DD>
Print the values in <EM>LIST</EM> using <EM>format</EM>
<P><DT><STRONG><A NAME="item_READ">READ this, scalar, length, offset</A></STRONG><P>
<DD>
Read <EM>length</EM> bytes of data into <EM>scalar</EM> starting at <EM>offset</EM>.
<P><DT><STRONG><A NAME="item_READLINE">READLINE this</A></STRONG><P>
<DD>
Read a single line
<P><DT><STRONG><A NAME="item_GETC">GETC this</A></STRONG><P>
<DD>
Get a single character
<P><DT><STRONG><A NAME="item_DESTROY">DESTROY this</A></STRONG><P>
<DD>
Free the storage associated with the tied handle referenced by <EM>this</EM>. This is rarely needed, as Perl manages its memory quite well. But the
option exists, should a class wish to perform specific actions upon the
destruction of an instance.
</DL>
<P>
<HR>
<H1><A NAME="MORE_INFORMATION">MORE INFORMATION</A></H1>
<P>
The [perlman:perltie|perltie] section contains an example of tying handles.
<HR>