Component/IRC/Plugin/Proxy.pm

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