1Object::Pad::MOP::ClassU(s3e)r Contributed Perl DocumentaOtbijoenct::Pad::MOP::Class(3)
2
3
4

NAME

6       "Object::Pad::MOP::Class" - meta-object representation of a
7       "Object::Pad" class
8

DESCRIPTION

10       Instances of this class represent a class or role implemented by
11       Object::Pad. Accessors provide information about the class or role, and
12       methods that can alter the class, typically by adding new elements to
13       it, allow a program to extend existing classes.
14
15       Where possible, this API is designed to be compatible with MOP::Class.
16
17       This API should be considered experimental even within the overall
18       context in which "Object::Pad" is expermental.
19

CONSTRUCTOR

21   for_class
22          $metaclass = Object::Pad::MOP::Class->for_class( $class )
23
24       Since version 0.38.
25
26       Returns the metaclass instance associated with the given class name.
27
28   for_caller
29          $metaclass = Object::Pad::MOP::Class->for_caller;
30
31       Since version 0.38.
32
33       A convenient shortcut for obtaining the metaclass instance of the
34       calling package scope. Often handy during "BEGIN" blocks of the class
35       itself to perform adjustments or additions.
36
37          class Some::Class::Here 1.234 {
38             BEGIN {
39                my $meta = Object::Pad::MOP::Class->for_caller;
40                ...
41             }
42          }
43
44   create_class
45          my $metaclass = Object::Pad::MOP::Class->create_class( $name, %args )
46
47       Since version 0.61.
48
49       Creates a new class of the given name and yields the metaclass for it.
50
51       Takes the following additional named arguments:
52
53       extends => STRING
54       isa => STRING
55           An optional name of a superclass that this class will extend. These
56           options are synonyms; new code should use "isa", as "extends" will
57           eventually be removed.
58
59       Once created, this metaclass must be sealed using the "seal" method
60       before it can be used to actually construct object instances.
61
62   create_role
63          my $metaclass = Object::Pad::MOP::Class->create_role( $name, %args )
64
65       Since version 0.61.
66
67       As "create_class" but creates a role instead of a class.
68
69   begin_class
70          BEGIN {
71             my $metaclass = Object::Pad::MOP::Class->begin_class( $name, %args )
72             ...
73          }
74
75       Since version 0.46.
76
77       A variant of "create_class" which sets the newly-created class as the
78       current complication scope of the surrounding code, allowing it to
79       accept "Object::Pad" syntax forms such as "has" and "method".
80
81       This must be done during "BEGIN" time because of this compiletime
82       effect.  It additionally creates a deferred code block at "UNITCHECK"
83       time of its surrounding scope, which is used to finalise the
84       constructed class. In this case you do not need to remember to call
85       "seal" on it; this happens automatically.
86
87   begin_role
88       Since version 0.46.
89
90       As "begin_class" but creates a role instead of a class.
91

METHODS

93   is_class
94   is_role
95          $bool = $metaclass->is_class
96          $bool = $metaclass->is_role
97
98       Exactly one of these methods will return true, depending on whether
99       this metaclass instance represents a true "class", or a "role".
100
101   name
102          $name = $metaclass->name
103
104       Returns the name of the class, as a plain string.
105
106   superclasses
107          @classes = $metaclass->superclasses
108
109       Returns a list of superclasses, as Object::Pad::MOP::Class instances.
110
111       Because "Object::Pad" does not support multiple superclasses, this list
112       will contain at most one item.
113
114   direct_roles
115          @roles = $metaclass->direct_roles
116
117       Returns a list of the roles introduced by this class (i.e. added by
118       `does` declarations but not inherited from the superclass), as
119       Object::Pad::MOP::Class instances.
120
121       This method is also aliased as "roles".
122
123   all_roles
124          @roles = $metaclass->all_roles
125
126       Since version 0.56.
127
128       Returns a list of all the roles implemented by this class (i.e.
129       including those inherited from the superclass), as
130       Object::Pad::MOP::Class instances.
131
132   add_role
133          $metaclass->add_role( $rolename )
134          $metaclass->add_role( $rolemeta )
135
136       Since verison 0.56.
137
138       Adds a new role to the list of those implemented by the class.
139
140       The new role can be specified either as a plain string giving its name,
141       or as an "Object::Pad::MOP::Class" meta instance directly.
142
143       Before version 0.56 this was called "compose_role".
144
145   add_BUILD
146          $metaclass->add_BUILD( $code )
147
148       Adds a new "BUILD" block to the class, as a CODE reference.
149
150   add_method
151          $metamethod = $metaclass->add_method( $name, %args, $code )
152
153       Adds a new named method to the class under the given name, as CODE
154       reference.
155
156       Returns an instance of Object::Pad::MOP::Method to represent it.
157
158       Recognises the following additional named arguments:
159
160       common => BOOL
161           Since version 0.62.
162
163           If true, the method is a class-common method.
164
165   get_direct_method
166          $metamethod = $metaclass->get_direct_method( $name )
167
168       Returns an instance of Object::Pad::MOP::Method to represent the method
169       of the given name, if one exists. If not an exception is thrown.
170
171       This can only see directly-applied methods; that is, methods created by
172       the "method" keyword on the class itself, or added via "add_method".
173       This will not see other names in the package stash, even if they
174       contain a "CODE" slot, nor will it see methods inherited from a
175       superclass.
176
177       This is also aliased as "get_own_method" for compatibility with the
178       MOP::Class interface.
179
180   get_method
181          $metamethod = $metaclass->get_method( $name )
182
183       Since version 0.57.
184
185       Returns an instance of Object::Pad::MOP::Method to represent the method
186       of the given name, if one exists. If not an exception is thrown.
187
188       This will additionally search superclasses, and may return a method
189       belonging to a parent class.
190
191   direct_methods
192          @metamethods = $metaclass->direct_methods
193
194       Since version 0.57.
195
196       Returns a list of Object::Pad::MOP::Method instances to represent all
197       the direct methods of the class. This list may be empty.
198
199   all_methods
200          @metamethods = $metaclass->all_methods
201
202       Since version 0.57.
203
204       Returns a list of Object::Pad::MOP::Method instances to represent all
205       the methods of the class, including those inherited from superclasses.
206       This list may be empty.
207
208   add_field
209          $metafield = $metaclass->add_field( $name, %args )
210
211       since version 0.60.
212
213       Adds a new field to the class, using the given name (which must begin
214       with the sigil character "$", "@" or "%").
215
216       Recognises the following additional named arguments:
217
218       default => SCALAR
219           Since version 0.43.
220
221           Provides a default value for the field; similar to using the syntax
222
223              has $field = SCALAR;
224
225           This value may be "undef", to set the value as being optional if it
226           additionally has a parameter name.
227
228       param => STRING
229           Since version 0.43.
230
231           Provides a parameter name for the field; similar to setting it
232           using the ":param" attribute. This parameter will be required
233           unless a default value is set (such value may still be "undef").
234
235       reader => STRING
236       writer => STRING
237       mutator => STRING
238           Since version 0.46.
239
240       accessor => STRING
241           Since version 0.56.
242
243           Provides method names for generated reader, writer, lvalue-mutator
244           or reader+writer accessor methods, similar to setting them via the
245           ":reader", ":writer", ":mutator" or ":accessor" attributes.
246
247       weak => BOOL
248           Since version 0.46.
249
250           If true, reference values assigned into the field by the
251           constructor or accessor methods will be weakened, similar to
252           setting the ":weak" attribute.
253
254       Returns an instance of Object::Pad::MOP::Field to represent it.
255
256   add_slot
257          $metafield = $metaclass->add_slot( $name, %args )
258
259       Now deprecated.
260
261       Back-compatibility alias for "add_field".
262
263   get_field
264          $metafield = $metaclass->get_field( $name )
265
266       Since version 0.60.
267
268       Returns an instance of Object::Pad::MOP::Field to represent the field
269       of the given name, if one exists. If not an exception is thrown.
270
271   get_slot
272          $metafield = $metaclass->get_slot( $name )
273
274       Now deprecated.
275
276       Back-compatibility alias for "get_field".
277
278   fields
279          @metafields = $metaclass->fields
280
281       Since version 0.60.
282
283       Returns a list of Object::Pad::MOP::Field instances to represent all
284       the fields of the class. This list may be empty.
285
286   slots
287          @metafields = $metaclass->slots
288
289       Since version 0.42; now deprecated.
290
291       Back-compatibility alias for "fields".
292
293   add_required_method
294          $metaclass->add_required_method( $name )
295
296       Since version 0.61.
297
298       Adds a new required method to the role, whose name is given as a plain
299       string.
300
301       Currently returns nothing. This should be considered temporary, as
302       eventually a metatype for required methods will be added, at which
303       point this method can return instances of it. It may also take
304       additional parameters to define the required method with. Currently
305       extra parameters are not permitted.
306
307   required_method_names
308          @names = $metaclass->required_method_names
309
310       Since version 0.61.
311
312       Returns a list names of required methods for the role, as plain
313       strings.
314
315       This should be considered a temporary method. Currently there is no
316       metatype for required methods, so they are represented as plain
317       strings. Eventually a type may be defined and a "required_methods"
318       method will be added.
319
320   seal
321          $metaclass->seal
322
323       Since version 0.61.
324
325       If the metaclass was created by "create_class" or "create_role", this
326       method must be called once everything has been added into it, as the
327       class will not yet be ready to construct actual object instances before
328       this is done.
329

AUTHOR

331       Paul Evans <leonerd@leonerd.org.uk>
332
333
334
335perl v5.34.0                      2022-03-02        Object::Pad::MOP::Class(3)
Impressum