0.33
[gitmo/Class-MOP.git] / examples / ArrayBasedStorage.pod
index 284e558..bc5a19b 100644 (file)
@@ -1,57 +1,4 @@
-
-package # hide the package from PAUSE
-    ArrayBasedStorage::Attribute;
-
-use strict;
-use warnings;
-
-use Carp 'confess';
-
-our $VERSION = '0.01';
-
-use base 'Class::MOP::Attribute';    
-
-sub generate_accessor_method {
-    my $self = shift;
-    my $attr_name = $self->name;
-    return sub {
-        my $meta_instance = $_[0]->meta->get_meta_instance;            
-        $meta_instance->set_slot_value($_[0], $attr_name, $_[1]) if scalar(@_) == 2;
-        $meta_instance->get_slot_value($_[0], $attr_name);
-    };
-}
-
-sub generate_reader_method {
-    my $self = shift;
-    my $attr_name = $self->name;
-    return sub { 
-        confess "Cannot assign a value to a read-only accessor" if @_ > 1;
-        $_[0]->meta
-             ->get_meta_instance
-             ->get_slot_value($_[0], $attr_name); 
-    };   
-}
-
-sub generate_writer_method {
-    my $self = shift;
-    my $attr_name = $self->name;
-    return sub { 
-        $_[0]->meta
-             ->get_meta_instance
-             ->set_slot_value($_[0], $attr_name, $_[1]);
-    };
-}
-
-sub generate_predicate_method {
-    my $self = shift;
-    my $attr_name = $self->name;
-    return sub {        
-        defined $_[0]->meta
-                     ->get_meta_instance
-                     ->get_slot_value($_[0], $attr_name) ? 1 : 0;
-    };
-}    
-
+  
 package # hide the package from PAUSE
     ArrayBasedStorage::Instance;
 
@@ -77,11 +24,18 @@ sub create_instance {
     $self->bless_instance_structure([]);
 }
 
+sub clone_instance {
+    my ($self, $instance) = shift;
+    $self->bless_instance_structure([ @$instance ]);
+}
+
 # operations on meta instance
 
+sub get_slot_index_map { (shift)->{slot_index_map} }
+
 sub get_all_slots {
     my $self = shift;
-    return sort @{$self->{slots}};
+    return sort $self->SUPER::get_all_slots;
 }
 
 sub get_slot_value {
@@ -94,11 +48,6 @@ sub set_slot_value {
     $instance->[ $self->{slot_index_map}->{$slot_name} ] = $value;
 }
 
-sub initialize_slot {
-    my ($self, $instance, $slot_name) = @_;
-    $instance->[ $self->{slot_index_map}->{$slot_name} ] = undef;
-}
-
 sub is_slot_initialized {
     # NOTE:
     # maybe use CLOS's *special-unbound-value*
@@ -120,8 +69,7 @@ ArrayBasedStorage - An example of an Array based instance storage
 
   package Foo;
   
-  use metaclass 'Class::MOP::Class' => (
-    ':attribute_metaclass' => 'ArrayBasedStorage::Attribute'
+  use metaclass (
     ':instance_metaclass'  => 'ArrayBasedStorage::Instance'
   );
   
@@ -142,10 +90,16 @@ ArrayBasedStorage - An example of an Array based instance storage
 This is a proof of concept using the Instance sub-protocol 
 which uses ARRAY refs to store the instance data. 
 
-=head1 AUTHOR
+This is very similar now to the InsideOutClass example, and 
+in fact, they both share the exact same test suite, with 
+the only difference being the Instance metaclass they use.
+
+=head1 AUTHORS
 
 Stevan Little E<lt>stevan@iinteractive.comE<gt>
 
+Yuval Kogman E<lt>nothingmuch@woobling.comE<gt>
+
 =head1 SEE ALSO
 
 =head1 COPYRIGHT AND LICENSE