summaryrefslogtreecommitdiffstats
path: root/lib/Bot/Games.pm
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2009-01-25 18:05:38 -0500
committerdoy <doy@tozt.net>2009-01-25 18:05:38 -0500
commit0442c25e47d2ead4534a80d10ca03462883bc6ff (patch)
tree3d29cdbfb8c3fb4e3878ba6406170ad97461867f /lib/Bot/Games.pm
parent3428c814c0cce55573c6f2f4491cb3f72192918d (diff)
downloadbot-games-0442c25e47d2ead4534a80d10ca03462883bc6ff.tar.gz
bot-games-0442c25e47d2ead4534a80d10ca03462883bc6ff.zip
set up $say in BUILD, and only install it as a method into Bot::Games::Game, rather than into each game individually
Diffstat (limited to 'lib/Bot/Games.pm')
-rw-r--r--lib/Bot/Games.pm17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/Bot/Games.pm b/lib/Bot/Games.pm
index bff15bd..afba5b2 100644
--- a/lib/Bot/Games.pm
+++ b/lib/Bot/Games.pm
@@ -27,11 +27,11 @@ has done_init => (
default => sub { {} },
);
-sub said {
+my $say;
+
+sub BUILD {
my $self = shift;
- my ($args) = @_;
- my $prefix = $self->prefix;
- my $say = sub {
+ $say = sub {
shift;
return $self->say(%$args, body => $self->_format(@_)) if @_ == 1;
my %overrides = @_;
@@ -39,6 +39,14 @@ sub said {
if exists $overrides{body};
return $self->say(%$args, %overrides);
};
+ require Bot::Games::Game;
+ _add_method('Bot::Games::Game', say => $say);
+}
+
+sub said {
+ my $self = shift;
+ my ($args) = @_;
+ my $prefix = $self->prefix;
return if $args->{channel} eq 'msg';
return unless $args->{body} =~ /^$prefix(\w+)(?:\s+(.*))?/;
@@ -50,7 +58,6 @@ sub said {
if (!defined $game) {
my $game_package = $self->game_package($game_name);
eval "require $game_package";
- _add_method($game_package, say => $say);
$game = $game_package->new;
$self->active_games->{$game_name} = $game;
$self->done_init->{$game_name} = 0;