1Object::Pad::MOP::ClassU(s3e)r Contributed Perl DocumentaOtbijoenct::Pad::MOP::Class(3)
2
3
4
6 "Object::Pad::MOP::Class" - meta-object representation of a
7 "Object::Pad" class
8
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
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 begin_class
45 BEGIN {
46 my $metaclass = Object::Pad::MOP::Class->begin_class( $name, %args )
47 ...
48 }
49
50 Since version 0.46.
51
52 Creates a new class of the given name and yields the metaclass for it.
53 This must be done during "BEGIN" time, as it creates a deferred code
54 block at "UNITCHECK" time of its surrounding scope, which is used to
55 finalise the constructed class.
56
57 Takes the following additional named arguments:
58
59 extends => STRING
60 An optional name of a superclass that this class will extend.
61
62 begin_role
63 Since version 0.46.
64
65 As "begin_class" but creates a role instead of a class.
66
68 is_class
69 is_role
70 $bool = $metaclass->is_class
71 $bool = $metaclass->is_role
72
73 Exactly one of these methods will return true, depending on whether
74 this metaclass instance represents a true "class", or a "role".
75
76 name
77 $name = $metaclass->name
78
79 Returns the name of the class, as a plain string.
80
81 superclasses
82 @classes = $metaclass->superclasses
83
84 Returns a list of superclasses, as Object::Pad::MOP::Class instances.
85
86 Because "Object::Pad" does not support multiple superclasses, this list
87 will contain at most one item.
88
89 roles
90 @roles = $metaclass->roles
91
92 Returns a list of roles implemented by this class, as
93 Object::Pad::MOP::Class instances.
94
95 compose_role
96 $metaclass->compose_role( $rolename )
97 $metaclass->compose_role( $rolemeta )
98
99 Adds a new role to the list of those implemented by the class.
100
101 The new role can be specified either as a plain string giving its name,
102 or as an "Object::Pad::MOP::Class" meta instance directly.
103
104 add_BUILD
105 $metaclass->add_BUILD( $code )
106
107 Adds a new "BUILD" block to the class, as a CODE reference.
108
109 add_method
110 $metamethod = $metaclass->add_method( $name, $code )
111
112 Adds a new named method to the class under the given name, as CODE
113 reference.
114
115 Returns an instance of Object::Pad::MOP::Method to represent it.
116
117 get_own_method
118 $metamethod = $metaclass->get_own_method( $name )
119
120 Returns an instance of Object::Pad::MOP::Method to represent the method
121 of the given name, if one exists. If not an exception is thrown.
122
123 This can only see directly-applied methods; that is, methods created by
124 the "method" keyword on the class itself, or added via "add_method".
125 This will not see other names in the package stash, even if they
126 contain a "CODE" slot, nor will it see methods inherited from a
127 superclass.
128
129 add_slot
130 $metaslot = $metaclass->add_slot( $name, %args )
131
132 Adds a new slot to the class, using the given name (which must begin
133 with the sigil character "$", "@" or "%").
134
135 Recognises the following additional named arguments:
136
137 default => SCALAR
138 Since version 0.43.
139
140 Provides a default value for the slot; similar to using the syntax
141
142 has $slot = SCALAR;
143
144 This value may be "undef", to set the value as being optional if it
145 additionally has a parameter name.
146
147 param => STRING
148 Since version 0.43.
149
150 Provides a parameter name for the slot; similar to setting it using
151 the ":param" attribute. This parameter will be required unless a
152 default value is set (such value may still be "undef").
153
154 reader => STRING
155 writer => STRING
156 mutator => STRING
157 Since version 0.46.
158
159 Provides method names for generated reader, writer or lvalue-
160 mutator accessor methods, similar to setting them via the
161 ":reader", ":writer" or ":mutator" attributes.
162
163 weak => BOOL
164 Since version 0.46.
165
166 If true, reference values assigned into the slot by the constructor
167 or accessor methods will be weakened, similar to setting the
168 ":weak" attribute.
169
170 Returns an instance of Object::Pad::MOP::Slot to represent it.
171
172 get_slot
173 $metaslot = $metaclass->get_slot( $name )
174
175 Returns an instance of Object::Pad::MOP::Slot to represent the slot of
176 the given name, if one exists. If not an exception is thrown.
177
178 slots
179 @metaslots = $metaclass->slots
180
181 Since version 0.42.
182
183 Returns a list of Object::Pad::MOP::Slot instances to represent all the
184 slots of the class. This list may be empty.
185
187 Paul Evans <leonerd@leonerd.org.uk>
188
189
190
191perl v5.34.0 2021-10-08 Object::Pad::MOP::Class(3)