perlfunc
root
<P>
Tie::Scalar, Tie::StdScalar - base class definitions for tied scalars
<P>
<HR>
<P>
<PRE> package NewScalar;
require Tie::Scalar;
@ISA = (Tie::Scalar);
sub FETCH { ... } # Provide a needed method
sub TIESCALAR { ... } # Overrides inherited method
package NewStdScalar
<P>
This module provides some skeletal methods for scalar-tying classes. See
[perlman:perltie|perltie] for a list of the functions required in tying a scalar to a package. The
basic <STRONG>Tie::Scalar</STRONG> package provides a <CODE>new</CODE> method, as well as methods <CODE>TIESCALAR</CODE>, <CODE>FETCH</CODE> and <CODE>STORE</CODE>. The <STRONG>Tie::StdScalar</STRONG>
package provides all the methods specified in [perlman:perltie|perltie]. It inherits from
<STRONG>Tie::Scalar</STRONG> and causes scalars tied to it to behave exactly like the built-in scalars,
allowing for selective overloading of methods. 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-scalar 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_TIESCALAR">TIESCALAR classname, LIST</A></STRONG><P>
<DD>
The method invoked by the command <CODE>tie $scalar, classname</CODE>. Associates a new scalar 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_FETCH">FETCH this</A></STRONG><P>
<DD>
Retrieve the value of the tied scalar referenced by <EM>this</EM>.
<P><DT><STRONG><A NAME="item_STORE">STORE this, value</A></STRONG><P>
<DD>
Store data <EM>value</EM> in the tied scalar referenced by <EM>this</EM>.
<P><DT><STRONG><A NAME="item_DESTROY">DESTROY this</A></STRONG><P>
<DD>
Free the storage associated with the tied scalar 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 uses a good example of tying scalars by associating process IDs
with priority.
<HR>