« 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
Condition33%1/3
$obj and builtin::blessed($obj)
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)
| |||||||||||||||||||||||||||||
| 15 | unless $obj and blessed $obj; | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | $obj->can('NON_RELOADABLE') && $obj->NON_RELOADABLE ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj->can("NON_RELOADABLE") and $obj->NON_RELOADABLE
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||