NAME

Class::MOP::Instance - Instance Meta Object

SYNOPSIS

# for the most part, this protocol is internal 
# and not for public usage, but this how one 
# might use it

package Foo;

use strict;
use warnings;
use metaclass (
    ':instance_metaclass'  => 'ArrayBasedStorage::Instance',
);

# now Foo->new produces blessed ARRAY ref based objects

DESCRIPTION

This is a sub-protocol which governs instance creation and access to the slots of the instance structure.

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 ($meta, @attrs)

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

meta

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

Creation of Instances

create_instance

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)

Instrospection

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

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

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.

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)

Inlineable Instance Operations

This part of the API is currently un-used. It is there for use in future experiments in class finailization mostly. Best to ignore this for now.

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::Class::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 AND LICENSE

Copyright 2006, 2007 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.