1MakeMethods::Emulator::UMseetrhoCdoMnatkreirb(u3t)ed PerMlakDeoMceutmheondtsa:t:iEomnulator::MethodMaker(3)
2
3
4
6 Class::MakeMethods::Emulator::MethodMaker - Emulate Class::MethodMaker
7
9 package MyObject;
10 use Class::MakeMethods::Emulator::MethodMaker(
11 new_with_init => 'new',
12 get_set => [ qw / foo bar baz / ];
13 );
14
15 ... OR ...
16
17 package MyObject;
18 use Class::MakeMethods::Emulator::MethodMaker '-take_namespace';
19 use Class::MethodMaker (
20 new_with_init => 'new',
21 get_set => [ qw / foo bar baz / ];
22 );
23
25 This module provides emulation of Class::MethodMaker, using the
26 Class::MakeMethods framework.
27
28 Although originally based on Class::MethodMaker, the calling convention
29 for Class::MakeMethods differs in a variety of ways; most notably, the
30 names given to various types of methods have been changed, and the for‐
31 mat for specifying method attributes has been standardized. This pack‐
32 age uses the aliasing capability provided by Class::MakeMethods, defin‐
33 ing methods that modify the declaration arguments as necessary and pass
34 them off to various subclasses of Class::MakeMethods.
35
37 Full compatibility is maintained with version 1.03; some of the changes
38 in versions 1.04 through 1.10 are not yet included.
39
40 The test suite from Class::MethodMaker version 1.10 is included with
41 this package, in the t/emulator_class_methodmaker/ directory. The
42 unsupported tests have names ending in ".todo".
43
44 The tests are unchanged from those in the Class::MethodMaker distribu‐
45 tion, except for the substitution of "Class::MakeMethods::Emula‐
46 tor::MethodMaker" in the place of "Class::MethodMaker".
47
48 In cases where earlier distributions of Class::MethodMaker contained a
49 different version of a test, it is also included. (Note that version
50 0.92's get_concat returned '' for empty values, but in version 0.96
51 this was changed to undef; this emulator follows the later behavior. To
52 avoid "use of undefined value" warnings from the 0.92 version of
53 get_concat.t, that test has been modified by appending a new flag after
54 the name, 'get_concat --noundef', which restores the earlier behavior.)
55
57 There are several ways to call this emulation module:
58
59 · Direct Access
60
61 Replace occurances in your code of "Class::MethodMaker" with
62 "Class::MakeMethods::Emulator::MethodMaker".
63
64 · Install Emulation
65
66 If you "use Class::MakeMethods::Emulator::MethodMaker '-take_names‐
67 pace'", the Class::MethodMaker namespace will be aliased to this
68 package, and calls to the original package will be transparently
69 handled by this emulator.
70
71 To remove the emulation aliasing, call "use Class::MakeMeth‐
72 ods::Emulator::MethodMaker '-release_namespace'".
73
74 Note: This affects all subsequent uses of Class::MethodMaker in
75 your program, including those in other modules, and might cause
76 unexpected effects.
77
78 · The -sugar Option
79
80 Passing '-sugar' as the first argument in a use or import call will
81 cause the 'methods' package to be declared as an alias to this one.
82
83 This allows you to write declarations in the following manner.
84
85 use Class::MakeMethods::Emulator::MethodMaker '-sugar';
86
87 make methods
88 get_set => [ qw / foo bar baz / ],
89 list => [ qw / a b c / ];
90
91 Note: This feature is deprecated in Class::MethodMaker version 0.96
92 and later.
93
95 NOTE: The documentation below is derived from version 1.02 of
96 Class::MethodMaker. Class::MakeMethods::Emulator::MethodMaker provides
97 support for all of the features and examples shown below, with no
98 changes required.
99
101 new
102
103 Equivalent to Class::MakeMethods 'Template::Hash:new --with_values'.
104
105 new_with_init
106
107 Equivalent to Class::MakeMethods 'Template::Hash:new --with_init'.
108
109 new_hash_init
110
111 Equivalent to Class::MakeMethods 'Template::Hash:new
112 --instance_with_methods'.
113
114 new_with_args
115
116 Equivalent to Class::MakeMethods 'Template::Hash:new --with_values'.
117
118 copy
119
120 Equivalent to Class::MakeMethods 'Template::Hash:new --copy_with_val‐
121 ues'.
122
124 get_set
125
126 Basically equivalent to Class::MakeMethods 'Template::Hash:scalar',
127 except that various arguments are intercepted and converted into the
128 parallel Class::MakeMethods::Template interface declarations.
129
130 get_concat
131
132 Equivalent to Class::MakeMethods 'Template::Hash:string' with a special
133 interface declaration that provides the get_concat and clear behaviors.
134
135 counter
136
137 Equivalent to Class::MakeMethods 'Template::Hash:number --counter'.
138
140 Basically equivalent to Class::MakeMethods 'Template::Hash:object' with
141 an declaration that provides the "delete_x" interface. Due to a differ‐
142 ence in expected argument syntax, the incoming arguments are revised
143 before being delegated to Template::Hash:object.
144
145 object_list
146
147 Basically equivalent to Class::MakeMethods 'Template::Hash:object_list'
148 with an declaration that provides the relevant helper methods. Due to a
149 difference in expected argument syntax, the incoming arguments are
150 revised before being delegated to Template::Hash:object_list.
151
152 forward
153
154 Basically equivalent to Class::MakeMethods 'Template::Universal:for‐
155 ward_methods'. Due to a difference in expected argument syntax, the
156 incoming arguments are revised before being delegated to Template::Uni‐
157 versal:forward_methods.
158
159 forward => [ comp => 'method1', comp2 => 'method2' ]
160
161 Define pass-through methods for certain fields. The above defines that
162 method "method1" will be handled by component "comp", whilst method
163 "method2" will be handled by component "comp2".
164
166 list
167
168 Equivalent to Class::MakeMethods 'Template::Hash:array' with a custom
169 method naming interface.
170
171 hash
172
173 Equivalent to Class::MakeMethods 'Template::Hash:hash' with a custom
174 method naming interface.
175
176 tie_hash
177
178 Equivalent to Class::MakeMethods 'Template::Hash:tiedhash' with a cus‐
179 tom method naming interface.
180
181 hash_of_lists
182
183 Equivalent to Class::MakeMethods 'Template::Hash:hash_of_arrays', or if
184 the -static flag is present, to 'Template::Static:hash_of_arrays'.
185
187 static_get_set
188
189 Equivalent to Class::MakeMethods 'Template::Static:scalar' with a cus‐
190 tom method naming interface.
191
192 static_list
193
194 Equivalent to Class::MakeMethods 'Template::Static:array' with a custom
195 method naming interface.
196
197 static_hash
198
199 Equivalent to Class::MakeMethods 'Template::Static:hash' with a custom
200 method naming interface.
201
203 boolean
204
205 Equivalent to Class::MakeMethods 'Template::Static:bits' with a custom
206 method naming interface.
207
208 grouped_fields
209
210 Creates get/set methods like get_set but also defines a method which
211 returns a list of the slots in the group.
212
213 use Class::MakeMethods::Emulator::MethodMaker
214 grouped_fields => [
215 some_group => [ qw / field1 field2 field3 / ],
216 ];
217
218 Its argument list is parsed as a hash of group-name => field-list
219 pairs. Get-set methods are defined for all the fields and a method with
220 the name of the group is defined which returns the list of fields in
221 the group.
222
223 struct
224
225 Equivalent to Class::MakeMethods 'Template::Hash::struct'.
226
227 Note: This feature is included but not documented in Class::MethodMaker
228 version 1.
229
231 listed_attrib
232
233 Equivalent to Class::MakeMethods 'Template::Flyweight:boolean_index'
234 with a custom method naming interface.
235
236 key_attrib
237
238 Equivalent to Class::MakeMethods 'Template::Hash:string_index'.
239
240 key_with_create
241
242 Equivalent to Class::MakeMethods 'Template::Hash:string_index
243 --find_or_new'.
244
246 code
247
248 Equivalent to Class::MakeMethods 'Template::Hash:code'.
249
250 method
251
252 Equivalent to Class::MakeMethods 'Template::Hash:code --method'.
253
254 abstract
255
256 Equivalent to Class::MakeMethods 'Template::Universal:croak
257 --abstract'.
258
260 builtin_class (EXPERIMENTAL)
261
262 Equivalent to Class::MakeMethods 'Template::StructBuiltin:builtin_isa'
263 with a modified argument order.
264
266 If you wish to convert your code from use of the Class::MethodMaker
267 emulator to direct use of Class::MakeMethods, you will need to adjust
268 the arguments specified in your "use" or "make" calls.
269
270 Often this is simply a matter of replacing the names of aliased method-
271 types listed below with the new equivalents.
272
273 For example, suppose that you code contained the following declaration:
274
275 use Class::MethodMaker (
276 counter => [ 'foo' ]
277 );
278
279 Consulting the listings below you can find that "counter" is an alias
280 for "Hash:number --counter" and you could thus revise your declaration
281 to read:
282
283 use Class::MakeMethods (
284 'Hash:number --counter' => [ 'foo' ]
285 );
286
287 However, note that those methods marked "(with custom interface)" below
288 have a different default naming convention for helper methods in
289 Class::MakeMethods, and you will need to either supply a similar inter‐
290 face or alter your module's calling interface.
291
292 Also note that the "forward", "object", and "object_list" method types,
293 marked "(with modified arguments)" below, require their arguments to be
294 specified differently.
295
296 See Class::MakeMethods::Template::Generic for more information about
297 the default interfaces of these method types.
298
299 Hash methods
300
301 The following equivalencies are declared for old meta-method names that
302 are now handled by the Hash implementation:
303
304 new 'Template::Hash:new --with_values'
305 new_with_init 'Template::Hash:new --with_init'
306 new_hash_init 'Template::Hash:new --instance_with_methods'
307 copy 'Template::Hash:copy'
308 get_set 'Template::Hash:scalar' (with custom interfaces)
309 counter 'Template::Hash:number --counter'
310 get_concat 'Template::Hash:string --get_concat' (with custom interface)
311 boolean 'Template::Hash:bits' (with custom interface)
312 list 'Template::Hash:array' (with custom interface)
313 struct 'Template::Hash:struct'
314 hash 'Template::Hash:hash' (with custom interface)
315 tie_hash 'Template::Hash:tiedhash' (with custom interface)
316 hash_of_lists 'Template::Hash:hash_of_arrays'
317 code 'Template::Hash:code'
318 method 'Template::Hash:code --method'
319 object 'Template::Hash:object' (with custom interface and modified arguments)
320 object_list 'Template::Hash:array_of_objects' (with custom interface and modified arguments)
321 key_attrib 'Template::Hash:string_index'
322 key_with_create 'Template::Hash:string_index --find_or_new'
323
324 Static methods
325
326 The following equivalencies are declared for old meta-method names that
327 are now handled by the Static implementation:
328
329 static_get_set 'Template::Static:scalar' (with custom interface)
330 static_hash 'Template::Static:hash' (with custom interface)
331
332 Flyweight method
333
334 The following equivalency is declared for the one old meta-method name
335 that us now handled by the Flyweight implementation:
336
337 listed_attrib 'Template::Flyweight:boolean_index'
338
339 Struct methods
340
341 The following equivalencies are declared for old meta-method names that
342 are now handled by the Struct implementation:
343
344 builtin_class 'Template::Struct:builtin_isa'
345
346 Universal methods
347
348 The following equivalencies are declared for old meta-method names that
349 are now handled by the Universal implementation:
350
351 abstract 'Template::Universal:croak --abstract'
352 forward 'Template::Universal:forward_methods' (with modified arguments)
353
355 In order to enable third-party subclasses of MethodMaker to run under
356 this emulator, several aliases or stub replacements are provided for
357 internal Class::MethodMaker methods which have been eliminated or
358 renamed.
359
360 · install_methods - now simply return the desired methods
361
362 · find_target_class - now passed in as the target_class attribute
363
364 · ima_method_maker - no longer supported; use target_class instead
365
367 This module aims to provide a 100% compatible drop-in replacement for
368 Class::MethodMaker; if you detect a difference when using this emula‐
369 tion, please inform the author.
370
372 See Class::MakeMethods for general information about this distribution.
373
374 See Class::MakeMethods::Emulator for more about this family of sub‐
375 classes.
376
377 See Class::MethodMaker for more information about the original module.
378
379 A good introduction to Class::MethodMaker is provided by pages 222-234
380 of Object Oriented Perl, by Damian Conway (Manning, 1999).
381
382 http://www.browsebooks.com/Conway/
383
384
385
386perl v5.8.8 2004-09-M0a6keMethods::Emulator::MethodMaker(3)