MultiProxy/ClientManager.pm

filter: Statementstmt 18.1% 24 / 132 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 37.5% 9 / 24 Podpod 40.0% 2 / 5 totaltotal 14.4% 35 / 243 CC 37 SCAR 59.5
CC
37
Cov
12%
_client_input
812.0
PCI_register
20.0
S_raw
20.0
CRAP 382.6
↑ Summary MultiProxy/State.pm »
1 package POE::Component::IRC::Plugin::MultiProxy::ClientManager;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $POE::Component::IRC::Plugin::MultiProxy::ClientManager::AUTHORITY = 'cpan:HINRIK';
4 }
5 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $POE::Component::IRC::Plugin::MultiProxy::ClientManager::VERSION = '0.01';
7 }
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use POE qw(Filter::Line Filter::Stackable);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use POE::Component::IRC::Common qw( u_irc );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use POE::Component::IRC::Plugin qw( :ALL );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use POE::Filter::IRCD;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
18 0 my ($package, %self) = @_;
19 0 return bless \%self, $package;
20 }
21  
22 0 ▶sub PCI_register {
Subroutine PCI_register: not called CC=4 SCAR=30.0
Pod undocumented
23 0 my ($self, $irc) = @_;
24  
25 0 ▶ if (!$irc->isa('POE::Component::IRC::State')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($irc->isa("POE::Component::IRC::State")) 0 0 0
26 0 die __PACKAGE__ . " requires PoCo::IRC::State or a subclass thereof\n";
27 }
28  
29 0 for my $plugin (qw(Recall State)) {
30 0 my $full = "POE::Component::IRC::Plugin::MultiProxy::$plugin";
31  
32 0 ▶ if (!grep { $_->isa($full) } values %{ $irc->plugin_list() } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_->isa($full);} values %{$irc->plugin_list;}) 0 0 0
33 0 die __PACKAGE__ . " requires $full\n";
34 }
35 }
36  
37 0 $self->{ircd_filter} = POE::Filter::IRCD->new();
38 0 $self->{wheels} = { };
39  
40 0 ($self->{state}) = grep { $_->isa('POE::Component::IRC::Plugin::MultiProxy::State') } values %{ $irc->plugin_list() };
41 0 $self->{irc} = $irc;
42 0 $irc->raw_events(1);
43 0 $irc->plugin_register($self, 'SERVER', qw(raw));
44  
45 0 POE::Session->create(
46 object_states => [
47 $self => [ qw(_start _client_new _client_error _client_input _drop_client) ],
48 ],
49 );
50  
51 0 return 1;
52 }
53  
54 0 ▶sub PCI_unregister {
Subroutine PCI_unregister: not called CC=2 SCAR=17.9
Pod undocumented
55 0 my ($self, $irc) = @_;
56  
57 0 for my $id (keys %{ $self->{wheels} }) {
58 0 $poe_kernel->call("$self", '_drop_client', $id);
59 }
60 0 $poe_kernel->alias_remove("$self");
61 0 return 1;
62 }
63  
64 0 ▶sub add_client {
Subroutine add_client: not called CC=1 SCAR=6.9
Pod documented
65 0 my ($self, $socket) = @_;
66 0 $poe_kernel->call("$self", '_client_new', $socket);
67 0 return;
68 }
69  
70 0 ▶sub _start {
Subroutine _start: not called CC=1 SCAR=6.9
71 0 my ($kernel, $self) = @_[KERNEL, OBJECT];
72 0 $kernel->alias_set("$self");
73 0 return;
74 }
75  
76 0 ▶sub _client_new {
Subroutine _client_new: not called CC=1 SCAR=6.9
77 0 my ($self, $socket) = @_[OBJECT, ARG0];
78  
79 0 my $filter = POE::Filter::Stackable->new(
80 Filters => [
81 POE::Filter::Line->new(),
82 POE::Filter::IRCD->new(),
83 ]
84 );
85  
86 0 my $wheel = POE::Wheel::ReadWrite->new(
87 Handle => $socket,
88 InputFilter => $filter,
89 OutputFilter => POE::Filter::Line->new(),
90 InputEvent => '_client_input',
91 ErrorEvent => '_client_error',
92 );
93  
94 0 $self->{wheels}{$wheel->ID} = $wheel;
95  
96 0 my ($recall_plug) = grep { $_->isa('POE::Component::IRC::Plugin::MultiProxy::Recall') } values %{ $self->{irc}->plugin_list() };
97 0 $wheel->put($recall_plug->recall());
98 0 return;
99 }
100  
101 0 ▶sub _client_error {
Subroutine _client_error: not called CC=1 SCAR=6.9
102 0 my ($kernel, $wheel_id) = @_[KERNEL, ARG3];
103 0 $kernel->yield('_drop_client', $wheel_id);
104 0 return;
105 }
106  
107 0 ▶sub _client_input {
Subroutine _client_input: not called CC=28 SCAR=67.0
108 0 my ($kernel, $self, $input, $wheel_id) = @_[KERNEL, OBJECT, ARG0, ARG1];
109 0 my $irc = $self->{irc};
110 0 my $state = $self->{state};
111 0 my $wheel = $self->{wheels}{$wheel_id};
112  
113 0 ▶ if ($input->{command} eq 'QUIT') {
Branch: 7 branches
BranchTrueFalseTotal
if ($input->{'command'} eq 'QUIT') { } 0 0 0
elsif ($input->{'command'} eq 'PING') { } 0 0 0
elsif ($input->{'command'} eq 'PRIVMSG') { } 0 0 0
elsif ($input->{'command'} eq 'WHO') { } 0 0 0
elsif ($input->{'command'} eq 'MODE') { } 0 0 0
elsif ($input->{'command'} eq 'NAMES') { } 0 0 0
elsif ($input->{'command'} eq 'TOPIC') { } 0 0 0
114 0 $kernel->yield('_drop_client', $wheel->ID);
115 0 return;
116 }
117 elsif ($input->{command} eq 'PING') {
118 0 ▶ $wheel->put('PONG'.(defined $input->{params}[0] ? " $input->{params}[0]" : ''));
Branch: 1 branch
BranchTrueFalseTotal
defined $input->{'params'}[0] ? : 0 0 0
119 0 return;
120 }
121 elsif ($input->{command} eq 'PRIVMSG') {
122 0 my ($recipient, $msg) = @{ $input->{params} }[0..1];
123 0 ▶ if ($recipient =~ /^[#&+!]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recipient =~ /^[#&+!]/) 0 0 0
124 # recreate channel messages from this client for
125 # other clients to see
126 0 my $line = ':' . $irc->nick_long_form($irc->nick_name()) . " PRIVMSG $recipient :$msg";
127  
128 0 for my $other (values %{ $self->{wheels} }) {
129 0 ▶ next if $other->ID == $wheel->ID;
Branch: 1 branch
BranchTrueFalseTotal
if $other->ID == $wheel->ID 0 0 0
130 0 $other->put($line);
131 }
132 }
133 }
134 elsif ($input->{command} eq 'WHO') {
135 0 ▶ if ($input->{params}[0] && $input->{params}[0] !~ tr/*//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input->{"params"}[0] and not $input->{"params"}[0] =~ tr/*//) 0 0 0
Condition0%0/3
$input->{"params"}[0] and not $input->{"params"}[0] =~ tr/*//
!ll&&!rl&&r
000
MC/DC0%0/2
$input->{"params"}[0] and not $input->{"params"}[0] =~ tr/*//
$input->{"params"}[0] not $input->{"params"}[0] =~ tr/*//
Truth table0%0/3
A and not(B)
A= $input->{"params"}[0]B= not $input->{"params"}[0] =~ tr/*//
ABresult
0X0
100
111
136 0 ▶ if (!defined $input->{params}[1]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $input->{"params"}[1]) 0 0 0
137 0 ▶ if ($input->{params}[0] !~ /^[#&+!]/ || $irc->channel_list($input->{params}[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $input->{"params"}[0] =~ /^[#&+!]/ or $irc->channel_list($input->{"params"}[0])) 0 0 0
Condition0%0/3
not $input->{"params"}[0] =~ /^[#&+!]/ or $irc->channel_list($input->{"params"}[0])
l!l&&r!l&&!r
000
MC/DC0%0/2
not $input->{"params"}[0] =~ /^[#&+!]/ or $irc->channel_list($input->{"params"}[0])
not $input->{"params"}[0] =~ /^[#&+!]/ $irc->channel_list($input->{"params"}[0])
Truth table0%0/3
not(A) or B
A= not $input->{"params"}[0] =~ /^[#&+!]/B= $irc->channel_list($input->{"params"}[0])
ABresult
1X1
011
000
138 0 ▶ $state->enqueue(sub { $self->_put($wheel->ID, @_) }, 'who_reply', $input->{params}[0]);
Subroutine __ANON__: not called CC=1 SCAR=6.9
139 0 return;
140 }
141 }
142 }
143 }
144 elsif ($input->{command} eq 'MODE') {
145 0 ▶ if ($input->{params}[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input->{"params"}[0]) 0 0 0
146 0 my $mapping = $irc->isupport('CASEMAPPING');
147 0 ▶ if (u_irc($input->{params}[0], $mapping) eq u_irc($irc->nick_name(), $mapping)) {
Branch: 2 branches
BranchTrueFalseTotal
if (u_irc($input->{'params'}[0], $mapping) eq u_irc($irc->nick_name, $mapping)) { } 0 0 0
elsif ($input->{'params'}[0] =~ /^[#&+!]/ and $irc->channel_list($input->{'params'}[0])) { } 0 0 0
148 0 ▶ if (!defined $input->{params}[1]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $input->{"params"}[1]) 0 0 0
149 0 $wheel->put($state->mode_reply($input->{params}[0]));
150 0 return;
151 }
152 }
153 ▶ elsif ($input->{params}[0] =~ /^[#&+!]/ && $irc->channel_list($input->{params}[0])) {
Condition0%0/3
$input->{"params"}[0] =~ /^[#&+!]/ and $irc->channel_list($input->{"params"}[0])
!ll&&!rl&&r
000
MC/DC0%0/2
$input->{"params"}[0] =~ /^[#&+!]/ and $irc->channel_list($input->{"params"}[0])
$input->{"params"}[0] =~ /^[#&+!]/ $irc->channel_list($input->{"params"}[0])
Truth table0%0/3
A and B
A= $input->{"params"}[0] =~ /^[#&+!]/B= $irc->channel_list($input->{"params"}[0])
ABresult
0X0
100
111
154 0 ▶ if (!defined $input->{params}[1] || $input->{params}[1] =~ /^[eIb]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $input->{"params"}[1] or $input->{"params"}[1] =~ /^[eIb]$/) 0 0 0
Condition0%0/3
not defined $input->{"params"}[1] or $input->{"params"}[1] =~ /^[eIb]$/
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $input->{"params"}[1] or $input->{"params"}[1] =~ /^[eIb]$/
not defined $input->{"params"}[1] $input->{"params"}[1] =~ /^[eIb]$/
Truth table0%0/3
not(A) or B
A= not defined $input->{"params"}[1]B= $input->{"params"}[1] =~ /^[eIb]$/
ABresult
1X1
011
000
155 0 ▶ $state->enqueue(sub { $self->_put($wheel->ID, @_) }, 'mode_reply', @{ $input->{params} }[0,1]);
Subroutine __ANON__: not called CC=1 SCAR=6.9
156 0 return;
157 }
158 }
159 }
160 }
161 elsif ($input->{command} eq 'NAMES') {
162 0 ▶ if ($irc->channel_list($input->{params}[0]) && !defined $input->{params}[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($irc->channel_list($input->{"params"}[0]) and not defined $input->{"params"}[1]) 0 0 0
Condition0%0/3
$irc->channel_list($input->{"params"}[0]) and not defined $input->{"params"}[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$irc->channel_list($input->{"params"}[0]) and not defined $input->{"params"}[1]
$irc->channel_list($input->{"params"}[0]) not defined $input->{"params"}[1]
Truth table0%0/3
A and not(B)
A= $irc->channel_list($input->{"params"}[0])B= not defined $input->{"params"}[1]
ABresult
0X0
100
111
163 0 ▶ $state->enqueue(sub { $self->_put($wheel->ID, @_) }, 'names_reply', $input->{params}[0]);
Subroutine __ANON__: not called CC=1 SCAR=6.9
164 0 return;
165 }
166 }
167 elsif ($input->{command} eq 'TOPIC') {
168 0 ▶ if ($irc->channel_list($input->{params}[0]) && !defined $input->{params}[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($irc->channel_list($input->{"params"}[0]) and not defined $input->{"params"}[1]) 0 0 0
Condition0%0/3
$irc->channel_list($input->{"params"}[0]) and not defined $input->{"params"}[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$irc->channel_list($input->{"params"}[0]) and not defined $input->{"params"}[1]
$irc->channel_list($input->{"params"}[0]) not defined $input->{"params"}[1]
Truth table0%0/3
A and not(B)
A= $irc->channel_list($input->{"params"}[0])B= not defined $input->{"params"}[1]
ABresult
0X0
100
111
169 0 ▶ $state->enqueue(sub { $self->_put($wheel->ID, @_) }, 'topic_reply', $input->{params}[0]);
Subroutine __ANON__: not called CC=1 SCAR=6.9
170 0 return;
171 }
172 }
173  
174 0 $irc->yield(quote => $input->{raw_line});
175  
176 0 return;
177 }
178  
179 0 ▶sub _drop_client {
Subroutine _drop_client: not called CC=2 SCAR=17.9
180 0 my ($self, $wheel_id) = @_[OBJECT, ARG0];
181 0 my $irc = $self->{irc};
182  
183 0 ▶ if (delete $self->{wheels}{$wheel_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $self->{"wheels"}{$wheel_id}) 0 0 0
184 0 $irc->send_event(irc_proxy_close => $wheel_id);
185 }
186 0 return;
187 }
188  
189 0 ▶sub S_raw {
Subroutine S_raw: not called CC=4 SCAR=30.0
Pod undocumented
190 0 my ($self, $irc) = splice @_, 0, 2;
191 0 my $raw_line = ${ $_[0] };
192 0 ▶ return PCI_EAT_NONE if !keys %{ $self->{wheels} };
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$$self{"wheels"};} 0 0 0
193  
194 0 my $input = $self->{ircd_filter}->get( [ $raw_line ] )->[0];
195 0 ▶ return PCI_EAT_NONE if $input->{command} !~ /^(?:PING|PONG)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $input->{"command"} =~ /^(?:PING|PONG)/ 0 0 0
196 0 $_->put($raw_line) for values %{ $self->{wheels} };
197 0 return PCI_EAT_NONE;
198 }
199  
200 0 ▶sub _put {
Subroutine _put: not called CC=2 SCAR=17.9
201 0 my ($self, $wheel_id, $raw_line) = @_;
202 0 ▶ return if !defined $self->{wheels}{$wheel_id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"wheels"}{$wheel_id} 0 0 0
203 0 $self->{wheels}{$wheel_id}->put($raw_line);
204 0 return;
205 }
206  
207 1 1;
208  
209 =encoding utf8
210  
211 =head1 NAME
212  
213 POE::Compoent::IRC::Plugin::MultiProxy::ClientManager - A PoCo-IRC plugin which handles a proxy clients
214  
215 =head1 SYNOPSIS
216  
217 use POE::Compoent::IRC::Plugin::MultiProxy::ClientManager;
218  
219 $irc->plugin_add('MultiProxyClient_1', POE::Compoent::IRC::Plugin::MultiProxy::Client->new());
220  
221 =head1 DESCRIPTION
222  
223 POE::Compoent::IRC::Plugin::MultiProxy::Client is a
224 L<POE::Component::IRC|POE::Component::IRC> plugin. It handles a input/output
225 and disconnects from a proxy client.
226  
227 This plugin requires the IRC component to be
228 L<POE::Component::IRC::State|POE::Component::IRC::State> or a subclass thereof.
229  
230 =head1 METHODS
231  
232 =head2 C<new>
233  
234 Takes no arguments. Returns a plugin object suitable for feeding to
235 L<POE::Component::IRC|POE::Component::IRC>'s C<plugin_add()> method.
236  
237 =head2 C<add_client>
238  
239 Takes one argument, the socket of the new proxy client.
240  
241 =head1 AUTHOR
242  
243 Hinrik E<Ouml>rn SigurE<eth>sson, hinrik.sig@gmail.com
244  
245 =cut
↑ Summary MultiProxy/State.pm »