Debian Codegraph @

upstream/opensuse-tumbleweed/man3/Tie::Scalar.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Tie::Scalar 3pm"
61 .TH Tie::Scalar 3pm 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Tie::Scalar, Tie::StdScalar \- base class definitions for tied scalars
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 2
71 \& package NewScalar;
72 \& require Tie::Scalar;
73 \&
74 \& @ISA = qw(Tie::Scalar);
75 \&
76 \& sub FETCH { ... } # Provide a needed method
77 \& sub TIESCALAR { ... } # Overrides inherited method
78 \&
79 \&
80 \& package NewStdScalar;
81 \& require Tie::Scalar;
82 \&
83 \& @ISA = qw(Tie::StdScalar);
84 \&
85 \& # All methods provided by default, so define
86 \& # only what needs be overridden
87 \& sub FETCH { ... }
88 \&
89 \&
90 \& package main;
91 \&
92 \& tie $new_scalar, \*(AqNewScalar\*(Aq;
93 \& tie $new_std_scalar, \*(AqNewStdScalar\*(Aq;
94 .Ve
95 .SH DESCRIPTION
96 .IX Header "DESCRIPTION"
97 This module provides some skeletal methods for scalar\-tying classes. See
98 perltie for a list of the functions required in tying a scalar to a
99 package. The basic \fBTie::Scalar\fR package provides a \f(CW\*(C`new\*(C'\fR method, as well
100 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
101 package provides all the methods specified in perltie. It inherits from
102 \&\fBTie::Scalar\fR and causes scalars tied to it to behave exactly like the
103 built\-in scalars, allowing for selective overloading of methods. The \f(CW\*(C`new\*(C'\fR
104 method is provided as a means of legacy support for classes that forget to
105 provide their own \f(CW\*(C`TIESCALAR\*(C'\fR method.
106 .PP
107 For developers wishing to write their own tied\-scalar classes, the methods
108 are summarized below. The perltie section not only documents these, but
109 has sample code as well:
110 .IP "TIESCALAR classname, LIST" 4
111 .IX Item "TIESCALAR classname, LIST"
112 The method invoked by the command \f(CW\*(C`tie $scalar, classname\*(C'\fR. Associates a new
113 scalar instance with the specified class. \f(CW\*(C`LIST\*(C'\fR would represent additional
114 arguments (along the lines of AnyDBM_File and compatriots) needed to
115 complete the association.
116 .IP "FETCH this" 4
117 .IX Item "FETCH this"
118 Retrieve the value of the tied scalar referenced by \fIthis\fR.
119 .IP "STORE this, value" 4
120 .IX Item "STORE this, value"
121 Store data \fIvalue\fR in the tied scalar referenced by \fIthis\fR.
122 .IP "DESTROY this" 4
123 .IX Item "DESTROY this"
124 Free the storage associated with the tied scalar referenced by \fIthis\fR.
125 This is rarely needed, as Perl manages its memory quite well. But the
126 option exists, should a class wish to perform specific actions upon the
127 destruction of an instance.
128 .SS "Tie::Scalar vs Tie::StdScalar"
129 .IX Subsection "Tie::Scalar vs Tie::StdScalar"
130 \&\f(CW\*(C`Tie::Scalar\*(C'\fR provides all the necessary methods, but one should realize
131 they do not do anything useful. Calling \f(CW\*(C`Tie::Scalar::FETCH\*(C'\fR or
132 \&\f(CW\*(C`Tie::Scalar::STORE\*(C'\fR results in a (trappable) croak. And if you inherit
133 from \f(CW\*(C`Tie::Scalar\*(C'\fR, you \fImust\fR provide either a \f(CW\*(C`new\*(C'\fR or a
134 \&\f(CW\*(C`TIESCALAR\*(C'\fR method.
135 .PP
136 If you are looking for a class that does everything for you that you don\*(Aqt
137 define yourself, use the \f(CW\*(C`Tie::StdScalar\*(C'\fR class, not the
138 \&\f(CW\*(C`Tie::Scalar\*(C'\fR one.
139 .SH "MORE INFORMATION"
140 .IX Header "MORE INFORMATION"
141 The perltie section uses a good example of tying scalars by associating
142 process IDs with priority.