1Class::MOP::Instance(3)User Contributed Perl DocumentatioCnlass::MOP::Instance(3)
2
3
4

NAME

6       Class::MOP::Instance - Instance Meta Object
7

VERSION

9       version 2.2203
10

DESCRIPTION

12       The Instance Protocol controls the creation of object instances, and
13       the storage of attribute values in those instances.
14
15       Using this API directly in your own code violates encapsulation, and we
16       recommend that you use the appropriate APIs in Class::MOP::Class and
17       Class::MOP::Attribute instead. Those APIs in turn call the methods in
18       this class as appropriate.
19
20       This class also participates in generating inlined code by providing
21       snippets of code to access an object instance.
22

METHODS

24   Object construction
25       Class::MOP::Instance->new(%options)
26           This method creates a new meta-instance object.
27
28           It accepts the following keys in %options:
29
30           •       associated_metaclass
31
32                   The Class::MOP::Class object for which instances will be
33                   created.
34
35           •       attributes
36
37                   An array reference of Class::MOP::Attribute objects. These
38                   are the attributes which can be stored in each instance.
39
40   Creating and altering instances
41       $metainstance->create_instance
42           This method returns a reference blessed into the associated
43           metaclass's class.
44
45           The default is to use a hash reference. Subclasses can override
46           this.
47
48       $metainstance->clone_instance($instance)
49           Given an instance, this method creates a new object by making
50           shallow clone of the original.
51
52   Introspection
53       $metainstance->associated_metaclass
54           This returns the Class::MOP::Class object associated with the meta-
55           instance object.
56
57       $metainstance->get_all_slots
58           This returns a list of slot names stored in object instances. In
59           almost all cases, slot names correspond directly attribute names.
60
61       $metainstance->is_valid_slot($slot_name)
62           This will return true if $slot_name is a valid slot name.
63
64       $metainstance->get_all_attributes
65           This returns a list of attributes corresponding to the attributes
66           passed to the constructor.
67
68   Operations on Instance Structures
69       It's important to understand that the meta-instance object is a
70       different entity from the actual instances it creates. For this reason,
71       any operations on the $instance_structure always require that the
72       object instance be passed to the method.
73
74       $metainstance->get_slot_value($instance_structure, $slot_name)
75       $metainstance->set_slot_value($instance_structure, $slot_name, $value)
76       $metainstance->initialize_slot($instance_structure, $slot_name)
77       $metainstance->deinitialize_slot($instance_structure, $slot_name)
78       $metainstance->initialize_all_slots($instance_structure)
79       $metainstance->deinitialize_all_slots($instance_structure)
80       $metainstance->is_slot_initialized($instance_structure, $slot_name)
81       $metainstance->weaken_slot_value($instance_structure, $slot_name)
82       $metainstance->slot_value_is_weak($instance_structure, $slot_name)
83       $metainstance->strengthen_slot_value($instance_structure, $slot_name)
84       $metainstance->rebless_instance_structure($instance_structure,
85       $new_metaclass)
86           The exact details of what each method does should be fairly obvious
87           from the method name.
88
89   Inlinable Instance Operations
90       $metainstance->is_inlinable
91           This is a boolean that indicates whether or not slot access
92           operations can be inlined. By default it is true, but subclasses
93           can override this.
94
95       $metainstance->inline_create_instance($class_variable)
96           This method expects a string that, when inlined, will become a
97           class name. This would literally be something like '$class', not an
98           actual class name.
99
100           It returns a snippet of code that creates a new object for the
101           class. This is something like " bless {}, $class_name ".
102
103       $metainstance->inline_get_is_lvalue
104           Returns whether or not "inline_get_slot_value" is a valid lvalue.
105           This can be used to do extra optimizations when generating inlined
106           methods.
107
108       $metainstance->inline_slot_access($instance_variable, $slot_name)
109       $metainstance->inline_get_slot_value($instance_variable, $slot_name)
110       $metainstance->inline_set_slot_value($instance_variable, $slot_name,
111       $value)
112       $metainstance->inline_initialize_slot($instance_variable, $slot_name)
113       $metainstance->inline_deinitialize_slot($instance_variable, $slot_name)
114       $metainstance->inline_is_slot_initialized($instance_variable,
115       $slot_name)
116       $metainstance->inline_weaken_slot_value($instance_variable, $slot_name)
117       $metainstance->inline_strengthen_slot_value($instance_variable,
118       $slot_name)
119           These methods all expect two arguments. The first is the name of a
120           variable, than when inlined, will represent the object instance.
121           Typically this will be a literal string like '$_[0]'.
122
123           The second argument is a slot name.
124
125           The method returns a snippet of code that, when inlined, performs
126           some operation on the instance.
127
128       $metainstance->inline_rebless_instance_structure($instance_variable,
129       $class_variable)
130           This takes the name of a variable that will, when inlined,
131           represent the object instance, and the name of a variable that will
132           represent the class to rebless into, and returns code to rebless an
133           instance into a class.
134
135   Introspection
136       Class::MOP::Instance->meta
137           This will return a Class::MOP::Class instance for this class.
138
139           It should also be noted that Class::MOP will actually bootstrap
140           this module by installing a number of attribute meta-objects into
141           its metaclass.
142

AUTHORS

144       •   Stevan Little <stevan@cpan.org>
145
146       •   Dave Rolsky <autarch@urth.org>
147
148       •   Jesse Luehrs <doy@cpan.org>
149
150       •   Shawn M Moore <sartak@cpan.org>
151
152       •   יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
153
154       •   Karen Etheridge <ether@cpan.org>
155
156       •   Florian Ragwitz <rafl@debian.org>
157
158       •   Hans Dieter Pearcey <hdp@cpan.org>
159
160       •   Chris Prather <chris@prather.org>
161
162       •   Matt S Trout <mstrout@cpan.org>
163
165       This software is copyright (c) 2006 by Infinity Interactive, Inc.
166
167       This is free software; you can redistribute it and/or modify it under
168       the same terms as the Perl 5 programming language system itself.
169
170
171
172perl v5.36.0                      2023-02-06           Class::MOP::Instance(3)
Impressum