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

filter: Statementstmt 48.5% 34 / 70 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 60.0% 12 / 20 Podpod 100% 5 / 5 totaltotal 38.6% 51 / 132 SCAR 43.9
CC
15
Cov
34%
_create_perplugin_obj
90.0
install_plugin
20.0
plugin
6.0
CRAP 80.7
« bin/cobalt2 ↑ Summary blib/lib/Bot/Cobalt/Core/Role/EasyAccessors.pm »
1 package Bot::Cobalt::Conf::File::Plugins;
2 $Bot::Cobalt::Conf::File::Plugins::VERSION = '0.021002';
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 1 ▶use Bot::Cobalt::Conf::File::PerPlugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Types::Path::Tiny -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use List::Objects::WithUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use List::Objects::Types -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 extends 'Bot::Cobalt::Conf::File';
20  
21  
22 has etcdir => (
23 required => 1,
24 is => 'rwp',
25 isa => Path,
26 coerce => 1,
27 );
28  
29  
30 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 sub _build_per_plugin_objs {
39 0 ▶ my ($self) = @_;
Subroutine _build_per_plugin_objs: not called CC=1 SCAR=6.9
40
41 ## Create PerPlugin cf objs for each plugin
42 hash(
43 $self->cfg_as_hash->keys->map(sub {
44 0 ▶ ( $_ => $self->_create_perplugin_obj($_) )
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 })->all
46 )
47 }
48  
49 sub _create_perplugin_obj {
50 0 ▶ my ($self, $alias) = @_;
Subroutine _create_perplugin_obj: not called CC=9 SCAR=45.0
51
52 0 ▶ my $this_cfg = $self->cfg_as_hash->get($alias)
Condition0%0/3
$self->cfg_as_hash->get($alias) || confess("_create_perplugin_obj passed unknown alias $alias")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->cfg_as_hash->get($alias) || confess("_create_perplugin_obj passed unknown alias $alias")
$self->cfg_as_hash->get($alias) confess("_create_perplugin_obj passed unknown alias $alias")
Truth table0%0/3
A || B
A= $self->cfg_as_hash->get($alias)B= confess("_create_perplugin_obj passed unknown alias $alias")
ABresult
1X1
011
000
53 || confess "_create_perplugin_obj passed unknown alias $alias";
54  
55 0 my %new_opts;
56  
57 $new_opts{module} = $this_cfg->{Module}
58 0 ▶ || confess "No Module defined for plugin $alias";
Condition0%0/3
$this_cfg->{'Module'} || confess("No Module defined for plugin $alias")
l!l&&r!l&&!r
000
MC/DC0%0/2
$this_cfg->{'Module'} || confess("No Module defined for plugin $alias")
$this_cfg->{'Module'} confess("No Module defined for plugin $alias")
Truth table0%0/3
A || B
A= $this_cfg->{'Module'}B= confess("No Module defined for plugin $alias")
ABresult
1X1
011
000
59  
60 0 ▶ if (defined $this_cfg->{Config}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this_cfg->{"Config"}) 0 0 0
61 0 my $this_cf_path = path($this_cfg->{Config});
62 0 ▶ unless ( $this_cf_path->is_absolute ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this_cf_path->is_absolute) 0 0 0
63 0 $this_cf_path = path( $self->etcdir .'/'. $this_cf_path );
64 }
65  
66 0 $new_opts{config_file} = $this_cf_path
67 }
68  
69 $new_opts{autoload} = 0
70 0 ▶ if $this_cfg->{NoAutoLoad};
Branch: 1 branch
BranchTrueFalseTotal
if $this_cfg->{"NoAutoLoad"} 0 0 0
71  
72 $new_opts{priority} = $this_cfg->{Priority}
73 0 ▶ if defined $this_cfg->{Priority};
Branch: 1 branch
BranchTrueFalseTotal
if defined $this_cfg->{"Priority"} 0 0 0
74  
75 0 ▶ if (defined $this_cfg->{Opts}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this_cfg->{"Opts"}) 0 0 0
76 confess "Opts: directive for plugin $alias is not a hash"
77 0 ▶ unless ref $this_cfg->{Opts} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this_cfg->{"Opts"} eq "HASH" 0 0 0
78
79 0 $new_opts{extra_opts} = $this_cfg->{Opts};
80 }
81  
82 Bot::Cobalt::Conf::File::PerPlugin->new(
83 0 %new_opts
84 );
85 }
86  
87 sub plugin {
88 0 ▶ my ($self, $plugin) = @_;
Subroutine plugin: not called CC=2 SCAR=17.9
Pod documented
89
90 0 ▶ confess "plugin() requires a plugin alias"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plugin 0 0 0
91 unless defined $plugin;
92  
93 0 $self->_per_plug_objs->{$plugin}
94 }
95  
96 sub list_plugins {
97 0 ▶ my ($self) = @_;
Subroutine list_plugins: not called CC=1 SCAR=6.9
Pod documented
98
99 0 [ keys %{ $self->_per_plug_objs } ]
100 }
101  
102 sub clear_plugin {
103 0 ▶ my ($self, $plugin) = @_;
Subroutine clear_plugin: not called CC=2 SCAR=17.9
Pod documented
104
105 0 ▶ confess "clear_plugin requires a plugin alias"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plugin 0 0 0
106 unless defined $plugin;
107  
108 0 delete $self->_per_plug_objs->{$plugin}
109 }
110  
111 sub load_plugin {
112 0 ▶ my ($self, $plugin) = @_;
Subroutine load_plugin: not called CC=2 SCAR=17.9
Pod documented
113
114 0 ▶ confess "load_plugin requires a plugin alias"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plugin 0 0 0
115 unless defined $plugin;
116
117 0 $self->_per_plug_objs->{$plugin}
118 = $self->_create_perplugin_obj($plugin)
119 }
120  
121 sub install_plugin {
122 0 ▶ my ($self, $plugin, $plugin_obj) = @_;
Subroutine install_plugin: not called CC=4 SCAR=30.0
Pod documented
123
124 0 ▶ unless (defined $plugin_obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $plugin_obj) 0 0 0
125 0 confess
126 "install_plugin requires a plugin alias and Conf object"
127 }
128
129 0 ▶ unless (blessed $plugin_obj &&
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($plugin_obj) and $plugin_obj->isa("Bot::Cobalt::Conf::File::PerPlugin")) 0 0 0
Condition0%0/3
builtin::blessed($plugin_obj) and $plugin_obj->isa("Bot::Cobalt::Conf::File::PerPlugin")
!ll&&!rl&&r
000
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 table0%0/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 0 $self->_per_plug_objs->{$plugin} = $plugin_obj
137 }
138  
139  
140 around 'validate' => sub {
141 1 ▶ my ($orig, $self, $cfg) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
142  
143 1 1
144 };
145  
146  
147 1;
148 __END__
« bin/cobalt2 ↑ Summary blib/lib/Bot/Cobalt/Core/Role/EasyAccessors.pm »