summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-11-28 15:40:24 -0600
committerJesse Luehrs <doy@tozt.net>2009-11-28 15:40:46 -0600
commit29c0d80c40d44eb77e3320c5c883357eb6b6f604 (patch)
treef20d05b0defcb969cb481240db4b454a7a5b95dd
parent765eca33ac35568caa92c5559cd1d20d0ad7315b (diff)
downloadcrawlbot-29c0d80c40d44eb77e3320c5c883357eb6b6f604.tar.gz
crawlbot-29c0d80c40d44eb77e3320c5c883357eb6b6f604.zip
make plugins a bit more flexible
-rw-r--r--lib/Crawl/Bot.pm31
-rw-r--r--lib/Crawl/Bot/Plugin.pm18
-rw-r--r--lib/Crawl/Bot/Plugin/Mantis.pm (renamed from lib/Crawl/Bot/Mantis.pm)11
-rw-r--r--lib/Crawl/Bot/Plugin/Wiki.pm (renamed from lib/Crawl/Bot/Wiki.pm)10
4 files changed, 30 insertions, 40 deletions
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;
}
diff --git a/lib/Crawl/Bot/Plugin.pm b/lib/Crawl/Bot/Plugin.pm
new file mode 100644
index 0000000..c70e102
--- /dev/null
+++ b/lib/Crawl/Bot/Plugin.pm
@@ -0,0 +1,18 @@
+package Crawl::Bot::Plugin;
+use Moose;
+
+has bot => (
+ is => 'ro',
+ isa => 'Crawl::Bot',
+ required => 1,
+ weak_ref => 1,
+ handles => [qw(say_all data_dir)],
+);
+
+# not all plugins require a tick method
+sub tick { }
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
diff --git a/lib/Crawl/Bot/Mantis.pm b/lib/Crawl/Bot/Plugin/Mantis.pm
index 8f4b937..9312237 100644
--- a/lib/Crawl/Bot/Mantis.pm
+++ b/lib/Crawl/Bot/Plugin/Mantis.pm
@@ -1,18 +1,11 @@
-package Crawl::Bot::Mantis;
+package Crawl::Bot::Plugin::Mantis;
use Moose;
+extends 'Crawl::Bot::Plugin';
use autodie;
use File::Spec;
use XML::RAI;
-has bot => (
- is => 'ro',
- isa => 'Crawl::Bot',
- required => 1,
- weak_ref => 1,
- handles => [qw(say_all data_dir)],
-);
-
has rss_feed => (
is => 'ro',
isa => 'Str',
diff --git a/lib/Crawl/Bot/Wiki.pm b/lib/Crawl/Bot/Plugin/Wiki.pm
index bffc925..9e08159 100644
--- a/lib/Crawl/Bot/Wiki.pm
+++ b/lib/Crawl/Bot/Plugin/Wiki.pm
@@ -1,16 +1,8 @@
-package Crawl::Bot::Wiki;
+package Crawl::Bot::Plugin::Wiki;
use Moose;
use XML::RPC;
-has bot => (
- is => 'ro',
- isa => 'Crawl::Bot',
- required => 1,
- weak_ref => 1,
- handles => [qw(say_all)],
-);
-
has xmlrpc_location => (
is => 'ro',
isa => 'Str',