To implement a tied scalar, a class must define the following methods:
DESTROY). When you
tie a scalar
variable, Perl calls
TIESCALAR. When you read the tied variable, it calls
FETCH, and when you assign a value to the
variable, it calls
If you’ve kept the object returned by the initial
tie (or if you retrieve it later
tied), you can access the
underlying object yourself—this does not trigger its
STORE methods. As an object it’s not magical
at all, but rather quite objective.
UNTIE, if you’ve
defined it, when it unties the variable. This gives you a chance to do
any bookkeeping or clean-up before the association disappears and the
variable is no longer special.
DESTROY method exists,
Perl invokes it when the last reference to the tied object disappears,
just as for any other object. That happens when your program ends or
when you call
eliminates the reference used by the tie. However,
untie doesn’t eliminate any outstanding
references you might have stored elsewhere;
DESTROY is deferred until those references
are gone, too.
Tie::StdScalar packages, both found in the standard
Tie::Scalar module, provide some simple base
class definitions if you don’t want to define all of these methods
elemental methods that do very little, and
Tie::StdScalar provides methods that make a tied scalar behave like a regular Perl scalar. ...