Class::MOP::Instance.3pm

Langue: en

Version: 2008-12-16 (ubuntu - 08/07/09)

Section: 3 (Bibliothèques de fonctions)

NAME

Class::MOP::Instance - Instance Meta Object

DESCRIPTION

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

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

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).

METHODS

new %args
Creates a new instance meta-object and gathers all the slots from the list of @attrs given.
BUILDARGS
Processes arguments for compatibility.
meta
Returns the metaclass of Class::MOP::Instance.

Creation of Instances

create_instance
This creates the appropriate structure needed for the instance and blesses it.
bless_instance_structure ($instance_structure)
This does just exactly what it says it does.

This method has been deprecated but remains for compatibility reasons. None of the subclasses of Class::MOP::Instance ever bothered to actually make use of it, so it was deemed unnecessary fluff.

clone_instance ($instance_structure)
Creates a shallow clone of $instance_structure.

Introspection

NOTE: There might be more methods added to this part of the API, we will add then when we need them basically.
associated_metaclass
This returns the metaclass associated with this instance.
get_all_slots
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.
is_dependent_on_superclasses
This method returns true when the meta instance must be recreated on any superclass changes.

Defaults to false.

get_all_attributes
This will return the current list of attributes (as Class::MOP::Attribute objects) based on what was given to this object in "new".

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

is_inlinable
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 Class::MOP::Immutable when performing optimizations.
inline_create_instance
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)

AUTHORS

Yuval Kogman <nothingmuch@woobling.com>

Stevan Little <stevan@iinteractive.com>

Copyright 2006-2008 by Infinity Interactive, Inc.

<http://www.iinteractive.com>

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