Skip to content

Commit

Permalink
Modules are now loaded on demand, moved to plugins/
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeusz Sośnierz committed May 20, 2010
1 parent c32abde commit eafa3d3
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 13 deletions.
17 changes: 9 additions & 8 deletions a8bot.pm
Expand Up @@ -3,7 +3,6 @@ use feature ':5.10';
use a8bot::Plugin;
use Moose;
use MooseX::NonMoose;
use Module::Pluggable sub_name => 'pluggable', require => 1;
use AnyEvent;
use AnyEvent::IRC::Client;

Expand Down Expand Up @@ -71,13 +70,6 @@ has 'wantconnection' => (

sub BUILD {
my $self = shift;
foreach my $plugin ($self->pluggable) {
my $plug = a8bot::Plugin->new(
bot => $self,
plugin => $plugin,
);
$self->add_plugin($plug);
}
$self->reg_cb(
disconnect => sub {
if ($self->wantconnection) {
Expand Down Expand Up @@ -118,6 +110,15 @@ sub BUILD {
# exit 0;
#}

sub load_plugin {
my ($self, $plugin) = @_;
my $plug = a8bot::Plugin->new(
bot => $self,
plugin => $plugin,
);
$self->add_plugin($plug);
}

sub log {
my ($self, @args) = @_;
if ($self->verbose) {
Expand Down
2 changes: 2 additions & 0 deletions a8bot/Plugin.pm
@@ -1,5 +1,6 @@
package a8bot::Plugin;
use feature ':5.10';
use lib 'plugins';
use Moose;

has 'bot' => (
Expand Down Expand Up @@ -47,6 +48,7 @@ has '_registered' => (

sub BUILD {
my $self = shift;
require $self->plugin . '.pm';
my $events = $self->plugin->init;
$self->_disconnect($events->{disconnect} // sub {});
$self->_publicmsg($events->{publicmsg} // sub {});
Expand Down
2 changes: 2 additions & 0 deletions app.pl
Expand Up @@ -7,6 +7,8 @@
verbose => 1,
);

$bot->load_plugin('Ping');

#$SIG{INT} = sub { $bot->cleanup };
#$SIG{TERM} = sub { $bot->cleanup };

Expand Down
2 changes: 1 addition & 1 deletion a8bot/Plugin/Odzywki.pm → plugins/Odzywki.pm
@@ -1,4 +1,4 @@
package a8bot::Plugin::Odzywki;
package Odzywki;
use Tie::RegexpHash;

tie my %db, 'Tie::RegexpHash';
Expand Down
2 changes: 1 addition & 1 deletion a8bot/Plugin/Ping.pm → plugins/Ping.pm
@@ -1,4 +1,4 @@
package a8bot::Plugin::Ping;
package Ping;
# example plugin for a8bot

# a plugin MUST have an 'init' subroutine, returning a hash with keys
Expand Down
2 changes: 1 addition & 1 deletion a8bot/Plugin/Powiedz.pm → plugins/Powiedz.pm
@@ -1,4 +1,4 @@
package a8bot::Plugin::Powiedz;
package Powiedz;
use strict;
use warnings;
use Hash::MultiValue;
Expand Down
2 changes: 1 addition & 1 deletion a8bot/Plugin/Seen.pm → plugins/Seen.pm
@@ -1,4 +1,4 @@
package a8bot::Plugin::Seen;
package Seen;
use POSIX 'strftime';

my %log;
Expand Down
2 changes: 1 addition & 1 deletion a8bot/Plugin/WebTitle.pm → plugins/WebTitle.pm
@@ -1,4 +1,4 @@
package a8bot::Plugin::WebTitle;
package WebTitle;
use LWP::Simple qw /get $ua/;

sub init {
Expand Down

0 comments on commit eafa3d3

Please sign in to comment.