1Tie::Array(3pm)        Perl Programmers Reference Guide        Tie::Array(3pm)
2
3
4

NAME

6       Tie::Array - base class for tied arrays
7

SYNOPSIS

9           package Tie::NewArray;
10           use Tie::Array;
11           @ISA = ('Tie::Array');
12
13           # mandatory methods
14           sub TIEARRAY { ... }
15           sub FETCH { ... }
16           sub FETCHSIZE { ... }
17
18           sub STORE { ... }        # mandatory if elements writeable
19           sub STORESIZE { ... }    # mandatory if elements can be added/deleted
20           sub EXISTS { ... }       # mandatory if exists() expected to work
21           sub DELETE { ... }       # mandatory if delete() expected to work
22
23           # optional methods - for efficiency
24           sub CLEAR { ... }
25           sub PUSH { ... }
26           sub POP { ... }
27           sub SHIFT { ... }
28           sub UNSHIFT { ... }
29           sub SPLICE { ... }
30           sub EXTEND { ... }
31           sub DESTROY { ... }
32
33           package Tie::NewStdArray;
34           use Tie::Array;
35
36           @ISA = ('Tie::StdArray');
37
38           # all methods provided by default
39
40           package main;
41
42           $object = tie @somearray,'Tie::NewArray';
43           $object = tie @somearray,'Tie::StdArray';
44           $object = tie @somearray,'Tie::NewStdArray';
45

DESCRIPTION

47       This module provides methods for array-tying classes. See perltie for a
48       list of the functions required in order to tie an array to a package.
49       The basic Tie::Array package provides stub "DESTROY", and "EXTEND"
50       methods that do nothing, stub "DELETE" and "EXISTS" methods that
51       croak() if the delete() or exists() builtins are ever called on the
52       tied array, and implementations of "PUSH", "POP", "SHIFT", "UNSHIFT",
53       "SPLICE" and "CLEAR" in terms of basic "FETCH", "STORE", "FETCHSIZE",
54       "STORESIZE".
55
56       The Tie::StdArray package provides efficient methods required for tied
57       arrays which are implemented as blessed references to an "inner" perl
58       array.  It inherits from Tie::Array, and should cause tied arrays to
59       behave exactly like standard arrays, allowing for selective overloading
60       of methods.
61
62       For developers wishing to write their own tied arrays, the required
63       methods are briefly defined below. See the perltie section for more
64       detailed descriptive, as well as example code:
65
66       TIEARRAY classname, LIST
67           The class method is invoked by the command "tie @array, classname".
68           Associates an array instance with the specified class. "LIST" would
69           represent additional arguments (along the lines of AnyDBM_File and
70           compatriots) needed to complete the association. The method should
71           return an object of a class which provides the methods below.
72
73       STORE this, index, value
74           Store datum value into index for the tied array associated with
75           object this. If this makes the array larger then class's mapping of
76           "undef" should be returned for new positions.
77
78       FETCH this, index
79           Retrieve the datum in index for the tied array associated with
80           object this.
81
82       FETCHSIZE this
83           Returns the total number of items in the tied array associated with
84           object this. (Equivalent to "scalar(@array)").
85
86       STORESIZE this, count
87           Sets the total number of items in the tied array associated with
88           object this to be count. If this makes the array larger then
89           class's mapping of "undef" should be returned for new positions.
90           If the array becomes smaller then entries beyond count should be
91           deleted.
92
93       EXTEND this, count
94           Informative call that array is likely to grow to have count
95           entries.  Can be used to optimize allocation. This method need do
96           nothing.
97
98       EXISTS this, key
99           Verify that the element at index key exists in the tied array this.
100
101           The Tie::Array implementation is a stub that simply croaks.
102
103       DELETE this, key
104           Delete the element at index key from the tied array this.
105
106           The Tie::Array implementation is a stub that simply croaks.
107
108       CLEAR this
109           Clear (remove, delete, ...) all values from the tied array
110           associated with object this.
111
112       DESTROY this
113           Normal object destructor method.
114
115       PUSH this, LIST
116           Append elements of LIST to the array.
117
118       POP this
119           Remove last element of the array and return it.
120
121       SHIFT this
122           Remove the first element of the array (shifting other elements
123           down) and return it.
124
125       UNSHIFT this, LIST
126           Insert LIST elements at the beginning of the array, moving existing
127           elements up to make room.
128
129       SPLICE this, offset, length, LIST
130           Perform the equivalent of "splice" on the array.
131
132           offset is optional and defaults to zero, negative values count back
133           from the end of the array.
134
135           length is optional and defaults to rest of the array.
136
137           LIST may be empty.
138
139           Returns a list of the original length elements at offset.
140

CAVEATS

142       There is no support at present for tied @ISA. There is a potential
143       conflict between magic entries needed to notice setting of @ISA, and
144       those needed to implement 'tie'.
145

AUTHOR

147       Nick Ing-Simmons <nik@tiuk.ti.com>
148
149
150
151perl v5.16.3                      2013-03-04                   Tie::Array(3pm)
Impressum