Component/IRC.pm

filter: Statementstmt 63.4% 460 / 725 Branchbran 46.2% 159 / 344 Conditioncond 37.2% 61 / 164 MC/DCmcdc 11.8% 11 / 93 Subroutinesub 74.1% 63 / 85 Podpod 52.9% 27 / 51 totaltotal 53.4% 781 / 1462 CC 238 SCAR 34.5
CC
238
Cov
55%
_configure
130.5
_sock_up
90.7
_got_dns_response
72.0
CRAP 31.6
« Component/IRC/Qnet/State.pm ↑ Summary Filter/IRC/Compat.pm »
1 package POE::Component::IRC;
2 79 $POE::Component::IRC::VERSION = '6.95';
3 79 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 79 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 79 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 79 ▶use POE qw(Wheel::SocketFactory Wheel::ReadWrite Driver::SysRW
Subroutine BEGIN: called CC=1 SCAR=0.0
7 79 Filter::Line Filter::Stream Filter::Stackable);
8 79 ▶use POE::Filter::IRCD;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 79 ▶use POE::Filter::IRC::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 79 ▶use POE::Component::IRC::Constants qw(:ALL);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 79 ▶use POE::Component::IRC::Plugin qw(:ALL);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 79 ▶use POE::Component::IRC::Plugin::DCC;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 79 ▶use POE::Component::IRC::Plugin::ISupport;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 79 ▶use POE::Component::IRC::Plugin::Whois;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 79 ▶use Socket qw(AF_INET SOCK_STREAM unpack_sockaddr_in inet_ntoa inet_aton);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 79 ▶use base qw(POE::Component::Syndicator);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 79 our ($GOT_SSL, $GOT_CLIENT_DNS, $GOT_SOCKET6, $GOT_ZLIB);
19  
20 79 ▶BEGIN {
Subroutine BEGIN: called CC=5 SCAR=22.2
21 79 eval {
22 79 require POE::Component::SSLify;
23 0 import POE::Component::SSLify qw( Client_SSLify SSLify_ContextCreate );
24 0 $GOT_SSL = 1;
25 };
26 79 eval {
27 79 require POE::Component::Client::DNS;
28 79 ▶ $GOT_CLIENT_DNS = 1 if $POE::Component::Client::DNS::VERSION >= 0.99;
Branch: 1 branch
BranchTrueFalseTotal
if $POE::Component::Client::DNS::VERSION >= "0.99" 79 0 79
29 };
30 79 eval {
31 79 require POE::Filter::Zlib::Stream;
32 0 ▶ $GOT_ZLIB = 1 if $POE::Filter::Zlib::Stream::VERSION >= 1.96;
Branch: 1 branch
BranchTrueFalseTotal
if $POE::Filter::Zlib::Stream::VERSION >= "1.96" 0 0 0
33 };
34 # Socket6 provides AF_INET6 where earlier Perls' Socket don't.
35 79 eval {
36 79 Socket->import(qw(AF_INET6 unpack_sockaddr_in6 inet_ntop));
37 79 $GOT_SOCKET6 = 1;
38 };
39 79 ▶ if (!$GOT_SOCKET6) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $POE::Component::IRC::GOT_SOCKET6) 0 79 79
40 0 eval {
41 0 require Socket6;
42 0 Socket6->import(qw(AF_INET6 unpack_sockaddr_in6 inet_ntop));
43 0 $GOT_SOCKET6 = 1;
44 };
45 0 ▶ if (!$GOT_SOCKET6) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $POE::Component::IRC::GOT_SOCKET6) 0 0 0
46 # provide a dummy sub so code compiles
47 0 ▶ *AF_INET6 = sub { ~0 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 }
49 }
50 }
51  
52 # BINGOS: I have bundled up all the stuff that needs changing
53 # for inherited classes into _create. This gets called from 'spawn'.
54 # $self->{OBJECT_STATES_ARRAYREF} contains event mappings to methods that have
55 # the same name, gets passed to POE::Session->create as $self => [ ];
56 # $self->{OBJECT_STATES_HASHREF} contains event mappings to methods, where the
57 # event and the method have diferent names.
58 # $self->{IRC_CMDS} contains the traditional %irc_commands, mapping commands
59 # to events and the priority that the command has.
60 115 ▶sub _create {
Subroutine _create: called CC=1 SCAR=0.0
61 115 my ($self) = @_;
62  
63 $self->{IRC_CMDS} = {
64 115 rehash => [ PRI_HIGH, 'noargs', ],
65 die => [ PRI_HIGH, 'noargs', ],
66 restart => [ PRI_HIGH, 'noargs', ],
67 quit => [ PRI_NORMAL, 'oneoptarg', ],
68 version => [ PRI_HIGH, 'oneoptarg', ],
69 time => [ PRI_HIGH, 'oneoptarg', ],
70 trace => [ PRI_HIGH, 'oneoptarg', ],
71 admin => [ PRI_HIGH, 'oneoptarg', ],
72 info => [ PRI_HIGH, 'oneoptarg', ],
73 away => [ PRI_HIGH, 'oneoptarg', ],
74 users => [ PRI_HIGH, 'oneoptarg', ],
75 lusers => [ PRI_HIGH, 'oneoptarg', ],
76 locops => [ PRI_HIGH, 'oneoptarg', ],
77 operwall => [ PRI_HIGH, 'oneoptarg', ],
78 wallops => [ PRI_HIGH, 'oneoptarg', ],
79 motd => [ PRI_HIGH, 'oneoptarg', ],
80 who => [ PRI_HIGH, 'oneoptarg', ],
81 nick => [ PRI_HIGH, 'onlyonearg', ],
82 oper => [ PRI_HIGH, 'onlytwoargs', ],
83 invite => [ PRI_HIGH, 'onlytwoargs', ],
84 squit => [ PRI_HIGH, 'onlytwoargs', ],
85 kill => [ PRI_HIGH, 'onlytwoargs', ],
86 privmsg => [ PRI_NORMAL, 'privandnotice', ],
87 privmsglo => [ PRI_NORMAL+1, 'privandnotice', ],
88 privmsghi => [ PRI_NORMAL-1, 'privandnotice', ],
89 notice => [ PRI_NORMAL, 'privandnotice', ],
90 noticelo => [ PRI_NORMAL+1, 'privandnotice', ],
91 noticehi => [ PRI_NORMAL-1, 'privandnotice', ],
92 squery => [ PRI_NORMAL, 'privandnotice', ],
93 join => [ PRI_HIGH, 'oneortwo', ],
94 summon => [ PRI_HIGH, 'oneortwo', ],
95 sconnect => [ PRI_HIGH, 'oneandtwoopt', ],
96 whowas => [ PRI_HIGH, 'oneandtwoopt', ],
97 stats => [ PRI_HIGH, 'spacesep', ],
98 links => [ PRI_HIGH, 'spacesep', ],
99 mode => [ PRI_HIGH, 'spacesep', ],
100 servlist => [ PRI_HIGH, 'spacesep', ],
101 cap => [ PRI_HIGH, 'spacesep', ],
102 part => [ PRI_HIGH, 'commasep', ],
103 names => [ PRI_HIGH, 'commasep', ],
104 list => [ PRI_HIGH, 'commasep', ],
105 whois => [ PRI_HIGH, 'commasep', ],
106 ctcp => [ PRI_HIGH, 'ctcp', ],
107 ctcpreply => [ PRI_HIGH, 'ctcp', ],
108 ping => [ PRI_HIGH, 'oneortwo', ],
109 pong => [ PRI_HIGH, 'oneortwo', ],
110 };
111  
112 5290 my %event_map = map {($_ => $self->{IRC_CMDS}->{$_}->[CMD_SUB])}
113 115 keys %{ $self->{IRC_CMDS} };
114  
115 $self->{OBJECT_STATES_HASHREF} = {
116 115 %event_map,
117 quote => 'sl',
118 };
119  
120 115 $self->{OBJECT_STATES_ARRAYREF} = [qw(
121 syndicator_started
122 _parseline
123 _sock_down
124 _sock_failed
125 _sock_up
126 _socks_proxy_connect
127 _socks_proxy_response
128 debug
129 connect
130 _resolve_addresses
131 _do_connect
132 _quit_timeout
133 _send_login
134 _got_dns_response
135 ison
136 kick
137 remove
138 nickserv
139 shutdown
140 sl
141 sl_login
142 sl_high
143 sl_delayed
144 sl_prioritized
145 topic
146 userhost
147 )];
148  
149 115 return;
150 }
151  
152 # BINGOS: the component can now configure itself via _configure() from
153 # either spawn() or connect()
154 ## no critic (Subroutines::ProhibitExcessComplexity)
155 206 ▶sub _configure {
Subroutine _configure: called CC=34 SCAR=48.7
156 206 my ($self, $args) = @_;
157 206 my $spawned = 0;
158  
159 206 ▶ if (ref $args eq 'HASH' && keys %{ $args }) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args eq "HASH" and keys %{$args;}) 206 0 206
Condition33%1/3
ref $args eq "HASH" and keys %{$args;}
!ll&&!rl&&r
00206
MC/DC0%0/2
ref $args eq "HASH" and keys %{$args;}
ref $args eq "HASH" keys %{$args;}
Truth table33%1/3
A and B
A= ref $args eq "HASH"B= keys %{$args;}
ABresult
0X0
100
111
160 206 $spawned = delete $args->{spawned};
161 206 $self->{use_localaddr} = delete $args->{localaddr};
162 206 @{ $self }{ keys %{ $args } } = values %{ $args };
163 }
164  
165 206 ▶ if ($ENV{POCOIRC_DEBUG}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"POCOIRC_DEBUG"}) 0 206 206
166 0 $self->{debug} = 1;
167 0 $self->{plugin_debug} = 1;
168 }
169  
170 206 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 206 206
171 0 $self->{ircd_filter}->debug(1);
172 0 $self->{ircd_compat}->debug(1);
173 }
174  
175 206 ▶ if ($self->{useipv6} && !$GOT_SOCKET6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"useipv6"} and not $POE::Component::IRC::GOT_SOCKET6) 0 206 206
Condition66%2/3
$self->{"useipv6"} and not $POE::Component::IRC::GOT_SOCKET6
!ll&&!rl&&r
20510
MC/DC0%0/2
$self->{"useipv6"} and not $POE::Component::IRC::GOT_SOCKET6
$self->{"useipv6"} not $POE::Component::IRC::GOT_SOCKET6
Truth table66%2/3
A and not(B)
A= $self->{"useipv6"}B= not $POE::Component::IRC::GOT_SOCKET6
ABresult
0X0
100
111
176 0 warn "'useipv6' option specified, but Socket/Socket6 was not found\n";
177 }
178  
179 206 ▶ if ($self->{usessl} && !$GOT_SSL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"usessl"} and not $POE::Component::IRC::GOT_SSL) 0 206 206
Condition33%1/3
$self->{"usessl"} and not $POE::Component::IRC::GOT_SSL
!ll&&!rl&&r
20600
MC/DC0%0/2
$self->{"usessl"} and not $POE::Component::IRC::GOT_SSL
$self->{"usessl"} not $POE::Component::IRC::GOT_SSL
Truth table33%1/3
A and not(B)
A= $self->{"usessl"}B= not $POE::Component::IRC::GOT_SSL
ABresult
0X0
100
111
180 0 warn "'usessl' option specified, but POE::Component::SSLify was not found\n";
181 }
182  
183 206 ▶ $self->{dcc}->nataddr($self->{nataddr}) if exists $self->{nataddr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"nataddr"} 2 204 206
184 206 ▶ $self->{dcc}->dccports($self->{dccports}) if exists $self->{dccports};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"dccports"} 0 206 206
185  
186 206 ▶ $self->{port} = 6667 if !$self->{port};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"port"} 115 91 206
187 206 ▶ $self->{msg_length} = 450 if !defined $self->{msg_length};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"msg_length"} 115 91 206
188  
189 206 ▶ if ($self->{use_localaddr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"use_localaddr"}) 0 206 206
190 $self->{localaddr} = $self->{use_localaddr}
191 0 ▶ . ($self->{localport} ? (':'.$self->{localport}) : '');
Branch: 1 branch
BranchTrueFalseTotal
$self->{'localport'} ? : 0 0 0
192 }
193  
194 # Make sure that we have reasonable defaults for all the attributes.
195 # The "IRC*" variables are ircII environment variables.
196 206 ▶ if (!defined $self->{nick}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"nick"}) 115 91 206
197 115 $self->{nick} = $ENV{IRCNICK} || eval { scalar getpwuid($>) }
198 115 ▶ || $ENV{USER} || $ENV{LOGNAME} || 'WankerBot';
Condition36%4/11
$ENV{'IRCNICK'} || eval { do { scalar getpwuid $> } } || $ENV{'USER'} || $ENV{'LOGNAME'} || 'WankerBot'
l!l
1150
$ENV{"IRCNICK"} or eval { do { scalar getpwuid $> } } or $ENV{"USER"} or $ENV{"LOGNAME"}
l!l&&r!l&&!r
11500
$ENV{"IRCNICK"} or eval { do { scalar getpwuid $> } } or $ENV{"USER"}
l!l&&r!l&&!r
11500
$ENV{"IRCNICK"} or eval { do { scalar getpwuid $> } }
l!l&&r!l&&!r
01150
MC/DC0%0/4
$ENV{'IRCNICK'} || eval { do { scalar getpwuid $> } } || $ENV{'USER'} || $ENV{'LOGNAME'} || 'WankerBot'
$ENV{"IRCNICK"} eval { do { scalar getpwuid $> } } $ENV{"USER"} $ENV{"LOGNAME"}
Truth table20%1/5
A or B or C or D
A= $ENV{"IRCNICK"}B= eval { do { scalar getpwuid $> } }C= $ENV{"USER"}D= $ENV{"LOGNAME"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
199 }
200  
201 206 ▶ if (!defined $self->{username}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"username"}) 115 91 206
202 115 $self->{username} = eval { scalar getpwuid($>) } || $ENV{USER}
203 115 ▶ || $ENV{LOGNAME} || 'foolio';
Condition37%3/8
eval { do { scalar getpwuid $> } } || $ENV{'USER'} || $ENV{'LOGNAME'} || 'foolio'
l!l
1150
eval { do { scalar getpwuid $> } } or $ENV{"USER"} or $ENV{"LOGNAME"}
l!l&&r!l&&!r
11500
eval { do { scalar getpwuid $> } } or $ENV{"USER"}
l!l&&r!l&&!r
11500
MC/DC0%0/3
eval { do { scalar getpwuid $> } } || $ENV{'USER'} || $ENV{'LOGNAME'} || 'foolio'
eval { do { scalar getpwuid $> } } $ENV{"USER"} $ENV{"LOGNAME"}
Truth table25%1/4
A or B or C
A= eval { do { scalar getpwuid $> } }B= $ENV{"USER"}C= $ENV{"LOGNAME"}
ABCresult
1XX1
01X1
0011
0000
204 }
205  
206 206 ▶ if (!defined $self->{ircname}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"ircname"}) 115 91 206
207 115 ▶ $self->{ircname} = $ENV{IRCNAME} || eval { (getpwuid $>)[6] }
Condition40%2/5
$ENV{'IRCNAME'} || eval { do { (getpwuid $>)[6] } } || 'Just Another Perl Hacker'
l!l
0115
$ENV{"IRCNAME"} or eval { do { (getpwuid $>)[6] } }
l!l&&r!l&&!r
00115
MC/DC0%0/2
$ENV{'IRCNAME'} || eval { do { (getpwuid $>)[6] } } || 'Just Another Perl Hacker'
$ENV{"IRCNAME"} eval { do { (getpwuid $>)[6] } }
Truth table33%1/3
A or B
A= $ENV{"IRCNAME"}B= eval { do { (getpwuid $>)[6] } }
ABresult
1X1
011
000
208 || 'Just Another Perl Hacker';
209 }
210  
211 206 ▶ if (!defined $self->{server} && !$spawned) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"server"} or $spawned) 0 206 206
Condition66%2/3
defined $self->{"server"} or $spawned
l!l&&r!l&&!r
931130
MC/DC0%0/2
defined $self->{"server"} or $spawned
defined $self->{"server"} $spawned
Truth table66%2/3
A or B
A= defined $self->{"server"}B= $spawned
ABresult
1X1
011
000
212 0 ▶ die "No IRC server specified\n" if !$ENV{IRCSERVER};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"IRCSERVER"} 0 0 0
213 0 $self->{server} = $ENV{IRCSERVER};
214 }
215  
216 206 ▶ if (defined $self->{webirc}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"webirc"}) 0 206 206
217 0 ▶ if (!(ref $self->{webirc} ne 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->{"webirc"} ne "HASH") 0 0 0
218 0 die "webirc param expects a hashref";
219 }
220 0 for my $expect_key (qw(pass user host ip)) {
221 0 ▶ if (!exists $self->{webirc}{$expect_key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"webirc"}{$expect_key}) 0 0 0
222 0 die "webirc value is missing key '$expect_key'";
223 }
224 }
225 }
226  
227 206 return;
228 }
229  
230 0 ▶sub debug {
Subroutine debug: not called CC=1 SCAR=6.9
Pod documented
231 0 my ($self, $switch) = @_[OBJECT, ARG0];
232  
233 0 $self->{debug} = $switch;
234 0 $self->{ircd_filter}->debug( $switch );
235 0 $self->{ircd_compat}->debug( $switch );
236 0 return;
237 }
238  
239 # Parse a message from the IRC server and generate the appropriate
240 # event(s) for listening sessions.
241 2559 ▶sub _parseline {
Subroutine _parseline: called CC=5 SCAR=16.1
242 2559 my ($session, $self, $ev) = @_[SESSION, OBJECT, ARG0];
243  
244 2559 ▶ return if !$ev->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $ev->{"name"} 0 2559 2559
245 2559 ▶ $self->send_event(irc_raw => $ev->{raw_line} ) if $self->{raw};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"raw"} 96 2463 2559
246  
247 # record our nickname
248 2559 ▶ if ( $ev->{name} eq '001' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ev->{"name"} eq "001") 91 2468 2559
249 91 $self->{INFO}{RealNick} = ( split / /, $ev->{raw_line} )[2];
250 }
251  
252 2559 $ev->{name} = 'irc_' . $ev->{name};
253 2559 $self->send_event( $ev->{name}, @{$ev->{args}} );
254  
255 2559 ▶ if ($ev->{name} =~ /^irc_ctcp_(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ev->{"name"} =~ /^irc_ctcp_(.+)$/) 12 2547 2559
256 12 $self->send_event(irc_ctcp => $1 => @{$ev->{args}});
257 }
258  
259 2559 return;
260 }
261  
262 # Internal function called when a socket is closed.
263 91 ▶sub _sock_down {
Subroutine _sock_down: called CC=1 SCAR=0.0
264 91 my ($kernel, $self) = @_[KERNEL, OBJECT];
265  
266 # Destroy the RW wheel for the socket.
267 91 delete $self->{socket};
268 91 delete $self->{localaddr};
269 91 $self->{connected} = 0;
270  
271 # Stop any delayed sends.
272 91 $self->{send_queue} = [ ];
273 91 $self->{send_time} = 0;
274 91 $kernel->delay( sl_delayed => undef );
275  
276 # Reset the filters if necessary
277 91 $self->_compress_uplink( 0 );
278 91 $self->_compress_downlink( 0 );
279 91 $self->{ircd_compat}->chantypes( [ '#', '&' ] );
280 91 $self->{ircd_compat}->identifymsg(0);
281  
282 # post a 'irc_disconnected' to each session that cares
283 91 $self->send_event(irc_disconnected => $self->{server} );
284 91 return;
285 }
286  
287 0 ▶sub disconnect {
Subroutine disconnect: not called CC=1 SCAR=6.9
Pod documented
288 0 my ($self) = @_;
289 0 $self->yield('_sock_down');
290 0 return;
291 }
292  
293 # Internal function called when a socket fails to be properly opened.
294 1 ▶sub _sock_failed {
Subroutine _sock_failed: called CC=1 SCAR=0.0
295 1 my ($self, $op, $errno, $errstr) = @_[OBJECT, ARG0..ARG2];
296  
297 1 delete $self->{socketfactory};
298 1 $self->send_event(irc_socketerr => "$op error $errno: $errstr" );
299 1 return;
300 }
301  
302 # Internal function called when a connection is established.
303 91 ▶sub _sock_up {
Subroutine _sock_up: called CC=17 SCAR=45.1
304 91 my ($kernel, $self, $session, $socket) = @_[KERNEL, OBJECT, SESSION, ARG0];
305  
306 # We no longer need the SocketFactory wheel. Scrap it.
307 91 delete $self->{socketfactory};
308  
309 # Remember what IP address we're connected through, for multihomed boxes.
310 91 my $localaddr;
311 91 ▶ if ($GOT_SOCKET6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($POE::Component::IRC::GOT_SOCKET6) 91 0 91
312 91 eval {
313 91 $localaddr = (unpack_sockaddr_in6( getsockname $socket ))[1];
314 1 $localaddr = inet_ntop( AF_INET6, $localaddr );
315 };
316 }
317  
318 91 ▶ if ( !$localaddr ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($localaddr) 90 1 91
319 90 $localaddr = (unpack_sockaddr_in( getsockname $socket ))[1];
320 90 $localaddr = inet_ntoa($localaddr);
321 }
322  
323 91 $self->{localaddr} = $localaddr;
324  
325 91 ▶ if ( $self->{socks_proxy} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"socks_proxy"}) 0 91 91
326 0 $self->{socket} = POE::Wheel::ReadWrite->new(
327 Handle => $socket,
328 Driver => POE::Driver::SysRW->new(),
329 Filter => POE::Filter::Stream->new(),
330 InputEvent => '_socks_proxy_response',
331 ErrorEvent => '_sock_down',
332 );
333  
334 0 ▶ if ( !$self->{socket} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"socket"}) 0 0 0
335 0 $self->send_event(irc_socketerr =>
336 "Couldn't create ReadWrite wheel for SOCKS socket" );
337 0 return;
338 }
339  
340 0 my $packet;
341 0 ▶ if ( _ip_is_ipv4( $self->{server} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_ip_is_ipv4($self->{'server'})) { } 0 0 0
342 # SOCKS 4
343 $packet = pack ('CCn', 4, 1, $self->{port}) .
344 0 ▶ inet_aton($self->{server}) . ($self->{socks_id} || '') . (pack 'x');
Condition0%0/2
$self->{'socks_id'} || ''
l!l
00
MC/DC0%0/1
$self->{'socks_id'} || ''
$self->{'socks_id'}
Truth table0%0/2
A
A= $self->{'socks_id'}
Aresult
11
00
345 }
346 else {
347 # SOCKS 4a
348 $packet = pack ('CCn', 4, 1, $self->{port}) .
349 inet_aton('0.0.0.1') . ($self->{socks_id} || '') . (pack 'x') .
350 0 ▶ $self->{server} . (pack 'x');
Condition0%0/2
$self->{'socks_id'} || ''
l!l
00
MC/DC0%0/1
$self->{'socks_id'} || ''
$self->{'socks_id'}
Truth table0%0/2
A
A= $self->{'socks_id'}
Aresult
11
00
351 }
352  
353 0 $self->{socket}->put( $packet );
354 0 return;
355 }
356  
357 # ssl!
358 91 ▶ if ($GOT_SSL and $self->{usessl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($POE::Component::IRC::GOT_SSL and $self->{"usessl"}) 0 91 91
Condition33%1/3
$POE::Component::IRC::GOT_SSL and $self->{"usessl"}
!ll&&!rl&&r
9100
MC/DC0%0/2
$POE::Component::IRC::GOT_SSL and $self->{"usessl"}
$POE::Component::IRC::GOT_SSL $self->{"usessl"}
Truth table33%1/3
A and B
A= $POE::Component::IRC::GOT_SSLB= $self->{"usessl"}
ABresult
0X0
100
111
359 0 eval {
360 0 my ($ctx);
361  
362 0 ▶ if( $self->{sslctx} )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'sslctx'}) { } 0 0 0
elsif ($self->{'sslkey'} and $self->{'sslcert'}) { } 0 0 0
363 {
364 0 $ctx = $self->{sslctx};
365 }
366 ▶ elsif( $self->{sslkey} && $self->{sslcert} )
Condition0%0/3
$self->{"sslkey"} and $self->{"sslcert"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"sslkey"} and $self->{"sslcert"}
$self->{"sslkey"} $self->{"sslcert"}
Truth table0%0/3
A and B
A= $self->{"sslkey"}B= $self->{"sslcert"}
ABresult
0X0
100
111
367 {
368 0 $ctx = SSLify_ContextCreate( $self->{sslkey}, $self->{sslcert} );
369 }
370 else
371 {
372 0 $ctx = undef;
373 }
374  
375 0 $socket = Client_SSLify($socket, undef, undef, $ctx);
376 };
377  
378 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
379 0 chomp $@;
380 0 warn "Couldn't use an SSL socket: $@\n";
381 0 $self->{usessl} = 0;
382 }
383 }
384  
385 91 ▶ if ( $self->{compress} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"compress"}) 0 91 91
386 0 $self->_compress_uplink(1);
387 0 $self->_compress_downlink(1);
388 }
389  
390 # Create a new ReadWrite wheel for the connected socket.
391 $self->{socket} = POE::Wheel::ReadWrite->new(
392 Handle => $socket,
393 Driver => POE::Driver::SysRW->new(),
394 InputFilter => $self->{srv_filter},
395 OutputFilter => $self->{out_filter},
396 91 InputEvent => '_parseline',
397 ErrorEvent => '_sock_down',
398 );
399  
400 91 ▶ if ($self->{socket}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'socket'}) { } 91 0 91
401 91 $self->{connected} = 1;
402 }
403 else {
404 0 $self->send_event(irc_socketerr => "Couldn't create ReadWrite wheel for IRC socket");
405 0 return;
406 }
407  
408 # Post a 'irc_connected' event to each session that cares
409 91 $self->send_event(irc_connected => $self->{server} );
410  
411 # CONNECT if we're using a proxy
412 91 ▶ if ($self->{proxy}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"proxy"}) 0 91 91
413 # The original proxy code, AFAIK, did not actually work
414 # with an HTTP proxy.
415 $self->call(
416 'sl_login',
417 0 'CONNECT ' . $self->{server} . ':' . $self->{port} . " HTTP/1.0\n\n",
418 );
419  
420 # KLUDGE: Also, the original proxy code assumes the connection
421 # is instantaneous Since this is not always the case, mess with
422 # the queueing so that the sent text is delayed...
423 0 $self->{send_time} = time() + 10;
424 }
425  
426 91 $kernel->yield('_send_login');
427 91 return;
428 }
429  
430 0 ▶sub _socks_proxy_response {
Subroutine _socks_proxy_response: not called CC=6 SCAR=37.4
431 0 my ($kernel, $self, $session, $input) = @_[KERNEL, OBJECT, SESSION, ARG0];
432  
433 0 ▶ if (length $input != 8) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $input != 8) 0 0 0
434 0 $self->send_event(
435 'irc_socks_failed',
436 'Mangled response from SOCKS proxy',
437 $input,
438 );
439 0 $self->disconnect();
440 0 return;
441 }
442  
443 0 my @resp = unpack 'CCnN', $input;
444 0 ▶ if (@resp != 4 || $resp[0] ne '0' || $resp[1] !~ /^(?:90|91|92|93)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@resp != 4 or $resp[0] ne 0 or not $resp[1] =~ /^(?:90|91|92|93)$/) 0 0 0
Condition0%0/6
@resp != 4 or $resp[0] ne 0 or not $resp[1] =~ /^(?:90|91|92|93)$/
l!l&&r!l&&!r
000
@resp != 4 or $resp[0] ne 0
l!l&&r!l&&!r
000
MC/DC0%0/3
@resp != 4 or $resp[0] ne 0 or not $resp[1] =~ /^(?:90|91|92|93)$/
@resp != 4 $resp[0] ne 0 not $resp[1] =~ /^(?:90|91|92|93)$/
Truth table0%0/4
A or B or not(C)
A= @resp != 4B= $resp[0] ne 0C= not $resp[1] =~ /^(?:90|91|92|93)$/
ABCresult
1XX1
01X1
0011
0000
445 0 $self->send_event(
446 'irc_socks_failed',
447 'Mangled response from SOCKS proxy',
448 $input,
449 );
450 0 $self->disconnect();
451 0 return;
452 }
453  
454 0 ▶ if ( $resp[1] eq '90' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp[1] eq '90') { } 0 0 0
455 0 $kernel->call($session => '_socks_proxy_connect');
456 0 $self->{connected} = 1;
457 0 $self->send_event( 'irc_connected', $self->{server} );
458 0 $kernel->yield('_send_login');
459 }
460 else {
461 $self->send_event(
462 'irc_socks_rejected',
463 $resp[1],
464 $self->{socks_proxy},
465 $self->{socks_port},
466 $self->{socks_id},
467 0 );
468 0 $self->disconnect();
469 }
470  
471 0 return;
472 }
473  
474 0 ▶sub _socks_proxy_connect {
Subroutine _socks_proxy_connect: not called CC=1 SCAR=6.9
475 0 my ($kernel, $self) = @_[KERNEL, OBJECT];
476 0 $self->{socket}->event( InputEvent => '_parseline' );
477 0 $self->{socket}->set_input_filter( $self->{srv_filter} );
478 0 $self->{socket}->set_output_filter( $self->{out_filter} );
479 0 return;
480 }
481  
482 91 ▶sub _send_login {
Subroutine _send_login: called CC=4 SCAR=14.2
483 91 my ($kernel, $self, $session) = @_[KERNEL, OBJECT, SESSION];
484  
485 # Now that we're connected, attempt to log into the server.
486  
487 # for servers which support CAP, it's customary to start with that
488 91 $kernel->call($session, 'sl_login', 'CAP REQ :identify-msg');
489 91 $kernel->call($session, 'sl_login', 'CAP REQ :multi-prefix');
490 91 $kernel->call($session, 'sl_login', 'CAP LS');
491 91 $kernel->call($session, 'sl_login', 'CAP END');
492  
493 # If we were told to use WEBIRC to spoof our host/IP, do so:
494 91 ▶ if (defined $self->{webirc}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"webirc"}) 0 91 91
495 $kernel->call($session => sl_login => 'WEBIRC '
496 0 . join " ", @{$self->{webirc}}{qw(pass user ip host)}
497 );
498 }
499  
500 91 ▶ if (defined $self->{password}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"password"}) 1 90 91
501 1 $kernel->call($session => sl_login => 'PASS ' . $self->{password});
502 }
503 91 $kernel->call($session => sl_login => 'NICK ' . $self->{nick});
504 $kernel->call(
505 $session,
506 'sl_login',
507 'USER ' .
508 join(' ', $self->{username},
509 (defined $self->{bitmode} ? $self->{bitmode} : 8),
510 '*',
511 ':' . $self->{ircname}
512 91 ▶ ),
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'bitmode'} ? : 0 91 91
513 );
514  
515 # If we have queued data waiting, its flush loop has stopped
516 # while we were disconnected. Start that up again.
517 91 $kernel->delay(sl_delayed => 0);
518  
519 91 return;
520 }
521  
522 # Set up the component's IRC session.
523 115 ▶sub syndicator_started {
Subroutine syndicator_started: called CC=1 SCAR=0.0
Pod documented
524 115 my ($kernel, $session, $sender, $self, $alias)
525 = @_[KERNEL, SESSION, SENDER, OBJECT, ARG0, ARG1 .. $#_];
526  
527 # Send queue is used to hold pending lines so we don't flood off.
528 # The count is used to track the number of lines sent at any time.
529 115 $self->{send_queue} = [ ];
530 115 $self->{send_time} = 0;
531  
532 115 $self->{ircd_filter} = POE::Filter::IRCD->new(debug => $self->{debug});
533 115 $self->{ircd_compat} = POE::Filter::IRC::Compat->new(debug => $self->{debug});
534  
535 my $srv_filters = [
536 POE::Filter::Line->new(
537 InputRegexp => '\015?\012',
538 OutputLiteral => '\015\012',
539 ),
540 $self->{ircd_filter},
541 $self->{ircd_compat},
542 115 ];
543  
544 115 $self->{srv_filter} = POE::Filter::Stackable->new(Filters => $srv_filters);
545 115 $self->{out_filter} = POE::Filter::Stackable->new(Filters => [
546 POE::Filter::Line->new( OutputLiteral => "\015\012" ),
547 ]);
548  
549 # Plugin 'irc_whois' and 'irc_whowas' support
550 115 $self->plugin_add('Whois_' . $self->session_id(),
551 POE::Component::IRC::Plugin::Whois->new()
552 );
553  
554 115 $self->{isupport} = POE::Component::IRC::Plugin::ISupport->new();
555 115 $self->plugin_add('ISupport_' . $self->session_id(), $self->{isupport});
556 115 $self->{dcc} = POE::Component::IRC::Plugin::DCC->new();
557 115 $self->plugin_add('DCC_' . $self->session_id(), $self->{dcc});
558  
559 115 return 1;
560 }
561  
562 # The handler for commands which have N arguments, separated by commas.
563 9 ▶sub commasep {
Subroutine commasep: called CC=10 SCAR=34.2
Pod undocumented
564 9 my ($kernel, $self, $state, @args) = @_[KERNEL, OBJECT, STATE, ARG0 .. $#_];
565 9 my $args;
566  
567 9 ▶ if ($state eq 'whois' and @args > 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($state eq 'whois' and @args > 1) { } 0 9 9
elsif ($state eq 'part' and @args > 1) { } 0 9 9
Condition66%2/3
$state eq "whois" and @args > 1
!ll&&!rl&&r
540
MC/DC0%0/2
$state eq "whois" and @args > 1
$state eq "whois" @args > 1
Truth table66%2/3
A and B
A= $state eq "whois"B= @args > 1
ABresult
0X0
100
111
568 0 $args = shift @args;
569 0 $args .= ' ' . join ',', @args;
570 }
571 ▶ elsif ( $state eq 'part' and @args > 1 ) {
Condition66%2/3
$state eq "part" and @args > 1
!ll&&!rl&&r
540
MC/DC0%0/2
$state eq "part" and @args > 1
$state eq "part" @args > 1
Truth table66%2/3
A and B
A= $state eq "part"B= @args > 1
ABresult
0X0
100
111
572 0 ▶ my $chantypes = join('', @{ $self->isupport('CHANTYPES') || ['#', '&']});
Condition0%0/2
$self->isupport('CHANTYPES') || ['#', '&']
l!l
00
MC/DC0%0/1
$self->isupport('CHANTYPES') || ['#', '&']
$self->isupport('CHANTYPES')
Truth table0%0/2
A
A= $self->isupport('CHANTYPES')
Aresult
11
00
573 0 my $message;
574 0 ▶ if ($args[-1] =~ / +/ || $args[-1] !~ /^[$chantypes]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args[-1] =~ / +/ or not $args[-1] =~ /^[$chantypes]/) 0 0 0
Condition0%0/3
$args[-1] =~ / +/ or not $args[-1] =~ /^[$chantypes]/
l!l&&r!l&&!r
000
MC/DC0%0/2
$args[-1] =~ / +/ or not $args[-1] =~ /^[$chantypes]/
$args[-1] =~ / +/ not $args[-1] =~ /^[$chantypes]/
Truth table0%0/3
A or not(B)
A= $args[-1] =~ / +/B= not $args[-1] =~ /^[$chantypes]/
ABresult
1X1
011
000
575 0 $message = pop @args;
576 }
577 0 $args = join(',', @args);
578 0 ▶ $args .= " :$message" if defined $message;
Branch: 1 branch
BranchTrueFalseTotal
if defined $message 0 0 0
579 }
580 else {
581 9 $args = join ',', @args;
582 }
583  
584 9 my $pri = $self->{IRC_CMDS}->{$state}->[CMD_PRI];
585 9 $state = uc $state;
586 9 ▶ $state .= " $args" if defined $args;
Branch: 1 branch
BranchTrueFalseTotal
if defined $args 9 0 9
587 9 $kernel->yield(sl_prioritized => $pri, $state );
588  
589 9 return;
590 }
591  
592 # Get variables in order for openning a connection
593 92 ▶sub connect {
Subroutine connect: called CC=13 SCAR=35.7
Pod documented
594 92 my ($kernel, $self, $session, $sender, $args)
595 = @_[KERNEL, OBJECT, SESSION, SENDER, ARG0];
596  
597 92 ▶ if ($args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args) 91 1 92
598 91 my %arg;
599 0 ▶ %arg = @{ $args } if ref $args eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args eq "ARRAY" 0 91 91
600 91 ▶ %arg = %{ $args } if ref $args eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args eq "HASH" 91 0 91
601 91 $arg{ lc $_ } = delete $arg{$_} for keys %arg;
602 91 $self->_configure( \%arg );
603 }
604  
605 92 ▶ if ( $self->{resolver} && $self->{res_addresses}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"resolver"} and $self->{"res_addresses"} and @{$self->{"res_addresses"};}) 0 92 92
Condition33%2/6
$self->{"resolver"} and $self->{"res_addresses"} and @{$self->{"res_addresses"};}
!ll&&!rl&&r
9200
$self->{"resolver"} and $self->{"res_addresses"}
!ll&&!rl&&r
0920
MC/DC0%0/3
$self->{"resolver"} and $self->{"res_addresses"} and @{$self->{"res_addresses"};}
$self->{"resolver"} $self->{"res_addresses"} @{$self->{"res_addresses"};}
Truth table25%1/4
A and B and C
A= $self->{"resolver"}B= $self->{"res_addresses"}C= @{$self->{"res_addresses"};}
ABCresult
0XX0
10X0
1100
1111
606 0 && @{ $self->{res_addresses} } ) {
607 0 push @{ $self->{res_addresses} }, $self->{server};
608 0 $self->{resolved_server} = shift @{ $self->{res_addresses} };
609 }
610  
611 # try and use non-blocking resolver if needed
612 92 ▶ if ( $self->{resolver} && !_ip_get_version( $self->{server} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'resolver'} and not _ip_get_version($self->{'server'}) and not $self->{'nodns'}) { } 0 92 92
Condition33%2/6
$self->{"resolver"} and not _ip_get_version($self->{"server"}) and not $self->{"nodns"}
!ll&&!rl&&r
9200
$self->{"resolver"} and not _ip_get_version($self->{"server"})
!ll&&!rl&&r
0920
MC/DC0%0/3
$self->{"resolver"} and not _ip_get_version($self->{"server"}) and not $self->{"nodns"}
$self->{"resolver"} not _ip_get_version($self->{"server"}) not $self->{"nodns"}
Truth table25%1/4
A and not(B) and not(C)
A= $self->{"resolver"}B= not _ip_get_version($self->{"server"})C= not $self->{"nodns"}
ABCresult
0XX0
10X0
1100
1111
613 && !$self->{nodns} ) {
614 $kernel->yield(
615 '_resolve_addresses',
616 $self->{server},
617 0 ▶ ( $self->{useipv6} && $GOT_SOCKET6 ? 'AAAA' : 'A' ),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'useipv6'} && $POE::Component::IRC::GOT_SOCKET6 ? : 0 0 0
Condition0%0/3
$self->{"useipv6"} and $POE::Component::IRC::GOT_SOCKET6
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"useipv6"} and $POE::Component::IRC::GOT_SOCKET6
$self->{"useipv6"} $POE::Component::IRC::GOT_SOCKET6
Truth table0%0/3
A and B
A= $self->{"useipv6"}B= $POE::Component::IRC::GOT_SOCKET6
ABresult
0X0
100
111
618 );
619 }
620 else {
621 92 $kernel->yield('_do_connect');
622 }
623  
624 92 $self->{INFO}{RealNick} = $self->{nick};
625 92 return;
626 }
627  
628 0 ▶sub _resolve_addresses {
Subroutine _resolve_addresses: not called CC=2 SCAR=17.9
629 0 my ($kernel, $self, $hostname, $type) = @_[KERNEL, OBJECT, ARG0 .. ARG1];
630  
631 my $response = $self->{resolver}->resolve(
632 0 event => '_got_dns_response',
633 host => $hostname,
634 type => $type,
635 context => { },
636 );
637  
638 0 ▶ $kernel->yield(_got_dns_response => $response) if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 0 0
639 0 return;
640 }
641  
642 # open the connection
643 92 ▶sub _do_connect {
Subroutine _do_connect: called CC=14 SCAR=33.9
644 92 my ($kernel, $self, $session) = @_[KERNEL, OBJECT, SESSION];
645 92 my $domain = AF_INET;
646  
647 # Disconnect if we're already logged into a server.
648 92 ▶ $kernel->call($session => 'quit') if $self->{socket};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"socket"} 0 92 92
649  
650 92 ▶ if ($self->{socks_proxy} && !$self->{socks_port}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"socks_proxy"} and not $self->{"socks_port"}) 0 92 92
Condition33%1/3
$self->{"socks_proxy"} and not $self->{"socks_port"}
!ll&&!rl&&r
9200
MC/DC0%0/2
$self->{"socks_proxy"} and not $self->{"socks_port"}
$self->{"socks_proxy"} not $self->{"socks_port"}
Truth table33%1/3
A and not(B)
A= $self->{"socks_proxy"}B= not $self->{"socks_port"}
ABresult
0X0
100
111
651 0 $self->{socks_port} = 1080;
652 }
653  
654 92 for my $address (qw(socks_proxy proxy server resolved_server use_localaddr)) {
655 460 ▶ next if !$self->{$address} || !_ip_is_ipv6( $self->{$address} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{$address} and _ip_is_ipv6($self->{$address}) 459 1 460
Condition100%3/3
$self->{$address} and _ip_is_ipv6($self->{$address})
!ll&&!rl&&r
368911
MC/DC100%2/2
$self->{$address} and _ip_is_ipv6($self->{$address})
$self->{$address} _ip_is_ipv6($self->{$address})
Truth table100%3/3
A and B
A= $self->{$address}B= _ip_is_ipv6($self->{$address})
ABresult
0X0
100
111
656 1 ▶ if (!$GOT_SOCKET6) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($POE::Component::IRC::GOT_SOCKET6) 0 1 1
657 0 warn "IPv6 address specified for '$address' but Socket/Socket6 not found\n";
658 0 return;
659 }
660 1 $domain = AF_INET6;
661 }
662  
663 $self->{socketfactory} = POE::Wheel::SocketFactory->new(
664 SocketDomain => $domain,
665 SocketType => SOCK_STREAM,
666 SocketProtocol => 'tcp',
667 RemoteAddress => $self->{socks_proxy} || $self->{proxy} || $self->{resolved_server} || $self->{server},
668 RemotePort => $self->{socks_port} || $self->{proxyport} || $self->{port},
669 SuccessEvent => '_sock_up',
670 FailureEvent => '_sock_failed',
671 92 ▶ ($self->{use_localaddr} ? (BindAddress => $self->{use_localaddr}) : ()),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'use_localaddr'} ? : 0 92 92
Condition33%5/15
$self->{'socks_proxy'} || $self->{'proxy'} || $self->{'resolved_server'} || $self->{'server'}
l!l&&r!l&&!r
0920
$self->{"socks_proxy"} or $self->{"proxy"} or $self->{"resolved_server"}
l!l&&r!l&&!r
0092
$self->{"socks_proxy"} or $self->{"proxy"}
l!l&&r!l&&!r
0092
$self->{'socks_port'} || $self->{'proxyport'} || $self->{'port'}
l!l&&r!l&&!r
0920
$self->{"socks_port"} or $self->{"proxyport"}
l!l&&r!l&&!r
0092
MC/DC0%0/4
$self->{'socks_proxy'} || $self->{'proxy'} || $self->{'resolved_server'} || $self->{'server'}
$self->{"socks_proxy"} $self->{"proxy"} $self->{"resolved_server"} $self->{'server'}
MC/DC0%0/3
$self->{'socks_port'} || $self->{'proxyport'} || $self->{'port'}
$self->{"socks_port"} $self->{"proxyport"} $self->{'port'}
Truth table20%1/5
A or B or C || D
A= $self->{"socks_proxy"}B= $self->{"proxy"}C= $self->{"resolved_server"}D= $self->{'server'}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
Truth table25%1/4
A or B || C
A= $self->{"socks_port"}B= $self->{"proxyport"}C= $self->{'port'}
ABCresult
1XX1
01X1
0011
0000
672 );
673  
674 92 return;
675 }
676  
677 # got response from POE::Component::Client::DNS
678 0 ▶sub _got_dns_response {
Subroutine _got_dns_response: not called CC=8 SCAR=42.8
679 0 my ($kernel, $self, $response) = @_[KERNEL, OBJECT, ARG0];
680  
681 0 my $type = uc $response->{type};
682 0 my $net_dns_packet = $response->{response};
683 0 my $net_dns_errorstring = $response->{error};
684 0 $self->{res_addresses} = [ ];
685  
686 0 ▶ if (!defined $net_dns_packet) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $net_dns_packet) 0 0 0
687 0 $self->send_event(irc_socketerr => $net_dns_errorstring );
688 0 return;
689 }
690  
691 0 my @net_dns_answers = $net_dns_packet->answer;
692  
693 0 for my $net_dns_answer (@net_dns_answers) {
694 0 ▶ next if $net_dns_answer->type !~ /^A/;
Branch: 1 branch
BranchTrueFalseTotal
unless $net_dns_answer->type =~ /^A/ 0 0 0
695 0 push @{ $self->{res_addresses} }, $net_dns_answer->rdstring;
696 }
697  
698 0 ▶ if ( !@{ $self->{res_addresses} } && $type eq 'AAAA') {
Branch: 1 branch
BranchTrueFalseTotal
if (not @{$self->{"res_addresses"};} and $type eq "AAAA") 0 0 0
Condition0%0/3
not @{$self->{"res_addresses"};} and $type eq "AAAA"
!ll&&!rl&&r
000
MC/DC0%0/2
not @{$self->{"res_addresses"};} and $type eq "AAAA"
not @{$self->{"res_addresses"};} $type eq "AAAA"
Truth table0%0/3
not(A) and B
A= not @{$self->{"res_addresses"};}B= $type eq "AAAA"
ABresult
0X0
100
111
699 0 $kernel->yield(_resolve_addresses => $self->{server}, 'A');
700 0 return;
701 }
702  
703 0 ▶ if ( !@{ $self->{res_addresses} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"res_addresses"};}) 0 0 0
704 0 $self->send_event(irc_socketerr => 'Unable to resolve ' . $self->{server});
705 0 return;
706 }
707  
708 0 ▶ if ( my $address = shift @{ $self->{res_addresses} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $address = shift @{$$self{"res_addresses"};}) 0 0 0
709 0 $self->{resolved_server} = $address;
710 0 $kernel->yield('_do_connect');
711 0 return;
712 }
713  
714 0 $self->send_event(irc_socketerr => 'Unable to resolve ' . $self->{server});
715 0 return;
716 }
717  
718 # Send a CTCP query or reply, with the same syntax as a PRIVMSG event.
719 27 ▶sub ctcp {
Subroutine ctcp: called CC=4 SCAR=14.8
Pod documented
720 27 my ($kernel, $state, $self, $to) = @_[KERNEL, STATE, OBJECT, ARG0];
721 27 my $message = join ' ', @_[ARG1 .. $#_];
722  
723 27 ▶ if (!defined $to || !defined $message) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $to and defined $message) 0 27 27
Condition33%1/3
defined $to and defined $message
!ll&&!rl&&r
0027
MC/DC0%0/2
defined $to and defined $message
defined $to defined $message
Truth table33%1/3
A and B
A= defined $toB= defined $message
ABresult
0X0
100
111
724 0 warn "The '$state' event requires two arguments\n";
725 0 return;
726 }
727  
728 # CTCP-quote the message text.
729 27 ($message) = @{$self->{ircd_compat}->put([ $message ])};
730  
731 # Should we send this as a CTCP request or reply?
732 27 ▶ $state = $state eq 'ctcpreply' ? 'notice' : 'privmsg';
Branch: 1 branch
BranchTrueFalseTotal
$state eq 'ctcpreply' ? : 6 21 27
733  
734 27 $kernel->yield($state, $to, $message);
735 27 return;
736 }
737  
738 # The way /notify is implemented in IRC clients.
739 0 ▶sub ison {
Subroutine ison: not called CC=4 SCAR=30.0
Pod documented
740 0 my ($kernel, @nicks) = @_[KERNEL, ARG0 .. $#_];
741 0 my $tmp = 'ISON';
742  
743 0 ▶ if (!@nicks) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@nicks) 0 0 0
744 0 warn "The 'ison' event requires one or more nicknames\n";
745 0 return;
746 }
747  
748 # We can pass as many nicks as we want, as long as it's shorter than
749 # the maximum command length (510). If the list we get is too long,
750 # w'll break it into multiple ISON commands.
751 0 ▶ while (@nicks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@nicks) 0 0 0
752 0 my $nick = shift @nicks;
753 0 ▶ if (length($tmp) + length($nick) >= 509) {
Branch: 1 branch
BranchTrueFalseTotal
if (length($tmp) + length($nick) >= 509) 0 0 0
754 0 $kernel->yield(sl_high => $tmp);
755 0 $tmp = 'ISON';
756 }
757 0 $tmp .= " $nick";
758 }
759  
760 0 $kernel->yield(sl_high => $tmp);
761 0 return;
762 }
763  
764 # Tell the IRC server to forcibly remove a user from a channel.
765 6 ▶sub kick {
Subroutine kick: called CC=4 SCAR=16.1
Pod documented
766 6 my ($kernel, $chan, $nick) = @_[KERNEL, ARG0, ARG1];
767 6 my $message = join '', @_[ARG2 .. $#_];
768  
769 6 ▶ if (!defined $chan || !defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan and defined $nick) 0 6 6
Condition33%1/3
defined $chan and defined $nick
!ll&&!rl&&r
006
MC/DC0%0/2
defined $chan and defined $nick
defined $chan defined $nick
Truth table33%1/3
A and B
A= defined $chanB= defined $nick
ABresult
0X0
100
111
770 0 warn "The 'kick' event requires at least two arguments\n";
771 0 return;
772 }
773  
774 6 ▶ $nick .= " :$message" if defined $message;
Branch: 1 branch
BranchTrueFalseTotal
if defined $message 6 0 6
775 6 $kernel->yield(sl_high => "KICK $chan $nick");
776 6 return;
777 }
778  
779 # Tell the IRC server to forcibly remove a user from a channel. Freenode extension
780 0 ▶sub remove {
Subroutine remove: not called CC=4 SCAR=30.0
Pod documented
781 0 my ($kernel, $chan, $nick) = @_[KERNEL, ARG0, ARG1];
782 0 my $message = join '', @_[ARG2 .. $#_];
783  
784 0 ▶ if (!defined $chan || !defined $nick) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chan and defined $nick) 0 0 0
Condition0%0/3
defined $chan and defined $nick
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chan and defined $nick
defined $chan defined $nick
Truth table0%0/3
A and B
A= defined $chanB= defined $nick
ABresult
0X0
100
111
785 0 warn "The 'remove' event requires at least two arguments\n";
786 0 return;
787 }
788  
789 0 ▶ $nick .= " :$message" if defined $message;
Branch: 1 branch
BranchTrueFalseTotal
if defined $message 0 0 0
790 0 $kernel->yield(sl_high => "REMOVE $chan $nick");
791 0 return;
792 }
793  
794 # Interact with NickServ
795 0 ▶sub nickserv {
Subroutine nickserv: not called CC=4 SCAR=30.0
Pod documented
796 0 my ($kernel, $self, $state) = @_[KERNEL, OBJECT, STATE];
797 0 my $args = join ' ', @_[ARG0 .. $#_];
798  
799 0 my $command = 'NICKSERV';
800 0 my $version = $self->server_version();
801 0 ▶ $command = 'NS' if defined $version && $version =~ /ratbox/i;
Branch: 1 branch
BranchTrueFalseTotal
if defined $version and $version =~ /ratbox/i 0 0 0
Condition0%0/3
defined $version and $version =~ /ratbox/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $version and $version =~ /ratbox/i
defined $version $version =~ /ratbox/i
Truth table0%0/3
A and B
A= defined $versionB= $version =~ /ratbox/i
ABresult
0X0
100
111
802 0 ▶ $command .= " $args" if defined $args;
Branch: 1 branch
BranchTrueFalseTotal
if defined $args 0 0 0
803  
804 0 $kernel->yield(sl_high => $command);
805 0 return;
806 }
807  
808 # Set up a new IRC component. Deprecated.
809 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
810 0 my ($package, $alias) = splice @_, 0, 2;
811 0 ▶ croak "$package options should be an even-sized list" if @_ & 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 0 0
812 0 my %options = @_;
813  
814 0 ▶ if (!defined $alias) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $alias) 0 0 0
815 0 croak 'Not enough arguments to POE::Component::IRC::new()';
816 }
817  
818 0 carp "Use of ${package}->new() is deprecated, please use spawn()";
819  
820 0 my $self = $package->spawn ( alias => $alias, options => \%options );
821 0 return $self;
822 }
823  
824 # Set up a new IRC component. New interface.
825 115 ▶sub spawn {
Subroutine spawn: called CC=10 SCAR=24.3
Pod documented
826 115 my ($package) = shift;
827 115 ▶ croak "$package requires an even number of arguments" if @_ & 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 115 115
828 115 my %params = @_;
829  
830 115 $params{ lc $_ } = delete $params{$_} for keys %params;
831 115 ▶ delete $params{options} if ref $params{options} ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $params{"options"} ne "HASH" 115 0 115
832  
833 115 my $self = bless { }, $package;
834 115 $self->_create();
835  
836 115 ▶ if ($ENV{POCOIRC_DEBUG}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"POCOIRC_DEBUG"}) 0 115 115
837 0 $params{debug} = 1;
838 0 $params{plugin_debug} = 1;
839 }
840  
841 115 my $options = delete $params{options};
842 115 my $alias = delete $params{alias};
843 115 my $plugin_debug = delete $params{plugin_debug};
844  
845 $self->_syndicator_init(
846 prefix => 'irc_',
847 reg_prefix => 'PCI_',
848 types => [SERVER => 'S', USER => 'U'],
849 alias => $alias,
850 register_signal => 'POCOIRC_REGISTER',
851 shutdown_signal => 'POCOIRC_SHUTDOWN',
852 object_states => [
853 $self => delete $self->{OBJECT_STATES_HASHREF},
854 $self => delete $self->{OBJECT_STATES_ARRAYREF},
855 115 ▶ ],
Branch: 2 branches
BranchTrueFalseTotal
$plugin_debug ? : 94 21 115
ref $options eq 'HASH' ? : 0 115 115
856 ($plugin_debug ? (debug => 1) : () ),
857 (ref $options eq 'HASH' ? ( options => $options ) : ()),
858 );
859  
860 115 $params{spawned} = 1;
861 115 $self->_configure(\%params);
862  
863 115 ▶ if (!$params{nodns} && $GOT_CLIENT_DNS && !$self->{resolver}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $params{"nodns"} and $POE::Component::IRC::GOT_CLIENT_DNS and not $self->{"resolver"}) 114 1 115
Condition50%3/6
not $params{"nodns"} and $POE::Component::IRC::GOT_CLIENT_DNS and not $self->{"resolver"}
!ll&&!rl&&r
01114
not $params{"nodns"} and $POE::Component::IRC::GOT_CLIENT_DNS
!ll&&!rl&&r
00115
MC/DC33%1/3
not $params{"nodns"} and $POE::Component::IRC::GOT_CLIENT_DNS and not $self->{"resolver"}
not $params{"nodns"} $POE::Component::IRC::GOT_CLIENT_DNS not $self->{"resolver"}
Truth table50%2/4
not(A) and B and not(C)
A= not $params{"nodns"}B= $POE::Component::IRC::GOT_CLIENT_DNSC= not $self->{"resolver"}
ABCresult
0XX0
10X0
1100
1111
864 114 $self->{resolver} = POE::Component::Client::DNS->spawn(
865 Alias => 'resolver' . $self->session_id()
866 );
867 114 $self->{mydns} = 1;
868 }
869  
870 115 return $self;
871 }
872  
873 # The handler for all IRC commands that take no arguments.
874 0 ▶sub noargs {
Subroutine noargs: not called CC=2 SCAR=17.9
Pod undocumented
875 0 my ($kernel, $state, $arg) = @_[KERNEL, STATE, ARG0];
876 0 my $pri = $_[OBJECT]->{IRC_CMDS}->{$state}->[CMD_PRI];
877  
878 0 ▶ if (defined $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) 0 0 0
879 0 warn "The '$state' event takes no arguments\n";
880 0 return;
881 }
882  
883 0 $state = uc $state;
884 0 $kernel->yield(sl_prioritized => $pri, $state);
885 0 return;
886 }
887  
888 # The handler for commands that take one required and two optional arguments.
889 0 ▶sub oneandtwoopt {
Subroutine oneandtwoopt: not called CC=4 SCAR=30.0
Pod undocumented
890 0 my ($kernel, $state) = @_[KERNEL, STATE];
891 0 my $arg = join '', @_[ARG0 .. $#_];
892 0 my $pri = $_[OBJECT]->{IRC_CMDS}->{$state}->[CMD_PRI];
893  
894 0 ▶ $state = 'connect' if $state eq 'sconnect';
Branch: 1 branch
BranchTrueFalseTotal
if $state eq "sconnect" 0 0 0
895 0 $state = uc $state;
896 0 ▶ if (defined $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) 0 0 0
897 0 ▶ $arg = ':' . $arg if $arg =~ /\x20/;
Branch: 1 branch
BranchTrueFalseTotal
if $arg =~ /\x20/ 0 0 0
898 0 $state .= " $arg";
899 }
900  
901 0 $kernel->yield(sl_prioritized => $pri, $state);
902 0 return;
903 }
904  
905 # The handler for commands that take at least one optional argument.
906 154 ▶sub oneoptarg {
Subroutine oneoptarg: called CC=3 SCAR=11.0
Pod undocumented
907 154 my ($kernel, $state) = @_[KERNEL, STATE];
908 154 my $pri = $_[OBJECT]->{IRC_CMDS}->{$state}->[CMD_PRI];
909 154 $state = uc $state;
910  
911 154 ▶ if (defined $_[ARG0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[10]) 54 100 154
912 54 my $arg = join '', @_[ARG0 .. $#_];
913 54 ▶ $arg = ':' . $arg if $arg =~ /\x20/;
Branch: 1 branch
BranchTrueFalseTotal
if $arg =~ /\x20/ 3 51 54
914 54 $state .= " $arg";
915 }
916  
917 154 $kernel->yield(sl_prioritized => $pri, $state);
918 154 return;
919 }
920  
921 # The handler for commands which take one required and one optional argument.
922 87 ▶sub oneortwo {
Subroutine oneortwo: called CC=3 SCAR=11.7
Pod undocumented
923 87 my ($kernel, $state, $one) = @_[KERNEL, STATE, ARG0];
924 87 my $two = join '', @_[ARG1 .. $#_];
925 87 my $pri = $_[OBJECT]->{IRC_CMDS}->{$state}->[CMD_PRI];
926  
927 87 ▶ if (!defined $one) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $one) 0 87 87
928 0 warn "The '$state' event requires at least one argument\n";
929 0 return;
930 }
931  
932 87 $state = uc( $state ) . " $one";
933 87 ▶ $state .= " $two" if defined $two;
Branch: 1 branch
BranchTrueFalseTotal
if defined $two 87 0 87
934 87 $kernel->yield(sl_prioritized => $pri, $state);
935 87 return;
936 }
937  
938 # Handler for commands that take exactly one argument.
939 9 ▶sub onlyonearg {
Subroutine onlyonearg: called CC=3 SCAR=11.5
Pod undocumented
940 9 my ($kernel, $state) = @_[KERNEL, STATE];
941 9 my $arg = join '', @_[ARG0 .. $#_];
942 9 my $pri = $_[OBJECT]->{IRC_CMDS}->{$state}->[CMD_PRI];
943  
944 9 ▶ if (!defined $arg) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $arg) 0 9 9
945 0 warn "The '$state' event requires one argument\n";
946 0 return;
947 }
948  
949 9 $state = uc $state;
950 9 ▶ $arg = ':' . $arg if $arg =~ /\x20/;
Branch: 1 branch
BranchTrueFalseTotal
if $arg =~ /\x20/ 0 9 9
951 9 $state .= " $arg";
952 9 $kernel->yield(sl_prioritized => $pri, $state);
953 9 return;
954 }
955  
956 # Handler for commands that take exactly two arguments.
957 1 ▶sub onlytwoargs {
Subroutine onlytwoargs: called CC=4 SCAR=15.2
Pod undocumented
958 1 my ($kernel, $state, $one) = @_[KERNEL, STATE, ARG0];
959 1 my ($two) = join '', @_[ARG1 .. $#_];
960 1 my $pri = $_[OBJECT]->{IRC_CMDS}->{$state}->[CMD_PRI];
961  
962 1 ▶ if (!defined $one || !defined $two) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $one and defined $two) 0 1 1
Condition33%1/3
defined $one and defined $two
!ll&&!rl&&r
001
MC/DC0%0/2
defined $one and defined $two
defined $one defined $two
Truth table33%1/3
A and B
A= defined $oneB= defined $two
ABresult
0X0
100
111
963 0 warn "The '$state' event requires two arguments\n";
964 0 return;
965 }
966  
967 1 $state = uc $state;
968 1 ▶ $two = ':' . $two if $two =~ /\x20/;
Branch: 1 branch
BranchTrueFalseTotal
if $two =~ /\x20/ 0 1 1
969 1 $state .= " $one $two";
970 1 $kernel->yield(sl_prioritized => $pri, $state);
971 1 return;
972 }
973  
974 # Handler for privmsg or notice events.
975 93 ▶sub privandnotice {
Subroutine privandnotice: called CC=4 SCAR=14.5
Pod undocumented
976 93 my ($kernel, $state, $to, $msg) = @_[KERNEL, STATE, ARG0, ARG1];
977 93 my $pri = $_[OBJECT]->{IRC_CMDS}->{$state}->[CMD_PRI];
978  
979 93 $state =~ s/privmsglo/privmsg/;
980 93 $state =~ s/privmsghi/privmsg/;
981 93 $state =~ s/noticelo/notice/;
982 93 $state =~ s/noticehi/notice/;
983  
984 93 ▶ if (!defined $to || !defined $msg) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $to and defined $msg) 0 93 93
Condition33%1/3
defined $to and defined $msg
!ll&&!rl&&r
0093
MC/DC0%0/2
defined $to and defined $msg
defined $to defined $msg
Truth table33%1/3
A and B
A= defined $toB= defined $msg
ABresult
0X0
100
111
985 0 warn "The '$state' event requires two arguments\n";
986 0 return;
987 }
988  
989 93 ▶ $to = join ',', @$to if ref $to eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $to eq "ARRAY" 3 90 93
990 93 $state = uc $state;
991  
992 93 $kernel->yield(sl_prioritized => $pri, "$state $to :$msg");
993 93 return;
994 }
995  
996 # Tell the IRC session to go away.
997 116 ▶sub shutdown {
Subroutine shutdown: called CC=7 SCAR=19.9
Pod documented
998 116 my ($kernel, $self, $sender, $session) = @_[KERNEL, OBJECT, SENDER, SESSION];
999 116 ▶ return if $self->{_shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_shutdown"} 1 115 116
1000 115 $self->{_shutdown} = $sender->ID();
1001  
1002 115 ▶ if ($self->logged_in()) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->logged_in) { } 2 113 115
elsif ($self->connected) { } 0 113 113
1003 2 my ($msg, $timeout) = @_[ARG0, ARG1];
1004 2 ▶ $msg = '' if !defined $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $msg 2 0 2
1005 2 ▶ $timeout = 5 if !defined $timeout;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timeout 2 0 2
1006 2 ▶ $msg = ":$msg" if $msg =~ /\x20/;
Branch: 1 branch
BranchTrueFalseTotal
if $msg =~ /\x20/ 0 2 2
1007 2 my $cmd = "QUIT $msg";
1008 2 $kernel->call($session => sl_high => $cmd);
1009 2 $kernel->delay('_quit_timeout', $timeout);
1010 2 $self->{_waiting} = 1;
1011 }
1012 elsif ($self->connected()) {
1013 0 $self->disconnect();
1014 }
1015 else {
1016 113 $self->_shutdown();
1017 }
1018  
1019 115 return;
1020 }
1021  
1022 0 ▶sub _quit_timeout {
Subroutine _quit_timeout: not called CC=1 SCAR=6.9
1023 0 my ($self) = $_[OBJECT];
1024 0 $self->disconnect();
1025 0 return;
1026 }
1027  
1028 115 ▶sub _shutdown {
Subroutine _shutdown: called CC=4 SCAR=13.9
1029 115 my ($self) = @_;
1030  
1031 115 $self->_syndicator_destroy($self->{_shutdown});
1032 115 delete $self->{$_} for qw(socketfactory dcc wheelmap);
1033 115 ▶ $self->{resolver}->shutdown() if $self->{resolver} && $self->{mydns};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"resolver"} and $self->{"mydns"} 114 1 115
Condition66%2/3
$self->{"resolver"} and $self->{"mydns"}
!ll&&!rl&&r
01114
MC/DC50%1/2
$self->{"resolver"} and $self->{"mydns"}
$self->{"resolver"} $self->{"mydns"}
Truth table66%2/3
A and B
A= $self->{"resolver"}B= $self->{"mydns"}
ABresult
0X0
100
111
1034 115 return;
1035 }
1036  
1037 # Send a line of login-priority IRC output. These are things which
1038 # must go first.
1039 547 ▶sub sl_login {
Subroutine sl_login: called CC=1 SCAR=0.0
Pod undocumented
1040 547 my ($kernel, $self) = @_[KERNEL, OBJECT];
1041 547 my $arg = join ' ', @_[ARG0 .. $#_];
1042 547 $kernel->yield(sl_prioritized => PRI_LOGIN, $arg );
1043 547 return;
1044 }
1045  
1046 # Send a line of high-priority IRC output. Things like channel/user
1047 # modes, kick messages, and whatever.
1048 8 ▶sub sl_high {
Subroutine sl_high: called CC=1 SCAR=0.0
Pod undocumented
1049 8 my ($kernel, $self) = @_[KERNEL, OBJECT];
1050 8 my $arg = join ' ', @_[ARG0 .. $#_];
1051 8 $kernel->yield(sl_prioritized => PRI_HIGH, $arg );
1052 8 return;
1053 }
1054  
1055 # Send a line of normal-priority IRC output to the server. PRIVMSG
1056 # and other random chatter. Uses sl() for compatibility with existing
1057 # code.
1058 5 ▶sub sl {
Subroutine sl: called CC=1 SCAR=0.0
Pod undocumented
1059 5 my ($kernel, $self) = @_[KERNEL, OBJECT];
1060 5 my $arg = join ' ', @_[ARG0 .. $#_];
1061 5 $kernel->yield(sl_prioritized => PRI_NORMAL, $arg );
1062 5 return;
1063 }
1064  
1065 # Prioritized sl(). This keeps the queue ordered by priority, low to
1066 # high in the UNIX tradition. It also throttles transmission
1067 # following the hybrid ircd's algorithm, so you can't accidentally
1068 # flood yourself off. Thanks to Raistlin for explaining how ircd
1069 # throttles messages.
1070 1040 ▶sub sl_prioritized {
Subroutine sl_prioritized: called CC=14 SCAR=30.4
Pod undocumented
1071 1040 my ($kernel, $self, $priority, @args) = @_[KERNEL, OBJECT, ARG0, ARG1];
1072  
1073 1040 ▶ if (my ($event) = $args[0] =~ /^(\w+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($event) = $args[0] =~ /^(\w+)/) { } 1040 0 1040
1074 # Let the plugin system process this
1075 1040 ▶ return 1 if $self->send_user_event($event, \@args) == PCI_EAT_ALL;
Branch: 1 branch
BranchTrueFalseTotal
if $self->send_user_event($event, \@args) == 4 0 1040 1040
1076 }
1077 else {
1078 0 warn "Unable to extract the event name from '$args[0]'\n";
1079 }
1080  
1081 1040 my $msg = $args[0];
1082 1040 my $now = time();
1083 1040 ▶ $self->{send_time} = $now if $self->{send_time} < $now;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"send_time"} < $now 92 948 1040
1084  
1085 # if we find a newline in the message, take that to be the end of it
1086 1040 $msg =~ s/[\015\012].*//s;
1087  
1088 1040 ▶ if (bytes::length($msg) > $self->{msg_length} - bytes::length($self->nick_name())) {
Branch: 1 branch
BranchTrueFalseTotal
if (&bytes::length($msg) > $self->{"msg_length"} - &bytes::length(scalar $self->nick_name)) 0 1040 1040
1089 0 $msg = bytes::substr($msg, 0, $self->{msg_length} - bytes::length($self->nick_name()));
1090 }
1091  
1092 1040 ▶ if (!$self->{flood} && @{ $self->{send_queue} }) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->{'flood'} and @{$self->{'send_queue'};}) { } 0 1040 1040
elsif (not $self->{'flood'} and $self->{'send_time'} - $now >= 10 or not defined $self->{'socket'}) { } 5 1035 1040
Condition66%2/3
not $self->{"flood"} and @{$self->{"send_queue"};}
!ll&&!rl&&r
1026140
MC/DC0%0/2
not $self->{"flood"} and @{$self->{"send_queue"};}
not $self->{"flood"} @{$self->{"send_queue"};}
Truth table66%2/3
not(A) and B
A= not $self->{"flood"}B= @{$self->{"send_queue"};}
ABresult
0X0
100
111
1093 0 my $i = @{ $self->{send_queue} };
1094 0 ▶ $i-- while ($i && $priority < $self->{send_queue}->[$i-1]->[MSG_PRI]);
Branch: 1 branch
BranchTrueFalseTotal
$i and $priority < $self->{"send_queue"}[$i - 1][0] and do { --$i } 0 0 0
Condition0%0/3
$i and $priority < $self->{"send_queue"}[$i - 1][0]
!ll&&!rl&&r
000
MC/DC0%0/2
$i and $priority < $self->{"send_queue"}[$i - 1][0]
$i $priority < $self->{"send_queue"}[$i - 1][0]
Truth table0%0/3
A and B
A= $iB= $priority < $self->{"send_queue"}[$i - 1][0]
ABresult
0X0
100
111
1095 0 splice( @{ $self->{send_queue} }, $i, 0, [ $priority, $msg ] );
1096 }
1097 ▶ elsif ( !$self->{flood} && $self->{send_time} - $now >= 10
Condition100%6/6
not $self->{"flood"} and $self->{"send_time"} - $now >= 10 or not defined $self->{"socket"}
l!l&&r!l&&!r
411035
not $self->{"flood"} and $self->{"send_time"} - $now >= 10
!ll&&!rl&&r
1026104
MC/DC100%3/3
not $self->{"flood"} and $self->{"send_time"} - $now >= 10 or not defined $self->{"socket"}
not $self->{"flood"} $self->{"send_time"} - $now >= 10 not defined $self->{"socket"}
Truth table80%4/5
not(A) and B or not(C)
A= not $self->{"flood"}B= $self->{"send_time"} - $now >= 10C= not defined $self->{"socket"}
ABCresult
11X1
0X11
1011
0X00
1000
1098 || !defined $self->{socket} ) {
1099 5 push( @{$self->{send_queue}}, [ $priority, $msg ] );
1100 5 $kernel->delay( sl_delayed => $self->{send_time} - $now - 10 );
1101 }
1102 else {
1103 1035 ▶ warn ">>> $msg\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 1035 1035
1104 1035 ▶ $self->send_event(irc_raw_out => $msg) if $self->{raw};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"raw"} 39 996 1035
1105 1035 $self->{send_time} += 2 + length($msg) / 120;
1106 1035 $self->{socket}->put($msg);
1107 }
1108  
1109 1040 return;
1110 }
1111  
1112 # Send delayed lines to the ircd. We manage a virtual "send time"
1113 # that progresses into the future based on hybrid ircd's rules every
1114 # time a message is sent. Once we find it ten or more seconds into
1115 # the future, we wait for the realtime clock to catch up.
1116 96 ▶sub sl_delayed {
Subroutine sl_delayed: called CC=8 SCAR=20.9
Pod undocumented
1117 96 my ($kernel, $self) = @_[KERNEL, OBJECT];
1118  
1119 96 ▶ return if !defined $self->{socket};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"socket"} 1 95 96
1120  
1121 95 my $now = time();
1122 95 ▶ $self->{send_time} = $now if $self->{send_time} < $now;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"send_time"} < $now 0 95 95
1123  
1124 95 ▶ while (@{ $self->{send_queue} } && ($self->{send_time} - $now < 10)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"send_queue"};} and $self->{"send_time"} - $now < 10) 4 95 99
Condition100%3/3
@{$self->{"send_queue"};} and $self->{"send_time"} - $now < 10
!ll&&!rl&&r
9324
MC/DC100%2/2
@{$self->{"send_queue"};} and $self->{"send_time"} - $now < 10
@{$self->{"send_queue"};} $self->{"send_time"} - $now < 10
Truth table100%3/3
A and B
A= @{$self->{"send_queue"};}B= $self->{"send_time"} - $now < 10
ABresult
0X0
100
111
1125 4 my $arg = (shift @{$self->{send_queue}})->[MSG_TEXT];
1126 4 ▶ warn ">>> $arg\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 4 4
1127 4 ▶ $self->send_event(irc_raw_out => $arg) if $self->{raw};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"raw"} 0 4 4
1128 4 $self->{send_time} += 2 + length($arg) / 120;
1129 4 $self->{socket}->put($arg);
1130 }
1131  
1132 95 ▶ if (@{ $self->{send_queue} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"send_queue"};}) 2 93 95
1133 2 $kernel->delay( sl_delayed => $self->{send_time} - $now - 10 );
1134 }
1135  
1136 95 return;
1137 }
1138  
1139 # The handler for commands which have N arguments, separated by spaces.
1140 121 ▶sub spacesep {
Subroutine spacesep: called CC=2 SCAR=7.0
Pod undocumented
1141 121 my ($kernel, $state) = @_[KERNEL, STATE];
1142 121 my $args = join ' ', @_[ARG0 .. $#_];
1143 121 my $pri = $_[OBJECT]->{IRC_CMDS}->{$state}->[CMD_PRI];
1144  
1145 121 $state = uc $state;
1146 121 ▶ $state .= " $args" if defined $args;
Branch: 1 branch
BranchTrueFalseTotal
if defined $args 121 0 121
1147 121 $kernel->yield(sl_prioritized => $pri, $state );
1148 121 return;
1149 }
1150  
1151 # Set or query the current topic on a channel.
1152 6 ▶sub topic {
Subroutine topic: called CC=4 SCAR=13.9
Pod documented
1153 6 my ($kernel, $chan, @args) = @_[KERNEL, ARG0..$#_];
1154 6 my $topic;
1155 6 ▶ $topic = join '', @args if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 5 1 6
1156  
1157 6 ▶ if (defined $topic) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $topic) 5 1 6
1158 5 $chan .= " :";
1159 5 ▶ $chan .= $topic if length $topic;
Branch: 1 branch
BranchTrueFalseTotal
if length $topic 5 0 5
1160 }
1161  
1162 6 $kernel->yield(sl_prioritized => PRI_NORMAL, "TOPIC $chan");
1163 6 return;
1164 }
1165  
1166 # Asks the IRC server for some random information about particular nicks.
1167 0 ▶sub userhost {
Subroutine userhost: not called CC=3 SCAR=24.8
Pod documented
1168 0 my ($kernel, @nicks) = @_[KERNEL, ARG0 .. $#_];
1169  
1170 0 ▶ if (!@nicks) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@nicks) 0 0 0
1171 0 warn "The 'userhost' event requires at least one nickname\n";
1172 0 return;
1173 }
1174  
1175 # According to the RFC, you can only send 5 nicks at a time.
1176 0 ▶ while (@nicks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@nicks) 0 0 0
1177 0 $kernel->yield(
1178 'sl_prioritized',
1179 PRI_HIGH,
1180 'USERHOST ' . join(' ', splice(@nicks, 0, 5)),
1181 );
1182 }
1183  
1184 0 return;
1185 }
1186  
1187 # Non-event methods
1188  
1189 0 ▶sub server {
Subroutine server: not called CC=1 SCAR=6.9
Pod documented
1190 0 my ($self) = @_;
1191 0 return $self->{server};
1192 }
1193  
1194 0 ▶sub port {
Subroutine port: not called CC=1 SCAR=6.9
Pod documented
1195 0 my ($self) = @_;
1196 0 return $self->{port};
1197 }
1198  
1199 7 ▶sub server_name {
Subroutine server_name: called CC=1 SCAR=0.0
Pod documented
1200 7 my ($self) = @_;
1201 7 return $self->{INFO}{ServerName};
1202 }
1203  
1204 0 ▶sub server_version {
Subroutine server_version: not called CC=1 SCAR=6.9
Pod documented
1205 0 my ($self) = @_;
1206 0 return $self->{INFO}{ServerVersion};
1207 }
1208  
1209 8 ▶sub localaddr {
Subroutine localaddr: called CC=1 SCAR=0.0
Pod documented
1210 8 my ($self) = @_;
1211 8 return $self->{localaddr};
1212 }
1213  
1214 1776 ▶sub nick_name {
Subroutine nick_name: called CC=1 SCAR=0.0
Pod documented
1215 1776 my ($self) = @_;
1216 1776 return $self->{INFO}{RealNick};
1217 }
1218  
1219 0 ▶sub send_queue {
Subroutine send_queue: not called CC=3 SCAR=24.8
Pod documented
1220 0 my ($self) = @_;
1221  
1222 0 ▶ if (defined $self->{send_queue} && ref $self->{send_queue} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"send_queue"} and ref $self->{"send_queue"} eq "ARRAY") 0 0 0
Condition0%0/3
defined $self->{"send_queue"} and ref $self->{"send_queue"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"send_queue"} and ref $self->{"send_queue"} eq "ARRAY"
defined $self->{"send_queue"} ref $self->{"send_queue"} eq "ARRAY"
Truth table0%0/3
A and B
A= defined $self->{"send_queue"}B= ref $self->{"send_queue"} eq "ARRAY"
ABresult
0X0
100
111
1223 0 return scalar @{ $self->{send_queue} };
1224 }
1225 0 return;
1226 }
1227  
1228 4 ▶sub raw_events {
Subroutine raw_events: called CC=2 SCAR=7.0
Pod documented
1229 4 my ($self, $value) = @_;
1230 4 ▶ return $self->{raw} if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 4 4
1231 4 $self->{raw} = $value;
1232 4 return;
1233 }
1234  
1235 117 ▶sub connected {
Subroutine connected: called CC=1 SCAR=0.0
Pod documented
1236 117 my ($self) = @_;
1237 117 return $self->{connected};
1238 }
1239  
1240 120 ▶sub logged_in {
Subroutine logged_in: called CC=2 SCAR=6.9
Pod documented
1241 120 my ($self) = @_;
1242 120 ▶ return 1 if $self->{INFO}{LoggedIn};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"INFO"}{"LoggedIn"} 4 116 120
1243 116 return;
1244 }
1245  
1246 91 ▶sub _compress_uplink {
Subroutine _compress_uplink: called CC=6 SCAR=33.1
1247 91 my ($self, $value) = @_;
1248  
1249 91 ▶ return if !$GOT_ZLIB;
Branch: 1 branch
BranchTrueFalseTotal
unless $POE::Component::IRC::GOT_ZLIB 91 0 91
1250 0 ▶ return $self->{uplink} if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
1251  
1252 0 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 0 0 0
1253 0 ▶ $self->{out_filter}->unshift( POE::Filter::Zlib::Stream->new() ) if !$self->{uplink};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"uplink"} 0 0 0
1254 0 $self->{uplink} = 1;
1255 }
1256 else {
1257 0 ▶ $self->{out_filter}->shift() if $self->{uplink};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"uplink"} 0 0 0
1258 0 $self->{uplink} = 0;
1259 }
1260  
1261 0 return $self->{uplink};
1262 }
1263  
1264 91 ▶sub _compress_downlink {
Subroutine _compress_downlink: called CC=6 SCAR=33.1
1265 91 my ($self, $value) = @_;
1266  
1267 91 ▶ return if !$GOT_ZLIB;
Branch: 1 branch
BranchTrueFalseTotal
unless $POE::Component::IRC::GOT_ZLIB 91 0 91
1268 0 ▶ return $self->{downlink} if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
1269  
1270 0 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 0 0 0
1271 0 ▶ $self->{srv_filter}->unshift( POE::Filter::Zlib::Stream->new() ) if !$self->{downlink};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"downlink"} 0 0 0
1272 0 $self->{downlink} = 1;
1273 }
1274 else {
1275 0 ▶ $self->{srv_filter}->shift() if $self->{uplink};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"uplink"} 0 0 0
1276 0 $self->{downlink} = 0;
1277 }
1278  
1279 0 return $self->{downlink};
1280 }
1281  
1282 91 ▶sub S_001 {
Subroutine S_001: called CC=1 SCAR=0.0
Pod undocumented
1283 91 my ($self, $irc) = splice @_, 0, 2;
1284 91 $self->{INFO}{ServerName} = ${ $_[0] };
1285 91 $self->{INFO}{LoggedIn} = 1;
1286 91 return PCI_EAT_NONE;
1287 }
1288  
1289 90 ▶sub S_004 {
Subroutine S_004: called CC=1 SCAR=0.0
Pod undocumented
1290 90 my ($self, $irc) = splice @_, 0, 2;
1291 90 my $args = ${ $_[2] };
1292 90 $self->{INFO}{ServerVersion} = $args->[1];
1293 90 return PCI_EAT_NONE;
1294 }
1295  
1296 93 ▶sub S_error {
Subroutine S_error: called CC=1 SCAR=0.0
Pod undocumented
1297 93 my ($self, $irc) = splice @_, 0, 2;
1298 93 $self->{INFO}{LoggedIn} = 0;
1299 93 return PCI_EAT_NONE;
1300 }
1301  
1302 91 ▶sub S_disconnected {
Subroutine S_disconnected: called CC=3 SCAR=11.0
Pod undocumented
1303 91 my ($self, $irc) = splice @_, 0, 2;
1304 91 $self->{INFO}{LoggedIn} = 0;
1305  
1306 91 ▶ if ($self->{_waiting}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_waiting"}) 2 89 91
1307 2 $poe_kernel->delay('_quit_timeout');
1308 2 delete $self->{_waiting};
1309 }
1310  
1311 91 ▶ $self->_shutdown() if $self->{_shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_shutdown"} 2 89 91
1312 91 return PCI_EAT_NONE;
1313 }
1314  
1315 115 ▶sub S_shutdown {
Subroutine S_shutdown: called CC=1 SCAR=0.0
Pod undocumented
1316 115 my ($self, $irc) = splice @_, 0, 2;
1317 115 $self->{INFO}{LoggedIn} = 0;
1318 115 return PCI_EAT_NONE;
1319 }
1320  
1321 # Automatically replies to a PING from the server. Do not confuse this
1322 # with CTCP PINGs, which are a wholly different animal that evolved
1323 # much later on the technological timeline.
1324 0 ▶sub S_ping {
Subroutine S_ping: not called CC=1 SCAR=6.9
Pod undocumented
1325 0 my ($self, $irc) = splice @_, 0, 2;
1326 0 my $arg = ${ $_[0] };
1327 0 $irc->yield(sl_login => "PONG :$arg");
1328 0 return PCI_EAT_NONE;
1329 }
1330  
1331 # NICK messages for the purposes of determining our current nickname
1332 10 ▶sub S_nick {
Subroutine S_nick: called CC=2 SCAR=6.9
Pod undocumented
1333 10 my ($self, $irc) = splice @_, 0, 2;
1334 10 my $nick = ( split /!/, ${ $_[0] } )[0];
1335 10 my $new = ${ $_[1] };
1336 10 ▶ $self->{INFO}{RealNick} = $new if ( $nick eq $self->{INFO}{RealNick} );
Branch: 1 branch
BranchTrueFalseTotal
if $nick eq $self->{"INFO"}{"RealNick"} 6 4 10
1337 10 return PCI_EAT_NONE;
1338 }
1339  
1340 # tell POE::Filter::IRC::Compat to handle IDENTIFY-MSG
1341 0 ▶sub S_290 {
Subroutine S_290: not called CC=2 SCAR=17.9
Pod undocumented
1342 0 my ($self, $irc) = splice @_, 0, 2;
1343 0 my $text = ${ $_[1] };
1344 0 ▶ $self->{ircd_compat}->identifymsg(1) if $text eq 'IDENTIFY-MSG';
Branch: 1 branch
BranchTrueFalseTotal
if $text eq "IDENTIFY-MSG" 0 0 0
1345 0 return PCI_EAT_NONE;
1346 }
1347  
1348 3 ▶sub S_cap {
Subroutine S_cap: called CC=5 SCAR=16.8
Pod undocumented
1349 3 my ($self, $irc) = splice @_, 0, 2;
1350 3 my $cmd = ${ $_[0] };
1351  
1352 3 ▶ if ($cmd eq 'ACK') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "ACK") 1 2 3
1353 0 ▶ my $list = ${ $_[1] } eq '*' ? ${ $_[2] } : ${ $_[1] };
Branch: 1 branch
BranchTrueFalseTotal
${$_[1];} eq '*' ? : 0 1 1
1354 1 my @enabled = split / /, $list;
1355  
1356 1 ▶ if (grep { $_ =~ /^=?identify-msg$/ } @enabled) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ =~ /^=?identify-msg$/;} @enabled) 0 1 1
1357 0 $self->{ircd_compat}->identifymsg(1);
1358 }
1359 1 ▶ if (grep { $_ =~ /^-identify-msg$/ } @enabled) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ =~ /^-identify-msg$/;} @enabled) 0 1 1
1360 0 $self->{ircd_compat}->identifymsg(0);
1361 }
1362 }
1363 3 return PCI_EAT_NONE;
1364 }
1365  
1366 90 ▶sub S_isupport {
Subroutine S_isupport: called CC=5 SCAR=16.8
Pod undocumented
1367 90 my ($self, $irc) = splice @_, 0, 2;
1368 90 my $isupport = ${ $_[0] };
1369 90 ▶ $self->{ircd_compat}->chantypes( $isupport->isupport('CHANTYPES') || [ '#', '&' ] );
Condition50%1/2
$isupport->isupport('CHANTYPES') || ['#', '&']
l!l
900
MC/DC0%0/1
$isupport->isupport('CHANTYPES') || ['#', '&']
$isupport->isupport('CHANTYPES')
Truth table50%1/2
A
A= $isupport->isupport('CHANTYPES')
Aresult
11
00
1370 90 ▶ $irc->yield(sl_login => 'CAPAB IDENTIFY-MSG') if $isupport->isupport('CAPAB');
Branch: 1 branch
BranchTrueFalseTotal
if $isupport->isupport("CAPAB") 0 90 90
1371 90 ▶ $irc->yield(sl_login => 'PROTOCTL NAMESX') if $isupport->isupport('NAMESX');
Branch: 1 branch
BranchTrueFalseTotal
if $isupport->isupport("NAMESX") 0 90 90
1372 90 ▶ $irc->yield(sl_login => 'PROTOCTL UHNAMES') if $isupport->isupport('UHNAMES');
Branch: 1 branch
BranchTrueFalseTotal
if $isupport->isupport("UHNAMES") 0 90 90
1373 90 return PCI_EAT_NONE;
1374 }
1375  
1376 # accesses the ISupport plugin
1377 1682 ▶sub isupport {
Subroutine isupport: called CC=1 SCAR=0.0
Pod documented
1378 1682 my ($self, @args) = @_;
1379 1682 return $self->{isupport}->isupport(@args);
1380 }
1381  
1382 0 ▶sub isupport_dump_keys {
Subroutine isupport_dump_keys: not called CC=1 SCAR=6.9
Pod documented
1383 0 return $_[0]->{isupport}->isupport_dump_keys();
1384 }
1385  
1386 2 ▶sub resolver {
Subroutine resolver: called CC=1 SCAR=0.0
Pod documented
1387 2 return $_[0]->{resolver};
1388 }
1389  
1390 92 ▶sub _ip_get_version {
Subroutine _ip_get_version: called CC=5 SCAR=17.2
1391 92 my ($ip) = @_;
1392 92 ▶ return if !defined $ip;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip 0 92 92
1393  
1394 # If the address does not contain any ':', maybe it's IPv4
1395 92 ▶ return 4 if $ip !~ /:/ && _ip_is_ipv4($ip);
Branch: 1 branch
BranchTrueFalseTotal
if not $ip =~ /:/ and _ip_is_ipv4($ip) 91 1 92
Condition66%2/3
not $ip =~ /:/ and _ip_is_ipv4($ip)
!ll&&!rl&&r
1091
MC/DC50%1/2
not $ip =~ /:/ and _ip_is_ipv4($ip)
not $ip =~ /:/ _ip_is_ipv4($ip)
Truth table66%2/3
not(A) and B
A= not $ip =~ /:/B= _ip_is_ipv4($ip)
ABresult
0X0
100
111
1396  
1397 # Is it IPv6 ?
1398 1 ▶ return 6 if _ip_is_ipv6($ip);
Branch: 1 branch
BranchTrueFalseTotal
if _ip_is_ipv6($ip) 1 0 1
1399  
1400 0 return;
1401 }
1402  
1403 91 ▶sub _ip_is_ipv4 {
Subroutine _ip_is_ipv4: called CC=13 SCAR=31.0
1404 91 my ($ip) = @_;
1405 91 ▶ return if !defined $ip;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip 0 91 91
1406  
1407 # Check for invalid chars
1408 91 ▶ return if $ip !~ /^[\d\.]+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $ip =~ /^[\d\.]+$/ 0 91 91
1409 91 ▶ return if $ip =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $ip =~ /^\./ 0 91 91
1410 91 ▶ return if $ip =~ /\.$/;
Branch: 1 branch
BranchTrueFalseTotal
if $ip =~ /\.$/ 0 91 91
1411  
1412 # Single Numbers are considered to be IPv4
1413 91 ▶ return 1 if $ip =~ /^(\d+)$/ && $1 < 256;
Branch: 1 branch
BranchTrueFalseTotal
if $ip =~ /^(\d+)$/ and $1 < 256 0 91 91
Condition33%1/3
$ip =~ /^(\d+)$/ and $1 < 256
!ll&&!rl&&r
9100
MC/DC0%0/2
$ip =~ /^(\d+)$/ and $1 < 256
$ip =~ /^(\d+)$/ $1 < 256
Truth table33%1/3
A and B
A= $ip =~ /^(\d+)$/B= $1 < 256
ABresult
0X0
100
111
1414  
1415 # Count quads
1416 91 my $n = ($ip =~ tr/\./\./);
1417  
1418 # IPv4 must have from 1 to 4 quads
1419 91 ▶ return if $n <= 0 || $n > 4;
Branch: 1 branch
BranchTrueFalseTotal
if $n <= 0 or $n > 4 0 91 91
Condition33%1/3
$n <= 0 or $n > 4
l!l&&r!l&&!r
0091
MC/DC0%0/2
$n <= 0 or $n > 4
$n <= 0 $n > 4
Truth table33%1/3
A or B
A= $n <= 0B= $n > 4
ABresult
1X1
011
000
1420  
1421 # Check for empty quads
1422 91 ▶ return if $ip =~ /\.\./;
Branch: 1 branch
BranchTrueFalseTotal
if $ip =~ /\.\./ 0 91 91
1423  
1424 91 for my $quad (split /\./, $ip) {
1425 # Check for invalid quads
1426 364 ▶ return if $quad < 0 || $quad >= 256;
Branch: 1 branch
BranchTrueFalseTotal
if $quad < 0 or $quad >= 256 0 364 364
Condition33%1/3
$quad < 0 or $quad >= 256
l!l&&r!l&&!r
00364
MC/DC0%0/2
$quad < 0 or $quad >= 256
$quad < 0 $quad >= 256
Truth table33%1/3
A or B
A= $quad < 0B= $quad >= 256
ABresult
1X1
011
000
1427 }
1428 91 return 1;
1429 }
1430  
1431 93 ▶sub _ip_is_ipv6 {
Subroutine _ip_is_ipv6: called CC=12 SCAR=29.0
1432 93 my ($ip) = @_;
1433 93 ▶ return if !defined $ip;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip 0 93 93
1434  
1435 # Count octets
1436 93 my $n = ($ip =~ tr/:/:/);
1437 93 ▶ return if ($n <= 0 || $n >= 8);
Branch: 1 branch
BranchTrueFalseTotal
if $n <= 0 or $n >= 8 91 2 93
Condition66%2/3
$n <= 0 or $n >= 8
l!l&&r!l&&!r
9102
MC/DC50%1/2
$n <= 0 or $n >= 8
$n <= 0 $n >= 8
Truth table66%2/3
A or B
A= $n <= 0B= $n >= 8
ABresult
1X1
011
000
1438  
1439 # $k is a counter
1440 2 my $k;
1441  
1442 2 for my $octet (split /:/, $ip) {
1443 6 $k++;
1444  
1445 # Empty octet ?
1446 6 ▶ next if $octet eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $octet eq "" 4 2 6
1447  
1448 # Normal v6 octet ?
1449 2 ▶ next if $octet =~ /^[a-f\d]{1,4}$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $octet =~ /^[a-f\d]{1,4}$/i 2 0 2
1450  
1451 # Last octet - is it IPv4 ?
1452 0 ▶ if ($k == $n + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k == $n + 1) 0 0 0
1453 0 ▶ next if (ip_is_ipv4($octet));
Branch: 1 branch
BranchTrueFalseTotal
if ip_is_ipv4($octet) 0 0 0
1454 }
1455  
1456 0 return;
1457 }
1458  
1459 # Does the IP address start with : ?
1460 2 ▶ return if $ip =~ m/^:[^:]/;
Branch: 1 branch
BranchTrueFalseTotal
if $ip =~ /^:[^:]/ 0 2 2
1461  
1462 # Does the IP address finish with : ?
1463 2 ▶ return if $ip =~ m/[^:]:$/;
Branch: 1 branch
BranchTrueFalseTotal
if $ip =~ /[^:]:$/ 0 2 2
1464  
1465 # Does the IP address have more than one '::' pattern ?
1466 2 ▶ return if $ip =~ s/:(?=:)//g > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $ip =~ s/:(?=:)//g > 1 0 2 2
1467  
1468 2 return 1;
1469 }
1470  
1471 79 1;
1472  
1473 =encoding utf8
1474  
1475 =head1 NAME
1476  
1477 POE::Component::IRC - A fully event-driven IRC client module
1478  
1479 =head1 SYNOPSIS
1480  
1481 # A simple Rot13 'encryption' bot
1482  
1483 use strict;
1484 use warnings;
1485 use POE qw(Component::IRC);
1486  
1487 my $nickname = 'Flibble' . $$;
1488 my $ircname = 'Flibble the Sailor Bot';
1489 my $server = 'irc.perl.org';
1490  
1491 my @channels = ('#Blah', '#Foo', '#Bar');
1492  
1493 # We create a new PoCo-IRC object
1494 my $irc = POE::Component::IRC->spawn(
1495 nick => $nickname,
1496 ircname => $ircname,
1497 server => $server,
1498 ) or die "Oh noooo! $!";
1499  
1500 POE::Session->create(
1501 package_states => [
1502 main => [ qw(_default _start irc_001 irc_public) ],
1503 ],
1504 heap => { irc => $irc },
1505 );
1506  
1507 $poe_kernel->run();
1508  
1509 sub _start {
1510 my $heap = $_[HEAP];
1511  
1512 # retrieve our component's object from the heap where we stashed it
1513 my $irc = $heap->{irc};
1514  
1515 $irc->yield( register => 'all' );
1516 $irc->yield( connect => { } );
1517 return;
1518 }
1519  
1520 sub irc_001 {
1521 my $sender = $_[SENDER];
1522  
1523 # Since this is an irc_* event, we can get the component's object by
1524 # accessing the heap of the sender. Then we register and connect to the
1525 # specified server.
1526 my $irc = $sender->get_heap();
1527  
1528 print "Connected to ", $irc->server_name(), "\n";
1529  
1530 # we join our channels
1531 $irc->yield( join => $_ ) for @channels;
1532 return;
1533 }
1534  
1535 sub irc_public {
1536 my ($sender, $who, $where, $what) = @_[SENDER, ARG0 .. ARG2];
1537 my $nick = ( split /!/, $who )[0];
1538 my $channel = $where->[0];
1539  
1540 if ( my ($rot13) = $what =~ /^rot13 (.+)/ ) {
1541 $rot13 =~ tr[a-zA-Z][n-za-mN-ZA-M];
1542 $irc->yield( privmsg => $channel => "$nick: $rot13" );
1543 }
1544 return;
1545 }
1546  
1547 # We registered for all events, this will produce some debug info.
1548 sub _default {
1549 my ($event, $args) = @_[ARG0 .. $#_];
1550 my @output = ( "$event: " );
1551  
1552 for my $arg (@$args) {
1553 if ( ref $arg eq 'ARRAY' ) {
1554 push( @output, '[' . join(', ', @$arg ) . ']' );
1555 }
1556 else {
1557 push ( @output, "'$arg'" );
1558 }
1559 }
1560 print join ' ', @output, "\n";
1561 return;
1562 }
1563  
1564 =head1 DESCRIPTION
1565  
1566 POE::Component::IRC is a POE component (who'd have guessed?) which
1567 acts as an easily controllable IRC client for your other POE
1568 components and sessions. You create an IRC component and tell it what
1569 events your session cares about and where to connect to, and it sends
1570 back interesting IRC events when they happen. You make the client do
1571 things by sending it events. That's all there is to it. Cool, no?
1572  
1573 [Note that using this module requires some familiarity with the
1574 details of the IRC protocol. I'd advise you to read up on the gory
1575 details of RFC 1459 (L<http://www.faqs.org/rfcs/rfc1459.html>) before you
1576 get started. Keep the list of server numeric codes handy while you
1577 program. Needless to say, you'll also need a good working knowledge of
1578 POE, or this document will be of very little use to you.]
1579  
1580 The POE::Component::IRC distribution has a F<docs/> folder with a collection of
1581 salient documentation including the pertinent RFCs.
1582  
1583 POE::Component::IRC consists of a POE::Session that manages the IRC connection
1584 and dispatches C<irc_> prefixed events to interested sessions and
1585 an object that can be used to access additional information using methods.
1586  
1587 Sessions register their interest in receiving C<irc_> events by sending
1588 L<C<register>|/register> to the component. One would usually do this in
1589 your C<_start> handler. Your session will continue to receive events until
1590 you L<C<unregister>|/unregister>. The component will continue to stay
1591 around until you tell it not to with L<C<shutdown>|/shutdown>.
1592  
1593 The L<SYNOPSIS|/SYNOPSIS> demonstrates a fairly basic bot.
1594  
1595 See L<POE::Component::IRC::Cookbook|POE::Component::IRC::Cookbook> for more
1596 examples.
1597  
1598 =head2 Useful subclasses
1599  
1600 Included with POE::Component::IRC are a number of useful subclasses. As they
1601 are subclasses they support all the methods, etc. documented here and have
1602 additional methods and quirks which are documented separately:
1603  
1604 =over 4
1605  
1606 =item * L<POE::Component::IRC::State|POE::Component::IRC::State>
1607  
1608 POE::Component::IRC::State provides all the functionality of POE::Component::IRC
1609 but also tracks IRC state entities such as nicks and channels.
1610  
1611 =item * L<POE::Component::IRC::Qnet|POE::Component::IRC::Qnet>
1612  
1613 POE::Component::IRC::Qnet is POE::Component::IRC tweaked for use on Quakenet IRC
1614 network.
1615  
1616 =item * L<POE::Component::IRC::Qnet::State|POE::Component::IRC::Qnet::State>
1617  
1618 POE::Component::IRC::Qnet::State is a tweaked version of POE::Component::IRC::State
1619 for use on the Quakenet IRC network.
1620  
1621 =back
1622  
1623 =head2 The Plugin system
1624  
1625 As of 3.7, PoCo-IRC sports a plugin system. The documentation for it can be
1626 read by looking at L<POE::Component::IRC::Plugin|POE::Component::IRC::Plugin>.
1627 That is not a subclass, just a placeholder for documentation!
1628  
1629 A number of useful plugins have made their way into the core distribution:
1630  
1631 =over 4
1632  
1633 =item * L<POE::Component::IRC::Plugin::DCC|POE::Component::IRC::Plugin::DCC>
1634  
1635 Provides DCC support. Loaded by default.
1636  
1637 =item * L<POE::Component::IRC::Plugin::AutoJoin|POE::Component::IRC::Plugin::AutoJoin>
1638  
1639 Keeps you on your favorite channels throughout reconnects and even kicks.
1640  
1641 =item * L<POE::Component::IRC::Plugin::Connector|POE::Component::IRC::Plugin::Connector>
1642  
1643 Glues an irc bot to an IRC network, i.e. deals with maintaining ircd connections.
1644  
1645 =item * L<POE::Component::IRC::Plugin::BotTraffic|POE::Component::IRC::Plugin::BotTraffic>
1646  
1647 Under normal circumstances irc bots do not normal the msgs and public msgs that
1648 they generate themselves. This plugin enables you to handle those events.
1649  
1650 =item * L<POE::Component::IRC::Plugin::BotAddressed|POE::Component::IRC::Plugin::BotAddressed>
1651  
1652 Generates C<irc_bot_addressed> / C<irc_bot_mentioned> / C<irc_bot_mentioned_action>
1653 events whenever your bot's name comes up in channel discussion.
1654  
1655 =item * L<POE::Component::IRC::Plugin::BotCommand|POE::Component::IRC::Plugin::BotCommand>
1656  
1657 Provides an easy way to handle commands issued to your bot.
1658  
1659 =item * L<POE::Component::IRC::Plugin::Console|POE::Component::IRC::Plugin::Console>
1660  
1661 See inside the component. See what events are being sent. Generate irc commands
1662 manually. A TCP based console.
1663  
1664 =item * L<POE::Component::IRC::Plugin::FollowTail|POE::Component::IRC::Plugin::FollowTail>
1665  
1666 Follow the tail of an ever-growing file.
1667  
1668 =item * L<POE::Component::IRC::Plugin::Logger|POE::Component::IRC::Plugin::Logger>
1669  
1670 Log public and private messages to disk.
1671  
1672 =item * L<POE::Component::IRC::Plugin::NickServID|POE::Component::IRC::Plugin::NickServID>
1673  
1674 Identify with NickServ when needed.
1675  
1676 =item * L<POE::Component::IRC::Plugin::Proxy|POE::Component::IRC::Plugin::Proxy>
1677  
1678 A lightweight IRC proxy/bouncer.
1679  
1680 =item * L<POE::Component::IRC::Plugin::CTCP|POE::Component::IRC::Plugin::CTCP>
1681  
1682 Automagically generates replies to ctcp version, time and userinfo queries.
1683  
1684 =item * L<POE::Component::IRC::Plugin::PlugMan|POE::Component::IRC::Plugin::PlugMan>
1685  
1686 An experimental Plugin Manager plugin.
1687  
1688 =item * L<POE::Component::IRC::Plugin::NickReclaim|POE::Component::IRC::Plugin::NickReclaim>
1689  
1690 Automagically deals with your nickname being in use and reclaiming it.
1691  
1692 =item * L<POE::Component::IRC::Plugin::CycleEmpty|POE::Component::IRC::Plugin::CycleEmpty>
1693  
1694 Cycles (parts and rejoins) channels if they become empty and opless, in order
1695 to gain ops.
1696  
1697 =back
1698  
1699 =head1 CONSTRUCTORS
1700  
1701 Both constructors return an object. The object is also available within 'irc_'
1702 event handlers by using C<< $_[SENDER]->get_heap() >>. See also
1703 L<C<register>|/register> and L<C<irc_registered>|/irc_registered>.
1704  
1705 =head2 C<spawn>
1706  
1707 Takes a number of arguments, all of which are optional. All the options
1708 below may be supplied to the L<C<connect>|/connect> input event as well,
1709 except for B<'alias'>, B<'options'>, B<'NoDNS'>, B<'debug'>, and
1710 B<'plugin_debug'>.
1711  
1712 =over 4
1713  
1714 =item * B<'alias'>, a name (kernel alias) that this instance will be known
1715 by;
1716  
1717 =item * B<'options'>, a hashref containing L<POE::Session|POE::Session>
1718 options;
1719  
1720 =item * B<'Server'>, the server name;
1721  
1722 =item * B<'Port'>, the remote port number;
1723  
1724 =item * B<'Password'>, an optional password for restricted servers;
1725  
1726 =item * B<'Nick'>, your client's IRC nickname;
1727  
1728 =item * B<'Username'>, your client's username;
1729  
1730 =item * B<'Ircname'>, some cute comment or something.
1731  
1732 =item * B<'Bitmode'>, an integer representing your initial user modes set
1733 in the USER command. See RFC 2812. If you do not set this, C<8> (+i) will
1734 be used.
1735  
1736 =item * B<'UseSSL'>, set to some true value if you want to connect using
1737 SSL.
1738  
1739 =item * B<'SSLCert'>, set to a SSL Certificate(PAM encoded) to connect using a client cert
1740  
1741 =item * B<'SSLKey'>, set to a SSL Key(PAM encoded) to connect using a client cert
1742  
1743 =item * B<'SSLCtx'>, set to a SSL Context to configure the SSL Connection
1744  
1745 The B<'SSLCert'> and B<'SSLKey'> both need to be specified. The B<'SSLCtx'> takes precedence specified.
1746  
1747 =item * B<'Raw'>, set to some true value to enable the component to send
1748 L<C<irc_raw>|/irc_raw> and L<C<irc_raw_out>|/irc_raw_out> events.
1749  
1750 =item * B<'LocalAddr'>, which local IP address on a multihomed box to
1751 connect as;
1752  
1753 =item * B<'LocalPort'>, the local TCP port to open your socket on;
1754  
1755 =item * B<'NoDNS'>, set this to 1 to disable DNS lookups using
1756 PoCo-Client-DNS. (See note below).
1757  
1758 =item * B<'Flood'>, when true, it disables the component's flood
1759 protection algorithms, allowing it to send messages to an IRC server at
1760 full speed. Disconnects and k-lines are some common side effects of
1761 flooding IRC servers, so care should be used when enabling this option.
1762 Default is false.
1763  
1764 Two new attributes are B<'Proxy'> and B<'ProxyPort'> for sending your
1765 =item * B<'Proxy'>, IP address or server name of a proxy server to use.
1766  
1767 =item * B<'ProxyPort'>, which tcp port on the proxy to connect to.
1768  
1769 =item * B<'NATAddr'>, what other clients see as your IP address.
1770  
1771 =item * B<'DCCPorts'>, an arrayref containing tcp ports that can be used
1772 for DCC sends.
1773  
1774 =item * B<'Resolver'>, provide a L<POE::Component::Client::DNS|POE::Component::Client::DNS> object for the component to use.
1775  
1776 =item * B<'msg_length'>, the maximum length of IRC messages, in bytes.
1777 Default is 450. The IRC component shortens all messages longer than this
1778 value minus the length of your current nickname. IRC only allows raw
1779 protocol lines messages that are 512 bytes or shorter, including the
1780 trailing "\r\n". This is most relevant to long PRIVMSGs. The IRC component
1781 can't be sure how long your user@host mask will be every time you send a
1782 message, considering that most networks mangle the 'user' part and some
1783 even replace the whole string (think FreeNode cloaks). If you have an
1784 unusually long user@host mask you might want to decrease this value if
1785 you're prone to sending long messages. Conversely, if you have an
1786 unusually short one, you can increase this value if you want to be able to
1787 send as long a message as possible. Be careful though, increase it too
1788 much and the IRC server might disconnect you with a "Request too long"
1789 message when you try to send a message that's too long.
1790  
1791 =item * B<'debug'>, if set to a true value causes the IRC component to
1792 print every message sent to and from the server, as well as print some
1793 warnings when it receives malformed messages. This option will be enabled
1794 if the C<POCOIRC_DEBUG> environment variable is set to a true value.
1795  
1796 =item * B<'plugin_debug'>, set to some true value to print plugin debug
1797 info, default 0. Plugins are processed inside an eval. When you enable
1798 this option, you will be notified when (and why) a plugin raises an
1799 exception. This option will be enabled if the C<POCOIRC_DEBUG> environment
1800 variable is set to a true value.
1801  
1802 =item * B<'socks_proxy'>, specify a SOCKS4/SOCKS4a proxy to use.
1803  
1804 =item * B<'socks_port'>, the SOCKS port to use, defaults to 1080 if not
1805 specified.
1806  
1807 =item * B<'socks_id'>, specify a SOCKS user_id. Default is none.
1808  
1809 =item * B<'useipv6'>, enable the use of IPv6 for connections.
1810  
1811 =item * B<'webirc'>, enable the use of WEBIRC to spoof host/IP.
1812 You must have a WEBIRC password set up on the IRC server/network (so will
1813 only work for servers which trust you to spoof the IP & host the connection
1814 is from) - value should be a hashref containing keys C<pass>, C<user>,
1815 C<host> and C<ip>.
1816  
1817 =back
1818  
1819 C<spawn> will supply reasonable defaults for any of these attributes
1820 which are missing, so don't feel obliged to write them all out.
1821  
1822 If the component finds that L<POE::Component::Client::DNS|POE::Component::Client::DNS>
1823 is installed it will use that to resolve the server name passed. Disable
1824 this behaviour if you like, by passing: C<< NoDNS => 1 >>.
1825  
1826 IRC traffic through a proxy server. B<'Proxy'>'s value should be the IP
1827 address or server name of the proxy. B<'ProxyPort'>'s value should be the
1828 port on the proxy to connect to. L<C<connect>|/connect> will default
1829 to using the I<actual> IRC server's port if you provide a proxy but omit
1830 the proxy's port. These are for HTTP Proxies. See B<'socks_proxy'> for
1831 SOCKS4 and SOCKS4a support.
1832  
1833 For those people who run bots behind firewalls and/or Network Address
1834 Translation there are two additional attributes for DCC. B<'DCCPorts'>,
1835 is an arrayref of ports to use when initiating DCC connections.
1836 B<'NATAddr'>, is the NAT'ed IP address that your bot is hidden behind,
1837 this is sent whenever you do DCC.
1838  
1839 SSL support requires L<POE::Component::SSLify|POE::Component::SSLify>, as
1840 well as an IRC server that supports SSL connections. If you're missing
1841 POE::Component::SSLify, specifying B<'UseSSL'> will do nothing. The
1842 default is to not try to use SSL.
1843  
1844 B<'Resolver'>, requires a L<POE::Component::Client::DNS|POE::Component::Client::DNS>
1845 object. Useful when spawning multiple poco-irc sessions, saves the
1846 overhead of multiple dns sessions.
1847  
1848 B<'NoDNS'> has different results depending on whether it is set with
1849 L<C<spawn>|/spawn> or L<C<connect>|/connect>. Setting it with
1850 C<spawn>, disables the creation of the POE::Component::Client::DNS
1851 completely. Setting it with L<C<connect>|/connect> on the other hand
1852 allows the PoCo-Client-DNS session to be spawned, but will disable
1853 any dns lookups using it.
1854  
1855 SOCKS4 proxy support is provided by B<'socks_proxy'>, B<'socks_port'> and
1856 B<'socks_id'> parameters. If something goes wrong with the SOCKS connection
1857 you should get a warning on STDERR. This is fairly experimental currently.
1858  
1859 IPv6 support is available for connecting to IPv6 enabled ircds (it won't
1860 work for DCC though). To enable it, specify B<'useipv6'>. Perl >=5.14 or
1861 L<Socket6|Socket6> (for older Perls) is required. If you that and
1862 L<POE::Component::Client::DNS|POE::Component::Client::DNS> installed and
1863 specify a hostname that resolves to an IPv6 address then IPv6 will be used.
1864 If you specify an ipv6 B<'localaddr'> then IPv6 will be used.
1865  
1866 =head2 C<new>
1867  
1868 This method is deprecated. See the L<C<spawn>|/spawn> method instead.
1869 The first argument should be a name (kernel alias) which this new
1870 connection will be known by. Optionally takes more arguments (see
1871 L<C<spawn>|/spawn> as name/value pairs. Returns a POE::Component::IRC
1872 object. :)
1873  
1874 B<Note:> Use of this method will generate a warning. There are currently no
1875 plans to make it die() >;]
1876  
1877 =head1 METHODS
1878  
1879 =head2 Information
1880  
1881 =head3 C<server>
1882  
1883 Takes no arguments. Returns the server host we are currently connected to
1884 (or trying to connect to).
1885  
1886 =head3 C<port>
1887  
1888 Takes no arguments. Returns the server port we are currently connected to
1889 (or trying to connect to).
1890  
1891 =head3 C<server_name>
1892  
1893 Takes no arguments. Returns the name of the IRC server that the component
1894 is currently connected to.
1895  
1896 =head3 C<server_version>
1897  
1898 Takes no arguments. Returns the IRC server version.
1899  
1900 =head3 C<nick_name>
1901  
1902 Takes no arguments. Returns a scalar containing the current nickname that the
1903 bot is using.
1904  
1905 =head3 C<localaddr>
1906  
1907 Takes no arguments. Returns the IP address being used.
1908  
1909 =head3 C<send_queue>
1910  
1911 The component provides anti-flood throttling. This method takes no arguments
1912 and returns a scalar representing the number of messages that are queued up
1913 waiting for dispatch to the irc server.
1914  
1915 =head3 C<logged_in>
1916  
1917 Takes no arguments. Returns true or false depending on whether the IRC
1918 component is logged into an IRC network.
1919  
1920 =head3 C<connected>
1921  
1922 Takes no arguments. Returns true or false depending on whether the component's
1923 socket is currently connected.
1924  
1925 =head3 C<disconnect>
1926  
1927 Takes no arguments. Terminates the socket connection disgracefully >;o]
1928  
1929 =head3 C<isupport>
1930  
1931 Takes one argument, a server capability to query. Returns C<undef> on failure
1932 or a value representing the applicable capability. A full list of capabilities
1933 is available at L<http://www.irc.org/tech_docs/005.html>.
1934  
1935 =head3 C<isupport_dump_keys>
1936  
1937 Takes no arguments, returns a list of the available server capabilities keys,
1938 which can be used with L<C<isupport>|/isupport>.
1939  
1940 =head3 C<resolver>
1941  
1942 Returns a reference to the L<POE::Component::Client::DNS|POE::Component::Client::DNS>
1943 object that is internally created by the component.
1944  
1945 =head2 Events
1946  
1947 =head3 C<session_id>
1948  
1949 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/session_id>>
1950  
1951 Takes no arguments. Returns the ID of the component's session. Ideal for posting
1952 events to the component.
1953  
1954 $kernel->post($irc->session_id() => 'mode' => $channel => '+o' => $dude);
1955  
1956 =head3 C<session_alias>
1957  
1958 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/session_alias>>
1959  
1960 Takes no arguments. Returns the session alias that has been set through
1961 L<C<spawn>|/spawn>'s B<'alias'> argument.
1962  
1963 =head3 C<raw_events>
1964  
1965 With no arguments, returns true or false depending on whether
1966 L<C<irc_raw>|/irc_raw> and L<C<irc_raw_out>|/irc_raw_out> events are being generated
1967 or not. Provide a true or false argument to enable or disable this feature
1968 accordingly.
1969  
1970 =head3 C<yield>
1971  
1972 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/yield>>
1973  
1974 This method provides an alternative object based means of posting events to the
1975 component. First argument is the event to post, following arguments are sent as
1976 arguments to the resultant post.
1977  
1978 $irc->yield(mode => $channel => '+o' => $dude);
1979  
1980 =head3 C<call>
1981  
1982 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/call>>
1983  
1984 This method provides an alternative object based means of calling events to the
1985 component. First argument is the event to call, following arguments are sent as
1986 arguments to the resultant
1987 call.
1988  
1989 $irc->call(mode => $channel => '+o' => $dude);
1990  
1991 =head3 C<delay>
1992  
1993 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/delay>>
1994  
1995 This method provides a way of posting delayed events to the component. The
1996 first argument is an arrayref consisting of the delayed command to post and
1997 any command arguments. The second argument is the time in seconds that one
1998 wishes to delay the command being posted.
1999  
2000 my $alarm_id = $irc->delay( [ mode => $channel => '+o' => $dude ], 60 );
2001  
2002 Returns an alarm ID that can be used with L<C<delay_remove>|/delay_remove>
2003 to cancel the delayed event. This will be undefined if something went wrong.
2004  
2005 =head3 C<delay_remove>
2006  
2007 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/delay_remove>>
2008  
2009 This method removes a previously scheduled delayed event from the component.
2010 Takes one argument, the C<alarm_id> that was returned by a
2011 L<C<delay>|/delay> method call.
2012  
2013 my $arrayref = $irc->delay_remove( $alarm_id );
2014  
2015 Returns an arrayref that was originally requested to be delayed.
2016  
2017 =head3 C<send_event>
2018  
2019 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/send_event>>
2020  
2021 Sends an event through the component's event handling system. These will get
2022 processed by plugins then by registered sessions. First argument is the event
2023 name, followed by any parameters for that event.
2024  
2025 =head3 C<send_event_next>
2026  
2027 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/send_event_next>>
2028  
2029 This sends an event right after the one that's currently being processed.
2030 Useful if you want to generate some event which is directly related to
2031 another event so you want them to appear together. This method can only be
2032 called when POE::Component::IRC is processing an event, e.g. from one of your
2033 event handlers. Takes the same arguments as L<C<send_event>|/send_event>.
2034  
2035 =head3 C<send_event_now>
2036  
2037 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/send_event_now>>
2038  
2039 This will send an event to be processed immediately. This means that if an
2040 event is currently being processed and there are plugins or sessions which
2041 will receive it after you do, then an event sent with C<send_event_now> will
2042 be received by those plugins/sessions I<before> the current event. Takes the
2043 same arguments as L<C<send_event>|/send_event>.
2044  
2045 =head2 Plugins
2046  
2047 =head3 C<pipeline>
2048  
2049 I<Inherited from L<Object::Pluggable|Object::Pluggable/pipeline>>
2050  
2051 Returns the L<Object::Pluggable::Pipeline|Object::Pluggable::Pipeline>
2052 object.
2053  
2054 =head3 C<plugin_add>
2055  
2056 I<Inherited from L<Object::Pluggable|Object::Pluggable/plugin_add>>
2057  
2058 Accepts two arguments:
2059  
2060 The alias for the plugin
2061 The actual plugin object
2062 Any number of extra arguments
2063  
2064 The alias is there for the user to refer to it, as it is possible to have
2065 multiple plugins of the same kind active in one Object::Pluggable object.
2066  
2067 This method goes through the pipeline's C<push()> method, which will call
2068 C<< $plugin->plugin_register($pluggable, @args) >>.
2069  
2070 Returns the number of plugins now in the pipeline if plugin was initialized,
2071 C<undef>/an empty list if not.
2072  
2073 =head3 C<plugin_del>
2074  
2075 I<Inherited from L<Object::Pluggable|Object::Pluggable/plugin_del>>
2076  
2077 Accepts the following arguments:
2078  
2079 The alias for the plugin or the plugin object itself
2080 Any number of extra arguments
2081  
2082 This method goes through the pipeline's C<remove()> method, which will call
2083 C<< $plugin->plugin_unregister($pluggable, @args) >>.
2084  
2085 Returns the plugin object if the plugin was removed, C<undef>/an empty list
2086 if not.
2087  
2088 =head3 C<plugin_get>
2089  
2090 I<Inherited from L<Object::Pluggable|Object::Pluggable/plugin_get>>
2091  
2092 Accepts the following arguments:
2093  
2094 The alias for the plugin
2095  
2096 This method goes through the pipeline's C<get()> method.
2097  
2098 Returns the plugin object if it was found, C<undef>/an empty list if not.
2099  
2100 =head3 C<plugin_list>
2101  
2102 I<Inherited from L<Object::Pluggable|Object::Pluggable/plugin_list>>
2103  
2104 Takes no arguments.
2105  
2106 Returns a hashref of plugin objects, keyed on alias, or an empty list if
2107 there are no plugins loaded.
2108  
2109 =head3 C<plugin_order>
2110  
2111 I<Inherited from L<Object::Pluggable|Object::Pluggable/plugin_order>>
2112  
2113 Takes no arguments.
2114  
2115 Returns an arrayref of plugin objects, in the order which they are
2116 encountered in the pipeline.
2117  
2118 =head3 C<plugin_register>
2119  
2120 I<Inherited from L<Object::Pluggable|Object::Pluggable/plugin_register>>
2121  
2122 Accepts the following arguments:
2123  
2124 The plugin object
2125 The type of the hook (the hook types are specified with _pluggable_init()'s 'types')
2126 The event name[s] to watch
2127  
2128 The event names can be as many as possible, or an arrayref. They correspond
2129 to the prefixed events and naturally, arbitrary events too.
2130  
2131 You do not need to supply events with the prefix in front of them, just the
2132 names.
2133  
2134 It is possible to register for all events by specifying 'all' as an event.
2135  
2136 Returns 1 if everything checked out fine, C<undef>/an empty list if something
2137 is seriously wrong.
2138  
2139 =head3 C<plugin_unregister>
2140  
2141 I<Inherited from L<Object::Pluggable|Object::Pluggable/plugin_unregister>>
2142  
2143 Accepts the following arguments:
2144  
2145 The plugin object
2146 The type of the hook (the hook types are specified with _pluggable_init()'s 'types')
2147 The event name[s] to unwatch
2148  
2149 The event names can be as many as possible, or an arrayref. They correspond
2150 to the prefixed events and naturally, arbitrary events too.
2151  
2152 You do not need to supply events with the prefix in front of them, just the
2153 names.
2154  
2155 It is possible to register for all events by specifying 'all' as an event.
2156  
2157 Returns 1 if all the event name[s] was unregistered, undef if some was not
2158 found.
2159  
2160 =head1 INPUT EVENTS
2161  
2162 How to talk to your new IRC component... here's the events we'll accept.
2163 These are events that are posted to the component, either via
2164 C<< $poe_kernel->post() >> or via the object method L<C<yield>|/yield>.
2165  
2166 So the following would be functionally equivalent:
2167  
2168 sub irc_001 {
2169 my ($kernel,$sender) = @_[KERNEL,SENDER];
2170 my $irc = $sender->get_heap(); # obtain the poco's object
2171  
2172 $irc->yield( privmsg => 'foo' => 'Howdy!' );
2173 $kernel->post( $sender => privmsg => 'foo' => 'Howdy!' );
2174 $kernel->post( $irc->session_id() => privmsg => 'foo' => 'Howdy!' );
2175 $kernel->post( $irc->session_alias() => privmsg => 'foo' => 'Howdy!' );
2176  
2177 return;
2178 }
2179  
2180 =head2 Important Commands
2181  
2182 =head3 C<register>
2183  
2184 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/register>>
2185  
2186 Takes N arguments: a list of event names that your session wants to
2187 listen for, minus the C<irc_> prefix. So, for instance, if you just
2188 want a bot that keeps track of which people are on a channel, you'll
2189 need to listen for JOINs, PARTs, QUITs, and KICKs to people on the
2190 channel you're in. You'd tell POE::Component::IRC that you want those
2191 events by saying this:
2192  
2193 $kernel->post('my client', 'register', qw(join part quit kick));
2194  
2195 Then, whenever people enter or leave a channel your bot is on (forcibly
2196 or not), your session will receive events with names like
2197 L<C<irc_join>|/irc_join>, L<C<irc_kick>|/irc_kick>, etc.,
2198 which you can use to update a list of people on the channel.
2199  
2200 Registering for B<'all'> will cause it to send all IRC-related events to
2201 you; this is the easiest way to handle it. See the test script for an
2202 example.
2203  
2204 Registering will generate an L<C<irc_registered>|/irc_registered>
2205 event that your session can trap. C<ARG0> is the components object. Useful
2206 if you want to bolt PoCo-IRC's new features such as Plugins into a bot
2207 coded to the older deprecated API. If you are using the new API, ignore this :)
2208  
2209 Registering with multiple component sessions can be tricky, especially if
2210 one wants to marry up sessions/objects, etc. Check the L<SIGNALS|/SIGNALS>
2211 section for an alternative method of registering with multiple poco-ircs.
2212  
2213 Starting with version 4.96, if you spawn the component from inside another POE
2214 session, the component will automatically register that session as wanting
2215 B<'all'> irc events. That session will receive an
2216 L<C<irc_registered>|/irc_registered> event indicating that the component
2217 is up and ready to go.
2218  
2219 =head3 C<unregister>
2220  
2221 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/unregister>>
2222  
2223 Takes N arguments: a list of event names which you I<don't> want to
2224 receive. If you've previously done a L<C<register>|/register>
2225 for a particular event which you no longer care about, this event will
2226 tell the IRC connection to stop sending them to you. (If you haven't, it just
2227 ignores you. No big deal.)
2228  
2229 If you have registered with 'all', attempting to unregister individual
2230 events such as 'mode', etc. will not work. This is a 'feature'.
2231  
2232 =head3 C<connect>
2233  
2234 Takes one argument: a hash reference of attributes for the new connection,
2235 see L<C<spawn>|/spawn> for details. This event tells the IRC client to
2236 connect to a new/different server. If it has a connection already open, it'll
2237 close it gracefully before reconnecting.
2238  
2239 =head3 C<ctcp> and C<ctcpreply>
2240  
2241 Sends a CTCP query or response to the nick(s) or channel(s) which you
2242 specify. Takes 2 arguments: the nick or channel to send a message to
2243 (use an array reference here to specify multiple recipients), and the
2244 plain text of the message to send (the CTCP quoting will be handled
2245 for you). The "/me" command in popular IRC clients is actually a CTCP action.
2246  
2247 # Doing a /me
2248 $irc->yield(ctcp => $channel => 'ACTION dances.');
2249  
2250 =head3 C<join>
2251  
2252 Tells your IRC client to join a single channel of your choice. Takes
2253 at least one arg: the channel name (required) and the channel key
2254 (optional, for password-protected channels).
2255  
2256 =head3 C<kick>
2257  
2258 Tell the IRC server to forcibly evict a user from a particular
2259 channel. Takes at least 2 arguments: a channel name, the nick of the
2260 user to boot, and an optional witty message to show them as they sail
2261 out the door.
2262  
2263 =head3 C<remove>
2264  
2265 Tell the IRC server to forcibly evict a user from a particular
2266 channel. Takes at least 2 arguments: a channel name, the nick of the
2267 user to boot, and an optional witty message to show them as they sail
2268 out the door. Similar to KICK but does an enforced PART instead. Not
2269 supported by all servers.
2270  
2271 =head3 C<mode>
2272  
2273 Request a mode change on a particular channel or user. Takes at least
2274 one argument: the mode changes to effect, as a single string (e.g.
2275 "#mychan +sm-p+o"), and any number of optional operands to the mode changes
2276 (nicks, hostmasks, channel keys, whatever.) Or just pass them all as one
2277 big string and it'll still work, whatever. I regret that I haven't the
2278 patience now to write a detailed explanation, but serious IRC users know
2279 the details anyhow.
2280  
2281 =head3 C<nick>
2282  
2283 Allows you to change your nickname. Takes exactly one argument: the
2284 new username that you'd like to be known as.
2285  
2286 =head3 C<nickserv>
2287  
2288 Talks to NickServ, on networks which have it. Takes any number of
2289 arguments.
2290  
2291 =head3 C<notice>
2292  
2293 Sends a NOTICE message to the nick(s) or channel(s) which you
2294 specify. Takes 2 arguments: the nick or channel to send a notice to
2295 (use an array reference here to specify multiple recipients), and the
2296 text of the notice to send.
2297  
2298 =head3 C<part>
2299  
2300 Tell your IRC client to leave the channels which you pass to it. Takes
2301 any number of arguments: channel names to depart from. If the last argument
2302 doesn't begin with a channel name identifier or contains a space character,
2303 it will be treated as a PART message and dealt with accordingly.
2304  
2305 =head3 C<privmsg>
2306  
2307 Sends a public or private message to the nick(s) or channel(s) which
2308 you specify. Takes 2 arguments: the nick or channel to send a message
2309 to (use an array reference here to specify multiple recipients), and
2310 the text of the message to send.
2311  
2312 Have a look at the constants in L<IRC::Utils|IRC::Utils> if you would
2313 like to use formatting and color codes in your messages.
2314  
2315 $irc->yield('primvsg', '#mychannel', 'Hello there');
2316  
2317 # same, but with a green Hello
2318 use IRC::Utils qw(GREEN NORMAL);
2319 $irc->yield('primvsg', '#mychannel', GREEN.'Hello'.NORMAL.' there');
2320  
2321 =head3 C<quit>
2322  
2323 Tells the IRC server to disconnect you. Takes one optional argument:
2324 some clever, witty string that other users in your channels will see
2325 as you leave. You can expect to get an
2326 L<C<irc_disconnected>|/irc_disconnected> event shortly after sending this.
2327  
2328 =head3 C<shutdown>
2329  
2330 By default, POE::Component::IRC sessions never go away. Even after
2331 they're disconnected, they're still sitting around in the background,
2332 waiting for you to call L<C<connect>|/connect> on them again to
2333 reconnect. (Whether this behavior is the Right Thing is doubtful, but I
2334 don't want to break backwards compatibility at this point.) You can send
2335 the IRC session a C<shutdown> event manually to make it delete itself.
2336  
2337 If you are logged into an IRC server, C<shutdown> first will send a quit
2338 message and wait to be disconnected. It will wait for up to 5 seconds before
2339 forcibly disconnecting from the IRC server. If you provide an argument, that
2340 will be used as the QUIT message. If you provide two arguments, the second
2341 one will be used as the timeout (in seconds).
2342  
2343 Terminating multiple components can be tricky. Check the L<SIGNALS|/SIGNALS>
2344 section for a method of shutting down multiple poco-ircs.
2345  
2346 =head3 C<topic>
2347  
2348 Retrieves or sets the topic for particular channel. If called with just
2349 the channel name as an argument, it will ask the server to return the
2350 current topic. If called with the channel name and a string, it will
2351 set the channel topic to that string. Supply an empty string to unset a
2352 channel topic.
2353  
2354 =head3 C<debug>
2355  
2356 Takes one argument: 0 to turn debugging off or 1 to turn debugging on.
2357 This flips the debugging flag in L<POE::Filter::IRCD|POE::Filter::IRCD>,
2358 L<POE::Filter::IRC::Compat|POE::Filter::IRC::Compat>, and
2359 POE::Component::IRC. This has the same effect as setting Debug in
2360 L<C<spawn>|/spawn> or L<C<connect>|/connect>.
2361  
2362 =head2 Not-So-Important Commands
2363  
2364 =head3 C<admin>
2365  
2366 Asks your server who your friendly neighborhood server administrators
2367 are. If you prefer, you can pass it a server name to query, instead of
2368 asking the server you're currently on.
2369  
2370 =head3 C<away>
2371  
2372 When sent with an argument (a message describig where you went), the
2373 server will note that you're now away from your machine or otherwise
2374 preoccupied, and pass your message along to anyone who tries to
2375 communicate with you. When sent without arguments, it tells the server
2376 that you're back and paying attention.
2377  
2378 =head3 C<cap>
2379  
2380 Used to query/enable/disable IRC protocol capabilities. Takes any number of
2381 arguments.
2382  
2383 =head3 C<dcc*>
2384  
2385 See the L<DCC plugin|POE::Component::IRC::Plugin/COMMANDS> (loaded by default)
2386 documentation for DCC-related commands.
2387  
2388 =head3 C<info>
2389  
2390 Basically the same as the L<C<version>|/version> command, except that the
2391 server is permitted to return any information about itself that it thinks is
2392 relevant. There's some nice, specific standards-writing for ya, eh?
2393  
2394 =head3 C<invite>
2395  
2396 Invites another user onto an invite-only channel. Takes 2 arguments:
2397 the nick of the user you wish to admit, and the name of the channel to
2398 invite them to.
2399  
2400 =head3 C<ison>
2401  
2402 Asks the IRC server which users out of a list of nicknames are
2403 currently online. Takes any number of arguments: a list of nicknames
2404 to query the IRC server about.
2405  
2406 =head3 C<links>
2407  
2408 Asks the server for a list of servers connected to the IRC
2409 network. Takes two optional arguments, which I'm too lazy to document
2410 here, so all you would-be linklooker writers should probably go dig up
2411 the RFC.
2412  
2413 =head3 C<list>
2414  
2415 Asks the server for a list of visible channels and their topics. Takes
2416 any number of optional arguments: names of channels to get topic
2417 information for. If called without any channel names, it'll list every
2418 visible channel on the IRC network. This is usually a really big list,
2419 so don't do this often.
2420  
2421 =head3 C<motd>
2422  
2423 Request the server's "Message of the Day", a document which typically
2424 contains stuff like the server's acceptable use policy and admin
2425 contact email addresses, et cetera. Normally you'll automatically
2426 receive this when you log into a server, but if you want it again,
2427 here's how to do it. If you'd like to get the MOTD for a server other
2428 than the one you're logged into, pass it the server's hostname as an
2429 argument; otherwise, no arguments.
2430  
2431 =head3 C<names>
2432  
2433 Asks the server for a list of nicknames on particular channels. Takes
2434 any number of arguments: names of channels to get lists of users
2435 for. If called without any channel names, it'll tell you the nicks of
2436 everyone on the IRC network. This is a really big list, so don't do
2437 this much.
2438  
2439 =head3 C<quote>
2440  
2441 Sends a raw line of text to the server. Takes one argument: a string
2442 of a raw IRC command to send to the server. It is more optimal to use
2443 the events this module supplies instead of writing raw IRC commands
2444 yourself.
2445  
2446 =head3 C<stats>
2447  
2448 Returns some information about a server. Kinda complicated and not
2449 terribly commonly used, so look it up in the RFC if you're
2450 curious. Takes as many arguments as you please.
2451  
2452 =head3 C<time>
2453  
2454 Asks the server what time it thinks it is, which it will return in a
2455 human-readable form. Takes one optional argument: a server name to
2456 query. If not supplied, defaults to current server.
2457  
2458 =head3 C<trace>
2459  
2460 If you pass a server name or nick along with this request, it asks the
2461 server for the list of servers in between you and the thing you
2462 mentioned. If sent with no arguments, it will show you all the servers
2463 which are connected to your current server.
2464  
2465 =head3 C<users>
2466  
2467 Asks the server how many users are logged into it. Defaults to the
2468 server you're currently logged into; however, you can pass a server
2469 name as the first argument to query some other machine instead.
2470  
2471 =head3 C<version>
2472  
2473 Asks the server about the version of ircd that it's running. Takes one
2474 optional argument: a server name to query. If not supplied, defaults
2475 to current server.
2476  
2477 =head3 C<who>
2478  
2479 Lists the logged-on users matching a particular channel name, hostname,
2480 nickname, or what-have-you. Takes one optional argument: a string for
2481 it to search for. Wildcards are allowed; in the absence of this
2482 argument, it will return everyone who's currently logged in (bad
2483 move). Tack an "o" on the end if you want to list only IRCops, as per
2484 the RFC.
2485  
2486 =head3 C<whois>
2487  
2488 Queries the IRC server for detailed information about a particular
2489 user. Takes any number of arguments: nicknames or hostmasks to ask for
2490 information about. As of version 3.2, you will receive an
2491 L<C<irc_whois>|/irc_whois> event in addition to the usual numeric
2492 responses. See below for details.
2493  
2494 =head3 C<whowas>
2495  
2496 Asks the server for information about nickname which is no longer
2497 connected. Takes at least one argument: a nickname to look up (no
2498 wildcards allowed), the optional maximum number of history entries to
2499 return, and the optional server hostname to query. As of version 3.2,
2500 you will receive an L<C<irc_whowas>|/irc_whowas> event in addition
2501 to the usual numeric responses. See below for details.
2502  
2503 =head3 C<ping> and C<pong>
2504  
2505 Included for completeness sake. The component will deal with ponging to
2506 pings automatically. Don't worry about it.
2507  
2508 =head2 Purely Esoteric Commands
2509  
2510 =head3 C<die>
2511  
2512 Tells the IRC server you're connect to, to terminate. Only useful for
2513 IRCops, thank goodness. Takes no arguments.
2514  
2515 =head3 C<locops>
2516  
2517 Opers-only command. This one sends a message to all currently
2518 logged-on local-opers (+l). This option is specific to EFNet.
2519  
2520 =head3 C<oper>
2521  
2522 In the exceedingly unlikely event that you happen to be an IRC
2523 operator, you can use this command to authenticate with your IRC
2524 server. Takes 2 arguments: your username and your password.
2525  
2526 =head3 C<operwall>
2527  
2528 Opers-only command. This one sends a message to all currently
2529 logged-on global opers. This option is specific to EFNet.
2530  
2531 =head3 C<rehash>
2532  
2533 Tells the IRC server you're connected to, to rehash its configuration
2534 files. Only useful for IRCops. Takes no arguments.
2535  
2536 =head3 C<restart>
2537  
2538 Tells the IRC server you're connected to, to shut down and restart itself.
2539 Only useful for IRCops, thank goodness. Takes no arguments.
2540  
2541 =head3 C<sconnect>
2542  
2543 Tells one IRC server (which you have operator status on) to connect to
2544 another. This is actually the CONNECT command, but I already had an
2545 event called L<C<connect>|/connect>, so too bad. Takes the args
2546 you'd expect: a server to connect to, an optional port to connect on,
2547 and an optional remote server to connect with, instead of the one you're
2548 currently on.
2549  
2550 =head3 C<squit>
2551  
2552 Operator-only command used to disconnect server links. Takes two arguments,
2553 the server to disconnect and a message explaining your action.
2554  
2555 =head3 C<summon>
2556  
2557 Don't even ask.
2558  
2559 =head3 C<servlist>
2560  
2561 Lists the currently connected services on the network that are visible to you.
2562 Takes two optional arguments, a mask for matching service names against, and
2563 a service type.
2564  
2565 =head3 C<squery>
2566  
2567 Sends a message to a service. Takes the same arguments as
2568 L<C<privmsg>|/privmsg>.
2569  
2570 =head3 C<userhost>
2571  
2572 Asks the IRC server for information about particular nicknames. (The
2573 RFC doesn't define exactly what this is supposed to return.) Takes any
2574 number of arguments: the nicknames to look up.
2575  
2576 =head3 C<wallops>
2577  
2578 Another opers-only command. This one sends a message to all currently
2579 logged-on opers (and +w users); sort of a mass PA system for the IRC
2580 server administrators. Takes one argument: some clever, witty message
2581 to send.
2582  
2583 =head1 OUTPUT EVENTS
2584  
2585 The events you will receive (or can ask to receive) from your running
2586 IRC component. Note that all incoming event names your session will
2587 receive are prefixed by C<irc_>, to inhibit event namespace pollution.
2588  
2589 If you wish, you can ask the client to send you every event it
2590 generates. Simply register for the event name "all". This is a lot
2591 easier than writing a huge list of things you specifically want to
2592 listen for.
2593  
2594 FIXME: I'd really like to classify these somewhat ("basic", "oper", "ctcp",
2595 "dcc", "raw" or some such), and I'd welcome suggestions for ways to make
2596 this easier on the user, if you can think of some.
2597  
2598 In your event handlers, C<$_[SENDER]> is the particular component session that
2599 sent you the event. C<< $_[SENDER]->get_heap() >> will retrieve the component's
2600 object. Useful if you want on-the-fly access to the object and its methods.
2601  
2602 =head2 Important Events
2603  
2604 =head3 C<irc_registered>
2605  
2606 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/syndicator_registered>>
2607  
2608 Sent once to the requesting session on registration (see
2609 L<C<register>|/register>). C<ARG0> is a reference tothe component's object.
2610  
2611 =head3 C<irc_shutdown>
2612  
2613 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/syndicator_shutdown>>
2614  
2615 Sent to all registered sessions when the component has been asked to
2616 L<C<shutdown>|/shutdown>. C<ARG0> will be the session ID of the requesting
2617 session.
2618  
2619 =head3 C<irc_connected>
2620  
2621 The IRC component will send an C<irc_connected> event as soon as it
2622 establishes a connection to an IRC server, before attempting to log
2623 in. C<ARG0> is the server name.
2624  
2625 B<NOTE:> When you get an C<irc_connected> event, this doesn't mean you
2626 can start sending commands to the server yet. Wait until you receive
2627 an L<C<irc_001>|/All numeric events> event (the server welcome message)
2628 before actually sending anything back to the server.
2629  
2630 =head3 C<irc_ctcp>
2631  
2632 C<irc_ctcp> events are generated upon receipt of CTCP messages, in addition to
2633 the C<irc_ctcp_*> events mentioned below. They are identical in every way to
2634 these, with one difference: instead of the * being in the method name, it
2635 is prepended to the argument list. For example, if someone types C</ctcp
2636 Flibble foo bar>, an C<irc_ctcp> event will be sent with B<'foo'> as C<ARG0>,
2637 and the rest as given below.
2638  
2639 It is not recommended that you register for both C<irc_ctcp> and C<irc_ctcp_*>
2640 events, since they will both be fired and presumably cause duplication.
2641  
2642 =head3 C<irc_ctcp_*>
2643  
2644 C<irc_ctcp_whatever> events are generated upon receipt of CTCP messages.
2645 For instance, receiving a CTCP PING request generates an C<irc_ctcp_ping>
2646 event, CTCP ACTION (produced by typing "/me" in most IRC clients)
2647 generates an C<irc_ctcp_action> event, blah blah, so on and so forth. C<ARG0>
2648 is the nick!hostmask of the sender. C<ARG1> is the channel/recipient
2649 name(s). C<ARG2> is the text of the CTCP message. On servers supporting the
2650 IDENTIFY-MSG feature (e.g. FreeNode), CTCP ACTIONs will have C<ARG3>, which
2651 will be C<1> if the sender has identified with NickServ, C<0> otherwise.
2652  
2653 Note that DCCs are handled separately -- see the
2654 L<DCC plugin|POE::Component::IRC::Plugin::DCC>.
2655  
2656 =head3 C<irc_ctcpreply_*>
2657  
2658 C<irc_ctcpreply_whatever> messages are just like C<irc_ctcp_whatever>
2659 messages, described above, except that they're generated when a response
2660 to one of your CTCP queries comes back. They have the same arguments and
2661 such as C<irc_ctcp_*> events.
2662  
2663 =head3 C<irc_disconnected>
2664  
2665 The counterpart to L<C<irc_connected>|/irc_connected>, sent whenever
2666 a socket connection to an IRC server closes down (whether intentionally or
2667 unintentionally). C<ARG0> is the server name.
2668  
2669 =head3 C<irc_error>
2670  
2671 You get this whenever the server sends you an ERROR message. Expect
2672 this to usually be accompanied by the sudden dropping of your
2673 connection. C<ARG0> is the server's explanation of the error.
2674  
2675 =head3 C<irc_join>
2676  
2677 Sent whenever someone joins a channel that you're on. C<ARG0> is the
2678 person's nick!hostmask. C<ARG1> is the channel name.
2679  
2680 =head3 C<irc_invite>
2681  
2682 Sent whenever someone offers you an invitation to another channel. C<ARG0>
2683 is the person's nick!hostmask. C<ARG1> is the name of the channel they want
2684 you to join.
2685  
2686 =head3 C<irc_kick>
2687  
2688 Sent whenever someone gets booted off a channel that you're on. C<ARG0>
2689 is the kicker's nick!hostmask. C<ARG1> is the channel name. C<ARG2> is the
2690 nick of the unfortunate kickee. C<ARG3> is the explanation string for the
2691 kick.
2692  
2693 =head3 C<irc_mode>
2694  
2695 Sent whenever someone changes a channel mode in your presence, or when
2696 you change your own user mode. C<ARG0> is the nick!hostmask of that
2697 someone. C<ARG1> is the channel it affects (or your nick, if it's a user
2698 mode change). C<ARG2> is the mode string (i.e., "+o-b"). The rest of the
2699 args (C<ARG3 .. $#_>) are the operands to the mode string (nicks,
2700 hostmasks, channel keys, whatever).
2701  
2702 =head3 C<irc_msg>
2703  
2704 Sent whenever you receive a PRIVMSG command that was addressed to you
2705 privately. C<ARG0> is the nick!hostmask of the sender. C<ARG1> is an array
2706 reference containing the nick(s) of the recipients. C<ARG2> is the text
2707 of the message. On servers supporting the IDENTIFY-MSG feature (e.g.
2708 FreeNode), there will be an additional argument, C<ARG3>, which will be
2709 C<1> if the sender has identified with NickServ, C<0> otherwise.
2710  
2711 =head3 C<irc_nick>
2712  
2713 Sent whenever you, or someone around you, changes nicks. C<ARG0> is the
2714 nick!hostmask of the changer. C<ARG1> is the new nick that they changed
2715 to.
2716  
2717 =head3 C<irc_notice>
2718  
2719 Sent whenever you receive a NOTICE command. C<ARG0> is the nick!hostmask
2720 of the sender. C<ARG1> is an array reference containing the nick(s) or
2721 channel name(s) of the recipients. C<ARG2> is the text of the NOTICE
2722 message.
2723  
2724 =head3 C<irc_part>
2725  
2726 Sent whenever someone leaves a channel that you're on. C<ARG0> is the
2727 person's nick!hostmask. C<ARG1> is the channel name. C<ARG2> is the part
2728 message.
2729  
2730 =head3 C<irc_public>
2731  
2732 Sent whenever you receive a PRIVMSG command that was sent to a channel.
2733 C<ARG0> is the nick!hostmask of the sender. C<ARG1> is an array
2734 reference containing the channel name(s) of the recipients. C<ARG2> is the
2735 text of the message. On servers supporting the IDENTIFY-MSG feature (e.g.
2736 FreeNode), there will be an additional argument, C<ARG3>, which will be
2737 C<1> if the sender has identified with NickServ, C<0> otherwise.
2738  
2739 =head3 C<irc_quit>
2740  
2741 Sent whenever someone on a channel with you quits IRC (or gets
2742 KILLed). C<ARG0> is the nick!hostmask of the person in question. C<ARG1> is
2743 the clever, witty message they left behind on the way out.
2744  
2745 =head3 C<irc_socketerr>
2746  
2747 Sent when a connection couldn't be established to the IRC server. C<ARG0>
2748 is probably some vague and/or misleading reason for what failed.
2749  
2750 =head3 C<irc_topic>
2751  
2752 Sent when a channel topic is set or unset. C<ARG0> is the nick!hostmask of the
2753 sender. C<ARG1> is the channel affected. C<ARG2> will be either: a string if the
2754 topic is being set; or a zero-length string (i.e. '') if the topic is being
2755 unset. Note: replies to queries about what a channel topic *is*
2756 (i.e. TOPIC #channel), are returned as numerics, not with this event.
2757  
2758 =head3 C<irc_whois>
2759  
2760 Sent in response to a WHOIS query. C<ARG0> is a hashref, with the following
2761 keys:
2762  
2763 =over 4
2764  
2765 =item * B<'nick'>, the users nickname;
2766  
2767 =item * B<'user'>, the users username;
2768  
2769 =item * B<'host'>, their hostname;
2770  
2771 =item * B<'real'>, their real name;
2772  
2773 =item * B<'idle'>, their idle time in seconds;
2774  
2775 =item * B<'signon'>, the epoch time they signed on (will be undef if ircd
2776 does not support this);
2777  
2778 =item * B<'channels'>, an arrayref listing visible channels they are on,
2779 the channel is prefixed with '@','+','%' depending on whether they have
2780 +o +v or +h;
2781  
2782 =item * B<'server'>, their server (might not be useful on some networks);
2783  
2784 =item * B<'oper'>, whether they are an IRCop, contains the IRC operator
2785 string if they are, undef if they aren't.
2786  
2787 =item * B<'actually'>, some ircds report the user's actual ip address,
2788 that'll be here;
2789  
2790 =item * B<'identified'>. if the user has identified with NICKSERV
2791 (ircu, seven, Plexus)
2792  
2793 =item * B<'modes'>, a string describing the user's modes (Rizon)
2794  
2795 =back
2796  
2797 =head3 C<irc_whowas>
2798  
2799 Similar to the above, except some keys will be missing.
2800  
2801 =head3 C<irc_raw>
2802  
2803 Enabled by passing C<< Raw => 1 >> to L<C<spawn>|/spawn> or
2804 L<C<connect>|/connect>, or by calling L<C<raw_events>|/raw_events> with
2805 a true argument. C<ARG0> is the raw IRC string received by the component from
2806 the IRC server, before it has been mangled by filters and such like.
2807  
2808 =head3 C<irc_raw_out>
2809  
2810 Enabled by passing C<< Raw => 1 >> to L<C<spawn>|/spawn> or
2811 L<C<connect>|/connect>, or by calling L<C<raw_events>|/raw_events> with
2812 a true argument. C<ARG0> is the raw IRC string sent by the component to the
2813 the IRC server.
2814  
2815 =head3 C<irc_isupport>
2816  
2817 Emitted by the first event after an L<C<irc_005>|/All numeric events>, to
2818 indicate that isupport information has been gathered. C<ARG0> is the
2819 L<POE::Component::IRC::Plugin::ISupport|POE::Component::IRC::Plugin::ISupport>
2820 object.
2821  
2822 =head3 C<irc_socks_failed>
2823  
2824 Emitted whenever we fail to connect successfully to a SOCKS server or the
2825 SOCKS server is not actually a SOCKS server. C<ARG0> will be some vague reason
2826 as to what went wrong. Hopefully.
2827  
2828 =head3 C<irc_socks_rejected>
2829  
2830 Emitted whenever a SOCKS connection is rejected by a SOCKS server. C<ARG0> is
2831 the SOCKS code, C<ARG1> the SOCKS server address, C<ARG2> the SOCKS port and
2832 C<ARG3> the SOCKS user id (if defined).
2833  
2834 =head3 C<irc_plugin_add>
2835  
2836 I<Inherited from L<Object::Pluggable|Object::Pluggable/_pluggable_event>>
2837  
2838 Emitted whenever a new plugin is added to the pipeline. C<ARG0> is the
2839 plugin alias. C<ARG1> is the plugin object.
2840  
2841 =head3 C<irc_plugin_del>
2842  
2843 I<Inherited from L<Object::Pluggable|Object::Pluggable/_pluggable_event>>
2844  
2845 Emitted whenever a plugin is removed from the pipeline. C<ARG0> is the
2846 plugin alias. C<ARG1> is the plugin object.
2847  
2848 =head3 C<irc_plugin_error>
2849  
2850 I<Inherited from L<Object::Pluggable|Object::Pluggable/_pluggable_event>>
2851  
2852 Emitted when an error occurs while executing a plugin handler. C<ARG0> is
2853 the error message. C<ARG1> is the plugin alias. C<ARG2> is the plugin object.
2854  
2855 =head2 Somewhat Less Important Events
2856  
2857 =head3 C<irc_cap>
2858  
2859 A reply from the server regarding protocol capabilities. C<ARG0> is the
2860 CAP subcommand (e.g. 'LS'). C<ARG1> is the result of the subcommand, unless
2861 this is a multi-part reply, in which case C<ARG1> is '*' and C<ARG2> contains
2862 the result.
2863  
2864 =head3 C<irc_dcc_*>
2865  
2866 See the L<DCC plugin|POE::Component::IRC::Plugin/OUTPUT> (loaded by default)
2867 documentation for DCC-related events.
2868  
2869 =head3 C<irc_ping>
2870  
2871 An event sent whenever the server sends a PING query to the
2872 client. (Don't confuse this with a CTCP PING, which is another beast
2873 entirely. If unclear, read the RFC.) Note that POE::Component::IRC will
2874 automatically take care of sending the PONG response back to the
2875 server for you, although you can still register to catch the event for
2876 informational purposes.
2877  
2878 =head3 C<irc_snotice>
2879  
2880 A weird, non-RFC-compliant message from an IRC server. Usually sent during
2881 to you during an authentication phase right after you connect, while the
2882 server does a hostname lookup or similar tasks. C<ARG0> is the text of the
2883 server's message. C<ARG1> is the target, which could be B<'*'> or B<'AUTH'>
2884 or whatever. Servers vary as to whether these notices include a server name
2885 as the sender, or no sender at all. C<ARG1> is the sender, if any.
2886  
2887 =head3 C<irc_delay_set>
2888  
2889 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/syndicator_delay_set>>
2890  
2891 Emitted on a successful addition of a delayed event using the
2892 L<C<delay>|/delay> method. C<ARG0> will be the alarm_id which can be used
2893 later with L<C<delay_remove>|/delay_remove>. Subsequent parameters are
2894 the arguments that were passed to L<C<delay>|/delay>.
2895  
2896 =head3 C<irc_delay_removed>
2897  
2898 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/syndicator_delay_removed>>
2899  
2900 Emitted when a delayed command is successfully removed. C<ARG0> will be the
2901 alarm_id that was removed. Subsequent parameters are the arguments that were
2902 passed to L<C<delay>|/delay>.
2903  
2904 =head2 All numeric events
2905  
2906 Most messages from IRC servers are identified only by three-digit
2907 numeric codes with undescriptive constant names like RPL_UMODEIS and
2908 ERR_NOTOPLEVEL. (Actually, the list of codes in the RFC is kind of
2909 out-of-date... the list in the back of Net::IRC::Event.pm is more
2910 complete, and different IRC networks have different and incompatible
2911 lists. Ack!) As an example, say you wanted to handle event 376
2912 (RPL_ENDOFMOTD, which signals the end of the MOTD message). You'd
2913 register for '376', and listen for C<irc_376> events. Simple, no? C<ARG0>
2914 is the name of the server which sent the message. C<ARG1> is the text of
2915 the message. C<ARG2> is an array reference of the parsed message, so there
2916 is no need to parse C<ARG1> yourself.
2917  
2918 =head1 SIGNALS
2919  
2920 The component will handle a number of custom signals that you may send using
2921 L<POE::Kernel|POE::Kernel>'s C<signal> method.
2922  
2923 =head2 C<POCOIRC_REGISTER>
2924  
2925 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/SYNDICATOR_REGISTER>>
2926  
2927 Registering with multiple PoCo-IRC components has been a pita. Well, no more,
2928 using the power of L<POE::Kernel|POE::Kernel> signals.
2929  
2930 If the component receives a C<POCOIRC_REGISTER> signal it'll register the
2931 requesting session and trigger an L<C<irc_registered>|/irc_registered>
2932 event. From that event one can get all the information necessary such as the
2933 poco-irc object and the SENDER session to do whatever one needs to build a
2934 poco-irc dispatch table.
2935  
2936 The way the signal handler in PoCo-IRC is written also supports sending the
2937 C<POCOIRC_REGISTER> to multiple sessions simultaneously, by sending the signal
2938 to the POE Kernel itself.
2939  
2940 Pass the signal your session, session ID or alias, and the IRC events (as
2941 specified to L<C<register>|/register>).
2942  
2943 To register with multiple PoCo-IRCs one can do the following in your session's
2944 _start handler:
2945  
2946 sub _start {
2947 my ($kernel, $session) = @_[KERNEL, SESSION];
2948  
2949 # Registering with multiple pocoircs for 'all' IRC events
2950 $kernel->signal($kernel, 'POCOIRC_REGISTER', $session->ID(), 'all');
2951  
2952 return:
2953 }
2954  
2955 Each poco-irc will send your session an
2956 L<C<irc_registered>|/irc_registered> event:
2957  
2958 sub irc_registered {
2959 my ($kernel, $sender, $heap, $irc_object) = @_[KERNEL, SENDER, HEAP, ARG0];
2960  
2961 # Get the poco-irc session ID
2962 my $sender_id = $sender->ID();
2963  
2964 # Or it's alias
2965 my $poco_alias = $irc_object->session_alias();
2966  
2967 # Store it in our heap maybe
2968 $heap->{irc_objects}->{ $sender_id } = $irc_object;
2969  
2970 # Make the poco connect
2971 $irc_object->yield(connect => { });
2972  
2973 return;
2974 }
2975  
2976 =head2 C<POCOIRC_SHUTDOWN>
2977  
2978 I<Inherited from L<POE::Component::Syndicator|POE::Component::Syndicator/SYNDICATOR_SHUTDOWN>>
2979  
2980 Telling multiple poco-ircs to shutdown was a pita as well. The same principle as
2981 with registering applies to shutdown too.
2982  
2983 Send a C<POCOIRC_SHUTDOWN> to the POE Kernel to terminate all the active
2984 poco-ircs simultaneously.
2985  
2986 $poe_kernel->signal($poe_kernel, 'POCOIRC_SHUTDOWN');
2987  
2988 Any additional parameters passed to the signal will become your quit messages
2989 on each IRC network.
2990  
2991 =head1 ENCODING
2992  
2993 This can be an issue. Take a look at L<IRC::Utils' section|IRC::Utils/ENCODING>
2994 on it.
2995  
2996 =head1 BUGS
2997  
2998 A few have turned up in the past and they are sure to again. Please use
2999 L<http://rt.cpan.org/> to report any. Alternatively, email the current
3000 maintainer.
3001  
3002 =head1 DEVELOPMENT
3003  
3004 You can find the latest source on github:
3005 L<http://github.com/bingos/poe-component-irc>
3006  
3007 The project's developers usually hang out in the C<#poe> IRC channel on
3008 irc.perl.org. Do drop us a line.
3009  
3010 =head1 MAINTAINERS
3011  
3012 Chris C<BinGOs> Williams <chris@bingosnet.co.uk>
3013  
3014 Hinrik E<Ouml>rn SigurE<eth>sson <hinrik.sig@gmail.com>
3015  
3016 =head1 AUTHOR
3017  
3018 Dennis Taylor.
3019  
3020 =head1 LICENCE
3021  
3022 Copyright (c) Dennis Taylor, Chris Williams and Hinrik E<Ouml>rn SigurE<eth>sson
3023  
3024 This module may be used, modified, and distributed under the same
3025 terms as Perl itself. Please see the license that came with your Perl
3026 distribution for details.
3027  
3028 =head1 MAD PROPS
3029  
3030 The maddest of mad props go out to Rocco "dngor" Caputo
3031 <troc@netrus.net>, for inventing something as mind-bogglingly
3032 cool as POE, and to Kevin "oznoid" Lenzo E<lt>lenzo@cs.cmu.eduE<gt>,
3033 for being the attentive parent of our precocious little infobot on
3034 #perl.
3035  
3036 Further props to a few of the studly bughunters who made this module not
3037 suck: Abys <abys@web1-2-3.com>, Addi <addi@umich.edu>, ResDev
3038 <ben@reser.org>, and Roderick <roderick@argon.org>. Woohoo!
3039  
3040 Kudos to Apocalypse, <apocal@cpan.org>, for the plugin system and to
3041 Jeff 'japhy' Pinyan, <japhy@perlmonk.org>, for Pipeline.
3042  
3043 Thanks to the merry band of POE pixies from #PoE @ irc.perl.org,
3044 including ( but not limited to ), ketas, ct, dec, integral, webfox,
3045 immute, perigrin, paulv, alias.
3046  
3047 IP functions are shamelessly 'borrowed' from L<Net::IP|Net::IP> by Manuel
3048 Valente
3049  
3050 Check out the Changes file for further contributors.
3051  
3052 =head1 SEE ALSO
3053  
3054 RFC 1459 L<http://www.faqs.org/rfcs/rfc1459.html>
3055  
3056 L<http://www.irchelp.org/>,
3057  
3058 L<http://poe.perl.org/>,
3059  
3060 L<http://www.infobot.org/>,
3061  
3062 Some good examples reside in the POE cookbook which has a whole section
3063 devoted to IRC programming L<http://poe.perl.org/?POE_Cookbook>.
3064  
3065 The examples/ folder of this distribution.
3066  
3067 =cut
« Component/IRC/Qnet/State.pm ↑ Summary Filter/IRC/Compat.pm »