1MakeMethods::Template::UGseenrerCiocn(t3r)ibuted Perl DoMcaukmeeMnettahtoidosn::Template::Generic(3)
2
3
4
6 Class::MakeMethods::Template::Generic - Templates for common
7 meta-method types
8
10 package MyObject;
11 use Class::MakeMethods (
12 'Template::Hash:new' => [ 'new' ],
13 'Template::Hash:scalar' => [ 'foo' ]
14 'Template::Static:scalar' => [ 'bar' ]
15 );
16
17 package main;
18
19 my $obj = MyObject->new( foo => "Foozle", bar => "Bozzle" );
20 print $obj->foo();
21 $obj->bar("Bamboozle");
22
24 This package provides a variety of abstract interfaces for constructors
25 and accessor methods, which form a common foundation for meta-methods
26 provided by the Hash, Scalar, Flyweight, Static, PackageVar, and
27 ClassVar implementations.
28
29 Generally speaking, the Generic meta-methods define calling interfaces
30 and behaviors which are bound to differently scoped data by each of
31 those subclasses.
32
33 new Constructor
34 There are several types of hash-based object constructors to choose
35 from.
36
37 Each of these methods creates and returns a reference to a new blessed
38 instance. They differ in how their (optional) arguments are interpreted
39 to set initial values, and in how they operate when called as class or
40 instance methods.
41
42 Interfaces: The following interfaces are supported.
43
44 -with_values,
45 Provides the with_values behavior.
46
47 -with_init
48 Provides the with_init behavior.
49
50 -with_methods
51 Provides the with_methods behavior.
52
53 -new_and_init
54 Provides the with_init behavior for *, and the general purpose
55 method_init behavior as an init method.
56
57 -copy_with_values
58 Provides the copy behavior.
59
60 Behaviors: The following types of constructor methods are available.
61
62 with_values
63 Creates and blesses a new instance.
64
65 If arguments are passed they are included in the instance,
66 otherwise it will be empty.
67
68 Returns the new instance.
69
70 May be called as a class or instance method.
71
72 with_methods
73 Creates, blesses, and returns a new instance.
74
75 The arguments are treated as a hash of method-name/argument-value
76 pairs, with each such pair causing a call "$self->name($value)".
77
78 with_init
79 Creates and blesses a new instance, then calls a method named
80 "init", passing along any arguments that were initially given.
81
82 Returns the new instance.
83
84 The init() method should be defined in the class declaring these
85 methods.
86
87 May be called as a class or instance method.
88
89 and_then_init
90 Creates a new instance using method-name/argument-value pairs, like
91 "with_methods", but then calls a method named "init" before
92 returning the new object. The "init" method does not receive any
93 arguments.
94
95 The init() method should be defined in the class declaring these
96 methods.
97
98 instance_with_methods
99 If called as a class method, creates, blesses, and returns a new
100 instance. If called as an object method, operates on and returns
101 the existing instance.
102
103 Accepts name-value pair arguments, or a reference to hash of such
104 pairs, and calls the named method for each with the supplied value
105 as a single argument. (See the Universal method_init behavior for
106 more discussion of this pattern.)
107
108 copy_with values
109 Produce a copy of an instance. Can not be called as a class method.
110
111 The copy is a *shallow* copy; any references will be shared by the
112 instance upon which the method is called and the returned newborn.
113
114 If a list of key-value pairs is passed as arguments to the method,
115 they are added to the copy, overwriting any values with the same
116 key that may have been copied from the original.
117
118 copy_with_methods
119 Produce a copy of an instance. Can not be called as a class method.
120
121 The copy is a *shallow* copy; any references will be shared by the
122 instance upon which the method is called and the returned newborn.
123
124 Accepts name-value pair arguments, or a reference to hash of such
125 pairs, and calls the named method on the copy for each with the
126 supplied value as a single argument before the copy is returned.
127
128 copy_instance_with_values
129 If called as a class method, creates, blesses, and returns a new
130 instance. If called as an object method, produces and returns a
131 copy of an instance.
132
133 The copy is a *shallow* copy; any references will be shared by the
134 instance upon which the method is called and the returned newborn.
135
136 If a list of key-value pairs is passed as arguments to the method,
137 they are added to the copy, overwriting any values with the same
138 key that may have been copied from the original.
139
140 copy_instance_with_methods
141 If called as a class method, creates, blesses, and returns a new
142 instance. If called as an object method, produces and returns a
143 copy of an instance.
144
145 The copy is a *shallow* copy; any references will be shared by the
146 instance upon which the method is called and the returned newborn.
147
148 Accepts name-value pair arguments, or a reference to hash of such
149 pairs, and calls the named method on the copy for each with the
150 supplied value as a single argument before the copy is returned.
151
152 Parameters: The following parameters are supported:
153
154 init_method
155 The name of the method to call after creating a new instance.
156 Defaults to 'init'.
157
158 scalar Accessor
159 A generic scalar-value accessor meta-method which serves as an
160 abstraction for basic "get_set" methods and numerous related interfaces
161
162 use Class::MakeMethods -MakerClass => "...",
163 scalar => [ 'foo', 'bar' ];
164 ...
165 $self->foo( 'my new foo value' );
166 print $self->foo();
167
168 (Note that while you can use the scalar methods to store references to
169 various data structures, there are other meta-methods defined below
170 that may be more useful for managing references to arrays, hashes, and
171 objects.)
172
173 Interfaces: The following calling interfaces are available.
174
175 get_set (default)
176 Provides get_set method for *.
177
178 Example: Create method foo, which sets the value of 'foo' for this
179 instance if an argument is passed in, and then returns the value
180 whether or not it's been changed:
181
182 use Class::MakeMethods -MakerClass => "...",
183 scalar => [ 'foo' ];
184
185 get_protected_set
186 Provides an get_set accessor for * that croaks if a new value is
187 passed in from a package that is not a subclass of the declaring
188 one.
189
190 get_private_set
191 Provides an get_set accessor for * that croaks if a new value is
192 passed in from a package other than the declaring one.
193
194 read_only
195 Provides an accessor for * that does not modify its value. (Its
196 initial value would have to be set by some other means.)
197
198 eiffel
199 Provides get behavior as *, and set behavior as set_*.
200
201 Example: Create methods bar which returns the value of 'bar' for
202 this instance (takes no arguments), and set_bar, which sets the
203 value of 'bar' (no return):
204
205 use Class::MakeMethods -MakerClass => "...",
206 scalar => [ --eiffel => 'bar' ];
207
208 java
209 Provides get behavior as get*, and set behavior as set*.
210
211 Example: Create methods getBaz which returns the value of 'Baz' for
212 this instance (takes no arguments), and setBaz, which sets the
213 value for this instance (no return):
214
215 use Class::MakeMethods -MakerClass => "...",
216 scalar => [ --java => 'Baz' ];
217
218 init_and_get
219 Creates methods which cache their results in a hash key.
220
221 Provides the get_init behavior for *, and an delete behavior for
222 clear_*. Specifies default value for init_method parameter of
223 init_*.
224
225 with_clear
226 Provides get_set behavior for *, and a clear_* method.
227
228 Behaviors: The following types of accessor methods are available.
229
230 get_set
231 If no argument is provided, returns the value of the current
232 instance. The value defaults to undef.
233
234 If an argument is provided, it is stored as the value of the
235 current instance (even if the argument is undef), and that value is
236 returned.
237
238 Also available as get_protected_set and get_private_set, which are
239 available for public read-only access, but have access control
240 limitations.
241
242 get Returns the value from the current instance.
243
244 set Sets the value for the current instance. If called with no
245 arguments, the value is set to undef. Does not return a value.
246
247 clear
248 Sets value to undef.
249
250 get_set_chain
251 Like get_set, but if called with an argument, returns the object it
252 was called on. This allows a series of mutators to be called as
253 follows:
254
255 package MyObject;
256 use Class::MakeMethods (
257 'Template::Hash:scalar --get_set_chain' => 'foo bar baz'
258 );
259 ...
260
261 my $obj = MyObject->new->foo('Foozle');
262 $obj->bar("none")->baz("Brazil");
263 print $obj->foo, $obj->bar, $obj->baz;
264
265 get_set_prev
266 Like get_set, but if called with an argument, returns the previous
267 value before it was changed to the new one.
268
269 get_init
270 If the value is currently undefined, calls the init_method. Returns
271 the value.
272
273 Parameters: The following parameters are supported:
274
275 init_method
276 The name of a method to be called to initialize this meta-method.
277
278 Only used by the get_init behavior.
279
280 string Accessor
281 A generic scalar-value accessor meta-method which serves as an
282 abstraction for basic "get_set" methods and numerous related interfaces
283
284 use Class::MakeMethods -MakerClass => "...",
285 string => [ 'foo', 'bar' ];
286 ...
287 $self->foo( 'my new foo value' );
288 print $self->foo();
289
290 This meta-method extends the scalar meta-method, and supports the same
291 interfaces and parameters.
292
293 However, it generally treats values as strings, and can not be used to
294 store references.
295
296 Interfaces: In addition to those provided by "scalar", the following
297 calling interfaces are available.
298
299 -get_concat
300 Provides the get_concat behavior for *, and a clear_* method.
301
302 Example:
303
304 use Class::MakeMethods
305 get_concat => { name => 'words', join => ", " };
306
307 $obj->words('foo');
308 $obj->words('bar');
309 $obj->words() eq 'foo, bar';
310
311 Behaviors: In addition to those provided by "scalar", the following
312 types of accessor methods are available.
313
314 concat
315 Concatenates the argument value with the existing value.
316
317 get_concat
318 Like get_set except sets do not clear out the original value, but
319 instead concatenate the new value to the existing one.
320
321 Parameters: In addition to those provided by "scalar", the following
322 parameters are supported.
323
324 join
325 If the join parameter is defined, each time the get_concat behavior
326 is invoked, it will glue its argument onto any existing value with
327 the join string as the separator. The join field is applied between
328 values, not prior to the first or after the last. Defaults to
329 undefined
330
331 string_index
332 string_index => [ qw / foo bar baz / ]
333
334 Creates string accessor methods, like string above, but also maintains
335 a static hash index in which each object is stored under the value of
336 the field when the slot is set.
337
338 This is a unique index, so only one object can have a given key. If an
339 object has a slot set to a value which another object is already set to
340 the object currently set to that value has that slot set to undef and
341 the new object will be put into the hash under that value.
342
343 Objects with undefined values are not stored in the index.
344
345 Note that to free items from memory, you must clear these values!
346
347 Methods:
348
349 • The method find_x is defined which if called with any arguments
350 returns a list of the objects stored under those values in the
351 hash. Called with no arguments, it returns a reference to the hash.
352
353 Profiles:
354
355 • find_or_new
356
357 'string_index -find_or_new' => [ qw / foo bar baz / ]
358
359 Just like string_index except the find_x method is defined to call
360 the new method to create an object if there is no object already
361 stored under any of the keys you give as arguments.
362
363 number Accessor
364 A generic scalar-value accessor meta-method which serves as an
365 abstraction for basic "get_set" methods and numerous related interfaces
366
367 use Class::MakeMethods -MakerClass => "...",
368 string => [ 'foo', 'bar' ];
369 ...
370 $self->foo( 23 );
371 print $self->foo();
372
373 This meta-method extends the scalar meta-method, and supports the same
374 interfaces and parameters.
375
376 However, it generally treats values as numbers, and can not be used to
377 store strings or references.
378
379 Interfaces: In addition to those provided by "scalar", the following
380 calling interfaces are available.
381
382 -counter
383 Provides the numeric get_set behavior for *, and numeric *_incr and
384 *_reset methods.
385
386 Behaviors: In addition to those provided by "scalar", the following
387 types of accessor methods are available.
388
389 get_set
390 The get_set behavior is similar to the default scalar behavior
391 except that empty values are treated as zero.
392
393 increment
394 If no argument is provided, increments the hash_key value by 1. If
395 an argument is provided, the value is incremented by that amount.
396 Returns the increased value.
397
398 clear
399 Sets the value to zero.
400
401 boolean Accessor
402 A generic scalar-value accessor meta-method which serves as an
403 abstraction for basic "get_set" methods and numerous related interfaces
404
405 use Class::MakeMethods -MakerClass => "...",
406 string => [ 'foo', 'bar' ];
407 ...
408 $self->foo( 1 );
409 print $self->foo();
410 $self->clear_foo;
411
412 This meta-method extends the scalar meta-method, and supports the same
413 interfaces and parameters. However, it generally treats values as true-
414 or-false flags, and can not be used to store strings, numbers, or
415 references.
416
417 Interfaces:
418
419 flag_set_clear (default)
420 Provides the get_set behavior for *, and set_* and clear_* methods
421 to set the value to true or false.
422
423 Behaviors: In addition to those provided by "scalar", the following
424 types of accessor methods are available.
425
426 get_set
427 The get_set behavior is similar to the get_set scalar behavior
428 except that empty or false values are treated as zero, and true
429 values are treated as zero.
430
431 set_true
432 Sets the value to one.
433
434 set_false
435 Sets the value to zero. =back
436
437 bits Accessor
438 A generic accessor for bit-field values.
439
440 The difference between 'Template::Generic:bits' and
441 'Template::Generic:boolean' is that all flags created with this meta-
442 method are stored in a single vector for space efficiency.
443
444 Interfaces: The following calling interfaces are available.
445
446 default
447 Provides get_set behavior for *, a set_* method which sets the
448 value to true and a clear_* method which sets the value to false.
449
450 Also defines methods named bits, bit_fields, and bit_dump with the
451 behaviors below. These methods are shared across all of the boolean
452 meta-methods defined by a single class.
453
454 class_methods
455 .
456
457 Basic Behaviors: The following types of bit-level accessor methods are
458 available.
459
460 get_set
461 Returns the value of the named flag. If called with an argument,
462 it first sets the named flag to the truth-value of the argument.
463
464 set_true
465 Sets the value to true.
466
467 set_false
468 Sets the value to false.
469
470 Group Methods: The following types of methods manipulate the overall
471 vector value.
472
473 bits
474 Returns the vector containing all of the bit fields (remember
475 however that a vector containing all 0 bits is still true).
476
477 bit_dump
478 Returns a hash of the flag-name/flag-value pairs.
479
480 bits_size
481 Returns the number of bits that can fit into the current vector.
482
483 bits_complement
484 Returns the twos-complement of the vector.
485
486 bit_pos_get
487 Takes a single argument and returns the value of the bit stored in
488 that position.
489
490 bit_pos_set
491 Takes two arguments and sets the bit stored in the position of the
492 first argument to the value of the second argument.
493
494 Class Methods: The following types of class methods are available.
495
496 bit_names
497 Returns a list of all the flags by name.
498
499 array Accessor
500 Creates accessor methods for manipulating arrays of values.
501
502 Interfaces: The following calling interfaces are available.
503
504 default
505 Provides get_set behavior for *, and verb_* methods for the non-get
506 behaviors below.
507
508 minimal
509 Provides get_set behavior for *, and *_verb methods for clear
510 behavior.
511
512 get_set_items
513 Provides the get_set_items for *.
514
515 x_verb
516 Provides get_push behavior for *, and *_verb methods for the non-
517 get behaviors below.
518
519 get_set_ref
520 Provides the get_set_ref for *.
521
522 get_set_ref_help
523 Provides the get_set_ref for *, and verb_* methods for the non-get
524 behaviors below.
525
526 Behaviors: The following types of accessor methods are available.
527
528 get_set_items
529 Called with no arguments returns a reference to the array stored in
530 the slot.
531
532 Called with one simple scalar argument it treats the argument as an
533 index and returns the value stored under that index.
534
535 Called with more than one argument, treats them as a series of
536 index/value pairs and adds them to the array.
537
538 get_push
539 If arguments are passed, these values are pushed on to the list; if
540 a single array ref is passed, its values are used as the arguments.
541
542 This method returns the list of values stored in the slot. In an
543 array context it returns them as an array and in a scalar context
544 as a reference to the array.
545
546 get_set_ref
547 If arguments are passed, these values are placed on the list,
548 replacing the current contents; if a single array ref is passed,
549 its values are used as the arguments.
550
551 This method returns the list of values stored in the slot. In an
552 array context it returns them as an array and in a scalar context
553 as a reference to the array.
554
555 get_set
556 If arguments are passed, these values are placed on the list,
557 replacing the current contents.
558
559 This method returns the list of values stored in the slot. In an
560 array context it returns them as an array and in a scalar context
561 as a reference to the array.
562
563 push
564 Append items to tail.
565
566 pop Remove an item from the tail.
567
568 shift
569 Remove an item from the front.
570
571 unshift
572 Prepend items to front.
573
574 splice
575 Remove or replace items.
576
577 clear
578 Remove all items.
579
580 count
581 Returns the number of item in the list.
582
583 hash Accessor
584 Creates accessor methods for manipulating hashes of key-value pairs.
585
586 Interfaces: The following calling interfaces are available.
587
588 default
589 Provides get_set behavior for *, and *_verb methods for most of the
590 other behaviors below.
591
592 get_set_items
593 Provides the get_set_items for *.
594
595 Behaviors: The following types of accessor methods are available.
596
597 get_set_items
598 Called with no arguments returns a reference to the hash stored.
599
600 Called with one simple scalar argument it treats the argument as a
601 key and returns the value stored under that key.
602
603 Called with more than one argument, treats them as a series of
604 key/value pairs and adds them to the hash.
605
606 get_push
607 Called with no arguments returns the hash stored, as a hash in a
608 list context or as a reference in a scalar context.
609
610 Called with one simple scalar argument it treats the argument as a
611 key and returns the value stored under that key.
612
613 Called with one array reference argument, the array elements are
614 considered to be be keys of the hash. x returns the list of values
615 stored under those keys (also known as a hash slice.)
616
617 Called with one hash reference argument, the keys and values of the
618 hash are added to the hash.
619
620 Called with more than one argument, treats them as a series of
621 key/value pairs and adds them to the hash.
622
623 get_set
624 Like get_push, except if called with more then one argument,
625 empties the current hash items before adding those arguments to the
626 hash.
627
628 push
629 Called with one hash reference argument, the keys and values of the
630 hash are added to the hash.
631
632 Called with more than one argument, treats them as a series of
633 key/value pairs and adds them to the hash.
634
635 keys
636 Returns a list of the keys of the hash.
637
638 values
639 Returns a list of the values in the hash.
640
641 tally
642 Takes a list of arguments and for each scalar in the list
643 increments the value stored in the hash and returns a list of the
644 current (after the increment) values.
645
646 exists
647 Takes a single key, returns whether that key exists in the hash.
648
649 delete
650 Takes a list, deletes each key from the hash, and returns the
651 corresponding values.
652
653 clear
654 Resets hash to empty.
655
656 tiedhash Accessor
657 A variant of Generic:hash which initializes the hash by tieing it to a
658 caller-specified package.
659
660 See the documentation on "Generic:hash" for interfaces and behaviors.
661
662 Parameters: The following parameters must be provided:
663
664 tie Required. The name of the class to tie to. Make sure you have
665 "use"d the required class.
666
667 args
668 Required. Additional arguments for the tie, as an array ref.
669
670 Example:
671
672 use Class::MakeMethods
673 tie_hash => [ hits => { tie => q/Tie::RefHash/, args => [] } ];
674
675 use Class::MakeMethods
676 tie_hash => [ [qw(hits errors)] => { tie => q/Tie::RefHash/, args => [] } ];
677
678 use Class::MakeMethods
679 tie_hash => [ { name => hits, tie => q/Tie::RefHash/, args => [] } ];
680
681 hash_of_arrays Accessor
682 Creates accessor methods for manipulating hashes of array-refs.
683
684 Interfaces: The following calling interfaces are available.
685
686 default
687 Provides get behavior for *, and *_verb methods for the other
688 behaviors below.
689
690 Behaviors: The following types of accessor methods are available.
691
692 get Returns all the values for all the given keys, in order. If no
693 keys are given, returns all the values (in an unspecified key
694 order).
695
696 The result is returned as an arrayref in scalar context. This
697 arrayref is not part of the data structure; messing with it will
698 not affect the contents directly (even if a single key was provided
699 as argument.)
700
701 If any argument is provided which is an arrayref, then the members
702 of that array are used as keys. Thus, the trivial empty-key case
703 may be utilized with an argument of [].
704
705 keys
706 Returns the keys of the hash. As an arrayref in scalar context.
707
708 exists
709 Takes a list of keys, and returns whether all of the key exists in
710 the hash (i.e., the "and" of whether the individual keys exist).
711
712 delete
713 Takes a list, deletes each key from the hash.
714
715 push
716 Takes a key, and some values. Pushes the values onto the list
717 denoted by the key. If the first argument is an arrayref, then
718 each element of that arrayref is treated as a key and the elements
719 pushed onto each appropriate list.
720
721 pop Takes a list of keys, and pops each one. Returns the list of
722 popped elements. undef is returned in the list for each key that
723 is has an empty list.
724
725 unshift
726 Like push, only the from the other end of the lists.
727
728 shift
729 Like pop, only the from the other end of the lists.
730
731 splice
732 Takes a key, offset, length, and a values list. Splices the list
733 named by the key. Anything from the offset argument (inclusive)
734 may be omitted. See "splice" in perlfunc.
735
736 clear
737 Takes a list of keys. Resets each named list to empty (but does
738 not delete the keys.)
739
740 count
741 Takes a list of keys. Returns the sum of the number of elements
742 for each named list.
743
744 index
745 Takes a key, and a list of indices. Returns a list of each item at
746 the corresponding index in the list of the given key. Uses undef
747 for indices beyond range.
748
749 remove
750 Takes a key, and a list of indices. Removes each corresponding
751 item from the named list. The indices are effectively looked up at
752 the point of call -- thus removing indices 3, 1 from list (a, b, c,
753 d) will remove (d) and (b).
754
755 sift
756 Takes a key, and a set of named arguments, which may be a list or a
757 hash ref. Removes list members based on a grep-like approach.
758
759 filter
760 The filter function used (as a coderef). Is passed two
761 arguments, the value compared against, and the value in the
762 list that is potential for grepping out. If returns true, the
763 value is removed. Default is "sub { $_[0] == $_[1] }".
764
765 keys
766 The list keys to sift through (as an arrayref). Unknown keys
767 are ignored. Default: all the known keys.
768
769 values
770 The values to sift out (as an arrayref). Default: "[undef]"
771
772 object Accessor
773 Creates accessor methods for manipulating references to objects.
774
775 In addition to creating a method to get and set the object reference,
776 the meta-method can also define forwarded methods that automatically
777 pass calls onto the object stored in that slot; see the description of
778 the 'delegate' parameter below.
779
780 Interfaces: The following calling interfaces are available.
781
782 default
783 Provides get_set behavior for *, clear behavior for 'delete_*', and
784 forwarding methods for any values in the method's 'delegate' or
785 'soft_delegate' parameters.
786
787 get_and_set
788 Provides named get method, set_x and clear_x methods.
789
790 get_init_and_set
791 Provides named get_init method, set_x and clear_x methods.
792
793 Behaviors: The following types of accessor methods are available.
794
795 get_set
796 The get_set method, if called with a reference to an object of the
797 given class as the first argument, stores it.
798
799 If called with any other arguments, creates and stores a new
800 object, passing the arguemnts to the new() method for the object.
801
802 If called without arguments, returns the current value, which may
803 be undefined if one has not been stored yet.
804
805 get_set_init
806 The get_set_init method, if called with a reference to an object of
807 the given class as the first argument, stores it.
808
809 If the slot is not filled yet it creates an object by calling the
810 given new method of the given class. Any arguments passed to the
811 get_set_init method are passed on to new.
812
813 In all cases the object now stored is returned.
814
815 get_init
816 If the instance is empty, creates and stores a new one. Returns the
817 instance.
818
819 get Returns the current value, which may be undefined if one has not
820 been stored yet.
821
822 set If called with a reference to an object of the given class as the
823 first argument, stores it.
824
825 If called with any other arguments, creates and stores a new
826 object, passing the arguments to the new() method.
827
828 If called without arguments, creates and stores a new object,
829 without any arguments to the new() method.
830
831 clear
832 Removes the reference value.
833
834 forwarding
835 If a 'delegate' or 'soft_delegate' parameter is provided, methods
836 with those names are created that are forwarded directly to the
837 object in the slot, as described below.
838
839 Parameters: The following parameters are supported:
840
841 class
842 Required. The type of object that will be stored.
843
844 new_method
845 The name of the method to call on the above class to create a new
846 instance. Defaults to 'new'.
847
848 delegate
849 The methods to forward to the object. Can contain a method name, a
850 string of space-spearated method names, or an array of method
851 names. This type of method will croak if it is called when the
852 target object is not defined.
853
854 soft_delegate
855 The methods to forward to the object, if it is present. Can contain
856 a method name, a string of space-spearated method names, or an
857 array of method names. This type of method will return nothing if
858 it is called when the target object is not defined.
859
860 instance Accessor
861 Creates methods to handle an instance of the calling class.
862
863 PROFILES
864
865 default
866 Provides named get method, and verb_x set, new, and clear methods.
867
868 -implicit_new
869 Provides named get_init method, and verb_x set, and clear methods.
870
871 -x_verb
872 Provides named get method, and x_verb set, new, and clear methods.
873
874 Behaviors: The following types of accessor methods are available.
875
876 get Returns the value of the instance parameter, which may be undefined
877 if one has not been stored yet.
878
879 get_init
880 If the instance is empty, creates and stores a new one. Returns the
881 instance.
882
883 set Takes a single argument and sets the instance to that value.
884
885 new Creates and stores a new instance.
886
887 clear
888 Sets the instance parameter to undef.
889
890 Parameters: The following parameters are supported:
891
892 instance
893 Holds the instance reference. Defaults to undef
894
895 new_method
896 The name of the method to call when creating a new instance.
897 Defaults to 'new'.
898
899 array_of_objects Accessor
900 Creates accessor methods for manipulating references to arrays of
901 object references.
902
903 Operates like "Generic:array", but prior to adding any item to the
904 array, it first checks to see if it is an instance of the designated
905 class, and if not passes it as an argument to that class's new method
906 and stores the result instead.
907
908 Forwarded methods return a list of the results returned by "map"ing the
909 method over each object in the array.
910
911 See the documentation on "Generic:array" for interfaces and behaviors.
912
913 Parameters: The following parameters are supported:
914
915 class
916 Required. The type of object that will be stored.
917
918 delegate
919 The methods to forward to the object. Can contain a method name, a
920 string of space-spearated method names, or an array of method
921 names.
922
923 new_method
924 The name of the method to call on the above class to create a new
925 instance. Defaults to 'new'.
926
927 code Accessor
928 Creates accessor methods for manipulating references to subroutines.
929
930 Interfaces: The following calling interfaces are available.
931
932 default
933 Provides the call_set functionality.
934
935 method
936 Provides the call_method functionality.
937
938 Behaviors: The following types of accessor methods are available.
939
940 call_set
941 If called with one argument which is a CODE reference, it installs
942 that code in the slot. Otherwise it runs the code stored in the
943 slot with whatever arguments (including none) were passed in.
944
945 call_method
946 Just like call_set, except the code is called like a method, with
947 $self as its first argument. Basically, you are creating a method
948 which can be different for each object.
949
950 code_or_scalar Accessor
951 Creates accessor methods for manipulating either strings or references
952 to subroutines.
953
954 You can store any scalar value; code refs are executed when you
955 retrieve the value, while other scalars are returned as-is.
956
957 Interfaces: The following calling interfaces are available.
958
959 default
960 Provides the call_set functionality.
961
962 method
963 Provides the call_method functionality.
964
965 eiffel
966 Provides the named get_method, and a helper set_* method.
967
968 Behaviors: The following types of accessor methods are available.
969
970 get_set_call
971 If called with an argument, either a CODE reference or some other
972 scalar, it installs that code in the slot. Otherwise, if the
973 current value runs the code stored in the slot with whatever
974 arguments (including none) were passed in.
975
976 get_set_method
977 Just like call_set, except the code is called like a method, with
978 $self as its first argument. Basically, you are creating a method
979 which can be different for each object.
980
982 See Class::MakeMethods for general information about this distribution.
983
984 See Class::MakeMethods::Template for information about this family of
985 subclasses.
986
988 Hey! The above document had some coding errors, which are explained
989 below:
990
991 Around line 933:
992 You forgot a '=back' before '=head2'
993
994
995
996perl v5.38.0 2023-07-20 MakeMethods::Template::Generic(3)