line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Alice::Test::MockIRC; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
696
|
use Any::Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
494
|
use AnyEvent::IRC::Util qw/parse_irc_msg prefix_nick mk_msg/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
61
|
|
5
|
1
|
|
|
1
|
|
5
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1179
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has cbs => (is => 'rw', default => sub {{}}); |
8
|
|
|
|
|
|
|
has nick => (is => 'rw'); |
9
|
|
|
|
|
|
|
has user_prefix => ( |
10
|
|
|
|
|
|
|
is => 'rw', |
11
|
|
|
|
|
|
|
lazy => 1, |
12
|
|
|
|
|
|
|
default => sub{$_[0]->nick."!".$_[0]->nick."\@host"} |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has events => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
default => sub { |
18
|
|
|
|
|
|
|
my $self = shift; |
19
|
|
|
|
|
|
|
{ |
20
|
|
|
|
|
|
|
TOPIC => sub { |
21
|
|
|
|
|
|
|
my $msg = shift; |
22
|
|
|
|
|
|
|
my $nick = prefix_nick($msg->{prefix}); |
23
|
|
|
|
|
|
|
$self->cbs->{channel_topic}->($self, @{$msg->{params}}, $nick); |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
JOIN => sub { |
26
|
|
|
|
|
|
|
my $msg = shift; |
27
|
|
|
|
|
|
|
my $nick = prefix_nick($msg->{prefix}); |
28
|
|
|
|
|
|
|
$self->cbs->{join}->($self, $nick, $msg->{params}[0], $nick eq $self->nick); |
29
|
|
|
|
|
|
|
$self->cbs->{channel_add}->($self, $msg, $msg->{params}[0], $nick); |
30
|
|
|
|
|
|
|
$self->send_srv(WHO => $msg->{params}[0]); |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
NICK => sub { |
33
|
|
|
|
|
|
|
my $msg = shift; |
34
|
|
|
|
|
|
|
my $nick = prefix_nick($msg->{prefix}); |
35
|
|
|
|
|
|
|
$self->cbs->{nick_change}->($self, $nick, ${$msg->{params}}[0], $nick eq $self->nick); |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
PART => sub { |
38
|
|
|
|
|
|
|
my $msg = shift; |
39
|
|
|
|
|
|
|
my $nick = prefix_nick($msg->{prefix}); |
40
|
|
|
|
|
|
|
$self->cbs->{part}->($self, $nick, $msg->{params}[0], $nick eq $self->nick); |
41
|
|
|
|
|
|
|
$self->cbs->{channel_remove}->($self, $msg, $msg->{params}[0], $nick); |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
PRIVMSG => sub { |
44
|
|
|
|
|
|
|
my $msg = shift; |
45
|
|
|
|
|
|
|
my $nick = prefix_nick($msg->{prefix}); |
46
|
|
|
|
|
|
|
$self->cbs->{privatemsg}->($self, $nick, $msg); |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
numeric => sub { |
49
|
|
|
|
|
|
|
my ($msg, $number) = @_; |
50
|
|
|
|
|
|
|
$self->cbs->{"irc_$number"}->($self, $msg); |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub send_srv { |
57
|
11
|
|
|
11
|
0
|
246
|
my ($self, $command, @args) = @_; |
58
|
11
|
|
|
5
|
|
58
|
my $echo = sub {mk_msg($self->user_prefix, $command, @args)}; |
|
5
|
|
|
|
|
43
|
|
59
|
44
|
|
|
|
|
146
|
my $map = { |
60
|
|
|
|
|
|
|
map({$_ => $echo} qw/TOPIC JOIN PART NICK/), |
61
|
|
|
|
|
|
|
WHO => sub{ |
62
|
6
|
100
|
|
6
|
|
32
|
my $user = ($args[0] =~ /^#/ ? "test" : $args[0]); |
63
|
6
|
|
|
|
|
53
|
":local.irc 352 ".$self->nick." #test $user il.comcast.net local.irc $user H :0 $user"; |
64
|
|
|
|
|
|
|
}, |
65
|
11
|
|
|
|
|
24
|
}; |
66
|
11
|
50
|
|
|
|
56
|
$map->{$command} ? $self->send_cl($map->{$command}->()) |
67
|
|
|
|
|
|
|
: warn "no line mapped for $command\n" |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub send_raw { |
71
|
1
|
|
|
1
|
0
|
11
|
my ($self, $line) = @_; |
72
|
1
|
|
|
|
|
7
|
$self->send_srv(split ' ', $line); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub send_cl { |
76
|
17
|
|
|
17
|
0
|
133
|
my ($self, $line) = @_; |
77
|
17
|
|
|
|
|
70
|
my $msg = parse_irc_msg($line); |
78
|
17
|
100
|
|
|
|
846
|
my $cmd = ($msg->{command} =~ /^\d+/ ? 'numeric' : $msg->{command}); |
79
|
17
|
50
|
|
17
|
|
702
|
try { $self->events->{$cmd}->($msg, $msg->{command}) if $self->events->{$cmd} } |
80
|
17
|
|
|
0
|
|
146
|
catch { warn "$_\n" }; |
|
0
|
|
|
|
|
0
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
0
|
0
|
0
|
sub enable_ssl {} |
84
|
3
|
|
|
3
|
0
|
18
|
sub isupport {} |
85
|
1
|
|
|
1
|
0
|
4
|
sub ctcp_auto_reply {} |
86
|
|
|
|
|
|
|
sub connect { |
87
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
88
|
1
|
|
|
|
|
9
|
$self->cbs->{connect}->(); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
sub register { |
91
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
92
|
1
|
|
|
|
|
8
|
$self->cbs->{registered}->(); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
sub disconnect { |
95
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
96
|
1
|
|
|
|
|
9
|
$self->cbs->{disconnect}->(); |
97
|
|
|
|
|
|
|
} |
98
|
1
|
|
|
1
|
0
|
3
|
sub enable_ping {} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub reg_cb { |
101
|
1
|
|
|
1
|
0
|
25
|
my ($self, %callbacks) = @_; |
102
|
1
|
|
|
|
|
7
|
for (keys %callbacks) { |
103
|
22
|
|
|
|
|
67
|
$self->cbs->{$_} = $callbacks{$_}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
108
|
|
|
|
|
|
|
1; |