Debian Codegraph @

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