Class::MOP::Instance - Instance Meta Object


Class::MOP::Instance - Instance Meta Object


The meta instance is used by attributes for low level storage.

Using this API generally violates attribute encapsulation and is not reccomended, instead look at get_value in the Class::MOP::Attribute manpage, set_value in the Class::MOP::Attribute manpage for the reccomended way to fiddle with attribute values in a generic way, independant of how/whether accessors have been defined. Accessors can be found using get_attribute in the Class::MOP::Class manpage.

This may seem like over-abstraction, but by abstracting this process into a sub-protocol we make it possible to easily switch the details of how an object's instance is stored with minimal impact. In most cases just subclassing this class will be all you need to do (see the examples; examples/ArrayBasedStorage.pod and examples/InsideOutClass.pod for details).


new ($meta, @attrs)
Creates a new instance meta-object and gathers all the slots from the list of @attrs given.

This will return a Class::MOP::Class instance which is related to this class.

Creation of Instances

This creates the appropriate structure needed for the instance and then calls bless_instance_structure to bless it into the class.

bless_instance_structure ($instance_structure)
This does just exactly what it says it does.

clone_instance ($instance_structure)
This too does just exactly what it says it does.


NOTE: There might be more methods added to this part of the API, we will add then when we need them basically.

This returns the metaclass associated with this instance.

This will return the current list of slots based on what was given to this object in new.

is_valid_slot ($slot_name)
This will return true if $slot_name is a valid slot name.

Operations on Instance Structures

An important distinction of this sub-protocol is that the instance meta-object is a different entity from the actual instance it creates. For this reason, any actions on slots require that the $instance_structure is passed into them.

The names of these methods pretty much explain exactly what they do, if that is not enough then I suggest reading the source, it is very straightfoward.

get_slot_value ($instance_structure, $slot_name)
set_slot_value ($instance_structure, $slot_name, $value)
initialize_slot ($instance_structure, $slot_name)
deinitialize_slot ($instance_structure, $slot_name)
initialize_all_slots ($instance_structure)
deinitialize_all_slots ($instance_structure)
is_slot_initialized ($instance_structure, $slot_name)
weaken_slot_value ($instance_structure, $slot_name)
strengthen_slot_value ($instance_structure, $slot_name)
rebless_instance_structure ($instance_structure, $new_metaclass)

Inlineable Instance Operations

Each meta-instance should override this method to tell Class::MOP if it's possible to inline the slot access. This is currently only used by the Class::MOP::Immutable manpage when performing optimizations.

inline_slot_access ($instance_structure, $slot_name)
inline_get_slot_value ($instance_structure, $slot_name)
inline_set_slot_value ($instance_structure, $slot_name, $value)
inline_initialize_slot ($instance_structure, $slot_name)
inline_deinitialize_slot ($instance_structure, $slot_name)
inline_is_slot_initialized ($instance_structure, $slot_name)
inline_weaken_slot_value ($instance_structure, $slot_name)
inline_strengthen_slot_value ($instance_structure, $slot_name)


Yuval Kogman <>

Stevan Little <>


Copyright 2006-2008 by Infinity Interactive, Inc.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

 Class::MOP::Instance - Instance Meta Object