blib/lib/Bot/Cobalt/Core/Loader.pm

filter: Statementstmt 60.0% 33 / 55 Branchbran 27.7% 5 / 18 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 71.4% 10 / 14 Podpod 60.0% 3 / 5 totaltotal 50.9% 52 / 102 CC 13 SCAR 19.2
CC
13
Cov
49%
unload
13.6
is_reloadable
13.3
load
7.8
CRAP 6.8
« blib/lib/Bot/Cobalt/Plugin/Games/Roulette.pm ↑ Summary blib/lib/Bot/Cobalt/Logger/Output/File.pm »
1 package Bot::Cobalt::Core::Loader;
2 2 $Bot::Cobalt::Core::Loader::VERSION = '0.021003';
3 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub new { bless [], shift }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
10  
11 1 ▶sub is_reloadable {
Subroutine is_reloadable: called CC=5 SCAR=25.9
Pod documented
12 1 my ($class, $obj) = @_;
13  
14 1 ▶ confess "is_reloadable() needs a plugin object"
Branch: 1 branch
BranchTrueFalseTotal
unless $obj and builtin::blessed($obj) 1 0 1
Condition33%1/3
$obj and builtin::blessed($obj)
!ll&&!rl&&r
100
MC/DC0%0/2
$obj and builtin::blessed($obj)
$obj builtin::blessed($obj)
Truth table33%1/3
A and B
A= $objB= builtin::blessed($obj)
ABresult
0X0
100
111
15 unless $obj and blessed $obj;
16  
17 0 ▶ $obj->can('NON_RELOADABLE') && $obj->NON_RELOADABLE ?
Branch: 1 branch
BranchTrueFalseTotal
$obj->can('NON_RELOADABLE') && $obj->NON_RELOADABLE ? : 0 0 0
Condition0%0/3
$obj->can("NON_RELOADABLE") and $obj->NON_RELOADABLE
!ll&&!rl&&r
000
MC/DC0%0/2
$obj->can("NON_RELOADABLE") and $obj->NON_RELOADABLE
$obj->can("NON_RELOADABLE") $obj->NON_RELOADABLE
Truth table0%0/3
A and B
A= $obj->can("NON_RELOADABLE")B= $obj->NON_RELOADABLE
ABresult
0X0
100
111
18 undef : 1
19 }
20  
21 1 ▶sub module_path {
Subroutine module_path: called CC=2 SCAR=7.1
Pod undocumented
22 1 my ($class, $module) = @_;
23  
24 1 ▶ confess "module_path() needs a module name" unless defined $module;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $module 0 1 1
25  
26 1 join('/', split /::/, $module).".pm";
27 }
28  
29 1 ▶sub load {
Subroutine load: called CC=5 SCAR=20.5
Pod documented
30 1 my ($class, $module, @newargs) = @_;
31  
32 1 ▶ confess "load() needs a module name" unless defined $module;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $module 0 1 1
33  
34 1 my $modpath = $class->module_path($module);
35  
36 1 local @INC = @INC;
37 1 ▶ pop @INC if $INC[-1] eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $INC[-1] eq "." 1 0 1
38  
39 1 my $orig_err;
40 0 ▶ unless (try { require $modpath;1 } catch { $orig_err = $_;0 }) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless (&try(sub { require $modpath; 1; } , &catch(sub { $orig_err = $_; 0; } ))) 1 0 1
41 ## die informatively
42 1 croak "Could not load $module: $orig_err";
43 ## Okay, so we require 5.12.1+ and this only happens on <=5.8 ...
44 ## ... but it's worth noting in case this code is ported to older
45 ## perls. $INC{$modpath} is set even if we died, so long as the file
46 ## exists in our INC path.
47 0 delete $INC{$modpath};
48 }
49  
50 0 my $obj;
51 0 ▶ my $err; try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 0 $obj = $module->new(@newargs)
53 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 0 $err = "new() failed for $module: $_";
55 undef
56 0 ▶ } or confess $err;
Branch: 1 branch
BranchTrueFalseTotal
&try(sub { $obj = $module->new(@newargs); } , &catch(sub { $err = "new() failed for ${module}: $_"; undef; } )) or confess($err) 0 0 0
57  
58 0 $obj
59 }
60  
61 0 ▶sub unload {
Subroutine unload: not called CC=4 SCAR=26.1
Pod documented
62 0 my ($class, $module) = @_;
63  
64 0 ▶ confess "unload() needs a module name" unless defined $module;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $module 0 0 0
65  
66 0 my $modpath = $class->module_path($module);
67  
68 0 delete $INC{$modpath};
69  
70 {
71 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
72 0 @{$module.'::ISA'} = ();
73  
74 0 my $s_table = $module.'::';
75 0 for my $symbol (keys %$s_table) {
76 0 ▶ next if $symbol =~ /^[^:]+::$/;
Branch: 1 branch
BranchTrueFalseTotal
if $symbol =~ /^[^:]+::$/ 0 0 0
77 0 delete $s_table->{$symbol}
78 }
79 }
80  
81 ## Pretty much always returns success, on the theory that
82 ## we did all we could from here.
83 1
84 0 }
85  
86 2 1;
87 __END__
« blib/lib/Bot/Cobalt/Plugin/Games/Roulette.pm ↑ Summary blib/lib/Bot/Cobalt/Logger/Output/File.pm »