| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "Tie::Scalar 3perl" |
| 58 |
.TH Tie::Scalar 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
Tie::Scalar, Tie::StdScalar \- base class definitions for tied scalars |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 2 |
| 68 |
\& package NewScalar; |
| 69 |
\& require Tie::Scalar; |
| 70 |
\& |
| 71 |
\& @ISA = qw(Tie::Scalar); |
| 72 |
\& |
| 73 |
\& sub FETCH { ... } # Provide a needed method |
| 74 |
\& sub TIESCALAR { ... } # Overrides inherited method |
| 75 |
\& |
| 76 |
\& |
| 77 |
\& package NewStdScalar; |
| 78 |
\& require Tie::Scalar; |
| 79 |
\& |
| 80 |
\& @ISA = qw(Tie::StdScalar); |
| 81 |
\& |
| 82 |
\& # All methods provided by default, so define |
| 83 |
\& # only what needs be overridden |
| 84 |
\& sub FETCH { ... } |
| 85 |
\& |
| 86 |
\& |
| 87 |
\& package main; |
| 88 |
\& |
| 89 |
\& tie $new_scalar, \*(AqNewScalar\*(Aq; |
| 90 |
\& tie $new_std_scalar, \*(AqNewStdScalar\*(Aq; |
| 91 |
.Ve |
| 92 |
.SH DESCRIPTION |
| 93 |
.IX Header "DESCRIPTION" |
| 94 |
This module provides some skeletal methods for scalar-tying classes. See |
| 95 |
perltie for a list of the functions required in tying a scalar to a |
| 96 |
package. The basic \fBTie::Scalar\fR package provides a \f(CW\*(C`new\*(C'\fR method, as well |
| 97 |
as methods \f(CW\*(C`TIESCALAR\*(C'\fR, \f(CW\*(C`FETCH\*(C'\fR and \f(CW\*(C`STORE\*(C'\fR. The \fBTie::StdScalar\fR |
| 98 |
package provides all the methods specified in perltie. It inherits from |
| 99 |
\&\fBTie::Scalar\fR and causes scalars tied to it to behave exactly like the |
| 100 |
built-in scalars, allowing for selective overloading of methods. The \f(CW\*(C`new\*(C'\fR |
| 101 |
method is provided as a means of legacy support for classes that forget to |
| 102 |
provide their own \f(CW\*(C`TIESCALAR\*(C'\fR method. |
| 103 |
.PP |
| 104 |
For developers wishing to write their own tied-scalar classes, the methods |
| 105 |
are summarized below. The perltie section not only documents these, but |
| 106 |
has sample code as well: |
| 107 |
.IP "TIESCALAR classname, LIST" 4 |
| 108 |
.IX Item "TIESCALAR classname, LIST" |
| 109 |
The method invoked by the command \f(CW\*(C`tie $scalar, classname\*(C'\fR. Associates a new |
| 110 |
scalar instance with the specified class. \f(CW\*(C`LIST\*(C'\fR would represent additional |
| 111 |
arguments (along the lines of AnyDBM_File and compatriots) needed to |
| 112 |
complete the association. |
| 113 |
.IP "FETCH this" 4 |
| 114 |
.IX Item "FETCH this" |
| 115 |
Retrieve the value of the tied scalar referenced by \fIthis\fR. |
| 116 |
.IP "STORE this, value" 4 |
| 117 |
.IX Item "STORE this, value" |
| 118 |
Store data \fIvalue\fR in the tied scalar referenced by \fIthis\fR. |
| 119 |
.IP "DESTROY this" 4 |
| 120 |
.IX Item "DESTROY this" |
| 121 |
Free the storage associated with the tied scalar referenced by \fIthis\fR. |
| 122 |
This is rarely needed, as Perl manages its memory quite well. But the |
| 123 |
option exists, should a class wish to perform specific actions upon the |
| 124 |
destruction of an instance. |
| 125 |
.SS "Tie::Scalar vs Tie::StdScalar" |
| 126 |
.IX Subsection "Tie::Scalar vs Tie::StdScalar" |
| 127 |
\&\f(CW\*(C`Tie::Scalar\*(C'\fR provides all the necessary methods, but one should realize |
| 128 |
they do not do anything useful. Calling \f(CW\*(C`Tie::Scalar::FETCH\*(C'\fR or |
| 129 |
\&\f(CW\*(C`Tie::Scalar::STORE\*(C'\fR results in a (trappable) croak. And if you inherit |
| 130 |
from \f(CW\*(C`Tie::Scalar\*(C'\fR, you \fImust\fR provide either a \f(CW\*(C`new\*(C'\fR or a |
| 131 |
\&\f(CW\*(C`TIESCALAR\*(C'\fR method. |
| 132 |
.PP |
| 133 |
If you are looking for a class that does everything for you that you don't |
| 134 |
define yourself, use the \f(CW\*(C`Tie::StdScalar\*(C'\fR class, not the |
| 135 |
\&\f(CW\*(C`Tie::Scalar\*(C'\fR one. |
| 136 |
.SH "MORE INFORMATION" |
| 137 |
.IX Header "MORE INFORMATION" |
| 138 |
The perltie section uses a good example of tying scalars by associating |
| 139 |
process IDs with priority. |