line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::IPMessenger::Bot; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
152407
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
32
|
use 5.008_005; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
65
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
998
|
use Net::IPMessenger; |
|
1
|
|
|
|
|
50607
|
|
|
1
|
|
|
|
|
10
|
|
9
|
1
|
|
|
1
|
|
770
|
use Net::IPMessenger::Bot::EventHandler; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
281
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
3
|
|
|
3
|
1
|
11855
|
my ( $class, %args ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
|
|
7
|
my $ipmsg = Net::IPMessenger->new( %{ $args{configure} } ); |
|
3
|
|
|
|
|
35
|
|
15
|
3
|
|
|
|
|
2229
|
my $handler = Net::IPMessenger::Bot::EventHandler->new( |
16
|
|
|
|
|
|
|
handler => $args{on_message}, |
17
|
|
|
|
|
|
|
); |
18
|
3
|
|
|
|
|
10
|
$ipmsg->add_event_handler($handler); |
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
|
|
29
|
my $self = bless { ipmsg => $ipmsg }, $class; |
21
|
3
|
|
|
|
|
23
|
$self->_set_signal_handlers; |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
143
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub start { |
27
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
28
|
0
|
|
|
|
|
0
|
$self->join(); |
29
|
0
|
|
|
|
|
0
|
while ( $self->{ipmsg}->recv() ) { } |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub join { |
33
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
my $cmd = $self->{ipmsg}->messagecommand('BR_ENTRY')->set_broadcast; |
36
|
0
|
|
|
|
|
0
|
$self->{ipmsg}->send( |
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
command => $cmd, |
39
|
|
|
|
|
|
|
option => $self->{ipmsg}->my_info, |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _set_signal_handlers { |
45
|
3
|
|
|
3
|
|
4
|
my $self = shift; |
46
|
3
|
|
|
0
|
|
76
|
$SIG{INT} = $SIG{TERM} = sub { $self->sighandle_INT() }; |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub sighandle_INT { |
50
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $cmd = $self->{ipmsg}->messagecommand('BR_EXIT')->set_broadcast; |
53
|
0
|
|
|
|
|
|
$self->{ipmsg}->send( { command => $cmd } ); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
exit; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |