From 50bec03e267b34401bac32f7936686b7dc51088e Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 1 Jun 2009 02:31:07 -0500 Subject: move the code for getting a command into the command class trait --- lib/Bot/Games.pm | 13 +------------ lib/Bot/Games/Trait/Class/Command.pm | 10 ++++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/Bot/Games.pm b/lib/Bot/Games.pm index 653e9da..ef61c5f 100644 --- a/lib/Bot/Games.pm +++ b/lib/Bot/Games.pm @@ -84,9 +84,7 @@ sub said { if ($action =~ /^-(\w+)\s*(.*)/) { my ($action, $arg) = ($1, $2); - # XXX: maybe the meta stuff should get pushed out into the plugins - # themselves, and this should become $game->meta->get_command or so? - if (my $method_meta = _get_command($game, $action)) { + if (my $method_meta = $game->meta->get_command($action)) { if ($method_meta->needs_init && !$self->active_games->{$game_name}->is_active) { $self->$say("Game $game_name hasn't started yet!"); @@ -147,15 +145,6 @@ sub find_game { return; } -sub _get_command { - my ($game, $action) = @_; - my $method_meta = $game->meta->find_method_by_name($action); - return $method_meta - if blessed($method_meta) - && $method_meta->meta->can('does_role') - && $method_meta->meta->does_role('Bot::Games::Trait::Method::Command'); -} - __PACKAGE__->meta->make_immutable(inline_constructor => 0); no Bot::Games::OO; diff --git a/lib/Bot/Games/Trait/Class/Command.pm b/lib/Bot/Games/Trait/Class/Command.pm index 3c242ae..462b9ea 100644 --- a/lib/Bot/Games/Trait/Class/Command.pm +++ b/lib/Bot/Games/Trait/Class/Command.pm @@ -18,6 +18,16 @@ after ((map { "add_${_}_method_modifier" } qw/before after around/) => sub { $method_metaclass->rebless_instance($method_meta, pass_args => $pass_args); }); +sub get_command { + my $self = shift; + my ($action) = @_; + my $method_meta = $self->find_method_by_name($action); + return $method_meta + if blessed($method_meta) + && $method_meta->meta->can('does_role') + && $method_meta->meta->does_role('Bot::Games::Trait::Method::Command'); +} + no Moose::Role; 1; -- cgit v1.2.3-54-g00ecf