XS versions of the most common readsers
[gitmo/Class-MOP.git] / lib / Class / MOP / Instance.pm
index 8b70fdd..46773de 100644 (file)
@@ -47,9 +47,9 @@ sub new {
         # assumption,.. but you can
         # never tell <:)
         'associated_metaclass' => $options->{associated_metaclass},
-        'attributes' => $options->{attributes},
-        'slots'      => $options->{slots},
-        'slot_hash'  => $options->{slot_hash},
+        'attributes'           => $options->{attributes},
+        'slots'                => $options->{slots},
+        'slot_hash'            => $options->{slot_hash},
     } => $class;
 
     # FIXME weak_ref => 1,
@@ -58,21 +58,24 @@ sub new {
     return $instance;
 }
 
-sub associated_metaclass { (shift)->{'associated_metaclass'} }
+sub _class_name { $_[0]->{_class_name} ||= $_[0]->associated_metaclass->name }
+
+sub associated_metaclass { $_[0]{'associated_metaclass'} }
 
 sub create_instance {
     my $self = shift;
-    $self->bless_instance_structure({});
+    bless {}, $self->_class_name;
 }
 
+# for compatibility
 sub bless_instance_structure {
     my ($self, $instance_structure) = @_;
-    bless $instance_structure, $self->associated_metaclass->name;
+    bless $instance_structure, $self->_class_name;
 }
 
 sub clone_instance {
     my ($self, $instance) = @_;
-    $self->bless_instance_structure({ %$instance });
+    bless { %$instance }, $self->_class_name;
 }
 
 # operations on meta instance
@@ -248,16 +251,19 @@ Returns the metaclass of L<Class::MOP::Instance>.
 
 =item B<create_instance>
 
-This creates the appropriate structure needed for the instance and
-then calls C<bless_instance_structure> to bless it into the class.
+This creates the appropriate structure needed for the instance and blesses it.
 
 =item B<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 L<Class::MOP::Instance> ever bothered to actually make use of
+it, so it was deemed unnecessary fluff.
+
 =item B<clone_instance ($instance_structure)>
 
-This too does just exactly what it says it does.
+Creates a shallow clone of $instance_structure.
 
 =back