1MakeMethods::Template::UUsneirveCrosnatlr(i3b)uted PerlMDaokceuMmeetnhtoadtsi:o:nTemplate::Universal(3)
2
3
4

NAME

6       Class::MakeMethods::Template::Universal - Meta-methods for any type of
7       object
8

SYNOPSIS

10         package MyObject;
11         use Class::MakeMethods::Template::Universal (
12           'no_op' => [ 'twiddle' ],
13           'croak' => [ 'fail', { croak_msg => 'Curses!' } ]
14         );
15
16         package main;
17
18         MyObject->twiddle;                    # Does nothing
19         if ( $foiled ) { MyObject->fail() }   # Dies with croak_msg
20

DESCRIPTION

UNIVERSAL META-METHODS

23       The following meta-methods and behaviors are applicable across multiple
24       types of classes and objects.
25
26       Universal:generic
27
28       This is not a directly-invokable method type, but instead provides code
29       expressions for use in other method-generators.
30
31       You can use any of these features in your meta-method interfaces with‐
32       out explicitly importing them.
33
34       Modifiers
35
36       ·   --private
37
38           Causes the method to croak if it is called from outside of the
39           package which originally declared it.
40
41           Note that this protection can currently be circumvented if your
42           class provides the method_init behavior, or another subroutine that
43           calls methods by name.
44
45       ·   --protected
46
47           Causes the method to croak if it is called from a package other
48           than the declaring package and its inheritors.
49
50           Note that this protection can currently be circumvented if your
51           class provides the method_init behavior, or another subroutine that
52           calls methods by name.
53
54       ·   --public
55
56           Cancels any previous -private or -protected declaration.
57
58       ·   --self_closure
59
60           Causes the method to return a function reference which is bound to
61           the arguments provided when it is first called.
62
63           For examples of usage, see the test scripts in t/*closure.t.
64
65       ·   --lvalue
66
67           Adds the ":lvalue" attribute to the subroutine declaration.
68
69           For examples of usage, see the test scripts in t/*lvalue.t.
70
71       ·   --warn_calls
72
73           For diagnostic purposes, call warn with the object reference,
74           method name, and arguments before executing the body of the method.
75
76       Behaviors
77
78       ·   attributes
79
80           Runtime access to method parameters.
81
82       ·   no_op -- See below.
83
84       ·   croak -- See below.
85
86       ·   method_init -- See below.
87
88       no_op
89
90       For each meta-method, creates a method with an empty body.
91
92         use Class::MakeMethods::Template::Universal (
93           'no_op' => [ 'foo bar baz' ],
94         );
95
96       You might want to create and use such methods to provide hooks for sub‐
97       class activity.
98
99       No interfaces or parameters supported.
100
101       croak
102
103       For each meta-method, creates a method which will croak if called.
104
105         use Class::MakeMethods::Template::Universal (
106           'croak' => [ 'foo bar baz' ],
107         );
108
109       This is intended to support the use of abstract methods, that must be
110       overidden in a useful subclass.
111
112       If each subclass is expected to provide an implementation of a given
113       method, using this abstract method will replace the generic error mes‐
114       sage below with the clearer, more explicit error message that follows
115       it:
116
117         Can't locate object method "foo" via package "My::Subclass"
118         The "foo" method is abstract and can not be called on My::Subclass
119
120       However, note that the existence of this method will be detected by
121       UNIVERSAL::can(), so it is not suitable for use in optional interfaces,
122       for which you may wish to be able to detect whether the method is sup‐
123       ported or not.
124
125       The -unsupported and -prohibited interfaces provide alternate error
126       messages, or a custom error message can be provided using the
127       'croak_msg' parameter.
128
129       method_init
130
131       Creates a method that accepts a hash of key-value pairs, or a reference
132       to hash of such pairs. For each pair, the key is interpreted as the
133       name of a method to call, and the value is the argument to be passed to
134       that method.
135
136       Sample declaration and usage:
137
138         package MyObject;
139         use Class::MakeMethods::Template::Universal (
140           method_init => 'init',
141         );
142         ...
143
144         my $object = MyObject->new()
145         $object->init( foo => 'Foozle', bar => 'Barbados' );
146
147         # Equivalent to:
148         $object->foo('Foozle');
149         $object->bar('Barbados');
150
151       You might want to create and use such methods to allow easy initializa‐
152       tion of multiple object or class parameters in a single call.
153
154       Note: including methods of this type will circumvent the protection of
155       "private" and "protected" methods, because it an outside caller can
156       cause an object to call specific methods on itself, bypassing the pri‐
157       vacy protection.
158
159       forward_methods
160
161       Creates a method which delegates to an object provided by another
162       method.
163
164       Example:
165
166         use Class::MakeMethods::Template::Universal
167           forward_methods => [
168                --target=> 'whistle', w,
169               [ 'x', 'y' ], { target=> 'xylophone' },
170               { name=>'z', target=>'zither', target_args=>[123], method_name=>do_zed },
171             ];
172
173       Example: The above defines that method "w" will be handled by the call‐
174       ing "w" on the object returned by "whistle", whilst methods "x" and "y"
175       will be handled by "xylophone", and method "z" will be handled by call‐
176       ing "do_zed" on the object returned by calling "zither(123)".
177
178       Interfaces:
179
180       forward (default)
181           Calls the method on the target object. If the target object is
182           missing, croaks at runtime with a message saying "Can't forward bar
183           because bar is empty."
184
185       delegate
186           Calls the method on the target object, if present. If the target
187           object is missing, returns nothing.
188
189       Parameters: The following additional parameters are supported:
190
191       target
192           Required. The name of the method that will provide the object that
193           will handle the operation.
194
195       target_args
196           Optional ref to an array of arguments to be passed to the target
197           method.
198
199       method_name
200           The name of the method to call on the handling object. Defaults to
201           the name of the meta-method being created.
202

SEE ALSO

204       See Class::MakeMethods for general information about this distribution.
205
206       See Class::MakeMethods::Template for information about this family of
207       subclasses.
208
209
210
211perl v5.8.8                       2004-09-06MakeMethods::Template::Universal(3)
Impressum