Class::MOP::Instance - Instance Meta Object
version 2.2207
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.
This method creates a new meta-instance object.
It accepts the following keys in %options
:
associated_metaclass
The Class::MOP::Class object for which instances will be created.
attributes
An array reference of Class::MOP::Attribute objects. These are the attributes which can be stored in each 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.
Given an instance, this method creates a new object by making shallow clone of the original.
This returns the Class::MOP::Class object associated with the meta-instance object.
This returns a list of slot names stored in object instances. In almost all cases, slot names correspond directly attribute names.
This will return true if $slot_name
is a valid slot name.
This 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.
The exact details of what each method does should be fairly obvious from the method name.
This is a boolean that indicates whether or not slot access operations can be inlined. By default it is true, but subclasses can override this.
This method expects a string that, when inlined, will become a class name. This would literally be something like '$class'
, not an actual class name.
It returns a snippet of code that creates a new object for the class. This is something like bless {}, $class_name
.
Returns whether or not inline_get_slot_value
is a valid lvalue. This can be used to do extra optimizations when generating inlined methods.
These methods all expect two arguments. The first is the name of a variable, than when inlined, will represent the object instance. Typically this will be a literal string like '$_[0]'
.
The second argument is a slot name.
The method returns a snippet of code that, when inlined, performs some operation on the instance.
This takes the name of a variable that will, when inlined, represent the object instance, and the name of a variable that will represent the class to rebless into, and returns code to rebless an instance into a class.
This will return a Class::MOP::Class instance for this class.
It should also be noted that Class::MOP will actually bootstrap this module by installing a number of attribute meta-objects into its metaclass.
Stevan Little <stevan@cpan.org>
Dave Rolsky <autarch@urth.org>
Jesse Luehrs <doy@cpan.org>
Shawn M Moore <sartak@cpan.org>
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
Karen Etheridge <ether@cpan.org>
Florian Ragwitz <rafl@debian.org>
Hans Dieter Pearcey <hdp@cpan.org>
Chris Prather <chris@prather.org>
Matt S Trout <mstrout@cpan.org>
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.