Added note to make clear that get_attribute does not search superclasses
[gitmo/Class-MOP.git] / examples / LazyClass.pod
index b4c308c..0c87b3a 100644 (file)
@@ -7,7 +7,7 @@ use warnings;
 
 use Carp 'confess';
 
-our $VERSION = '0.04';
+our $VERSION = '0.05';
 
 use base 'Class::MOP::Attribute';
 
@@ -24,8 +24,22 @@ sub initialize_instance_slot {
        }
 }
 
-sub generate_accessor_method {
-    my $attr = shift;
+sub accessor_metaclass { 'LazyClass::Method::Accessor' }
+
+package # hide the package from PAUSE
+    LazyClass::Method::Accessor;
+
+use strict;
+use warnings;
+
+use Carp 'confess';
+
+our $VERSION = '0.01';
+
+use base 'Class::MOP::Method::Accessor';
+
+sub _generate_accessor_method {
+    my $attr = (shift)->associated_attribute;
 
        my $attr_name = $attr->name;
        my $meta_instance = $attr->associated_class->get_meta_instance;
@@ -45,8 +59,8 @@ sub generate_accessor_method {
     };
 }
 
-sub generate_reader_method {
-       my $attr = shift;
+sub _generate_reader_method {
+    my $attr = (shift)->associated_attribute;
 
        my $attr_name = $attr->name;
        my $meta_instance = $attr->associated_class->get_meta_instance;
@@ -63,8 +77,6 @@ sub generate_reader_method {
     };   
 }
 
-
-
 package # hide the package from PAUSE
     LazyClass::Instance;
 
@@ -91,21 +103,22 @@ LazyClass - An example metaclass with lazy initialization
 
   package BinaryTree;
   
-  use metaclass 'Class::MOP::Class' => (
-      ':attribute_metaclass' => 'LazyClass::Attribute'
+  use metaclass (
+      ':attribute_metaclass' => 'LazyClass::Attribute',
+      ':instance_metaclass'  => 'LazyClass::Instance',      
   );
   
-  BinaryTree->meta->add_attribute('$:node' => (
+  BinaryTree->meta->add_attribute('node' => (
       accessor => 'node',
       init_arg => ':node'
   ));
   
-  BinaryTree->meta->add_attribute('$:left' => (
+  BinaryTree->meta->add_attribute('left' => (
       reader  => 'left',
       default => sub { BinaryTree->new() }
   ));
   
-  BinaryTree->meta->add_attribute('$:right' => (
+  BinaryTree->meta->add_attribute('right' => (
       reader  => 'right',
       default => sub { BinaryTree->new() }    
   ));    
@@ -132,13 +145,15 @@ without complicating the programing of it. This would also be
 ideal for a class which has a large amount of attributes, 
 several of which are optional. 
 
-=head1 AUTHOR
+=head1 AUTHORS
 
 Stevan Little E<lt>stevan@iinteractive.comE<gt>
 
+Yuval Kogman E<lt>nothingmuch@woobling.comE<gt>
+
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2006 by Infinity Interactive, Inc.
+Copyright 2006-2008 by Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>