blib/lib/Bot/Cobalt/Conf/File/Plugins.pm

filter: Statementstmt 97.3% 74 / 76 Branchbran 68.1% 15 / 22 Conditioncond 42.8% 3 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 20 / 20 Podpod 100% 5 / 5 totaltotal 87.3% 117 / 134 CC 15 SCAR 13.6
CC
15
Cov
88%
_create_perplugin_obj
9.2
install_plugin
5.6
plugin
2.0
CRAP 3.9
« blib/lib/Bot/Cobalt/Core/ContextMeta.pm ↑ Summary blib/lib/Bot/Cobalt/Common.pm »
1 package Bot::Cobalt::Conf::File::Plugins;
2 2 $Bot::Cobalt::Conf::File::Plugins::VERSION = '0.021003';
3 2 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Bot::Cobalt::Common ':types';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Bot::Cobalt::Conf::File::PerPlugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Types::Path::Tiny -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use List::Objects::WithUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use List::Objects::Types -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 extends 'Bot::Cobalt::Conf::File';
20  
21  
22 2 has etcdir => (
23 required => 1,
24 is => 'rwp',
25 isa => Path,
26 coerce => 1,
27 );
28  
29  
30 2 has _per_plug_objs => (
31 lazy => 1,
32 is => 'ro',
33 isa => HashObj,
34 coerce => 1,
35 builder => '_build_per_plugin_objs',
36 );
37  
38 2 ▶sub _build_per_plugin_objs {
Subroutine _build_per_plugin_objs: called CC=1 SCAR=0.0
39 2 my ($self) = @_;
40
41 ## Create PerPlugin cf objs for each plugin
42 hash(
43 40 ▶ $self->cfg_as_hash->keys->map(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
44 40 ( $_ => $self->_create_perplugin_obj($_) )
45 2 })->all
46 )
47 }
48  
49 41 ▶sub _create_perplugin_obj {
Subroutine _create_perplugin_obj: called CC=9 SCAR=22.2
50 41 my ($self, $alias) = @_;
51
52 41 ▶ my $this_cfg = $self->cfg_as_hash->get($alias)
Condition50%1/2
$self->cfg_as_hash->get($alias) || confess("_create_perplugin_obj passed unknown alias $alias")
l!l
410
MC/DC0%0/1
$self->cfg_as_hash->get($alias) || confess("_create_perplugin_obj passed unknown alias $alias")
$self->cfg_as_hash->get($alias)
Truth table50%1/2
A
A= $self->cfg_as_hash->get($alias)
Aresult
11
00
53 || confess "_create_perplugin_obj passed unknown alias $alias";
54  
55 41 my %new_opts;
56  
57 $new_opts{module} = $this_cfg->{Module}
58 41 ▶ || confess "No Module defined for plugin $alias";
Condition50%1/2
$this_cfg->{'Module'} || confess("No Module defined for plugin $alias")
l!l
410
MC/DC0%0/1
$this_cfg->{'Module'} || confess("No Module defined for plugin $alias")
$this_cfg->{'Module'}
Truth table50%1/2
A
A= $this_cfg->{'Module'}
Aresult
11
00
59  
60 41 ▶ if (defined $this_cfg->{Config}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this_cfg->{"Config"}) 14 27 41
61 14 my $this_cf_path = path($this_cfg->{Config});
62 14 ▶ unless ( $this_cf_path->is_absolute ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this_cf_path->is_absolute) 14 0 14
63 14 $this_cf_path = path( $self->etcdir .'/'. $this_cf_path );
64 }
65  
66 14 $new_opts{config_file} = $this_cf_path
67 }
68  
69 $new_opts{autoload} = 0
70 41 ▶ if $this_cfg->{NoAutoLoad};
Branch: 1 branch
BranchTrueFalseTotal
if $this_cfg->{"NoAutoLoad"} 6 35 41
71  
72 $new_opts{priority} = $this_cfg->{Priority}
73 41 ▶ if defined $this_cfg->{Priority};
Branch: 1 branch
BranchTrueFalseTotal
if defined $this_cfg->{"Priority"} 6 35 41
74  
75 41 ▶ if (defined $this_cfg->{Opts}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this_cfg->{"Opts"}) 7 34 41
76 confess "Opts: directive for plugin $alias is not a hash"
77 7 ▶ unless ref $this_cfg->{Opts} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this_cfg->{"Opts"} eq "HASH" 0 7 7
78
79 7 $new_opts{extra_opts} = $this_cfg->{Opts};
80 }
81  
82 Bot::Cobalt::Conf::File::PerPlugin->new(
83 41 %new_opts
84 );
85 }
86  
87 52 ▶sub plugin {
Subroutine plugin: called CC=2 SCAR=7.1
Pod documented
88 52 my ($self, $plugin) = @_;
89
90 52 ▶ confess "plugin() requires a plugin alias"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plugin 0 52 52
91 unless defined $plugin;
92  
93 52 $self->_per_plug_objs->{$plugin}
94 }
95  
96 2 ▶sub list_plugins {
Subroutine list_plugins: called CC=1 SCAR=0.0
Pod documented
97 2 my ($self) = @_;
98
99 2 [ keys %{ $self->_per_plug_objs } ]
100 }
101  
102 1 ▶sub clear_plugin {
Subroutine clear_plugin: called CC=2 SCAR=7.1
Pod documented
103 1 my ($self, $plugin) = @_;
104
105 1 ▶ confess "clear_plugin requires a plugin alias"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plugin 0 1 1
106 unless defined $plugin;
107  
108 1 delete $self->_per_plug_objs->{$plugin}
109 }
110  
111 1 ▶sub load_plugin {
Subroutine load_plugin: called CC=2 SCAR=7.1
Pod documented
112 1 my ($self, $plugin) = @_;
113
114 1 ▶ confess "load_plugin requires a plugin alias"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plugin 0 1 1
115 unless defined $plugin;
116
117 1 $self->_per_plug_objs->{$plugin}
118 = $self->_create_perplugin_obj($plugin)
119 }
120  
121 1 ▶sub install_plugin {
Subroutine install_plugin: called CC=4 SCAR=17.2
Pod documented
122 1 my ($self, $plugin, $plugin_obj) = @_;
123
124 1 ▶ unless (defined $plugin_obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $plugin_obj) 0 1 1
125 0 confess
126 "install_plugin requires a plugin alias and Conf object"
127 }
128
129 1 ▶ unless (blessed $plugin_obj &&
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($plugin_obj) and $plugin_obj->isa("Bot::Cobalt::Conf::File::PerPlugin")) 0 1 1
Condition33%1/3
builtin::blessed($plugin_obj) and $plugin_obj->isa("Bot::Cobalt::Conf::File::PerPlugin")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($plugin_obj) and $plugin_obj->isa("Bot::Cobalt::Conf::File::PerPlugin")
builtin::blessed($plugin_obj) $plugin_obj->isa("Bot::Cobalt::Conf::File::PerPlugin")
Truth table33%1/3
A and B
A= builtin::blessed($plugin_obj)B= $plugin_obj->isa("Bot::Cobalt::Conf::File::PerPlugin")
ABresult
0X0
100
111
130 $plugin_obj->isa('Bot::Cobalt::Conf::File::PerPlugin') ) {
131
132 0 confess
133 "install_plugin requires a Bot::Cobalt::Conf::File::PerPlugin object"
134 }
135
136 1 $self->_per_plug_objs->{$plugin} = $plugin_obj
137 }
138  
139  
140 3 ▶around 'validate' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
141 3 my ($orig, $self, $cfg) = @_;
142  
143 3 1
144 2 };
145  
146  
147 2 1;
148 __END__
« blib/lib/Bot/Cobalt/Core/ContextMeta.pm ↑ Summary blib/lib/Bot/Cobalt/Common.pm »