| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id: Filter-IRC.pm,v 1.3 1999/12/12 11:48:07 dennis Exp $ |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# POE::Filter::IRC, by Dennis Taylor |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# This module may be used, modified, and distributed under the same |
|
6
|
|
|
|
|
|
|
# terms as Perl itself. Please see the license that came with your Perl |
|
7
|
|
|
|
|
|
|
# distribution for details. |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package POE::Filter::IRC::Hybrid; |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
22
|
|
|
13
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
58
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
856
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$VERSION = '0.998'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Create a new, empty POE::Filter::IRC object. |
|
19
|
|
|
|
|
|
|
sub new { |
|
20
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
21
|
0
|
|
|
|
|
|
my %args = @_; |
|
22
|
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
bless {}, $class; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Set/clear the 'debug' flag. |
|
28
|
|
|
|
|
|
|
sub debug { |
|
29
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
30
|
0
|
0
|
|
|
|
|
$self->{'debug'} = $_[0] if @_; |
|
31
|
0
|
|
|
|
|
|
return $self->{'debug'}; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# For each line of raw IRC input data that we're fed, spit back the |
|
36
|
|
|
|
|
|
|
# appropriate IRC events. |
|
37
|
|
|
|
|
|
|
sub get { |
|
38
|
0
|
|
|
0
|
1
|
|
my ($self, $raw) = @_; |
|
39
|
0
|
|
|
|
|
|
my $events = []; |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
foreach my $line (@$raw) { |
|
42
|
0
|
0
|
|
|
|
|
warn "<<< $line\n" if $self->{'debug'}; |
|
43
|
0
|
0
|
|
|
|
|
next unless $line =~ /\S/; |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if ($line =~ /^PING (.+)$/) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
push @$events, { name => 'ping', args => [ _decolon ( $1 ) ] }; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# PRIVMSG and NOTICE |
|
49
|
|
|
|
|
|
|
} elsif ($line =~ /^:(\S+) +(PRIVMSG|NOTICE) +(\S+) +(.+)$/) { |
|
50
|
0
|
0
|
0
|
|
|
|
if ($2 eq 'NOTICE') { |
|
|
|
0
|
0
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
push @$events, { name => 'notice', |
|
52
|
|
|
|
|
|
|
args => [$1, [split /,/, $3], _decolon( $4 )] }; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Using tr/// to count characters here tickles a bug in 5.004. Suck. |
|
55
|
|
|
|
|
|
|
} elsif (index( $3, '#' ) >= 0 or index( $3, '&' ) >= 0 |
|
56
|
|
|
|
|
|
|
or index( $3, '+' ) >= 0) { |
|
57
|
0
|
|
|
|
|
|
push @$events, { name => 'public', |
|
58
|
|
|
|
|
|
|
args => [$1, [split /,/, $3], _decolon( $4 )] }; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} else { |
|
61
|
0
|
|
|
|
|
|
push @$events, { name => 'msg', |
|
62
|
|
|
|
|
|
|
args => [$1, [split /,/, $3], _decolon( $4 )] }; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Numeric events |
|
66
|
|
|
|
|
|
|
} elsif ($line =~ /^:(\S+) +(\d+) +(\S+) +(.+)$/) { |
|
67
|
0
|
|
|
|
|
|
push @$events, { name => $2, args => [$1, _decolon( $4 )] }; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# MODE... just split the args and pass them wholesale. |
|
70
|
|
|
|
|
|
|
} elsif ($line =~ /^:(\S+) +MODE +(\S+) +(.+)$/) { |
|
71
|
0
|
|
|
|
|
|
push @$events, { name => 'mode', args => [$1, $2, split(/\s+/, $3)] }; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} elsif ($line =~ /^:(\S+) +KICK +(\S+) +(\S+) +(.+)$/) { |
|
74
|
0
|
|
|
|
|
|
push @$events, { name => 'kick', args => [$1, $2, $3, _decolon( $4 )] }; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} elsif ($line =~ /^:(\S+) +TOPIC +(\S+) +(.+)$/) { |
|
77
|
0
|
|
|
|
|
|
push @$events, { name => 'topic', args => [$1, $2, _decolon( $3 )] }; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} elsif ($line =~ /^:(\S+) +INVITE +\S+ +(.+)$/) { |
|
80
|
0
|
|
|
|
|
|
push @$events, { name => 'invite', args => [$1, _decolon( $2 )] }; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} elsif ($line =~ /^:(\S+) +EOB$/) { |
|
83
|
0
|
|
|
|
|
|
push @$events, { name => 'eob', args => [$1] }; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# NICK, QUIT, JOIN, PART, possibly more? |
|
86
|
|
|
|
|
|
|
} elsif ($line =~ /^:(\S+) +(\S+) +(.+)$/) { |
|
87
|
0
|
0
|
|
|
|
|
unless (grep {$_ eq lc $2} qw(nick sjoin quit part pong server)) { |
|
|
0
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
warn "*** ACCIDENTAL MATCH: $2\n"; |
|
89
|
0
|
|
|
|
|
|
warn "*** Accident line: $line\n"; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
0
|
|
|
|
|
|
push @$events, { name => lc $2, args => [$1, _decolon( $3 )] }; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# We'll call this 'snotice' (server notice), for lack of a better name. |
|
94
|
|
|
|
|
|
|
} elsif ($line =~ /^NOTICE +\S+ +(.+)$/) { |
|
95
|
0
|
|
|
|
|
|
push @$events, { name => 'snotice', args => [_decolon( $1 )] }; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} elsif ($line =~ /^NICK +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(.+)$/) { |
|
98
|
0
|
|
|
|
|
|
push @$events, { name => 'nick', args => [ $1, $2, $3, $4, $5, $6, $7, _decolon( $8 )] }; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} elsif ($line =~ /^PONG +(.+)$/) { |
|
101
|
0
|
|
|
|
|
|
push @$events, { name => 'pong', args => [_decolon( $1 )] }; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} elsif ($line =~ /^SERVER +(\S+) +(\S+) +(.+)$/) { |
|
104
|
0
|
|
|
|
|
|
push @$events, { name => 'server_link', args => [ $1, $2, _decolon( $3 )] }; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} elsif ($line =~ /^CAPAB +(.+)$/) { |
|
107
|
0
|
|
|
|
|
|
push @$events, { name => 'capab', args => [ _decolon( $1 )] }; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
} elsif ($line =~ /^PASS +(\S+) +(.+)$/) { |
|
110
|
0
|
|
|
|
|
|
push @$events, { name => 'capab', args => [ $1, _decolon( $2 )] }; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} elsif ($line =~ /^SVINFO +(\S+) +(\S+) +(\S+) +(.+)$/) { |
|
113
|
0
|
|
|
|
|
|
push @$events, { name => 'svinfo', args => [ $1, $2, $3, _decolon( $4 )] }; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Eeek. |
|
116
|
|
|
|
|
|
|
} elsif ($line =~ /^ERROR +(.+)$/) { |
|
117
|
0
|
|
|
|
|
|
push @$events, { name => 'error', args => [_decolon( $1 )] }; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# If nothing matches, barf and keep reading. Seems reasonable. |
|
120
|
|
|
|
|
|
|
# I'll reuse the famous "Funky parse case!" error from Net::IRC, |
|
121
|
|
|
|
|
|
|
# just for a sense of historical continuity. |
|
122
|
|
|
|
|
|
|
} else { |
|
123
|
0
|
|
|
|
|
|
warn "*** Funky parse case!\nFunky line: \"$line\"\n"; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
return $events; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Strips superfluous colons from the beginning of text chunks. I can't |
|
132
|
|
|
|
|
|
|
# believe that this ludicrous protocol can handle ":foo" and ":foo bar" |
|
133
|
|
|
|
|
|
|
# in a totally different manner. |
|
134
|
|
|
|
|
|
|
sub _decolon ($) { |
|
135
|
0
|
|
|
0
|
|
|
my $line = shift; |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# This is very, very, wrong. |
|
138
|
|
|
|
|
|
|
# if ($line =~ /^:.*\s.*$/) { |
|
139
|
|
|
|
|
|
|
# $line = substr $line, 1; |
|
140
|
|
|
|
|
|
|
# } |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
$line =~ s/^://; |
|
143
|
0
|
|
|
|
|
|
return $line; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# This sub is so useless to implement that I won't even bother. |
|
148
|
|
|
|
|
|
|
sub put { |
|
149
|
0
|
|
|
0
|
1
|
|
croak "Call to unimplemented subroutine POE::Filter::IRC->put()"; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
__END__ |