line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::Cobalt::Conf::File::Plugins; |
2
|
|
|
|
|
|
|
$Bot::Cobalt::Conf::File::Plugins::VERSION = '0.021001'; |
3
|
5
|
|
|
5
|
|
12456
|
use v5.10; |
|
5
|
|
|
|
|
11
|
|
4
|
5
|
|
|
5
|
|
442
|
use strictures 2; |
|
5
|
|
|
|
|
1066
|
|
|
5
|
|
|
|
|
128
|
|
5
|
5
|
|
|
5
|
|
625
|
use Carp; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
216
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
18
|
use Scalar::Util 'blessed'; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
188
|
|
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
326
|
use Bot::Cobalt::Common ':types'; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
22
|
|
10
|
5
|
|
|
5
|
|
1702
|
use Bot::Cobalt::Conf::File::PerPlugin; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
129
|
|
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
24
|
use Path::Tiny; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
217
|
|
13
|
5
|
|
|
5
|
|
20
|
use Types::Path::Tiny -types; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
24
|
|
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
5
|
|
2760
|
use List::Objects::WithUtils; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
26
|
|
16
|
5
|
|
|
5
|
|
4655
|
use List::Objects::Types -types; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
21
|
|
17
|
|
|
|
|
|
|
|
18
|
5
|
|
|
5
|
|
3754
|
use Moo; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
16
|
|
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
|
2
|
|
|
2
|
|
1186
|
my ($self) = @_; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
## Create PerPlugin cf objs for each plugin |
42
|
|
|
|
|
|
|
hash( |
43
|
|
|
|
|
|
|
$self->cfg_as_hash->keys->map(sub { |
44
|
40
|
|
|
40
|
|
2703
|
( $_ => $self->_create_perplugin_obj($_) ) |
45
|
2
|
|
|
|
|
33
|
})->all |
46
|
|
|
|
|
|
|
) |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _create_perplugin_obj { |
50
|
41
|
|
|
41
|
|
41
|
my ($self, $alias) = @_; |
51
|
|
|
|
|
|
|
|
52
|
41
|
|
33
|
|
|
547
|
my $this_cfg = $self->cfg_as_hash->get($alias) |
53
|
|
|
|
|
|
|
|| confess "_create_perplugin_obj passed unknown alias $alias"; |
54
|
|
|
|
|
|
|
|
55
|
41
|
|
|
|
|
292
|
my %new_opts; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$new_opts{module} = $this_cfg->{Module} |
58
|
41
|
|
33
|
|
|
79
|
|| confess "No Module defined for plugin $alias"; |
59
|
|
|
|
|
|
|
|
60
|
41
|
100
|
|
|
|
68
|
if (defined $this_cfg->{Config}) { |
61
|
14
|
|
|
|
|
31
|
my $this_cf_path = path($this_cfg->{Config}); |
62
|
14
|
50
|
|
|
|
221
|
unless ( $this_cf_path->is_absolute ) { |
63
|
14
|
|
|
|
|
266
|
$this_cf_path = path( $self->etcdir .'/'. $this_cf_path ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
14
|
|
|
|
|
222
|
$new_opts{config_file} = $this_cf_path |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$new_opts{autoload} = 0 |
70
|
41
|
100
|
|
|
|
59
|
if $this_cfg->{NoAutoLoad}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$new_opts{priority} = $this_cfg->{Priority} |
73
|
41
|
100
|
|
|
|
56
|
if defined $this_cfg->{Priority}; |
74
|
|
|
|
|
|
|
|
75
|
41
|
100
|
|
|
|
58
|
if (defined $this_cfg->{Opts}) { |
76
|
|
|
|
|
|
|
confess "Opts: directive for plugin $alias is not a hash" |
77
|
7
|
50
|
|
|
|
16
|
unless ref $this_cfg->{Opts} eq 'HASH'; |
78
|
|
|
|
|
|
|
|
79
|
7
|
|
|
|
|
12
|
$new_opts{extra_opts} = $this_cfg->{Opts}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Bot::Cobalt::Conf::File::PerPlugin->new( |
83
|
41
|
|
|
|
|
568
|
%new_opts |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub plugin { |
88
|
52
|
|
|
52
|
1
|
14766
|
my ($self, $plugin) = @_; |
89
|
|
|
|
|
|
|
|
90
|
52
|
50
|
|
|
|
99
|
confess "plugin() requires a plugin alias" |
91
|
|
|
|
|
|
|
unless defined $plugin; |
92
|
|
|
|
|
|
|
|
93
|
52
|
|
|
|
|
933
|
$self->_per_plug_objs->{$plugin} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub list_plugins { |
97
|
2
|
|
|
2
|
1
|
443
|
my ($self) = @_; |
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
3
|
[ keys %{ $self->_per_plug_objs } ] |
|
2
|
|
|
|
|
21
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub clear_plugin { |
103
|
1
|
|
|
1
|
1
|
283
|
my ($self, $plugin) = @_; |
104
|
|
|
|
|
|
|
|
105
|
1
|
50
|
|
|
|
4
|
confess "clear_plugin requires a plugin alias" |
106
|
|
|
|
|
|
|
unless defined $plugin; |
107
|
|
|
|
|
|
|
|
108
|
1
|
|
|
|
|
19
|
delete $self->_per_plug_objs->{$plugin} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub load_plugin { |
112
|
1
|
|
|
1
|
1
|
263
|
my ($self, $plugin) = @_; |
113
|
|
|
|
|
|
|
|
114
|
1
|
50
|
|
|
|
4
|
confess "load_plugin requires a plugin alias" |
115
|
|
|
|
|
|
|
unless defined $plugin; |
116
|
|
|
|
|
|
|
|
117
|
1
|
|
|
|
|
2
|
$self->_per_plug_objs->{$plugin} |
118
|
|
|
|
|
|
|
= $self->_create_perplugin_obj($plugin) |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub install_plugin { |
122
|
1
|
|
|
1
|
1
|
293
|
my ($self, $plugin, $plugin_obj) = @_; |
123
|
|
|
|
|
|
|
|
124
|
1
|
50
|
|
|
|
4
|
unless (defined $plugin_obj) { |
125
|
0
|
|
|
|
|
0
|
confess |
126
|
|
|
|
|
|
|
"install_plugin requires a plugin alias and Conf object" |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
1
|
50
|
33
|
|
|
11
|
unless (blessed $plugin_obj && |
130
|
|
|
|
|
|
|
$plugin_obj->isa('Bot::Cobalt::Conf::File::PerPlugin') ) { |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
0
|
confess |
133
|
|
|
|
|
|
|
"install_plugin requires a Bot::Cobalt::Conf::File::PerPlugin object" |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
1
|
|
|
|
|
20
|
$self->_per_plug_objs->{$plugin} = $plugin_obj |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
around 'validate' => sub { |
141
|
|
|
|
|
|
|
my ($orig, $self, $cfg) = @_; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1 |
144
|
|
|
|
|
|
|
}; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |
148
|
|
|
|
|
|
|
__END__ |