| 1 | # $Id: Filter-IRC.pm,v 1.3 1999/12/12 11:48:07 dennis Exp $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # POE::Filter::IRC, by Dennis Taylor <dennis@funkplanet.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Modified for P10 Protocol by Chris Williams | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # This module may be used, modified, and distributed under the same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # terms as Perl itself. Please see the license that came with your Perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # distribution for details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | package POE::Filter::IRC::P10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | $VERSION = '0.998'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # Create a new, empty POE::Filter::IRC object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # Set/clear the 'debug' flag. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub debug { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $self->{'debug'} = $_[0] if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | return $self->{'debug'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # For each line of raw IRC input data that we're fed, spit back the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # appropriate IRC events. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=22 SCAR=51.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | my ($self, $raw) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | my $events = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | my %token2cmd = ('AC' => 'ACCOUNT', 'AD' => 'ADMIN', 'LL' => 'ASLL', 'A' => 'AWAY', 'B' => 'BURST', 'CM' => 'CLEARMODE', 'CLOSE' => 'CLOSE', 'CN' => 'CNOTICE', 'CO' => 'CONNECT', 'CP' => 'CPRIVMSG', 'C' => 'CREATE', 'DE' => 'DESTRUCT', 'DS' => 'DESYNCH', 'DIE' => 'DIE', 'DNS' => 'DNS', 'EB' => 'END_OF_BURST', 'EA' => 'EOB_ACK', 'Y' => 'ERROR', 'GET' => 'GET', 'GL' => 'GLINE', 'HASH' => 'HASH', 'HELP' => 'HELP', 'F' => 'INFO', 'I' => 'INVITE', 'ISON' => 'ISON', 'J' => 'JOIN', 'JU' => 'JUPE', 'K' => 'KICK', 'D' => 'KILL', 'LI' => 'LINKS', 'LIST' => 'LIST', 'LU' => 'LUSERS', 'MAP' => 'MAP', 'M' => 'MODE', 'MO' => 'MOTD', 'E' => 'NAMES', 'N' => 'NICK', 'O' => 'NOTICE', 'OPER' => 'OPER', 'OM' => 'OPMODE', 'L' => 'PART', 'PA' => 'PASS', 'G' => 'PING', 'Z' => 'PONG', 'POST' => 'POST', 'P' => 'PRIVMSG', 'PRIVS' => 'PRIVS', 'PROTO' => 'PROTO', 'Q' => 'QUIT', 'REHASH' => 'REHASH', 'RESET' => 'RESET', 'RESTART' => 'RESTART', 'RI' => 'RPING', 'RO' => 'RPONG', 'S' => 'SERVER', 'SET' => 'SET', 'SE' => 'SETTIME', 'U' => 'SILENCE', 'SQ' => 'SQUIT', 'R' => 'STATS', 'TI' => 'TIME', 'T' => 'TOPIC', 'TR' => 'TRACE', 'UP' => 'UPING', 'USER' => 'USER', 'USERHOST' => 'USERHOST', 'USERIP' => 'USERIP', 'V' => 'VERSION', 'WC' => 'WALLCHOPS', 'WA' => 'WALLOPS', 'WU' => 'WALLUSERS', 'WV' => 'WALLVOICES', 'H' => 'WHO', 'W' => 'WHOIS', 'X' => 'WHOWAS'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | foreach my $line (@$raw) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | ▶ | warn "<<< $line\n" if $self->{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | next unless $line =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | ▶ | if ($line =~ /^(\S+) G (.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 13 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | push @$events, { name => 'ping', args => [$1] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # PRIVMSG and NOTICE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } elsif ($line =~ /^(\S+) +(P|O) +(\S+) +(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($2 eq 'O') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | push @$events, { name => 'notice', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | args => [$1, [split /,/, $3], _decolon( $4 )] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # Using tr/// to count characters here tickles a bug in 5.004. Suck. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ▶ | } elsif (index( $3, '#' ) >= 0 or index( $3, '&' ) >= 0 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
index($3, "#") != -1 or index($3, "&") != -1 or index($3, "+") != -1
index($3, "#") != -1 or index($3, "&") != -1
MC/DC0%0/3
index($3, "#") != -1 or index($3, "&") != -1 or index($3, "+") != -1
index($3, "#") != -1
index($3, "&") != -1
index($3, "+") != -1
Truth table0%0/4
A or B or C
A= index($3, "#") != -1B= index($3, "&") != -1C= index($3, "+") != -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | or index( $3, '+' ) >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | push @$events, { name => 'public', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | args => [$1, [split /,/, $3], _decolon( $4 )] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # Need a fix here for nick\@server format i think | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | push @$events, { name => 'msg', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | args => [$1, [split /,/, $3], _decolon( $4 )] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # Numeric events | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } elsif ($line =~ /^(\S+) +(\d+) +(\S+) +(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | push @$events, { name => $2, args => [$1, _decolon( $4 )] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # MODE... just split the args and pass them wholesale. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } elsif ($line =~ /^(\S+) +(M|OM) +(\S+) +(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | push @$events, { name => lc $token2cmd{$2}, args => [$1, $3, split(/\s+/, $4)] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } elsif ($line =~ /^(\S+) +K +(\S+) +(\S+) +(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | push @$events, { name => 'kick', args => [$1, $2, $3, _decolon( $4 )] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } elsif ($line =~ /^(\S+) +T +(\S+) +(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | push @$events, { name => 'topic', args => [$1, $2, _decolon( $3 )] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } elsif ($line =~ /^(\S+) +I +(\S+) +(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | push @$events, { name => 'invite', args => [$1, $2, _decolon( $3 )] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } elsif ($line =~ /^SERVER +(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | push @$events, { name => 'server_link', args => [ split(/ /,$1,8), _decolon( substr($1,index($1," :")) ) ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # NICK, QUIT, JOIN, PART, possibly more? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } elsif ($line =~ /^(\S+) +(\S+) +(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | unless (grep {$_ eq lc $2} qw(n j q l z r eb b s sq w ac cm gl c ds d)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | warn "*** ACCIDENTAL MATCH: $2\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | warn "*** Accident line: $line\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | push @$events, { name => lc $token2cmd{$2}, args => [$1, _decolon( $3 )] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # We'll call this 'snotice' (server notice), for lack of a better name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } elsif ($line =~ /^NOTICE +\S+ +(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | push @$events, { name => 'snotice', args => [_decolon( $1 )] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # Eeek. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } elsif ($line =~ /^ERROR +(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # If nothing matches, barf and keep reading. Seems reasonable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # I'll reuse the famous "Funky parse case!" error from Net::IRC, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # just for a sense of historical continuity. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } elsif ($line =~ /^(\S+) +(EB|EA)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | push @$events, { name => lc $token2cmd{$2}, args => [_decolon( $1 )] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } elsif ($line =~ /^PASS +(\S+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | push @$events, { name => 'pass', args => [_decolon( $1 )] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | warn "*** Funky parse case!\nFunky line: \"$line\"\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | return $events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Strips superfluous colons from the beginning of text chunks. I can't | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # believe that this ludicrous protocol can handle ":foo" and ":foo bar" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # in a totally different manner. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | ▶ | sub _decolon ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decolon: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | my $line = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # This is very, very, wrong. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # if ($line =~ /^:.*\s.*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # $line = substr $line, 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | $line =~ s/^://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 2 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # This sub is so useless to implement that I won't even bother. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub put { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | croak "Call to unimplemented subroutine POE::Filter::IRC->put()"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||