1Tie::Scalar(3pm) Perl Programmers Reference Guide Tie::Scalar(3pm)
2
3
4
6 Tie::Scalar, Tie::StdScalar - base class definitions for tied scalars
7
9 package NewScalar;
10 require Tie::Scalar;
11
12 @ISA = (Tie::Scalar);
13
14 sub FETCH { ... } # Provide a needed method
15 sub TIESCALAR { ... } # Overrides inherited method
16
17 package NewStdScalar;
18 require Tie::Scalar;
19
20 @ISA = (Tie::StdScalar);
21
22 # All methods provided by default, so define only what needs be overridden
23 sub FETCH { ... }
24
25 package main;
26
27 tie $new_scalar, 'NewScalar';
28 tie $new_std_scalar, 'NewStdScalar';
29
31 This module provides some skeletal methods for scalar-tying classes.
32 See perltie for a list of the functions required in tying a scalar to a
33 package. The basic Tie::Scalar package provides a "new" method, as well
34 as methods "TIESCALAR", "FETCH" and "STORE". The Tie::StdScalar package
35 provides all the methods specified in perltie. It inherits from
36 Tie::Scalar and causes scalars tied to it to behave exactly like the
37 built-in scalars, allowing for selective overloading of methods. The
38 "new" method is provided as a means of grandfathering, for classes that
39 forget to provide their own "TIESCALAR" method.
40
41 For developers wishing to write their own tied-scalar classes, the
42 methods are summarized below. The perltie section not only documents
43 these, but has sample code as well:
44
45 TIESCALAR classname, LIST
46 The method invoked by the command "tie $scalar, classname". Asso‐
47 ciates a new scalar instance with the specified class. "LIST" would
48 represent additional arguments (along the lines of AnyDBM_File and
49 compatriots) needed to complete the association.
50
51 FETCH this
52 Retrieve the value of the tied scalar referenced by this.
53
54 STORE this, value
55 Store data value in the tied scalar referenced by this.
56
57 DESTROY this
58 Free the storage associated with the tied scalar referenced by
59 this. This is rarely needed, as Perl manages its memory quite
60 well. But the option exists, should a class wish to perform spe‐
61 cific actions upon the destruction of an instance.
62
64 The perltie section uses a good example of tying scalars by associating
65 process IDs with priority.
66
67
68
69perl v5.8.8 2001-09-21 Tie::Scalar(3pm)