From 29c0d80c40d44eb77e3320c5c883357eb6b6f604 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 28 Nov 2009 15:40:24 -0600 Subject: make plugins a bit more flexible --- lib/Crawl/Bot.pm | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'lib/Crawl/Bot.pm') diff --git a/lib/Crawl/Bot.pm b/lib/Crawl/Bot.pm index b6d956e..7d34403 100644 --- a/lib/Crawl/Bot.pm +++ b/lib/Crawl/Bot.pm @@ -4,6 +4,10 @@ use MooseX::NonMoose; extends 'Bot::BasicBot'; use File::Path; +use Module::Pluggable ( + instantiate => 'new', + sub_name => 'create_plugins', +); has [qw(username name)] => ( # don't need (or want) accessors, just want to initialize the hash slot @@ -26,33 +30,17 @@ has update_time => ( default => 300, ); -has mantis => ( - is => 'ro', - isa => 'Crawl::Bot::Mantis', - lazy => 1, - default => sub { - my $self = shift; - require Crawl::Bot::Mantis; - Crawl::Bot::Mantis->new(bot => $self); - }, -); - -has wiki => ( +has plugins => ( is => 'ro', - isa => 'Crawl::Bot::Wiki', + isa => 'ArrayRef[Crawl::Bot::Plugin]', lazy => 1, - default => sub { - my $self = shift; - require Crawl::Bot::Wiki; - Crawl::Bot::Wiki->new(bot => $self); - }, + default => sub { [__PACKAGE__->create_plugins(bot => shift)] }, ); sub BUILD { my $self = shift; File::Path::mkpath($self->data_dir); - $self->mantis; - $self->wiki; + $self->plugins; } before say => sub { @@ -63,8 +51,7 @@ before say => sub { sub tick { my $self = shift; - $self->mantis->tick; - $self->wiki->tick; + $_->tick for @{ $self->plugins }; return $self->update_time; } -- cgit v1.2.3-54-g00ecf