File Coverage

blib/lib/POE/Component/IRC/Plugin/Whois.pm
Criterion Covered Total %
statement 69 124 55.6
branch 2 8 25.0
condition n/a
subroutine 14 20 70.0
pod 1 14 7.1
total 86 166 51.8


line stmt bran cond sub pod time code
1             package POE::Component::IRC::Plugin::Whois;
2             $POE::Component::IRC::Plugin::Whois::VERSION = '6.95';
3 79     79   514 use strict;
  79         160  
  79         3459  
4 79     79   438 use warnings FATAL => 'all';
  79         155  
  79         4646  
5 79     79   498 use POE;
  79         163  
  79         642  
6 79     79   34184 use POE::Component::IRC::Plugin qw( PCI_EAT_NONE );
  79         440  
  79         5395  
7 79     79   51144 use IRC::Utils qw(uc_irc);
  79         1708227  
  79         84141  
8              
9             sub new {
10 116     116 1 3981 return bless { }, shift;
11             }
12              
13             sub PCI_register {
14 116     116 0 12580 my( $self, $irc ) = @_;
15 116         1309 $irc->plugin_register( $self, 'SERVER', qw(307 310 311 312 313 314 317 318 319 330 338 369) );
16 116         11976 return 1;
17             }
18              
19             sub PCI_unregister {
20 116     116 0 25508 return 1;
21             }
22              
23             # RPL_WHOISUSER
24             sub S_311 {
25 4     4 0 3104 my ($self, $irc) = splice @_, 0, 2;
26 4         31 my $mapping = $irc->isupport('CASEMAPPING');
27 4         11 my @args = @{ ${ $_[2] } };
  4         10  
  4         18  
28 4         11 my $real = pop @args;
29 4         15 my ($rnick,$user,$host) = @args;
30 4         19 my $nick = uc_irc $rnick, $mapping;
31              
32 4         77 $self->{WHOIS}->{ $nick }->{nick} = $rnick;
33 4         16 $self->{WHOIS}->{ $nick }->{user} = $user;
34 4         13 $self->{WHOIS}->{ $nick }->{host} = $host;
35 4         11 $self->{WHOIS}->{ $nick }->{real} = $real;
36              
37 4         17 return PCI_EAT_NONE;
38             }
39              
40             # RPL_WHOISOPERATOR
41             sub S_313 {
42 0     0 0 0 my ($self, $irc) = splice @_, 0, 2;
43 0         0 my $mapping = $irc->isupport('CASEMAPPING');
44 0         0 my $nick = uc_irc ${ $_[2] }->[0], $mapping;
  0         0  
45 0         0 my $oper = ${ $_[2] }->[1];
  0         0  
46              
47 0         0 $self->{WHOIS}->{ $nick }->{oper} = $oper;
48 0         0 return PCI_EAT_NONE;
49             }
50              
51             # RPL_WHOISSERVER
52             sub S_312 {
53 4     4 0 1486 my ($self, $irc) = splice @_, 0, 2;
54 4         27 my $mapping = $irc->isupport('CASEMAPPING');
55 4         10 my ($nick,$server) = @{ ${ $_[2] } };
  4         12  
  4         161  
56 4         31 $nick = uc_irc $nick, $mapping;
57              
58             # This can be returned in reply to either a WHOIS or a WHOWAS *sigh*
59 4 50       87 if ( defined $self->{WHOWAS}->{ $nick } ) {
60 0         0 $self->{WHOWAS}->{ $nick }->{server} = $server;
61             }
62             else {
63 4         17 $self->{WHOIS}->{ $nick }->{server} = $server;
64             }
65              
66 4         16 return PCI_EAT_NONE;
67             }
68              
69             # RPL_WHOISIDLE
70             sub S_317 {
71 4     4 0 1625 my ($self, $irc) = splice @_, 0, 2;
72 4         24 my $mapping = $irc->isupport('CASEMAPPING');
73 4         10 my ($nick,@args) = @{ ${ $_[2] } };
  4         12  
  4         21  
74 4         28 $nick = uc_irc $nick, $mapping;
75              
76 4         68 $self->{WHOIS}->{ $nick }->{idle} = $args[0];
77 4         16 $self->{WHOIS}->{ $nick }->{signon} = $args[1];
78              
79 4         35 return PCI_EAT_NONE;
80             }
81              
82             # RPL_WHOISCHANNELS
83             sub S_319 {
84 0     0 0 0 my ($self, $irc) = splice @_, 0, 2;
85 0         0 my $mapping = $irc->isupport('CASEMAPPING');
86 0         0 my @args = @{ ${ $_[2] } };
  0         0  
  0         0  
87 0         0 my $nick = uc_irc shift ( @args ), $mapping;
88 0         0 my @chans = split / /, shift @args;
89              
90 0 0       0 if ( !defined $self->{WHOIS}->{ $nick }->{channels} ) {
91 0         0 $self->{WHOIS}->{ $nick }->{channels} = [ @chans ];
92             }
93             else {
94 0         0 push( @{ $self->{WHOIS}->{ $nick }->{channels} }, @chans );
  0         0  
95             }
96              
97 0         0 return PCI_EAT_NONE;
98             }
99              
100             # RPL_WHOISACCOUNT
101             sub S_330 {
102 0     0 0 0 my ($self, $irc) = splice @_, 0, 2;
103 0         0 my $mapping = $irc->isupport('CASEMAPPING');
104 0         0 my ($nick, $ident) = @{ ${ $_[2] } };
  0         0  
  0         0  
105              
106 0         0 $self->{WHOIS}->{ uc_irc ( $nick, $mapping ) }->{identified} = $ident;
107              
108 0         0 return PCI_EAT_NONE;
109             }
110              
111             {
112 79     79   853 no warnings 'once';
  79         194  
  79         56222  
113             *S_307 = \&S_330; # RPL_WHOISREGNICK
114             }
115              
116             # RPL_WHOISMODES
117             sub S_310 {
118 0     0 0 0 my ($self, $irc) = splice @_, 0, 2;
119 0         0 my $mapping = $irc->isupport('CASEMAPPING');
120 0         0 my ($nick, $modes) = @{ ${ $_[2] } };
  0         0  
  0         0  
121              
122 0         0 $self->{WHOIS}->{ uc_irc ( $nick, $mapping ) }->{modes} = $modes;
123              
124 0         0 return PCI_EAT_NONE;
125             }
126              
127             # RPL_WHOISACTUALLY (Hybrid/Ratbox/others)
128             sub S_338 {
129 4     4 0 2203 my ($self, $irc) = splice @_, 0, 2;
130 4         21 my $mapping = $irc->isupport('CASEMAPPING');
131 4         11 my $nick = uc_irc ${ $_[2] }->[0], $mapping;
  4         25  
132 4         57 my $ip = ${ $_[2] }->[1];
  4         12  
133              
134 4         16 $self->{WHOIS}->{ $nick }->{actually} = $ip;
135              
136 4         14 return PCI_EAT_NONE;
137             }
138              
139             # RPL_ENDOFWHOIS
140             sub S_318 {
141 4     4 0 2065 my ($self, $irc) = splice @_, 0, 2;
142 4         20 my $mapping = $irc->isupport('CASEMAPPING');
143 4         10 my $nick = uc_irc ${ $_[2] }->[0], $mapping;
  4         23  
144 4         61 my $whois = delete $self->{WHOIS}->{ $nick };
145              
146 4 50       94 $irc->send_event_next( 'irc_whois', $whois ) if defined $whois;
147 4         155 return PCI_EAT_NONE;
148             }
149              
150             # RPL_WHOWASUSER
151             sub S_314 {
152 0     0 0   my ($self, $irc) = splice @_, 0, 2;
153 0           my $mapping = $irc->isupport('CASEMAPPING');
154 0           my @args = @{ ${ $_[2] } };
  0            
  0            
155 0           my $real = pop @args;
156 0           my ($rnick,$user,$host) = @args;
157 0           my $nick = uc_irc $rnick, $mapping;
158              
159 0           $self->{WHOWAS}->{ $nick }->{nick} = $rnick;
160 0           $self->{WHOWAS}->{ $nick }->{user} = $user;
161 0           $self->{WHOWAS}->{ $nick }->{host} = $host;
162 0           $self->{WHOWAS}->{ $nick }->{real} = $real;
163              
164 0           return PCI_EAT_NONE;
165             }
166              
167             # RPL_ENDOFWHOWAS
168             sub S_369 {
169 0     0 0   my ($self, $irc) = splice @_, 0, 2;
170 0           my $mapping = $irc->isupport('CASEMAPPING');
171 0           my $nick = uc_irc ${ $_[2] }->[0], $mapping;
  0            
172              
173 0           my $whowas = delete $self->{WHOWAS}->{ $nick };
174 0 0         $irc->send_event_next( 'irc_whowas', $whowas ) if defined $whowas;
175 0           return PCI_EAT_NONE;
176             }
177              
178             1;
179              
180             =encoding utf8
181              
182             =head1 NAME
183              
184             POE::Component::IRC::Plugin::Whois - A PoCo-IRC plugin that generates events
185             for WHOIS and WHOWAS replies
186              
187             =head1 DESCRIPTION
188              
189             POE::Component::IRC::Plugin::Whois is the reimplementation of the C
190             and C code from L as a
191             plugin. It is used internally by L
192             so there is no need to use this plugin yourself.
193              
194             =head1 METHODS
195              
196             =head2 C
197              
198             No arguments required. Returns a plugin object suitable for feeding to
199             L's C method.
200              
201              
202             =head1 AUTHOR
203              
204             Chris "BinGOs" Williams
205              
206             =head1 SEE ALSO
207              
208             L
209              
210             L
211              
212             =cut