X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FMOP%2FInstance.pm;h=7a709911c533c574e227d15787925f3b6c05b7b4;hb=98bf345be99307c66d4e8c3ff6e40e3d2bf09ce3;hp=2da9b3c2ab9d3755518873c1db4438ac31d41a5b;hpb=3d9e46468e384bb12661e1b9df7a22ab8f8ee839;p=gitmo%2FClass-MOP.git diff --git a/lib/Class/MOP/Instance.pm b/lib/Class/MOP/Instance.pm index 2da9b3c..7a70991 100644 --- a/lib/Class/MOP/Instance.pm +++ b/lib/Class/MOP/Instance.pm @@ -6,13 +6,10 @@ use warnings; use Scalar::Util 'weaken', 'blessed'; -our $VERSION = '0.03'; +our $VERSION = '0.05'; our $AUTHORITY = 'cpan:STEVAN'; -sub meta { - require Class::MOP::Class; - Class::MOP::Class->initialize(blessed($_[0]) || $_[0]); -} +use base 'Class::MOP::Object'; sub new { my ($class, $meta, @attrs) = @_; @@ -63,14 +60,14 @@ sub get_all_slots { sub is_valid_slot { my ($self, $slot_name) = @_; - exists $self->{'@!slots'}->{$slot_name} ? 1 : 0; + exists $self->{'@!slots'}->{$slot_name}; } # operations on created instances sub get_slot_value { my ($self, $instance, $slot_name) = @_; - $self->is_slot_initialized($instance, $slot_name) ? $instance->{$slot_name} : undef; + $instance->{$slot_name}; } sub set_slot_value { @@ -104,7 +101,7 @@ sub deinitialize_all_slots { sub is_slot_initialized { my ($self, $instance, $slot_name, $value) = @_; - exists $instance->{$slot_name} ? 1 : 0; + exists $instance->{$slot_name}; } sub weaken_slot_value { @@ -138,8 +135,7 @@ sub inline_slot_access { sub inline_get_slot_value { my ($self, $instance, $slot_name) = @_; - 'exists ' . $self->inline_slot_access($instance, $slot_name) . - ' ? ' . $self->inline_slot_access($instance, $slot_name) . ' : undef' + $self->inline_slot_access($instance, $slot_name); } sub inline_set_slot_value { @@ -158,7 +154,7 @@ sub inline_deinitialize_slot { } sub inline_is_slot_initialized { my ($self, $instance, $slot_name) = @_; - "exists " . $self->inline_slot_access($instance, $slot_name) . " ? 1 : 0"; + "exists " . $self->inline_slot_access($instance, $slot_name); } sub inline_weaken_slot_value { @@ -181,26 +177,15 @@ __END__ Class::MOP::Instance - Instance Meta Object -=head1 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 - =head1 DESCRIPTION -This is a sub-protocol which governs instance creation -and access to the slots of the instance structure. +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 @@ -241,9 +226,11 @@ This does just exactly what it says it does. =item B +This too does just exactly what it says it does. + =back -=head2 Instrospection +=head2 Introspection NOTE: There might be more methods added to this part of the API, we will add then when we need them basically. @@ -252,6 +239,8 @@ we will add then when we need them basically. =item B +This returns the metaclass associated with this instance. + =item B This will return the current list of slots based on what was @@ -259,6 +248,8 @@ given to this object in C. =item B +This will return true if C<$slot_name> is a valid slot name. + =back =head2 Operations on Instance Structures @@ -268,6 +259,10 @@ 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. + =over 4 =item B @@ -288,23 +283,19 @@ require that the C<$instance_structure> is passed into them. =item B +=item B + =back =head2 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. - =over 4 =item B 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. +possible to inline the slot access. This is currently only used by +L when performing optimizations. =item B