| 1 | package Bot::BasicBot::Pluggable::WithConfig; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use base qw(Bot::BasicBot::Pluggable); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use YAML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub new_with_config { | ||||||||||||||||||||||||||
|
Subroutine
new_with_config: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 13 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 14 | 0 | ▶ | croak 'config param must be set!!' unless $args{config}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | my $conf = YAML::LoadFile( $args{config} ) | ||||||||||||||||||||||||||||
| 16 | 0 | ▶ | or croak "Can't load a config file:" . $args{config}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my @modules = @{ delete $conf->{modules} || [] }; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $conf->{'modules'} || []
MC/DC0%0/1
delete $conf->{'modules'} || []
delete $conf->{'modules'}
Truth table0%0/2
A
A= delete $conf->{'modules'}
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my $bot = $class->new( %{ $conf || {} } ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$conf || {}
MC/DC0%0/1
$conf || {}
$conf
Truth table0%0/2
A
A= $conf
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | foreach my $module (@modules) { | |||||||||||||||||||||||||||
| 22 | 0 | $bot->load( $module->{module}, $module->{config} ); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | $bot; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: not called CC=7 SCAR=37.7
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 30 | 0 | my $module = shift; | |||||||||||||||||||||||||||
| 31 | 0 | my $module_config = shift; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # it's safe to die here, mostly this call is evaled | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | die "Need name" unless $module; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | die "Already loaded" if $self->handler($module); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # This is possible a leeeetle bit evil. | ||||||||||||||||||||||||||||
| 38 | 0 | print STDERR "Loading module '$module'.. "; | |||||||||||||||||||||||||||
| 39 | 0 | my $file = "Bot/BasicBot/Pluggable/Module/$module.pm"; | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | $file = "./modules/$module.pm" if ( -e "./modules/$module.pm" ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | print STDERR "from file $file\n"; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # force a reload of the file (in the event that we've already loaded it) | ||||||||||||||||||||||||||||
| 44 | 1 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 0 | delete $INC{$file}; | |||||||||||||||||||||||||||
| 46 | 0 | require $file; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # Ok, it's very evil. Don't bother me, I'm working. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | my $m = "Bot::BasicBot::Pluggable::Module::$module"->new( | |||||||||||||||||||||||||||
| 51 | Bot => $self, | ||||||||||||||||||||||||||||
| 52 | Param => $module_config | ||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | die "->new didn't return an object" unless ( $m and ref($m) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$m and ref $m
MC/DC0%0/2
$m and ref $m
$m
ref $m
Truth table0%0/3
A and B
A= $mB= ref $m
| |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | die ref($m) . " isn't a $module" unless ref($m) =~ /\Q$module/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | $self->add_handler( $m, $module ); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | return $m; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | 1; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||