Debian Codegraph @

upstream/debian-unstable/man3/Tie::Array.3perl

raw
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::Array 3perl"
58 .TH Tie::Array 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::Array \- base class for tied arrays
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 3
68 \& package Tie::NewArray;
69 \& use Tie::Array;
70 \& @ISA = (\*(AqTie::Array\*(Aq);
71 \&
72 \& # mandatory methods
73 \& sub TIEARRAY { ... }
74 \& sub FETCH { ... }
75 \& sub FETCHSIZE { ... }
76 \&
77 \& sub STORE { ... } # mandatory if elements writeable
78 \& sub STORESIZE { ... } # mandatory if elements can be added/deleted
79 \& sub EXISTS { ... } # mandatory if exists() expected to work
80 \& sub DELETE { ... } # mandatory if delete() expected to work
81 \&
82 \& # optional methods \- for efficiency
83 \& sub CLEAR { ... }
84 \& sub PUSH { ... }
85 \& sub POP { ... }
86 \& sub SHIFT { ... }
87 \& sub UNSHIFT { ... }
88 \& sub SPLICE { ... }
89 \& sub EXTEND { ... }
90 \& sub DESTROY { ... }
91 \&
92 \& package Tie::NewStdArray;
93 \& use Tie::Array;
94 \&
95 \& @ISA = (\*(AqTie::StdArray\*(Aq);
96 \&
97 \& # all methods provided by default
98 \&
99 \& package main;
100 \&
101 \& $object = tie @somearray,\*(AqTie::NewArray\*(Aq;
102 \& $object = tie @somearray,\*(AqTie::StdArray\*(Aq;
103 \& $object = tie @somearray,\*(AqTie::NewStdArray\*(Aq;
104 .Ve
105 .SH DESCRIPTION
106 .IX Header "DESCRIPTION"
107 This module provides methods for array-tying classes. See
108 perltie for a list of the functions required in order to tie an array
109 to a package. The basic \fBTie::Array\fR package provides stub \f(CW\*(C`DESTROY\*(C'\fR,
110 and \f(CW\*(C`EXTEND\*(C'\fR methods that do nothing, stub \f(CW\*(C`DELETE\*(C'\fR and \f(CW\*(C`EXISTS\*(C'\fR
111 methods that \fBcroak()\fR if the \fBdelete()\fR or \fBexists()\fR builtins are ever called
112 on the tied array, and implementations of \f(CW\*(C`PUSH\*(C'\fR, \f(CW\*(C`POP\*(C'\fR, \f(CW\*(C`SHIFT\*(C'\fR,
113 \&\f(CW\*(C`UNSHIFT\*(C'\fR, \f(CW\*(C`SPLICE\*(C'\fR and \f(CW\*(C`CLEAR\*(C'\fR in terms of basic \f(CW\*(C`FETCH\*(C'\fR, \f(CW\*(C`STORE\*(C'\fR,
114 \&\f(CW\*(C`FETCHSIZE\*(C'\fR, \f(CW\*(C`STORESIZE\*(C'\fR.
115 .PP
116 The \fBTie::StdArray\fR package provides efficient methods required for tied arrays
117 which are implemented as blessed references to an "inner" perl array.
118 It inherits from \fBTie::Array\fR, and should cause tied arrays to behave exactly
119 like standard arrays, allowing for selective overloading of methods.
120 .PP
121 For developers wishing to write their own tied arrays, the required methods
122 are briefly defined below. See the perltie section for more detailed
123 descriptive, as well as example code:
124 .IP "TIEARRAY classname, LIST" 4
125 .IX Item "TIEARRAY classname, LIST"
126 The class method is invoked by the command \f(CW\*(C`tie @array, classname\*(C'\fR. Associates
127 an array instance with the specified class. \f(CW\*(C`LIST\*(C'\fR would represent
128 additional arguments (along the lines of AnyDBM_File and compatriots) needed
129 to complete the association. The method should return an object of a class which
130 provides the methods below.
131 .IP "STORE this, index, value" 4
132 .IX Item "STORE this, index, value"
133 Store datum \fIvalue\fR into \fIindex\fR for the tied array associated with
134 object \fIthis\fR. If this makes the array larger then
135 class's mapping of \f(CW\*(C`undef\*(C'\fR should be returned for new positions.
136 .IP "FETCH this, index" 4
137 .IX Item "FETCH this, index"
138 Retrieve the datum in \fIindex\fR for the tied array associated with
139 object \fIthis\fR.
140 .IP "FETCHSIZE this" 4
141 .IX Item "FETCHSIZE this"
142 Returns the total number of items in the tied array associated with
143 object \fIthis\fR. (Equivalent to \f(CWscalar(@array)\fR).
144 .IP "STORESIZE this, count" 4
145 .IX Item "STORESIZE this, count"
146 Sets the total number of items in the tied array associated with
147 object \fIthis\fR to be \fIcount\fR. If this makes the array larger then
148 class's mapping of \f(CW\*(C`undef\*(C'\fR should be returned for new positions.
149 If the array becomes smaller then entries beyond count should be
150 deleted.
151 .IP "EXTEND this, count" 4
152 .IX Item "EXTEND this, count"
153 Informative call that array is likely to grow to have \fIcount\fR entries.
154 Can be used to optimize allocation. This method need do nothing.
155 .IP "EXISTS this, key" 4
156 .IX Item "EXISTS this, key"
157 Verify that the element at index \fIkey\fR exists in the tied array \fIthis\fR.
158 .Sp
159 The \fBTie::Array\fR implementation is a stub that simply croaks.
160 .IP "DELETE this, key" 4
161 .IX Item "DELETE this, key"
162 Delete the element at index \fIkey\fR from the tied array \fIthis\fR.
163 .Sp
164 The \fBTie::Array\fR implementation is a stub that simply croaks.
165 .IP "CLEAR this" 4
166 .IX Item "CLEAR this"
167 Clear (remove, delete, ...) all values from the tied array associated with
168 object \fIthis\fR.
169 .IP "DESTROY this" 4
170 .IX Item "DESTROY this"
171 Normal object destructor method.
172 .IP "PUSH this, LIST" 4
173 .IX Item "PUSH this, LIST"
174 Append elements of LIST to the array.
175 .IP "POP this" 4
176 .IX Item "POP this"
177 Remove last element of the array and return it.
178 .IP "SHIFT this" 4
179 .IX Item "SHIFT this"
180 Remove the first element of the array (shifting other elements down)
181 and return it.
182 .IP "UNSHIFT this, LIST" 4
183 .IX Item "UNSHIFT this, LIST"
184 Insert LIST elements at the beginning of the array, moving existing elements
185 up to make room.
186 .IP "SPLICE this, offset, length, LIST" 4
187 .IX Item "SPLICE this, offset, length, LIST"
188 Perform the equivalent of \f(CW\*(C`splice\*(C'\fR on the array.
189 .Sp
190 \&\fIoffset\fR is optional and defaults to zero, negative values count back
191 from the end of the array.
192 .Sp
193 \&\fIlength\fR is optional and defaults to rest of the array.
194 .Sp
195 \&\fILIST\fR may be empty.
196 .Sp
197 Returns a list of the original \fIlength\fR elements at \fIoffset\fR.
198 .SH CAVEATS
199 .IX Header "CAVEATS"
200 There is no support at present for tied \f(CW@ISA\fR. There is a potential conflict
201 between magic entries needed to notice setting of \f(CW@ISA\fR, and those needed to
202 implement 'tie'.
203 .SH AUTHOR
204 .IX Header "AUTHOR"
205 Nick Ing-Simmons <[email protected]>