lib/Bot/BasicBot/Pluggable/WithConfig.pm

filter: Statementstmt 42.5% 20 / 47 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 6 / 8 Podpod 50.0% 1 / 2 totaltotal 32.9% 27 / 82 CC 12 SCAR 33.9
CC
12
Cov
29%
load
43.5
new_with_config
42.0
BEGIN
1.0
CRAP 29.6
↑ Summary script/bbpbot-config.pl »
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
BranchTrueFalseTotal
unless $args{"config"} 0 0 0
15 my $conf = YAML::LoadFile( $args{config} )
16 0 ▶ or croak "Can't load a config file:" . $args{config};
Branch: 1 branch
BranchTrueFalseTotal
my $conf = YAML::LoadFile($args{"config"}) or croak(q[Can't load a config file:] . $args{"config"}) 0 0 0
17  
18 0 ▶ my @modules = @{ delete $conf->{modules} || [] };
Condition0%0/2
delete $conf->{'modules'} || []
l!l
00
MC/DC0%0/1
delete $conf->{'modules'} || []
delete $conf->{'modules'}
Truth table0%0/2
A
A= delete $conf->{'modules'}
Aresult
11
00
19 0 ▶ my $bot = $class->new( %{ $conf || {} } );
Condition0%0/2
$conf || {}
l!l
00
MC/DC0%0/1
$conf || {}
$conf
Truth table0%0/2
A
A= $conf
Aresult
11
00
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
BranchTrueFalseTotal
unless $module 0 0 0
35 0 ▶ die "Already loaded" if $self->handler($module);
Branch: 1 branch
BranchTrueFalseTotal
if $self->handler($module) 0 0 0
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
BranchTrueFalseTotal
if -e "./modules/$module.pm" 0 0 0
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
BranchTrueFalseTotal
unless $m and ref $m 0 0 0
Condition0%0/3
$m and ref $m
!ll&&!rl&&r
000
MC/DC0%0/2
$m and ref $m
$m ref $m
Truth table0%0/3
A and B
A= $mB= ref $m
ABresult
0X0
100
111
56 0 ▶ die ref($m) . " isn't a $module" unless ref($m) =~ /\Q$module/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref($m) =~ /\Q$module\E/ 0 0 0
57  
58 0 $self->add_handler( $m, $module );
59  
60 0 return $m;
61 }
62  
63 1 1;
64  
65 __END__
↑ Summary script/bbpbot-config.pl »