From: Dave Rolsky Date: Mon, 16 Mar 2009 20:50:43 +0000 (-0500) Subject: docs for CMOP::Instance X-Git-Tag: 0.78_02~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fbedcfb3e98c797922bad3788f9b08063cafebcf;p=gitmo%2FClass-MOP.git docs for CMOP::Instance --- diff --git a/lib/Class/MOP/Instance.pm b/lib/Class/MOP/Instance.pm index 853081b..16dd6e0 100644 --- a/lib/Class/MOP/Instance.pm +++ b/lib/Class/MOP/Instance.pm @@ -223,160 +223,178 @@ Class::MOP::Instance - Instance Meta Object =head1 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 L, -L 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 L. - -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; -F and -F for details). +The meta instance API 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 L +and L 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. =head1 METHODS +=head2 Object construction + =over 4 -=item B +=item B<< Class::MOP::Instance->new(%options) >> -Creates a new instance meta-object and gathers all the slots from -the list of C<@attrs> given. +This method creates a new meta-instance object. -=item B +It accepts the following keys in C<%options>: -Processes arguments for compatibility. +=over 8 -=item B +=item * associated_metaclass -Returns the metaclass of L. +The L object for which instances will be created. -=back +=item * attributes -=head2 Creation of Instances +An array reference of L objects. These are the +attributes which can be stored in each instance. -=over 4 +=back -=item B +=back -This creates the appropriate structure needed for the instance and blesses it. +=head2 Creating and altering instances -=item B +=over 4 -This does just exactly what it says it does. +=item B<< $metainstance->create_instance >> -This method has been deprecated but remains for compatibility reasons. None of -the subclasses of L ever bothered to actually make use of -it, so it was deemed unnecessary fluff. +This method returns a reference blessed into the associated +metaclass's class. -=item B +The default is to use a hash reference. Subclasses can override this. -Creates a shallow clone of $instance_structure. +=item B<< $metainstance->clone_instance($instance) >> + +Given an instance, this method creates a new object by making +I clone of the original. =back =head2 Introspection -NOTE: There might be more methods added to this part of the API, -we will add then when we need them basically. - =over 4 -=item B +=item B<< $metainstance->associated_metaclass >> -This returns the metaclass associated with this instance. +This returns the L object associated with the +meta-instance object. -=item B +=item B<< $metainstance->get_all_slots >> -This will return the current list of slots based on what was -given to this object in C. +This returns a list of slot names stored in object instances. In +almost all cases, slot names correspond directly attribute names. -=item B +=item B<< $metainstance->is_valid_slot($slot_name) >> This will return true if C<$slot_name> is a valid slot name. -=item B - -This method returns true when the meta instance must be recreated on any -superclass changes. - -Defaults to false. +=item B<< $metainstance->get_all_attributes >> -=item B - -This will return the current list of attributes (as -Class::MOP::Attribute objects) based on what was given to this object -in C. +This returns a list of attributes corresponding to the attributes +passed to the constructor. =back =head2 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 C<$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. +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 C<$instance_structure> always require +that the object instance be passed to the method. =over 4 -=item B +=item B<< $metainstance->get_slot_value($instance_structure, $slot_name) >> + +=item B<< $metainstance->set_slot_value($instance_structure, $slot_name, $value) >> -=item B +=item B<< $metainstance->initialize_slot($instance_structure, $slot_name) >> -=item B +=item B<< $metainstance->deinitialize_slot($instance_structure, $slot_name) >> -=item B +=item B<< $metainstance->initialize_all_slots($instance_structure) >> -=item B +=item B<< $metainstance->deinitialize_all_slots($instance_structure) >> -=item B +=item B<< $metainstance->is_slot_initialized($instance_structure, $slot_name) >> -=item B +=item B<< $metainstance->weaken_slot_value($instance_structure, $slot_name) >> -=item B +=item B<< $metainstance->strengthen_slot_value($instance_structure, $slot_name) >> -=item B +=item B<< $metainstance->rebless_instance_structure($instance_structure, $new_metaclass) >> -=item B +The exact details of what each method does should be fairly obvious +from the method name. =back -=head2 Inlineable Instance Operations +=head2 Inlinable Instance Operations =over 4 -=item B +=item B<< $metainstance->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 -L when performing optimizations. +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. -=item B +=item B<< $metainstance->inline_create_instance($class_variable) >> -=item B +This method expects a string that, I, will become a +class name. This would literally be something like C<'$class'>, not an +actual class name. -=item B +It returns a snippet of code that creates a new object for the +class. This is something like C< bless {}, $class_name >. -=item B +=item B<< $metainstance->inline_slot_access($instance_variable, $slot_name) >> -=item B +=item B<< $metainstance->inline_get_slot_value($instance_variable, $slot_name) >> -=item B +=item B<< $metainstance->inline_set_slot_value($instance_variable, $slot_name, $value) >> + +=item B<< $metainstance->inline_initialize_slot($instance_variable, $slot_name) >> + +=item B<< $metainstance->inline_deinitialize_slot($instance_variable, $slot_name) >> + +=item B<< $metainstance->inline_is_slot_initialized($instance_variable, $slot_name) >> + +=item B<< $metainstance->inline_weaken_slot_value($instance_variable, $slot_name) >> + +=item B<< $metainstance->inline_strengthen_slot_value($instance_variable, $slot_name) >> + +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 C<'$_[0]'>. + +The second argument is a slot name. + +The method returns a snippet of code that, when inlined, performs some +operation on the instance. + +=back + +=head2 Introspection + +=over 4 -=item B +=item B<< Class::MOP::Instance->meta >> -=item B +This will return a L instance for this class. -=item B +It should also be noted that L will actually bootstrap +this module by installing a number of attribute meta-objects into its +metaclass. =back diff --git a/xt/pod_coverage.t b/xt/pod_coverage.t index 70e6585..bf70646 100644 --- a/xt/pod_coverage.t +++ b/xt/pod_coverage.t @@ -45,6 +45,46 @@ my %trustme = ( 'compute_all_applicable_attributes', ], + + 'Class::MOP::Instance' => [ + qw( BUILDARGS + bless_instance_structure + is_dependent_on_superclasses ), + ], + + 'Class::MOP::Method::Accessor' => [ + qw( generate_accessor_method + generate_accessor_method_inline + generate_clearer_method + generate_clearer_method_inline + generate_predicate_method + generate_predicate_method_inline + generate_reader_method + generate_reader_method_inline + generate_writer_method + generate_writer_method_inline + initialize_body + ) + ], + + 'Class::MOP::Method::Constructor' => [ + qw( attributes + generate_constructor_method + generate_constructor_method_inline + initialize_body + meta_instance + ) + ], + + 'Class::MOP::Method::Generated' => [ + qw( new + definition_context + is_inline + initialize_body + ) + ], + + 'Class::MOP::Module' => ['create'], ); for my $module ( sort @modules ) { diff --git a/xt/pod_spell.t b/xt/pod_spell.t index 52c590f..2609cdd 100644 --- a/xt/pod_spell.t +++ b/xt/pod_spell.t @@ -100,6 +100,7 @@ Immutabilization immutabilization immutabilize immutabilized +Inlinable inline invocant invocant's