From 492128b96d195ba9813053bd72a09c334019beb7 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 2 Jun 2009 20:47:05 -0500 Subject: only apply the command accessor metatrait for readers --- lib/Bot/Games/Trait/Attribute/Command.pm | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/Bot/Games/Trait/Attribute/Command.pm b/lib/Bot/Games/Trait/Attribute/Command.pm index a873461..acc306e 100644 --- a/lib/Bot/Games/Trait/Attribute/Command.pm +++ b/lib/Bot/Games/Trait/Attribute/Command.pm @@ -13,6 +13,12 @@ has needs_init => ( default => 1, ); +has _use_accessor_metatrait => ( + is => 'rw', + isa => 'Bool', + default => 0, +); + before _process_options => sub { my $self = shift; my ($name, $options) = @_; @@ -20,14 +26,11 @@ before _process_options => sub { if exists($options->{needs_init}) && !$options->{command}; }; -# XXX: accessor_metaclass is also used for things like predicates, so all -# predicates associated with command attributes are being made commands too... -# this shouldn't be the case around accessor_metaclass => sub { my $orig = shift; my $self = shift; my $metaclass = $self->$orig(@_); - return $metaclass unless $self->command; + return $metaclass unless $self->command && $self->_use_accessor_metatrait; return Moose::Meta::Class->create_anon_class( superclasses => [$metaclass], roles => ['Bot::Games::Trait::Method::Command'], @@ -43,6 +46,17 @@ after install_accessors => sub { $method_meta->needs_init($self->needs_init); }; +around _process_accessors => sub { + my $orig = shift; + my $self = shift; + my ($type) = @_; + $self->_use_accessor_metatrait(1) if $type eq 'accessor' + || $type eq 'reader'; + my @ret = $self->$orig(@_); + $self->_use_accessor_metatrait(0); + return @ret; +}; + no Bot::Games::OO::Role; 1; -- cgit v1.2.3