line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::Cobalt::Core::Role::EasyAccessors; |
2
|
|
|
|
|
|
|
$Bot::Cobalt::Core::Role::EasyAccessors::VERSION = '0.021003'; |
3
|
5
|
|
|
5
|
|
2024
|
use strictures 2; |
|
5
|
|
|
|
|
24
|
|
|
5
|
|
|
|
|
147
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
642
|
use Scalar::Util 'blessed', 'reftype'; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
200
|
|
6
|
5
|
|
|
5
|
|
17
|
use Carp; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
183
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
15
|
use Moo::Role; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
24
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
requires qw/ |
11
|
|
|
|
|
|
|
cfg |
12
|
|
|
|
|
|
|
PluginObjects |
13
|
|
|
|
|
|
|
/; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub get_channels_cfg { |
17
|
1
|
|
|
1
|
1
|
334
|
my ($self, $context) = @_; |
18
|
|
|
|
|
|
|
|
19
|
1
|
50
|
|
|
|
4
|
confess "get_channels_cfg expects a server context name" |
20
|
|
|
|
|
|
|
unless defined $context; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
## Returns empty hash if there's no conf for this context |
23
|
1
|
|
50
|
|
|
21
|
my $chcfg = $self->cfg->channels->context($context) || {}; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
11
|
for my $channel (keys %$chcfg) { |
26
|
|
|
|
|
|
|
## Might be an empty string: |
27
|
|
|
|
|
|
|
$chcfg->{$channel} = +{} |
28
|
|
|
|
|
|
|
unless ref $chcfg->{$channel} |
29
|
1
|
50
|
33
|
|
|
10
|
and reftype $chcfg->{$channel} eq 'HASH' |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$chcfg |
33
|
1
|
|
|
|
|
5
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub get_core_cfg { |
36
|
2
|
|
|
2
|
1
|
1450
|
my ($self) = @_; |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
44
|
$self->cfg->core |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub get_plugin_alias { |
42
|
0
|
|
|
0
|
1
|
0
|
my ($self, $plugobj) = @_; |
43
|
0
|
0
|
|
|
|
0
|
confess "get_plugin_alias expects an object" |
44
|
|
|
|
|
|
|
unless blessed $plugobj; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
0
|
$self->PluginObjects->{$plugobj} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub get_plugin_cfg { |
50
|
1
|
|
|
1
|
1
|
2
|
my ($self, $plugin) = @_; |
51
|
|
|
|
|
|
|
## my $plugcf = $core->get_plugin_cfg( $self ) |
52
|
|
|
|
|
|
|
|
53
|
1
|
50
|
|
|
|
10
|
confess "get_plugin_cfg expects a plugin alias or loaded object" |
54
|
|
|
|
|
|
|
unless defined $plugin; |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
2
|
my $alias; |
57
|
|
|
|
|
|
|
|
58
|
1
|
50
|
|
|
|
4
|
if (blessed $plugin) { |
59
|
|
|
|
|
|
|
## plugin obj specified |
60
|
0
|
0
|
|
|
|
0
|
unless ($alias = $self->PluginObjects->{$plugin}) { |
61
|
0
|
|
|
|
|
0
|
carp "get_plugin_cfg; No alias for $plugin"; |
62
|
|
|
|
|
|
|
return |
63
|
0
|
|
|
|
|
0
|
} |
64
|
|
|
|
|
|
|
} else { |
65
|
|
|
|
|
|
|
## string alias specified |
66
|
1
|
|
|
|
|
2
|
$alias = $plugin; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
22
|
my $pcfg_obj = $self->cfg->plugins->plugin($alias); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
## Return empty hash if this plugin has no config |
72
|
1
|
50
|
|
|
|
271
|
return {} unless blessed $pcfg_obj; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
## Return opts() hash |
75
|
0
|
|
|
|
|
|
$pcfg_obj->opts |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
__END__ |