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

filter: Statementstmt 58.4% 31 / 53 Branchbran 25.0% 4 / 16 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 69.2% 9 / 13 Podpod 60.0% 3 / 5 totaltotal 49.4% 48 / 97 CC 12 SCAR 18.7
CC
12
Cov
48%
unload
13.6
is_reloadable
13.3
load
6.3
CRAP 6.5
« blib/lib/Bot/Cobalt/Plugin/Games/Roulette.pm ↑ Summary blib/lib/Bot/Cobalt/Logger/Output/File.pm »
1 package Bot::Cobalt::Core::Loader;
2 3 $Bot::Cobalt::Core::Loader::VERSION = '0.021001';
3 3 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶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 sub is_reloadable {
12 1 ▶ my ($class, $obj) = @_;
Subroutine is_reloadable: called CC=5 SCAR=25.9
Pod documented
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 sub module_path {
22 1 ▶ my ($class, $module) = @_;
Subroutine module_path: called CC=2 SCAR=7.1
Pod undocumented
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 sub load {
30 1 ▶ my ($class, $module, @newargs) = @_;
Subroutine load: called CC=4 SCAR=18.4
Pod documented
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 my $orig_err;
37 1 ▶ unless (try { require $modpath;1 } catch { $orig_err = $_;0 }) {
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
38 ## die informatively
39 1 croak "Could not load $module: $orig_err";
40 ## Okay, so we require 5.12.1+ and this only happens on <=5.8 ...
41 ## ... but it's worth noting in case this code is ported to older
42 ## perls. $INC{$modpath} is set even if we died, so long as the file
43 ## exists in our INC path.
44 0 delete $INC{$modpath};
45 }
46  
47 0 my $obj;
48 my $err; try {
49 0 ▶ $obj = $module->new(@newargs)
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 } catch {
51 0 ▶ $err = "new() failed for $module: $_";
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 undef
53 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
54  
55 0 $obj
56 }
57  
58 sub unload {
59 0 ▶ my ($class, $module) = @_;
Subroutine unload: not called CC=4 SCAR=26.1
Pod documented
60  
61 0 ▶ confess "unload() needs a module name" unless defined $module;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $module 0 0 0
62  
63 0 my $modpath = $class->module_path($module);
64  
65 0 delete $INC{$modpath};
66  
67 {
68 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
69 0 @{$module.'::ISA'} = ();
70  
71 0 my $s_table = $module.'::';
72 0 for my $symbol (keys %$s_table) {
73 0 ▶ next if $symbol =~ /^[^:]+::$/;
Branch: 1 branch
BranchTrueFalseTotal
if $symbol =~ /^[^:]+::$/ 0 0 0
74 0 delete $s_table->{$symbol}
75 }
76 }
77  
78 ## Pretty much always returns success, on the theory that
79 ## we did all we could from here.
80 1
81 0 }
82  
83 3 1;
84 __END__
« blib/lib/Bot/Cobalt/Plugin/Games/Roulette.pm ↑ Summary blib/lib/Bot/Cobalt/Logger/Output/File.pm »