summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-06-02 20:47:05 -0500
committerJesse Luehrs <doy@tozt.net>2009-06-02 20:47:05 -0500
commit492128b96d195ba9813053bd72a09c334019beb7 (patch)
tree8a835b1ed3348b95eec61dd91e88156dc4d5bed1
parent880dfe8177549891a31f1632821f6fdefbd69c4f (diff)
downloadbot-games-492128b96d195ba9813053bd72a09c334019beb7.tar.gz
bot-games-492128b96d195ba9813053bd72a09c334019beb7.zip
only apply the command accessor metatrait for readers
-rw-r--r--lib/Bot/Games/Trait/Attribute/Command.pm22
1 files 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;