Filter/IRC/Hybrid.pm

filter: Statementstmt 20.7% 11 / 53 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 37.5% 3 / 8 Podpod 100% 4 / 4 totaltotal 15.0% 18 / 120 CC 27 SCAR 62.9
CC
27
Cov
10%
get
702.0
debug
6.0
new
2.0
CRAP 537.4
↑ Summary Component/IRC/Service/Hybrid.pm »
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 #
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 $VERSION = '0.998';
17  
18 # Create a new, empty POE::Filter::IRC object.
19 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
20 0 my $class = shift;
21 0 my %args = @_;
22  
23 0 bless {}, $class;
24 }
25  
26  
27 # Set/clear the 'debug' flag.
28 0 ▶sub debug {
Subroutine debug: not called CC=2 SCAR=17.9
Pod documented
29 0 my $self = shift;
30 0 ▶ $self->{'debug'} = $_[0] if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
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 0 ▶sub get {
Subroutine get: not called CC=26 SCAR=65.5
Pod documented
38 0 my ($self, $raw) = @_;
39 0 my $events = [];
40  
41 0 foreach my $line (@$raw) {
42 0 ▶ warn "<<< $line\n" if $self->{'debug'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
43 0 ▶ next unless $line =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\S/ 0 0 0
44  
45 0 ▶ if ($line =~ /^PING (.+)$/) {
Branch: 17 branches
BranchTrueFalseTotal
if ($line =~ /^PING (.+)$/) { } 0 0 0
elsif ($line =~ /^:(\S+) +(PRIVMSG|NOTICE) +(\S+) +(.+)$/) { } 0 0 0
elsif ($line =~ /^:(\S+) +(\d+) +(\S+) +(.+)$/) { } 0 0 0
elsif ($line =~ /^:(\S+) +MODE +(\S+) +(.+)$/) { } 0 0 0
elsif ($line =~ /^:(\S+) +KICK +(\S+) +(\S+) +(.+)$/) { } 0 0 0
elsif ($line =~ /^:(\S+) +TOPIC +(\S+) +(.+)$/) { } 0 0 0
elsif ($line =~ /^:(\S+) +INVITE +\S+ +(.+)$/) { } 0 0 0
elsif ($line =~ /^:(\S+) +EOB$/) { } 0 0 0
elsif ($line =~ /^:(\S+) +(\S+) +(.+)$/) { } 0 0 0
elsif ($line =~ /^NOTICE +\S+ +(.+)$/) { } 0 0 0
elsif ($line =~ /^NICK +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(.+)$/) { } 0 0 0
elsif ($line =~ /^PONG +(.+)$/) { } 0 0 0
elsif ($line =~ /^SERVER +(\S+) +(\S+) +(.+)$/) { } 0 0 0
elsif ($line =~ /^CAPAB +(.+)$/) { } 0 0 0
elsif ($line =~ /^PASS +(\S+) +(.+)$/) { } 0 0 0
elsif ($line =~ /^SVINFO +(\S+) +(\S+) +(\S+) +(.+)$/) { } 0 0 0
elsif ($line =~ /^ERROR +(.+)$/) { } 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 ▶ if ($2 eq 'NOTICE') {
Branch: 2 branches
BranchTrueFalseTotal
if ($2 eq 'NOTICE') { } 0 0 0
elsif (index($3, '#') != -1 or index($3, '&') != -1 or index($3, '+') != -1) { } 0 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
Condition0%0/6
index($3, "#") != -1 or index($3, "&") != -1 or index($3, "+") != -1
l!l&&r!l&&!r
000
index($3, "#") != -1 or index($3, "&") != -1
l!l&&r!l&&!r
000
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
ABCresult
1XX1
01X1
0011
0000
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 ▶ unless (grep {$_ eq lc $2} qw(nick sjoin quit part pong server)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq lc $2;} "nick", "sjoin", "quit", "part", "pong", "server") 0 0 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 0 ▶sub _decolon ($) {
Subroutine _decolon: not called CC=1 SCAR=6.9
135 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 0 ▶sub put {
Subroutine put: not called CC=1 SCAR=6.9
Pod documented
149 0 croak "Call to unimplemented subroutine POE::Filter::IRC->put()";
150 }
151  
152  
153 1 1;
154  
155  
156 __END__
↑ Summary Component/IRC/Service/Hybrid.pm »