Class::MOP::Instance - Instance Meta Object
| Use Case | Command | Description |
|---|---|---|
| Create a new meta-instance object | Class::MOP::Instance->new(%options) | Creates a meta-instance with associated metaclass and attributes |
| Create an object instance | $metainstance->create_instance | Returns a reference blessed into the class |
| Clone an instance | $metainstance->clone_instance($instance) | Shallow clone of an existing instance |
| Get slot value | $metainstance->get_slot_value($instance_structure, $slot_name) | Retrieve attribute value from instance |
| Set slot value | $metainstance->set_slot_value($instance_structure, $slot_name, $value) | Set attribute value in instance |
| Inline instance creation | $metainstance->inline_create_instance($class_variable) | Returns code snippet for inlined object creation |
| Check if operations are inlinable | $metainstance->is_inlinable | Boolean indicating whether slot access can be inlined (default true) |
version 2.2200
The Instance Protocol controls the creation of object instances, and the storage of attribute values in those instances.
Using this API directly in your own code violates encapsulation, and we recommend that you use the appropriate APIs in Class::MOP::Class and Class::MOP::Attribute instead. Those APIs in turn call the methods in this class as appropriate.
This class also participates in generating inlined code by providing snippets of code to access an object instance.
Class::MOP::Instance->new(%options)
This method creates a new meta-instance object.
It accepts the following keys in %options:
$metainstance->create_instance
This method returns a reference blessed into the associated metaclass's class.
The default is to use a hash reference. Subclasses can override this.
$metainstance->clone_instance($instance)
Given an instance, this method creates a new object by making a shallow clone of the original.
$metainstance->associated_metaclass â Returns the Class::MOP::Class object associated with the meta-instance object.$metainstance->get_all_slots â Returns a list of slot names stored in object instances. In almost all cases, slot names correspond directly to attribute names.$metainstance->is_valid_slot($slot_name) â Returns true if $slot_name is a valid slot name.$metainstance->get_all_attributes â Returns a list of attributes corresponding to the attributes passed to the constructor.It's important to understand that the meta-instance object is a different entity from the actual instances it creates. For this reason, any operations on the $instance_structure always require that the object instance be passed to the method.
$metainstance->get_slot_value($instance_structure, $slot_name)$metainstance->set_slot_value($instance_structure, $slot_name, $value)$metainstance->initialize_slot($instance_structure, $slot_name)$metainstance->deinitialize_slot($instance_structure, $slot_name)$metainstance->initialize_all_slots($instance_structure)$metainstance->deinitialize_all_slots($instance_structure)$metainstance->is_slot_initialized($instance_structure, $slot_name)$metainstance->weaken_slot_value($instance_structure, $slot_name)$metainstance->slot_value_is_weak($instance_structure, $slot_name)$metainstance->strengthen_slot_value($instance_structure, $slot_name)$metainstance->rebless_instance_structure($instance_structure, $new_metaclass)The exact details of what each method does should be fairly obvious from the method name.
$metainstance->is_inlinable â Boolean indicating whether slot access operations can be inlined. Default is true; subclasses can override.$metainstance->inline_create_instance($class_variable)
Expects a string that, when inlined, will become a class name (e.g., '$class', not an actual class name). Returns code snippet: bless {}, $class_name.
$metainstance->inline_get_is_lvalue â Returns whether inline_get_slot_value is a valid lvalue, allowing extra optimizations.$metainstance->inline_slot_access($instance_variable, $slot_name)$metainstance->inline_get_slot_value($instance_variable, $slot_name)$metainstance->inline_set_slot_value($instance_variable, $slot_name, $value)$metainstance->inline_initialize_slot($instance_variable, $slot_name)$metainstance->inline_deinitialize_slot($instance_variable, $slot_name)$metainstance->inline_is_slot_initialized($instance_variable, $slot_name)$metainstance->inline_weaken_slot_value($instance_variable, $slot_name)$metainstance->inline_strengthen_slot_value($instance_variable, $slot_name)These methods expect two arguments: the variable name representing the object instance (e.g., '$_[0]') and a slot name. They return a code snippet for the inlined operation.
$metainstance->inline_rebless_instance_structure($instance_variable, $class_variable) â Returns code to rebless an instance into a class.Class::MOP::Instance->meta â Returns a Class::MOP::Class instance for this class. Class::MOP bootstraps this module by installing attribute meta-objects into its metaclass.This software is copyright (c) 2006 by Infinity Interactive, Inc.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-25 17:50 @216.73.217.127
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)