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
45 is_class
46 is_role
47 $bool = $metaclass->is_class
48 $bool = $metaclass->is_role
49
50 Exactly one of these methods will return true, depending on whether
51 this metaclass instance represents a true "class", or a "role".
52
53 name
54 $name = $metaclass->name
55
56 Returns the name of the class, as a plain string.
57
58 superclasses
59 @classes = $metaclass->superclasses
60
61 Returns a list of superclasses, as Object::Pad::MOP::Class instances.
62
63 Because "Object::Pad" does not support multiple superclasses, this list
64 will contain at most one item.
65
66 roles
67 @roles = $metaclass->roles
68
69 Returns a list of roles implemented by this class, as
70 Object::Pad::MOP::Class instances.
71
72 compose_role
73 $metaclass->compose_role( $rolename )
74 $metaclass->compose_role( $rolemeta )
75
76 Adds a new role to the list of those implemented by the class.
77
78 The new role can be specified either as a plain string giving its name,
79 or as an "Object::Pad::MOP::Class" meta instance directly.
80
81 add_BUILD
82 $metaclass->add_BUILD( $code )
83
84 Adds a new "BUILD" block to the class, as a CODE reference.
85
86 add_method
87 $metamethod = $metaclass->add_method( $name, $code )
88
89 Adds a new named method to the class under the given name, as CODE
90 reference.
91
92 Returns an instance of Object::Pad::MOP::Method to represent it.
93
94 get_own_method
95 $metamethod = $metaclass->get_own_method( $name )
96
97 Returns an instance of Object::Pad::MOP::Slot to represent the method
98 of the given name, if one exists. If not an exception is thrown.
99
100 This can only see directly-applied methods; that is, methods created by
101 the "method" keyword on the class itself, or added via "add_method".
102 This will not see other names in the package stash, even if they
103 contain a "CODE" slot, nor will it see methods inherited from a
104 superclass.
105
106 add_slot
107 $metaslot = $metaclass->add_slot( $name )
108
109 Adds a new slot to the class, using the given name (which must begin
110 with the sigil character "$", "@" or "%").
111
112 Returns an instance of Object::Pad::MOP::Slot to represent it.
113
114 get_slot
115 $metaslot = $metaclass->get_slot( $name )
116
117 Returns an instance of Object::Pad::MOP::Slot to represent the slot of
118 the given name, if one exists. If not an exception is thrown.
119
121 Paul Evans <leonerd@leonerd.org.uk>
122
123
124
125perl v5.32.1 2021-05-14 Object::Pad::MOP::Class(3)