line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::ChatBots::MojoPlugin; |
2
|
2
|
|
|
2
|
|
111752
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
50
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
74
|
|
4
|
|
|
|
|
|
|
{ our $VERSION = '0.014'; } |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
375
|
use Bot::ChatBots::Utils qw< load_module >; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
92
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
10
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
14
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has [qw< app instances >]; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub helper_name { |
13
|
3
|
|
|
3
|
1
|
123
|
my $self = shift; |
14
|
3
|
|
66
|
|
|
24
|
(my $name = lc(ref $self || $self)) =~ s{.*::}{}mxs; |
15
|
3
|
|
|
|
|
15
|
return "chatbots.$name"; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub add_instance { |
19
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
20
|
1
|
|
|
|
|
4
|
my $module = load_module(shift, ref $self); |
21
|
1
|
50
|
33
|
|
|
27426
|
my @args = (@_ && ref($_[0])) ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
22
|
1
|
|
|
|
|
8
|
my $instance = $module->new(@args, app => $self->app); |
23
|
1
|
|
|
|
|
911
|
push @{$self->instances}, $instance; |
|
1
|
|
|
|
|
5
|
|
24
|
1
|
|
|
|
|
9
|
return $instance; |
25
|
|
|
|
|
|
|
} ## end sub add_instance |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub register { |
28
|
2
|
|
|
2
|
1
|
779
|
my ($self, $app, $conf) = @_; |
29
|
2
|
|
100
|
|
|
8
|
$conf //= {}; |
30
|
2
|
|
33
|
|
|
6
|
my $helper_name = $conf->{helper_name} // $self->helper_name; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# initialize object |
33
|
2
|
|
|
|
|
9
|
$self->app($app); |
34
|
2
|
|
|
|
|
19
|
$self->instances([]); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# add helper to be usable |
37
|
2
|
|
|
1
|
|
19
|
$app->helper($helper_name => sub { return $self }); |
|
1
|
|
|
|
|
1100
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# initialize with instances passed on the fly |
40
|
2
|
|
100
|
|
|
168
|
$self->add_instance(@$_) for @{$conf->{instances} // []}; |
|
2
|
|
|
|
|
13
|
|
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
10
|
$app->log->debug("helper $helper_name registered"); |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
|
|
324
|
return $self; |
45
|
|
|
|
|
|
|
} ## end sub register |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
__END__ |