use strict;
use warnings;
-our $VERSION = '0.04';
+our $VERSION = '0.05';
use base 'Class::MOP::Attribute';
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) = @_;
+ 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]\} = [];
}
sub generate_accessor_method {
- my ($self, $attr_name) = @_;
+ my $attr_name = (shift)->associated_attribute->name;
eval qq{sub {
if (scalar(\@_) == 2) {
unless (ref \$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\}) \{
}
sub generate_writer_method {
- my ($self, $attr_name) = @_;
+ 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]\} = [];
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;
autogenerate a means of accessing that history for the class
which these attributes are added too.
-=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>