From 010297ccd797b2de560ba1d52d6be8cfa7d5f013 Mon Sep 17 00:00:00 2001 From: doy Date: Sun, 26 Apr 2009 22:30:02 -0500 Subject: 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 --- lib/Bot/Games/OO/Game.pm | 9 +++++---- 1 file 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'], ); -- cgit v1.2.3-54-g00ecf