Permalink
Browse files

Checking in changes prior to tagging of version 0.03. Changelog diff is:

  • Loading branch information...
1 parent e106734 commit 772fd10a0f1be830fc0884af505ed3d09a8cb064 @dann committed Nov 16, 2008
Showing with 46 additions and 7 deletions.
  1. +4 −0 Changes
  2. +42 −7 lib/Bot/BasicBot/Pluggable/WithConfig.pm
View
@@ -1,5 +1,9 @@
Revision history for Perl extension Bot::BasicBot::Pluggable::WithConfig
+0.03 Sun Nov 16 16:20:12 2008
+ * changed configuration format. See POD.
+ * fix the bug to load config for module correctly
+
0.02 Sun Nov 9 16:20:12 2008
* added bot script
@@ -2,7 +2,7 @@ package Bot::BasicBot::Pluggable::WithConfig;
use strict;
use warnings;
-our $VERSION = '0.02';
+our $VERSION = '0.03';
use base qw(Bot::BasicBot::Pluggable);
use YAML;
@@ -12,19 +12,54 @@ sub new_with_config {
my $class = shift;
my %args = @_;
croak 'config param must be set!!' unless $args{config};
- my $conf = YAML::LoadFile($args{config})
+ my $conf = YAML::LoadFile( $args{config} )
or croak "Can't load a config file:" . $args{config};
my @modules = @{ delete $conf->{modules} || [] };
my $bot = $class->new( %{ $conf || {} } );
foreach my $module (@modules) {
- $bot->load( $module->{name}, $module->{config} );
+ $bot->load( $module->{module}, $module->{config} );
}
$bot;
}
+sub load {
+ my $self = shift;
+ my $module = shift;
+ my $module_config = shift;
+
+ # it's safe to die here, mostly this call is evaled
+ die "Need name" unless $module;
+ die "Already loaded" if $self->handler($module);
+
+ # This is possible a leeeetle bit evil.
+ print STDERR "Loading module '$module'.. ";
+ my $file = "Bot/BasicBot/Pluggable/Module/$module.pm";
+ $file = "./modules/$module.pm" if ( -e "./modules/$module.pm" );
+ print STDERR "from file $file\n";
+
+ # force a reload of the file (in the event that we've already loaded it)
+ no warnings 'redefine';
+ delete $INC{$file};
+ require $file;
+
+ # Ok, it's very evil. Don't bother me, I'm working.
+
+ my $m = "Bot::BasicBot::Pluggable::Module::$module"->new(
+ Bot => $self,
+ Param => $module_config
+ );
+
+ die "->new didn't return an object" unless ( $m and ref($m) );
+ die ref($m) . " isn't a $module" unless ref($m) =~ /\Q$module/;
+
+ $self->add_handler( $m, $module );
+
+ return $m;
+}
+
1;
__END__
@@ -54,10 +89,10 @@ Create a new Bot with YAML file.
dsn: dbi:SQLite:dann.db
table: pluggablebot
modules:
- - name: Karma
- - name: Seen
- - name: Infobot
- - name: Title
+ - module: Karma
+ - module: Seen
+ - module: Infobot
+ - module: Title
channels:
- #pluggablebot

0 comments on commit 772fd10

Please sign in to comment.