line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package LiBot; |
2
|
2
|
|
|
2
|
|
680
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
75
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
52
|
|
4
|
2
|
|
|
2
|
|
908
|
use utf8; |
|
2
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
11
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
96
|
use 5.010000; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
80
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1665
|
use version; our $VERSION = version->declare("v0.0.3"); |
|
2
|
|
|
|
|
6517
|
|
|
2
|
|
|
|
|
15
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
1280
|
use LiBot::Message; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
79
|
|
11
|
2
|
|
|
2
|
|
2276
|
use Log::Pony; |
|
2
|
|
|
|
|
33706
|
|
|
2
|
|
|
|
|
67
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
20
|
use Mouse; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
18
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has providers => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
default => sub { [] }, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has handlers => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
default => sub { +[ ] }, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has log_level => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
default => 'info', |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has log => ( |
31
|
|
|
|
|
|
|
is => 'ro', |
32
|
|
|
|
|
|
|
lazy => 1, |
33
|
|
|
|
|
|
|
default => sub { |
34
|
|
|
|
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
Log::Pony->new(log_level => $self->log_level) |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
2
|
|
1216
|
no Mouse; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
2
|
|
2346
|
use Module::Runtime; |
|
2
|
|
|
|
|
3443
|
|
|
2
|
|
|
|
|
14
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub register { |
44
|
1
|
|
|
1
|
0
|
2
|
my ($self, $re, $code) = @_; |
45
|
1
|
|
|
|
|
2
|
push @{$self->{handlers}}, [$re, $code]; |
|
1
|
|
|
|
|
8
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub load_provider { |
49
|
0
|
|
|
0
|
0
|
0
|
my ($self, $name, $args) = @_; |
50
|
0
|
|
|
|
|
0
|
push @{$self->{providers}}, $self->load_plugin('Provider', $name, $args); |
|
0
|
|
|
|
|
0
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub load_plugin { |
54
|
1
|
|
|
1
|
0
|
4
|
my ($self, $prefix, $name, $args) = @_; |
55
|
|
|
|
|
|
|
|
56
|
1
|
50
|
|
|
|
8
|
my $klass = $name =~ s!^\+!! ? $name : "LiBot::${prefix}::$name"; |
57
|
1
|
|
|
|
|
7
|
Module::Runtime::require_module($klass); |
58
|
1
|
|
|
|
|
15
|
$self->log->info("Loading $klass"); |
59
|
1
|
|
50
|
|
|
386
|
my $obj = $klass->new($args || +{}); |
60
|
1
|
50
|
|
|
|
58
|
$obj->init($self) if $obj->can('init'); |
61
|
1
|
|
|
|
|
11
|
$obj; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub handle_message { |
65
|
2
|
|
|
2
|
0
|
6
|
my ($self, $callback, $msg) = @_; |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
5
|
for my $handler (@{$self->{handlers}}) { |
|
2
|
|
|
|
|
5
|
|
68
|
2
|
50
|
|
|
|
25
|
if (my @matched = ($msg->text =~ $handler->[0])) { |
69
|
2
|
|
|
|
|
9
|
$handler->[1]->($callback, $msg, @matched); |
70
|
|
|
|
|
|
|
# Handled well |
71
|
2
|
|
|
|
|
1252
|
return 1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
return 0; # Does not handled. |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub run { |
78
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
for my $provider (@{$self->providers}) { |
|
0
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$provider->run($self); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
__END__ |