summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-06-01 02:31:07 -0500
committerJesse Luehrs <doy@tozt.net>2009-06-01 02:57:21 -0500
commit50bec03e267b34401bac32f7936686b7dc51088e (patch)
treec647502afcd694a9a3e5c32825a78439f03b9fa4
parent5d697170e22d75928a361e1c7b1d007632de29c1 (diff)
downloadbot-games-50bec03e267b34401bac32f7936686b7dc51088e.tar.gz
bot-games-50bec03e267b34401bac32f7936686b7dc51088e.zip
move the code for getting a command into the command class trait
-rw-r--r--lib/Bot/Games.pm13
-rw-r--r--lib/Bot/Games/Trait/Class/Command.pm10
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;