1MakeMethods::Standard::UIsnehrerCiotnatbrlieb(u3t)ed PerMlakDeoMceutmheondtsa:t:iSotnandard::Inheritable(3)
2
3
4

NAME

6       Class::MakeMethods::Standard::Inheritable - Overridable data
7

SYNOPSIS

9         package MyClass;
10
11         use Class::MakeMethods( 'Standard::Inheritable:scalar' => 'foo' );
12         # We now have an accessor method for an "inheritable" scalar value
13
14         MyClass->foo( 'Foozle' );   # Set a class-wide value
15         print MyClass->foo();       # Retrieve class-wide value
16
17         my $obj = MyClass->new(...);
18         print $obj->foo();          # All instances "inherit" that value...
19
20         $obj->foo( 'Foible' );      # until you set a value for an instance.
21         print $obj->foo();          # This now finds object-specific value.
22         ...
23
24         package MySubClass;
25         @ISA = 'MyClass';
26
27         print MySubClass->foo();    # Intially same as superclass,
28         MySubClass->foo('Foobar');  # but overridable per subclass,
29         print $subclass_obj->foo(); # and shared by its instances
30         $subclass_obj->foo('Fosil');# until you override them...
31         ...
32
33         # Similar behaviour for hashes and arrays is currently incomplete
34         package MyClass;
35         use Class::MakeMethods::Standard::Inheritable (
36           array => 'my_list',
37           hash => 'my_index',
38         );
39
40         MyClass->my_list(0 => 'Foozle', 1 => 'Bang!');
41         print MyClass->my_list(1);
42
43         MyClass->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
44         print MyClass->my_index('foo');
45

DESCRIPTION

47       The MakeMethods subclass provides accessor methods that search an
48       inheritance tree to find a value. This allows you to set a shared or
49       default value for a given class, optionally override it in a subclass,
50       and then optionally override it on a per-instance basis.
51
52       Note that all MakeMethods methods are inheritable, in the sense that
53       they work as expected for subclasses. These methods are different in
54       that the data accessed by each method can be inherited or overridden in
55       each subclass or instance. See Class::MakeMethods::Utility::Inheritable
56       for more about this type of "inheritable" or overridable" data.
57
58       Calling Conventions
59
60       When you "use" this package, the method names you provide as arguments
61       cause subroutines to be generated and installed in your module.
62
63       See "Calling Conventions" in Class::MakeMethods::Standard for more
64       information.
65
66       Declaration Syntax
67
68       To declare methods, pass in pairs of a method-type name followed by one
69       or more method names.
70
71       Valid method-type names for this package are listed in "METHOD GENERA‐
72       TOR TYPES".
73
74       See "Declaration Syntax" in Class::MakeMethods::Standard and "Parameter
75       Syntax" in Class::MakeMethods::Standard for more information.
76

METHOD GENERATOR TYPES

78       scalar - Class-specific Accessor
79
80       For each method name passed, uses a closure to generate a subroutine
81       with the following characteristics:
82
83       ·   May be called as a class or instance method, on the declaring class
84           or any subclass.
85
86       ·   If called without any arguments returns the current value for the
87           callee. If the callee has not had a value defined for this method,
88           searches up from instance to class, and from class to superclass,
89           until a callee with a value is located.
90
91       ·   If called with an argument, stores that as the value associated
92           with the callee, whether instance or class, and returns it,
93
94       Sample declaration and usage:
95
96         package MyClass;
97         use Class::MakeMethods::Standard::Inheritable (
98           scalar => 'foo',
99         );
100         ...
101
102         # Store value
103         MyClass->foo('Foozle');
104
105         # Retrieve value
106         print MyClass->foo;
107
108       array - Class-specific Ref Accessor
109
110       For each method name passed, uses a closure to generate a subroutine
111       with the following characteristics:
112
113       ·   May be called as a class method, or on any instance or subclass,
114           Must be called on a hash-based instance.
115
116       ·   The class value will be a reference to an array (or undef).
117
118       ·   If called without any arguments, returns the contents of the array
119           in list context, or an array reference in scalar context (or
120           undef).
121
122       ·   If called with a single array ref argument, sets the contents of
123           the array to match the contents of the provided one.
124
125       ·   If called with a single numeric argument, uses that argument as an
126           index to retrieve from the referenced array, and returns that value
127           (or undef).
128
129       ·   If called with a two arguments, the first undefined and the second
130           an array ref argument, uses that array's contents as a list of
131           indexes to return a slice of the referenced array.
132
133       ·   If called with a list of argument pairs, each with a non-ref index
134           and an associated value, stores the value at the given index in the
135           referenced array. If the class value was previously undefined, a
136           new array is autovivified. The current value in each position will
137           be overwritten, and later arguments with the same index will over‐
138           ride earlier ones. Returns the current array-ref value.
139
140       ·   If called with a list of argument pairs, each with the first item
141           being a reference to an array of up to two numbers, loops over each
142           pair and uses those numbers to splice the value array.
143
144           The first controlling number is the position at which the splice
145           will begin. Zero will start before the first item in the list. Neg‐
146           ative numbers count backwards from the end of the array.
147
148           The second number is the number of items to be removed from the
149           list. If it is omitted, or undefined, or zero, no items are
150           removed. If it is a positive integer, that many items will be
151           returned.
152
153           If both numbers are omitted, or are both undefined, they default to
154           containing the entire value array.
155
156           If the second argument is undef, no values will be inserted; if it
157           is a non-reference value, that one value will be inserted; if it is
158           an array-ref, its values will be copied.
159
160           The method returns the items that removed from the array, if any.
161
162       Sample declaration and usage:
163
164         package MyClass;
165         use Class::MakeMethods::Standard::Inheritable (
166           array => 'bar',
167         );
168         ...
169
170         # Clear and set contents of list
171         print MyClass->bar([ 'Spume', 'Frost' ] );
172
173         # Set values by position
174         MyClass->bar(0 => 'Foozle', 1 => 'Bang!');
175
176         # Positions may be overwritten, and in any order
177         MyClass->bar(2 => 'And Mash', 1 => 'Blah!');
178
179         # Retrieve value by position
180         print MyClass->bar(1);
181
182         # Direct access to referenced array
183         print scalar @{ MyClass->bar() };
184
185       There are also calling conventions for slice and splice operations:
186
187         # Retrieve slice of values by position
188         print join(', ', MyClass->bar( undef, [0, 2] ) );
189
190         # Insert an item at position in the array
191         MyClass->bar([3], 'Potatoes' );
192
193         # Remove 1 item from position 3 in the array
194         MyClass->bar([3, 1], undef );
195
196         # Set a new value at position 2, and return the old value
197         print MyClass->bar([2, 1], 'Froth' );
198
199       hash - Class-specific Ref Accessor
200
201       For each method name passed, uses a closure to generate a subroutine
202       with the following characteristics:
203
204       ·   May be called as a class method, or on any instance or subclass,
205           Must be called on a hash-based instance.
206
207       ·   The class value will be a reference to a hash (or undef).
208
209       ·   If called without any arguments, returns the contents of the hash
210           in list context, or a hash reference in scalar context. If the
211           callee has not had a value defined for this method, searches up
212           from instance to class, and from class to superclass, until a
213           callee with a value is located.
214
215       ·   If called with one non-ref argument, uses that argument as an index
216           to retrieve from the referenced hash, and returns that value (or
217           undef). If the callee has not had a value defined for this method,
218           searches up from instance to class, and from class to superclass,
219           until a callee with a value is located.
220
221       ·   If called with one array-ref argument, uses the contents of that
222           array to retrieve a slice of the referenced hash. If the callee has
223           not had a value defined for this method, searches up from instance
224           to class, and from class to superclass, until a callee with a value
225           is located.
226
227       ·   If called with one hash-ref argument, sets the contents of the ref‐
228           erenced hash to match that provided.
229
230       ·   If called with a list of key-value pairs, stores the value under
231           the given key in the hash associated with the callee, whether
232           instance or class. If the callee did not previously have a hash-ref
233           value associated with it, searches up instance to class, and from
234           class to superclass, until a callee with a value is located, and
235           copies that hash before making the assignments. The current value
236           under each key will be overwritten, and later arguments with the
237           same key will override earlier ones. Returns the contents of the
238           hash in list context, or a hash reference in scalar context.
239
240       Sample declaration and usage:
241
242         package MyClass;
243         use Class::MakeMethods::Standard::Inheritable (
244           hash => 'baz',
245         );
246         ...
247
248         # Set values by key
249         MyClass->baz('foo' => 'Foozle', 'bar' => 'Bang!');
250
251         # Values may be overwritten, and in any order
252         MyClass->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle');
253
254         # Retrieve value by key
255         print MyClass->baz('foo');
256
257         # Retrive slice of values by position
258         print join(', ', MyClass->baz( ['foo', 'bar'] ) );
259
260         # Direct access to referenced hash
261         print keys %{ MyClass->baz() };
262
263         # Reset the hash contents to empty
264         @{ MyClass->baz() } = ();
265
266       NOTE: THIS METHOD GENERATOR IS INCOMPLETE.
267
268       object - Class-specific Ref Accessor
269
270       For each method name passed, uses a closure to generate a subroutine
271       with the following characteristics:
272
273       ·   May be called as a class method, or on any instance or subclass,
274           Must be called on a hash-based instance.
275
276       ·   The class value will be a reference to an object (or undef).
277
278       ·   If called without any arguments returns the current value for the
279           callee. If the callee has not had a value defined for this method,
280           searches up from instance to class, and from class to superclass,
281           until a callee with a value is located.
282
283       ·   If called with an argument, stores that as the value associated
284           with the callee, whether instance or class, and returns it,
285
286       Sample declaration and usage:
287
288         package MyClass;
289         use Class::MakeMethods::Standard::Inheritable (
290           object => 'foo',
291         );
292         ...
293
294         # Store value
295         MyClass->foo( Foozle->new() );
296
297         # Retrieve value
298         print MyClass->foo;
299
300       NOTE: THIS METHOD GENERATOR HAS NOT BEEN WRITTEN YET.
301

SEE ALSO

303       See Class::MakeMethods for general information about this distribution.
304
305       See Class::MakeMethods::Standard for more about this family of sub‐
306       classes.
307
308
309
310perl v5.8.8                       2004-09-M0a6keMethods::Standard::Inheritable(3)
Impressum