X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=examples%2FLazyClass.pod;h=262cd73d939df0901e41af647866f1d045e2af98;hb=0310d95d482349208449c86f91b5aa661d6411d4;hp=b4c308c8c41539fccdb93caeb77cd123a8e768ef;hpb=f892c0f0fa293dff33f6b20826493c089a69218e;p=gitmo%2FClass-MOP.git diff --git a/examples/LazyClass.pod b/examples/LazyClass.pod index b4c308c..262cd73 100644 --- a/examples/LazyClass.pod +++ b/examples/LazyClass.pod @@ -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 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; + my $attr = (shift)->associated_attribute; my $attr_name = $attr->name; my $meta_instance = $attr->associated_class->get_meta_instance; @@ -46,7 +60,7 @@ sub generate_accessor_method { } sub generate_reader_method { - my $attr = shift; + 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 Estevan@iinteractive.comE +Yuval Kogman Enothingmuch@woobling.comE + =head1 COPYRIGHT AND LICENSE -Copyright 2006 by Infinity Interactive, Inc. +Copyright 2006-2008 by Infinity Interactive, Inc. L