X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=examples%2FAttributesWithHistory.pod;h=e7ae1c26ac797298af47390118ead85bf72b8cfc;hb=f1af2436a0bc78cca31deb547233ef30983a2663;hp=3d2128187dfed5735ca30836e31e85d7534c814f;hpb=1a09d9cce4930577a39060a03029a32cd51d41c7;p=gitmo%2FClass-MOP.git diff --git a/examples/AttributesWithHistory.pod b/examples/AttributesWithHistory.pod index 3d21281..e7ae1c2 100644 --- a/examples/AttributesWithHistory.pod +++ b/examples/AttributesWithHistory.pod @@ -5,7 +5,7 @@ package # hide the package from PAUSE use strict; use warnings; -our $VERSION = '0.04'; +our $VERSION = '0.05'; use base 'Class::MOP::Attribute'; @@ -25,10 +25,30 @@ AttributesWithHistory->meta->add_attribute('_history' => ( default => sub { {} }, )); +sub accessor_metaclass { 'AttributesWithHistory::Method::Accessor' } + +AttributesWithHistory->meta->add_after_method_modifier('install_accessors' => sub { + my ($self) = @_; + # and now add the history accessor + $self->associated_class->add_method( + $self->_process_accessors('history_accessor' => $self->history_accessor()) + ) if $self->has_history_accessor(); +}); + +package # hide the package from PAUSE + AttributesWithHistory::Method::Accessor; + +use strict; +use warnings; + +our $VERSION = '0.01'; + +use base 'Class::MOP::Method::Accessor'; + # generate the methods -sub generate_history_accessor_method { - my ($self, $attr_name) = @_; +sub _generate_history_accessor_method { + my $attr_name = (shift)->associated_attribute->name; eval qq{sub { unless (ref \$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\}) \{ \$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\} = []; @@ -37,8 +57,8 @@ sub generate_history_accessor_method { }}; } -sub generate_accessor_method { - my ($self, $attr_name) = @_; +sub _generate_accessor_method { + my $attr_name = (shift)->associated_attribute->name; eval qq{sub { if (scalar(\@_) == 2) { unless (ref \$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\}) \{ @@ -51,8 +71,8 @@ sub generate_accessor_method { }}; } -sub generate_writer_method { - my ($self, $attr_name) = @_; +sub _generate_writer_method { + my $attr_name = (shift)->associated_attribute->name; eval qq{sub { unless (ref \$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\}) \{ \$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\} = []; @@ -60,15 +80,7 @@ sub generate_writer_method { push \@\{\$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\}\} => \$_[1]; \$_[0]->{'$attr_name'} = \$_[1]; }}; -} - -AttributesWithHistory->meta->add_after_method_modifier('install_accessors' => sub { - my ($self) = @_; - # and now add the history accessor - $self->associated_class->add_method( - $self->process_accessors('history_accessor' => $self->history_accessor()) - ) if $self->has_history_accessor(); -}); +} 1; @@ -114,7 +126,7 @@ Yuval Kogman Enothingmuch@woobling.comE =head1 COPYRIGHT AND LICENSE -Copyright 2006 by Infinity Interactive, Inc. +Copyright 2006-2008 by Infinity Interactive, Inc. L