Component/IRC/Plugin/Proxy.pm

filter: Statementstmt 11.5% 21 / 182 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 21.4% 6 / 28 Podpod 33.3% 4 / 12 totaltotal 9.4% 31 / 327 CC 45 SCAR 50.9
CC
45
Cov
8%
_client_input
506.0
S_raw
42.0
_spawn_listener
20.0
CRAP 162.9
« Component/IRC/Plugin/BotCommand.pm ↑ Summary Filter/IRC/Compat.pm »
1 package POE::Component::IRC::Plugin::Proxy;
2 1 our $AUTHORITY = 'cpan:HINRIK';
3 1 $POE::Component::IRC::Plugin::Proxy::VERSION = '6.92';
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Socket qw(inet_ntoa);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::IRCD
9 1 ▶ Filter::Line Filter::Stackable);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use POE::Component::IRC::Plugin qw(PCI_EAT_NONE);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub new {
13 0 ▶ my ($package) = shift;
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
14 0 ▶ croak "$package requires an even number of arguments" if @_ & 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 0 0
15 0 my %args = @_;
16 0 $args{ lc $_ } = delete $args{ $_ } for keys %args;
17 0 return bless \%args, $package;
18 }
19  
20 sub PCI_register {
21 0 ▶ my ($self, $irc) = splice @_, 0, 2;
Subroutine PCI_register: not called CC=2 SCAR=17.9
Pod undocumented
22  
23 0 ▶ if (!$irc->isa('POE::Component::IRC::State')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($irc->isa("POE::Component::IRC::State")) 0 0 0
24 0 die __PACKAGE__ . ' requires PoCo::IRC::State or a subclass thereof';
25 }
26  
27 0 $irc->raw_events(1);
28 0 $self->{irc} = $irc;
29 0 $irc->plugin_register(
30 $self,
31 'SERVER',
32 qw(
33 connected
34 disconnected
35 001
36 error
37 socketerr
38 raw
39 )
40 );
41  
42 0 POE::Session->create(
43 object_states => [
44 $self => [qw(
45 _client_error
46 _client_flush
47 _client_input
48 _listener_accept
49 _listener_failed
50 _start
51 _shutdown
52 _spawn_listener
53 )],
54 ],
55 );
56  
57 0 return 1;
58 }
59  
60 sub PCI_unregister {
61 0 ▶ my ($self, $irc) = splice @_, 0, 2;
Subroutine PCI_unregister: not called CC=1 SCAR=6.9
Pod undocumented
62 0 $poe_kernel->post($self->{SESSION_ID} => _shutdown => delete $self->{irc});
63 0 $poe_kernel->refcount_decrement($self->{SESSION_ID}, __PACKAGE__);
64 0 return 1;
65 }
66  
67 sub S_connected {
68 0 ▶ my ($self, $irc) = splice @_, 0, 2;
Subroutine S_connected: not called CC=1 SCAR=6.9
Pod undocumented
69 0 $self->{stashed} = 0;
70 0 $self->{stash} = [ ];
71 0 return PCI_EAT_NONE;
72 }
73  
74 sub S_001 {
75 0 ▶ my ($self, $irc) = splice @_, 0, 2;
Subroutine S_001: not called CC=1 SCAR=6.9
Pod undocumented
76 0 $poe_kernel->post($self->{SESSION_ID} => '_shutdown');
77 0 $poe_kernel->post($self->{SESSION_ID} => '_spawn_listener');
78 0 return PCI_EAT_NONE;
79 }
80  
81 sub S_disconnected {
82 0 ▶ my ($self, $irc) = splice @_, 0, 2;
Subroutine S_disconnected: not called CC=1 SCAR=6.9
Pod undocumented
83 0 $poe_kernel->post($self->{SESSION_ID} => '_shutdown');
84 0 return PCI_EAT_NONE;
85 }
86  
87 sub S_socketerr {
88 0 ▶ my ($self, $irc) = splice @_, 0, 2;
Subroutine S_socketerr: not called CC=1 SCAR=6.9
Pod undocumented
89 0 $poe_kernel->post($self->{SESSION_ID} => '_shutdown');
90 0 return PCI_EAT_NONE;
91 }
92  
93 sub S_error {
94 0 ▶ my ($self, $irc) = splice @_, 0, 2;
Subroutine S_error: not called CC=1 SCAR=6.9
Pod undocumented
95 0 $poe_kernel->post($self->{SESSION_ID} => '_shutdown');
96 0 return PCI_EAT_NONE;
97 }
98  
99 sub S_raw {
100 0 ▶ my ($self, $irc) = splice @_, 0, 2;
Subroutine S_raw: not called CC=6 SCAR=37.4
Pod undocumented
101 0 my $line = ${ $_[0] };
102 0 my $input = $self->{irc_filter}->get( [$line] )->[0];
103  
104 0 ▶ return PCI_EAT_NONE if $input->{command} eq 'PING';
Branch: 1 branch
BranchTrueFalseTotal
if $input->{"command"} eq "PING" 0 0 0
105  
106 0 for my $wheel_id (keys %{ $self->{wheels} }) {
107 0 $self->_send_to_client($wheel_id, $line);
108 }
109  
110 0 ▶ return PCI_EAT_NONE if $self->{stashed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"stashed"} 0 0 0
111  
112 0 ▶ if ($input->{command} =~ /^(?:NOTICE|\d{3})$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input->{"command"} =~ /^(?:NOTICE|\d{3})$/) 0 0 0
113 0 push @{ $self->{stash} }, $line;
114 }
115  
116 0 ▶ $self->{stashed} = 1 if $input->{command} =~ /^(?:376|422)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $input->{"command"} =~ /^(?:376|422)$/ 0 0 0
117 0 return PCI_EAT_NONE;
118 }
119  
120 sub _send_to_client {
121 0 ▶ my ($self, $wheel_id, $line) = splice @_, 0, 3;
Subroutine _send_to_client: not called CC=3 SCAR=24.8
122 0 ▶ return if !defined $self->{wheels}->{ $wheel_id }->{wheel};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"wheels"}{$wheel_id}{"wheel"} 0 0 0
123 0 ▶ return if !$self->{wheels}->{ $wheel_id }->{reg};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"wheels"}{$wheel_id}{"reg"} 0 0 0
124  
125 0 $self->{wheels}->{ $wheel_id }->{wheel}->put($line);
126 0 return;
127 }
128  
129 sub _close_wheel {
130 0 ▶ my ($self, $wheel_id) = splice @_, 0, 2;
Subroutine _close_wheel: not called CC=2 SCAR=17.9
131 0 ▶ return if !defined $self->{wheels}->{ $wheel_id };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"wheels"}{$wheel_id} 0 0 0
132  
133 0 delete $self->{wheels}->{ $wheel_id };
134 0 $self->{irc}->send_event(irc_proxy_close => $wheel_id);
135 0 return;
136 }
137  
138 sub _start {
139 0 ▶ my ($kernel, $self) = @_[KERNEL, OBJECT];
Subroutine _start: not called CC=2 SCAR=17.9
140  
141 0 $self->{SESSION_ID} = $_[SESSION]->ID();
142 0 $kernel->refcount_increment($self->{SESSION_ID}, __PACKAGE__);
143  
144 0 $self->{irc_filter} = POE::Filter::IRCD->new();
145 $self->{ircd_filter} = POE::Filter::Stackable->new(
146 Filters => [
147 POE::Filter::Line->new(),
148 $self->{irc_filter},
149 0 ],
150 );
151  
152 0 ▶ if ($self->{irc}->connected()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"irc"}->connected) 0 0 0
153 0 $kernel->yield('_spawn_listener');
154 }
155 0 return;
156 }
157  
158 sub _spawn_listener {
159 0 ▶ my $self = $_[OBJECT];
Subroutine _spawn_listener: not called CC=4 SCAR=30.0
160  
161 $self->{listener} = POE::Wheel::SocketFactory->new(
162 BindAddress => $self->{bindaddress} || 'localhost',
163 0 ▶ BindPort => $self->{bindport} || 0,
Condition0%0/4
$self->{'bindaddress'} || 'localhost'
l!l
00
$self->{'bindport'} || 0
l!l
00
MC/DC0%0/1
$self->{'bindaddress'} || 'localhost'
$self->{'bindaddress'}
MC/DC0%0/1
$self->{'bindport'} || 0
$self->{'bindport'}
Truth table0%0/2
A
A= $self->{'bindaddress'}
Aresult
11
00
Truth table0%0/2
A
A= $self->{'bindport'}
Aresult
11
00
164 SuccessEvent => '_listener_accept',
165 FailureEvent => '_listener_failed',
166 Reuse => 'yes',
167 );
168  
169 0 ▶ if (!$self->{listener}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"listener"}) 0 0 0
170 0 my $irc = $self->{irc};
171 0 $irc->plugin_del($self);
172 0 return;
173 }
174  
175 0 $self->{irc}->send_event(irc_proxy_up => $self->{listener}->getsockname());
176 0 return;
177 }
178  
179 sub _listener_accept {
180 0 ▶ my ($self, $socket, $peeradr, $peerport) = @_[OBJECT, ARG0 .. ARG2];
Subroutine _listener_accept: not called CC=2 SCAR=17.9
181  
182 my $wheel = POE::Wheel::ReadWrite->new(
183 Handle => $socket,
184 InputFilter => $self->{ircd_filter},
185 0 OutputFilter => POE::Filter::Line->new(),
186 InputEvent => '_client_input',
187 ErrorEvent => '_client_error',
188 FlushedEvent => '_client_flush',
189 );
190  
191 0 ▶ if ($wheel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wheel) { } 0 0 0
192 0 my $wheel_id = $wheel->ID();
193 0 $self->{wheels}->{ $wheel_id }->{wheel} = $wheel;
194 0 $self->{wheels}->{ $wheel_id }->{port} = $peerport;
195 0 $self->{wheels}->{ $wheel_id }->{peer} = inet_ntoa( $peeradr );
196 0 $self->{wheels}->{ $wheel_id }->{start} = time;
197 0 $self->{wheels}->{ $wheel_id }->{reg} = 0;
198 0 $self->{wheels}->{ $wheel_id }->{register} = 0;
199 0 $self->{irc}->send_event(irc_proxy_connect => $wheel_id);
200 }
201 else {
202 0 $self->{irc}->send_event(irc_proxy_rw_fail => inet_ntoa( $peeradr ) => $peerport);
203 }
204  
205 0 return;
206 }
207  
208 sub _listener_failed {
209 0 ▶ delete ( $_[OBJECT]->{listener} );
Subroutine _listener_failed: not called CC=1 SCAR=6.9
210 0 return;
211 }
212  
213 sub _client_flush {
214 0 ▶ my ($self, $wheel_id) = @_[OBJECT, ARG0];
Subroutine _client_flush: not called CC=3 SCAR=24.8
215  
216 0 ▶ return if !defined $self->{wheels}->{ $wheel_id } || !$self->{wheels}->{ $wheel_id }->{quiting};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"wheels"}{$wheel_id} and $self->{"wheels"}{$wheel_id}{"quiting"} 0 0 0
Condition0%0/3
defined $self->{"wheels"}{$wheel_id} and $self->{"wheels"}{$wheel_id}{"quiting"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"wheels"}{$wheel_id} and $self->{"wheels"}{$wheel_id}{"quiting"}
defined $self->{"wheels"}{$wheel_id} $self->{"wheels"}{$wheel_id}{"quiting"}
Truth table0%0/3
A and B
A= defined $self->{"wheels"}{$wheel_id}B= $self->{"wheels"}{$wheel_id}{"quiting"}
ABresult
0X0
100
111
217 0 $self->_close_wheel($wheel_id);
218 0 return;
219 }
220  
221 # this code needs refactoring
222 ## no critic (Subroutines::ProhibitExcessComplexity)
223 sub _client_input {
224 0 ▶ my ($self, $input, $wheel_id) = @_[OBJECT, ARG0, ARG1];
Subroutine _client_input: not called CC=22 SCAR=62.3
225 0 my ($irc, $wheels) = ($self->{irc}, $self->{wheels});
226  
227 0 ▶ return if $wheels->{$wheel_id}{quiting};
Branch: 1 branch
BranchTrueFalseTotal
if $wheels->{$wheel_id}{"quiting"} 0 0 0
228  
229 0 ▶ if ($input->{command} eq 'QUIT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($input->{"command"} eq "QUIT") 0 0 0
230 0 $self->_close_wheel($wheel_id);
231 0 return;
232 }
233  
234 0 ▶ if ($input->{command} eq 'PASS' && $wheels->{$wheel_id}{reg} < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input->{"command"} eq "PASS" and $wheels->{$wheel_id}{"reg"} < 2) 0 0 0
Condition0%0/3
$input->{"command"} eq "PASS" and $wheels->{$wheel_id}{"reg"} < 2
!ll&&!rl&&r
000
MC/DC0%0/2
$input->{"command"} eq "PASS" and $wheels->{$wheel_id}{"reg"} < 2
$input->{"command"} eq "PASS" $wheels->{$wheel_id}{"reg"} < 2
Truth table0%0/3
A and B
A= $input->{"command"} eq "PASS"B= $wheels->{$wheel_id}{"reg"} < 2
ABresult
0X0
100
111
235 0 $wheels->{$wheel_id}{pass} = $input->{params}[0];
236 }
237  
238 0 ▶ if ($input->{command} eq 'NICK' && $wheels->{$wheel_id}{reg} < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input->{"command"} eq "NICK" and $wheels->{$wheel_id}{"reg"} < 2) 0 0 0
Condition0%0/3
$input->{"command"} eq "NICK" and $wheels->{$wheel_id}{"reg"} < 2
!ll&&!rl&&r
000
MC/DC0%0/2
$input->{"command"} eq "NICK" and $wheels->{$wheel_id}{"reg"} < 2
$input->{"command"} eq "NICK" $wheels->{$wheel_id}{"reg"} < 2
Truth table0%0/3
A and B
A= $input->{"command"} eq "NICK"B= $wheels->{$wheel_id}{"reg"} < 2
ABresult
0X0
100
111
239 0 $wheels->{$wheel_id}{nick} = $input->{params}[0];
240 0 $wheels->{$wheel_id}{register}++;
241 }
242  
243 0 ▶ if ($input->{command} eq 'USER' && $wheels->{$wheel_id}{reg} < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input->{"command"} eq "USER" and $wheels->{$wheel_id}{"reg"} < 2) 0 0 0
Condition0%0/3
$input->{"command"} eq "USER" and $wheels->{$wheel_id}{"reg"} < 2
!ll&&!rl&&r
000
MC/DC0%0/2
$input->{"command"} eq "USER" and $wheels->{$wheel_id}{"reg"} < 2
$input->{"command"} eq "USER" $wheels->{$wheel_id}{"reg"} < 2
Truth table0%0/3
A and B
A= $input->{"command"} eq "USER"B= $wheels->{$wheel_id}{"reg"} < 2
ABresult
0X0
100
111
244 0 $wheels->{$wheel_id}{user} = $input->{params}[0];
245 0 $wheels->{$wheel_id}{register}++;
246 }
247  
248 0 ▶ if (!$wheels->{$wheel_id}{reg} && $wheels->{$wheel_id}{register} >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $wheels->{$wheel_id}{"reg"} and $wheels->{$wheel_id}{"register"} >= 2) 0 0 0
Condition0%0/3
not $wheels->{$wheel_id}{"reg"} and $wheels->{$wheel_id}{"register"} >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
not $wheels->{$wheel_id}{"reg"} and $wheels->{$wheel_id}{"register"} >= 2
not $wheels->{$wheel_id}{"reg"} $wheels->{$wheel_id}{"register"} >= 2
Truth table0%0/3
not(A) and B
A= not $wheels->{$wheel_id}{"reg"}B= $wheels->{$wheel_id}{"register"} >= 2
ABresult
0X0
100
111
249 0 my $password = delete $wheels->{$wheel_id}{pass};
250 0 $wheels->{$wheel_id}{reg} = 1;
251  
252 0 ▶ if (!$password || $password ne $self->{password}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $password or $password ne $self->{"password"}) 0 0 0
Condition0%0/3
not $password or $password ne $self->{"password"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $password or $password ne $self->{"password"}
not $password $password ne $self->{"password"}
Truth table0%0/3
not(A) or B
A= not $passwordB= $password ne $self->{"password"}
ABresult
1X1
011
000
253 $self->_send_to_client($wheel_id,
254 'ERROR :Closing Link: * ['
255 . ($wheels->{$wheel_id}{user} || 'unknown')
256 . '@' . $wheels->{$wheel_id}{peer}
257 0 ▶ . '] (Unauthorised connection)'
Condition0%0/2
$wheels->{$wheel_id}{'user'} || 'unknown'
l!l
00
MC/DC0%0/1
$wheels->{$wheel_id}{'user'} || 'unknown'
$wheels->{$wheel_id}{'user'}
Truth table0%0/2
A
A= $wheels->{$wheel_id}{'user'}
Aresult
11
00
258 );
259 0 $wheels->{$wheel_id}{quiting}++;
260 0 return;
261 }
262  
263 0 my $nickname = $irc->nick_name();
264 0 my $fullnick = $irc->nick_long_form($nickname);
265 0 ▶ if ($nickname ne $wheels->{$wheel_id}{nick}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nickname ne $wheels->{$wheel_id}{"nick"}) 0 0 0
266 0 $self->_send_to_client($wheel_id, "$wheels->{$wheel_id}{nick} NICK :$nickname");
267 }
268  
269 0 for my $line (@{ $self->{stash} }) {
270 0 $self->_send_to_client($wheel_id, $line);
271 }
272  
273 0 for my $channel ($irc->nick_channels($nickname)) {
274 0 $self->_send_to_client($wheel_id, ":$fullnick JOIN $channel");
275 0 $irc->yield(names => $channel);
276 0 $irc->yield(topic => $channel);
277 }
278  
279 0 $irc->send_event(irc_proxy_authed => $wheel_id);
280 0 return;
281 }
282  
283 0 ▶ return if !$wheels->{$wheel_id}{reg};
Branch: 1 branch
BranchTrueFalseTotal
unless $wheels->{$wheel_id}{"reg"} 0 0 0
284  
285 0 ▶ if ($input->{command} =~ /^(?:NICK|USER|PASS)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input->{"command"} =~ /^(?:NICK|USER|PASS)$/) 0 0 0
286 0 return;
287 }
288  
289 0 ▶ if ($input->{command} eq 'PING') {
Branch: 1 branch
BranchTrueFalseTotal
if ($input->{"command"} eq "PING") 0 0 0
290 0 $self->_send_to_client($wheel_id, "PONG $input->{params}[0]");
291 0 return;
292 }
293  
294 0 ▶ if ($input->{command} eq 'PONG' and $input->{params}[0] =~ /^[0-9]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input->{"command"} eq "PONG" and $input->{"params"}[0] =~ /^[0-9]+$/) 0 0 0
Condition0%0/3
$input->{"command"} eq "PONG" and $input->{"params"}[0] =~ /^[0-9]+$/
!ll&&!rl&&r
000
MC/DC0%0/2
$input->{"command"} eq "PONG" and $input->{"params"}[0] =~ /^[0-9]+$/
$input->{"command"} eq "PONG" $input->{"params"}[0] =~ /^[0-9]+$/
Truth table0%0/3
A and B
A= $input->{"command"} eq "PONG"B= $input->{"params"}[0] =~ /^[0-9]+$/
ABresult
0X0
100
111
295 0 $wheels->{$wheel_id}{lag} = time() - $input->{params}[0];
296 0 return;
297 }
298  
299 0 $irc->yield(quote => $input->{raw_line});
300 0 return;
301 }
302  
303 sub _client_error {
304 0 ▶ my ($self, $wheel_id) = @_[OBJECT, ARG3];
Subroutine _client_error: not called CC=1 SCAR=6.9
305  
306 0 $self->_close_wheel($wheel_id);
307 0 return;
308 }
309  
310 sub _shutdown {
311 0 ▶ my $self = $_[OBJECT];
Subroutine _shutdown: not called CC=3 SCAR=24.8
312 0 ▶ my $irc = $self->{irc} || $_[ARG0];
Condition0%0/3
$self->{'irc'} || $_[10]
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'irc'} || $_[10]
$self->{'irc'} $_[10]
Truth table0%0/3
A || B
A= $self->{'irc'}B= $_[10]
ABresult
1X1
011
000
313  
314 0 my $mysockaddr = $self->getsockname();
315 0 delete $self->{listener};
316  
317 0 for my $wheel_id ( $self->list_wheels() ) {
318 0 $self->_close_wheel( $wheel_id );
319 }
320 0 delete $self->{wheels};
321 0 $irc->send_event(irc_proxy_down => $mysockaddr);
322  
323 0 return;
324 }
325  
326 sub getsockname {
327 0 ▶ my ($self) = @_;
Subroutine getsockname: not called CC=2 SCAR=17.9
Pod documented
328 0 ▶ return if !$self->{listener};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"listener"} 0 0 0
329 0 return $self->{listener}->getsockname();
330 }
331  
332 sub list_wheels {
333 0 ▶ my ($self) = @_;
Subroutine list_wheels: not called CC=1 SCAR=6.9
Pod documented
334 0 return keys %{ $self->{wheels} };
335 }
336  
337 sub wheel_info {
338 0 ▶ my ($self, $wheel_id) = @_;
Subroutine wheel_info: not called CC=3 SCAR=24.8
Pod documented
339 0 ▶ return if !defined $self->{wheels}->{ $wheel_id };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"wheels"}{$wheel_id} 0 0 0
340 0 ▶ return $self->{wheels}->{ $wheel_id }->{start} if !wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
341 0 return map { $self->{wheels}->{ $wheel_id }->{$_} } qw(peer port start lag);
342 }
343  
344 1 1;
345  
346 =encoding utf8
347  
348 =head1 NAME
349  
350 POE::Component::IRC::Plugin::Proxy - A PoCo-IRC plugin that provides a
351 lightweight IRC proxy/bouncer
352  
353 =head1 SYNOPSIS
354  
355 use strict;
356 use warnings;
357 use POE qw(Component::IRC::State Component::IRC::Plugin::Proxy Component::IRC::Plugin::Connector);
358  
359 my $irc = POE::Component::IRC::State->spawn();
360  
361 POE::Session->create(
362 package_states => [
363 main => [ qw(_start) ],
364 ],
365 heap => { irc => $irc },
366 );
367  
368 $poe_kernel->run();
369  
370 sub _start {
371 my ($kernel, $heap) = @_[KERNEL, HEAP];
372 $heap->{irc}->yield( register => 'all' );
373 $heap->{proxy} = POE::Component::IRC::Plugin::Proxy->new( bindport => 6969, password => "m00m00" );
374 $heap->{irc}->plugin_add( 'Connector' => POE::Component::IRC::Plugin::Connector->new() );
375 $heap->{irc}->plugin_add( 'Proxy' => $heap->{proxy} );
376 $heap->{irc}->yield ( connect => { Nick => 'testbot', Server => 'someserver.com' } );
377 return;
378 }
379  
380 =head1 DESCRIPTION
381  
382 POE::Component::IRC::Plugin::Proxy is a L<POE::Component::IRC>
383 plugin that provides lightweight IRC proxy/bouncer server to your
384 L<POE::Component::IRC> bots. It enables multiple IRC
385 clients to be hidden behind a single IRC client-server connection.
386  
387 Spawn a L<POE::Component::IRC::State> session and add in a
388 POE::Component::IRC::Plugin::Proxy plugin object, specifying a bindport and a
389 password the connecting IRC clients have to use. When the component is
390 connected to an IRC network a listening port is opened by the plugin for
391 multiple IRC clients to connect.
392  
393 Neat, huh? >;o)
394  
395 This plugin will activate L<POE::Component::IRC>'s raw
396 events (L<C<irc_raw>|POE::Component::IRC/irc_raw>) by calling
397 C<< $irc->raw_events(1) >>.
398  
399 This plugin requires the IRC component to be
400 L<POE::Component::IRC::State> or a subclass thereof.
401  
402 =head1 METHODS
403  
404 =head2 C<new>
405  
406 Takes a number of arguments:
407  
408 B<'password'>, the password to require from connecting clients;
409  
410 B<'bindaddress'>, a local address to bind the listener to, default is 'localhost';
411  
412 B<'bindport'>, what port to bind to, default is 0, ie. randomly allocated by OS;
413  
414 Returns an object suitable for passing to
415 L<POE::Component::IRC>'s C<plugin_add> method.
416  
417 =head2 C<getsockname>
418  
419 Takes no arguments. Accesses the listeners C<getsockname> method. See
420 L<POE::Wheel::SocketFactory> for details of the
421 return value;
422  
423 =head2 C<list_wheels>
424  
425 Takes no arguments. Returns a list of wheel ids of the current connected clients.
426  
427 =head2 C<wheel_info>
428  
429 Takes one parameter, a wheel ID to query. Returns undef if an invalid wheel id
430 is passed. In a scalar context returns the time that the client connected in
431 unix time. In a list context returns a list consisting of the peer address,
432 port, tthe connect time and the lag in seconds for that connection.
433  
434 =head1 OUTPUT EVENTS
435  
436 The plugin emits the following L<POE::Component::IRC>
437 events:
438  
439 =head2 C<irc_proxy_up>
440  
441 Emitted when the listener is successfully started. C<ARG0> is the result of the
442 listener C<getsockname>.
443  
444 =head2 C<irc_proxy_connect>
445  
446 Emitted when a client connects to the listener. C<ARG0> is the wheel ID of the
447 client.
448  
449 =head2 C<irc_proxy_rw_fail>
450  
451 Emitted when the L<POE::Wheel::ReadWrite> fails on a
452 connection. C<ARG0> is the wheel ID of the client.
453  
454 =head2 C<irc_proxy_authed>
455  
456 Emitted when a connecting client successfully negotiates an IRC session with
457 the plugin. C<ARG0> is the wheel ID of the client.
458  
459 =head2 C<irc_proxy_close>
460  
461 Emitted when a connected client disconnects. C<ARG0> is the wheel ID of the
462 client.
463  
464 =head2 C<irc_proxy_down>
465  
466 Emitted when the listener is successfully shutdown. C<ARG0> is the result of the
467 listener C<getsockname>.
468  
469 =head1 QUIRKS
470  
471 Connecting IRC clients will not be able to change nickname. This is a feature.
472  
473 =head1 AUTHOR
474  
475 Chris 'BinGOs' Williams
476  
477 =head1 SEE ALSO
478  
479 L<POE::Component::IRC>
480  
481 L<POE::Component::IRC::State>
482  
483 =cut
« Component/IRC/Plugin/BotCommand.pm ↑ Summary Filter/IRC/Compat.pm »