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