blib/lib/Bot/Cobalt/Core/Role/EasyAccessors.pm

filter: Statementstmt 40.5% 15 / 37 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 4 / 8 Podpod 100% 4 / 4 totaltotal 32.3% 23 / 71 CC 11 SCAR 31.5
CC
11
Cov
27%
get_channels_cfg
42.0
get_plugin_cfg
30.0
get_plugin_alias
6.0
CRAP 23.3
« blib/lib/Bot/Cobalt/Logger/Output.pm ↑ Summary blib/lib/Bot/Cobalt/Plugin/Games/RockPaperScissors.pm »
1 package Bot::Cobalt::Core::Role::EasyAccessors;
2 1 $Bot::Cobalt::Core::Role::EasyAccessors::VERSION = '0.021001';
3 1 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Scalar::Util 'blessed', 'reftype';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 requires qw/
11 cfg
12 PluginObjects
13 /;
14  
15  
16 sub get_channels_cfg {
17 0 ▶ my ($self, $context) = @_;
Subroutine get_channels_cfg: not called CC=6 SCAR=37.4
Pod documented
18  
19 0 ▶ confess "get_channels_cfg expects a server context name"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context 0 0 0
20 unless defined $context;
21  
22 ## Returns empty hash if there's no conf for this context
23 0 ▶ my $chcfg = $self->cfg->channels->context($context) || {};
Condition0%0/2
$self->cfg->channels->context($context) || {}
l!l
00
MC/DC0%0/1
$self->cfg->channels->context($context) || {}
$self->cfg->channels->context($context)
Truth table0%0/2
A
A= $self->cfg->channels->context($context)
Aresult
11
00
24
25 0 for my $channel (keys %$chcfg) {
26 ## Might be an empty string:
27 $chcfg->{$channel} = +{}
28 unless ref $chcfg->{$channel}
29 0 ▶ and reftype $chcfg->{$channel} eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $chcfg->{$channel} and builtin::reftype($chcfg->{$channel}) eq "HASH" 0 0 0
Condition0%0/3
ref $chcfg->{$channel} and builtin::reftype($chcfg->{$channel}) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $chcfg->{$channel} and builtin::reftype($chcfg->{$channel}) eq "HASH"
ref $chcfg->{$channel} builtin::reftype($chcfg->{$channel}) eq "HASH"
Truth table0%0/3
A and B
A= ref $chcfg->{$channel}B= builtin::reftype($chcfg->{$channel}) eq "HASH"
ABresult
0X0
100
111
30 }
31
32 $chcfg
33 0 }
34  
35 sub get_core_cfg {
36 0 ▶ my ($self) = @_;
Subroutine get_core_cfg: not called CC=1 SCAR=6.9
Pod documented
37  
38 0 $self->cfg->core
39 }
40  
41 sub get_plugin_alias {
42 0 ▶ my ($self, $plugobj) = @_;
Subroutine get_plugin_alias: not called CC=2 SCAR=17.9
Pod documented
43 0 ▶ confess "get_plugin_alias expects an object"
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($plugobj) 0 0 0
44 unless blessed $plugobj;
45
46 0 $self->PluginObjects->{$plugobj}
47 }
48  
49 sub get_plugin_cfg {
50 0 ▶ my ($self, $plugin) = @_;
Subroutine get_plugin_cfg: not called CC=5 SCAR=34.0
Pod documented
51 ## my $plugcf = $core->get_plugin_cfg( $self )
52  
53 0 ▶ confess "get_plugin_cfg expects a plugin alias or loaded object"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plugin 0 0 0
54 unless defined $plugin;
55  
56 0 my $alias;
57  
58 0 ▶ if (blessed $plugin) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($plugin)) { } 0 0 0
59 ## plugin obj specified
60 0 ▶ unless ($alias = $self->PluginObjects->{$plugin}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($alias = $self->PluginObjects->{$plugin}) 0 0 0
61 0 carp "get_plugin_cfg; No alias for $plugin";
62 return
63 0 }
64 } else {
65 ## string alias specified
66 0 $alias = $plugin;
67 }
68  
69 0 my $pcfg_obj = $self->cfg->plugins->plugin($alias);
70  
71 ## Return empty hash if this plugin has no config
72 0 ▶ return {} unless blessed $pcfg_obj;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($pcfg_obj) 0 0 0
73
74 ## Return opts() hash
75 0 $pcfg_obj->opts
76 }
77  
78  
79 1 1;
80 __END__
« blib/lib/Bot/Cobalt/Logger/Output.pm ↑ Summary blib/lib/Bot/Cobalt/Plugin/Games/RockPaperScissors.pm »