summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2009-04-26 22:30:02 -0500
committerdoy <doy@tozt.net>2009-04-26 22:30:02 -0500
commit010297ccd797b2de560ba1d52d6be8cfa7d5f013 (patch)
treed029b7d5caa18944d0e02525e121a79fca746342
parent86233c470263d60ad5aaa2e656a96c3029a54b6b (diff)
downloadbot-games-010297ccd797b2de560ba1d52d6be8cfa7d5f013.tar.gz
bot-games-010297ccd797b2de560ba1d52d6be8cfa7d5f013.zip
method_metaclass_roles only applies to methods that already exist when the class is being generated (so stuff at BEGIN time, like sub foo {})... i want to be applying the formatted role during the command keyword
-rw-r--r--lib/Bot/Games/OO/Game.pm9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/Bot/Games/OO/Game.pm b/lib/Bot/Games/OO/Game.pm
index e6cb762..9a521cb 100644
--- a/lib/Bot/Games/OO/Game.pm
+++ b/lib/Bot/Games/OO/Game.pm
@@ -6,9 +6,12 @@ sub command {
my ($name, $code, %args) = @_;
my $method_meta = $class->meta->get_method($name);
my $superclass = Moose::blessed($method_meta) || 'Moose::Meta::Method';
+ my @method_metaclass_roles = ('Bot::Games::Trait::Method::Command');
+ push @method_metaclass_roles, 'Bot::Games::Trait::Method::Formatted'
+ if $args{formatter};
my $method_metaclass = Moose::Meta::Class->create_anon_class(
superclasses => [$superclass],
- roles => ['Bot::Games::Trait::Method::Command'],
+ roles => [@method_metaclass_roles],
cache => 1,
);
if ($method_meta) {
@@ -22,7 +25,7 @@ sub command {
);
$class->meta->add_method($name, $method_meta);
}
- for my $attr ($method_metaclass->get_attribute_list) {
+ for my $attr (map { $_->meta->get_attribute_list } @method_metaclass_roles) {
$method_meta->$attr($args{$attr}) if exists $args{$attr};
}
}
@@ -42,8 +45,6 @@ sub init_meta {
attribute_metaclass_roles =>
['Bot::Games::Trait::Attribute::Command',
'Bot::Games::Trait::Attribute::Formatted'],
- method_metaclass_roles =>
- ['Bot::Games::Trait::Method::Formatted'],
metaclass_roles =>
['Bot::Games::Trait::Class::Command'],
);