SimpleHTTP.pm

filter: Statementstmt 59.8% 308 / 515 Branchbran 40.0% 96 / 240 Conditioncond 21.4% 27 / 126 MC/DCmcdc 0.0% 0 / 74 Subroutinesub 72.8% 43 / 59 Podpod 11.1% 1 / 9 totaltotal 46.4% 475 / 1023 CC 265 SCAR 41.4
CC
265
Cov
49%
STREAM
272.0
__ANON__
272.0
DONE
108.3
CRAP 63.0
↑ Summary SimpleHTTP/Connection.pm »
1 package POE::Component::Server::SimpleHTTP;
2 8 $POE::Component::Server::SimpleHTTP::VERSION = '2.30';
3 #ABSTRACT: Perl extension to serve HTTP requests in POE.
4  
5 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use POE::Wheel::SocketFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use POE::Wheel::ReadWrite;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use POE::Filter::HTTPD;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use POE::Filter::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use Socket qw( AF_INET AF_INET6 INADDR_ANY IN6ADDR_ANY inet_pton );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 8 ▶use HTTP::Date qw( time2str );
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 8 ▶use POE::Component::Server::SimpleHTTP::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use POE::Component::Server::SimpleHTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 8 ▶use POE::Component::Server::SimpleHTTP::State;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 8 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.4
24  
25 # Debug fun!
26 8 ▶ if ( !defined &DEBUG ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &POE::Component::Server::SimpleHTTP::DEBUG) 8 0 8
27 8 eval "sub DEBUG () { 0 }";
28 }
29  
30 # Our own definition of the max retries
31 8 ▶ if ( !defined &MAX_RETRIES ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined &POE::Component::Server::SimpleHTTP::MAX_RETRIES) 8 0 8
32 8 eval "sub MAX_RETRIES () { 5 }";
33 }
34 }
35  
36 8 ▶use MooseX::POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 8 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39  
40 8 has 'alias' => (
41 is => 'ro',
42 );
43  
44 8 has 'domain' => (
45 is => 'ro',
46 );
47  
48 8 has 'address' => (
49 is => 'ro',
50 );
51  
52 has 'port' => (
53 is => 'ro',
54 0 ▶ default => sub { 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 8 writer => '_set_port',
56 );
57  
58 has 'hostname' => (
59 is => 'ro',
60 0 ▶ default => sub { require Sys::Hostname; return Sys::Hostname::hostname(); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
61 8 );
62  
63 has 'proxymode' => (
64 is => 'ro',
65 isa => 'Bool',
66 7 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
67 8 );
68  
69 has 'keepalive' => (
70 is => 'ro',
71 isa => 'Bool',
72 6 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
73 8 );
74  
75 has 'sslkeycert' => (
76 is => 'ro',
77 0 ▶ isa => subtype 'ArrayRef' => where { scalar @$_ == 2 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 8 );
79  
80 8 has 'sslintermediatecacert' => (
81 is => 'ro',
82 isa => 'Str',
83 );
84  
85 has 'headers' => (
86 is => 'ro',
87 isa => 'HashRef',
88 7 ▶ default => sub {{}},
Subroutine __ANON__: called CC=1 SCAR=0.0
89 8 );
90  
91 8 has 'handlers' => (
92 is => 'ro',
93 isa => 'ArrayRef',
94 required => 1,
95 writer => '_set_handlers',
96 );
97  
98 has 'errorhandler' => (
99 is => 'ro',
100 isa => 'HashRef',
101 7 ▶ default => sub {{}},
Subroutine __ANON__: called CC=1 SCAR=0.0
102 8 );
103  
104 has 'loghandler' => (
105 is => 'ro',
106 isa => 'HashRef',
107 7 ▶ default => sub {{}},
Subroutine __ANON__: called CC=1 SCAR=0.0
108 8 );
109  
110 has 'log2handler' => (
111 is => 'ro',
112 isa => 'HashRef',
113 7 ▶ default => sub {{}},
Subroutine __ANON__: called CC=1 SCAR=0.0
114 8 );
115  
116 has 'setuphandler' => (
117 is => 'ro',
118 isa => 'HashRef',
119 0 ▶ default => sub {{}},
Subroutine __ANON__: not called CC=1 SCAR=6.9
120 8 );
121  
122 has 'retries' => (
123 traits => ['Counter'],
124 is => 'ro',
125 isa => 'Num',
126 7 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
127 8 handles => {
128 inc_retry => 'inc',
129 dec_retry => 'dec',
130 reset_retries => 'reset',
131 },
132 );
133  
134 has '_requests' => (
135 is => 'ro',
136 isa => 'HashRef',
137 7 ▶ default => sub {{}},
Subroutine __ANON__: called CC=1 SCAR=0.0
138 8 init_arg => undef,
139 clearer => '_clear_requests',
140 );
141  
142 has '_connections' => (
143 is => 'ro',
144 isa => 'HashRef',
145 7 ▶ default => sub {{}},
Subroutine __ANON__: called CC=1 SCAR=0.0
146 8 init_arg => undef,
147 clearer => '_clear_connections',
148 );
149  
150 has '_chunkcount' => (
151 is => 'ro',
152 isa => 'HashRef',
153 7 ▶ default => sub {{}},
Subroutine __ANON__: called CC=1 SCAR=0.0
154 8 init_arg => undef,
155 clearer => '_clear_chunkcount',
156 );
157  
158 has '_responses' => (
159 is => 'ro',
160 isa => 'HashRef',
161 7 ▶ default => sub {{}},
Subroutine __ANON__: called CC=1 SCAR=0.0
162 8 init_arg => undef,
163 clearer => '_clear_responses',
164 );
165  
166 8 has '_factory' => (
167 is => 'ro',
168 isa => 'POE::Wheel::SocketFactory',
169 init_arg => undef,
170 clearer => '_clear_factory',
171 writer => '_set_factory',
172 );
173  
174 7 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=7 SCAR=32.4
Pod documented
175 7 my $class = shift;
176 7 my %args = @_;
177 7 $args{lc $_} = delete $args{$_} for keys %args;
178  
179 7 ▶ if ( $args{sslkeycert} and ref $args{sslkeycert} eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"sslkeycert"} and ref $args{"sslkeycert"} eq "ARRAY" and scalar @{$args{"sslkeycert"};} == 2) 0 7 7
Condition33%2/6
$args{"sslkeycert"} and ref $args{"sslkeycert"} eq "ARRAY" and scalar @{$args{"sslkeycert"};} == 2
!ll&&!rl&&r
700
$args{"sslkeycert"} and ref $args{"sslkeycert"} eq "ARRAY"
!ll&&!rl&&r
700
MC/DC0%0/3
$args{"sslkeycert"} and ref $args{"sslkeycert"} eq "ARRAY" and scalar @{$args{"sslkeycert"};} == 2
$args{"sslkeycert"} ref $args{"sslkeycert"} eq "ARRAY" scalar @{$args{"sslkeycert"};} == 2
Truth table25%1/4
A and B and C
A= $args{"sslkeycert"}B= ref $args{"sslkeycert"} eq "ARRAY"C= scalar @{$args{"sslkeycert"};} == 2
ABCresult
0XX0
10X0
1100
1111
180 0 and scalar @{ $args{sslkeycert} } == 2 ) {
181  
182 0 eval {
183 0 require POE::Component::SSLify;
184 0 import POE::Component::SSLify
185 qw( SSLify_Options SSLify_GetSocket Server_SSLify SSLify_GetCipher SSLify_GetCTX );
186 0 SSLify_Options( @{ $args{sslkeycert} } );
187 };
188 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
189 0 warn "Unable to load PoCo::SSLify -> $@" if DEBUG;
190 0 delete $args{sslkeycert};
191 }
192 else {
193 0 ▶ if ( $args{sslintermediatecacert} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"sslintermediatecacert"}) 0 0 0
194 0 my $ctx = SSLify_GetCTX();
195 0 Net::SSLeay::CTX_load_verify_locations($ctx, $args{sslintermediatecacert}, '');
196 }
197 }
198 }
199  
200 7 return $class->SUPER::BUILDARGS(%args);
201 }
202  
203 0 ▶sub session_id {
Subroutine session_id: not called CC=1 SCAR=6.9
Pod undocumented
204 0 shift->get_session_id;
205 }
206  
207 0 ▶sub getsockname {
Subroutine getsockname: not called CC=1 SCAR=6.9
Pod undocumented
208 0 shift->_factory->getsockname;
209 }
210  
211 0 ▶sub shutdown {
Subroutine shutdown: not called CC=1 SCAR=6.9
Pod undocumented
212 0 my $self = shift;
213 0 $poe_kernel->call( $self->get_session_id, 'SHUTDOWN', @_ );
214 }
215  
216 # This subroutine, when SimpleHTTP exits, will search for leaks
217 7 ▶sub STOP {
Subroutine STOP: called CC=2 SCAR=7.1
Pod undocumented
218 7 my $self = $_[OBJECT];
219 # Loop through all of the requests
220 7 foreach my $req ( keys %{ $self->_requests } ) {
221  
222 # Bite the programmer!
223 warn 'Did not get DONE/CLOSE event for Wheel ID '
224 . $req
225 . ' from IP '
226 0 . $self->_requests->{$req}->response->connection->remote_ip;
227 }
228  
229 # All done!
230 7 return 1;
231 }
232  
233 7 ▶sub START {
Subroutine START: called CC=3 SCAR=11.2
Pod undocumented
234 7 my ($kernel,$self) = @_[KERNEL,OBJECT];
235 7 ▶ $kernel->alias_set( $self->alias ) if $self->alias;
Branch: 1 branch
BranchTrueFalseTotal
if $self->alias 7 0 7
236 7 ▶ $kernel->refcount_increment( $self->get_session_id, __PACKAGE__ )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->alias 0 7 7
237 unless $self->alias;
238 7 MassageHandlers( $self->handlers );
239 # Start Listener
240 7 $kernel->yield( 'start_listener' );
241 7 return;
242 }
243  
244 # 'SHUTDOWN'
245 # Stops the server!
246 2 ▶event 'SHUTDOWN' => sub {
Subroutine SHUTDOWN: called CC=13 SCAR=41.1
247 2 my ($kernel,$self,$graceful) = @_[KERNEL,OBJECT,ARG0];
248 # Shutdown the SocketFactory wheel
249 2 ▶ $self->_clear_factory if $self->_factory;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_factory 2 0 2
250  
251 # Debug stuff
252 2 warn 'Stopped listening for new connections!' if DEBUG;
253  
254 # Are we gracefully shutting down or not?
255 2 ▶ if ( $graceful ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($graceful) 0 2 2
256  
257 # Check for existing requests and keep-alive connections
258 0 ▶ if ( keys( %{ $self->_requests } ) == 0
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$self->_requests;} == 0 and keys %{$self->_connections;} == 0) 0 0 0
Condition0%0/3
keys %{$self->_requests;} == 0 and keys %{$self->_connections;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
keys %{$self->_requests;} == 0 and keys %{$self->_connections;} == 0
keys %{$self->_requests;} == 0 keys %{$self->_connections;} == 0
Truth table0%0/3
A and B
A= keys %{$self->_requests;} == 0B= keys %{$self->_connections;} == 0
ABresult
0X0
100
111
259 0 and keys( %{ $self->_connections } ) == 0 )
260 {
261  
262 # Alright, shutdown anyway
263  
264 # Delete our alias
265 0 $kernel->alias_remove( $_ ) for $kernel->alias_list();
266 0 ▶ $kernel->refcount_decrement( $self->get_session_id, __PACKAGE__ )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->alias 0 0 0
267 unless $self->alias;
268  
269 # Debug stuff
270 0 warn 'Stopped SimpleHTTP gracefully, no requests left' if DEBUG;
271 }
272  
273 # All done!
274 0 return 1;
275 }
276  
277 # Forcibly close all sockets that are open
278 2 foreach my $S ( $self->_requests, $self->_connections ) {
279 4 foreach my $conn ( keys %$S ) {
280  
281 # Can't call method "shutdown_input" on an undefined value at
282 # /usr/lib/perl5/site_perl/5.8.2/POE/Component/Server/SimpleHTTP.pm line 323.
283 0 ▶ if ( defined $S->{$conn}->wheel
Branch: 1 branch
BranchTrueFalseTotal
if (defined $S->{$conn}->wheel and defined $S->{$conn}->wheel->get_input_handle) 0 0 0
Condition0%0/3
defined $S->{$conn}->wheel and defined $S->{$conn}->wheel->get_input_handle
!ll&&!rl&&r
000
MC/DC0%0/2
defined $S->{$conn}->wheel and defined $S->{$conn}->wheel->get_input_handle
defined $S->{$conn}->wheel defined $S->{$conn}->wheel->get_input_handle
Truth table0%0/3
A and B
A= defined $S->{$conn}->wheelB= defined $S->{$conn}->wheel->get_input_handle
ABresult
0X0
100
111
284 and defined $S->{$conn}->wheel->get_input_handle() )
285 {
286 0 $S->{$conn}->close_wheel;
287 }
288  
289 # Delete this request
290 0 delete $S->{$conn};
291 }
292 }
293  
294 # Delete our alias
295 2 $kernel->alias_remove( $_ ) for $kernel->alias_list();
296 2 ▶ $kernel->refcount_decrement( $self->get_session_id, __PACKAGE__ )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->alias 0 2 2
297 unless $self->alias;
298  
299 # Debug stuff
300 2 warn 'Successfully stopped SimpleHTTP' if DEBUG;
301  
302 # Return success
303 2 return 1;
304 8 };
305  
306 # Sets up the SocketFactory wheel :)
307 2 ▶event 'start_listener' => sub {
Subroutine __ANON__: called CC=19 SCAR=39.7
308 2 my ($kernel,$self,$noinc) = @_[KERNEL,OBJECT,ARG0];
309  
310 2 warn "Creating SocketFactory wheel now\n" if DEBUG;
311  
312 # Check if we should set up the wheel
313 2 ▶ if ( $self->retries == MAX_RETRIES ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->retries == 5) { } 0 2 2
314 0 die 'POE::Component::Server::SimpleHTTP tried '
315 . MAX_RETRIES
316 . ' times to create a Wheel and is giving up...';
317 }
318 else {
319  
320 2 ▶ $self->inc_retry unless $noinc;
Branch: 1 branch
BranchTrueFalseTotal
unless $noinc 2 0 2
321  
322 2 my $domain = $self->domain;
323 2 my $bindaddress = $self->address;
324 2 ▶ if ( not defined $bindaddress and not defined $domain ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $bindaddress || defined $domain) { } 0 2 2
elsif (not defined $bindaddress) { } 0 2 2
Condition33%1/3
defined $bindaddress || defined $domain
l!l&&r!l&&!r
200
MC/DC0%0/2
defined $bindaddress || defined $domain
defined $bindaddress defined $domain
Truth table33%1/3
A || B
A= defined $bindaddressB= defined $domain
ABresult
1X1
011
000
325 0 $domain = AF_INET6;
326 0 $bindaddress = IN6ADDR_ANY;
327 } elsif ( not defined $bindaddress ) {
328 0 ▶ if ( $domain == AF_INET6 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($domain == 10) { } 0 0 0
elsif ($domain == 2) { } 0 0 0
329 0 $bindaddress = IN6ADDR_ANY;
330 } elsif ( $domain == AF_INET ) {
331 0 $bindaddress = INADDR_ANY;
332 }
333 } else {
334 2 ▶ if ( defined inet_pton(AF_INET6, $bindaddress) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined inet_pton(10, $bindaddress)) { } 1 1 2
elsif (defined inet_pton(2, $bindaddress)) { } 1 0 1
335 1 $domain = AF_INET6;
336 } elsif ( defined inet_pton(AF_INET, $bindaddress) ) {
337 1 $domain = AF_INET;
338 }
339 }
340  
341 # Create our own SocketFactory Wheel :)
342 2 ▶ my $factory = POE::Wheel::SocketFactory->new(
Branch: 2 branches
BranchTrueFalseTotal
$domain ? : 2 0 2
$bindaddress ? : 2 0 2
343 ( $domain ? ( SocketDomain => $domain ) : () ),
344 ( $bindaddress ? ( BindAddress => $bindaddress ) : () ),
345 BindPort => $self->port,
346 Reuse => 'yes',
347 SuccessEvent => 'got_connection',
348 FailureEvent => 'listener_error',
349 );
350  
351 2 my ( $family, $address, $port, $straddress ) =
352 POE::Component::Server::SimpleHTTP::Connection->get_sockaddr_info(
353 $factory->getsockname );
354 2 ▶ $self->_set_port( $port ) if ( $self->port == 0 and $port );
Branch: 1 branch
BranchTrueFalseTotal
if $self->port == 0 and $port 2 0 2
Condition33%1/3
$self->port == 0 and $port
!ll&&!rl&&r
002
MC/DC0%0/2
$self->port == 0 and $port
$self->port == 0 $port
Truth table33%1/3
A and B
A= $self->port == 0B= $port
ABresult
0X0
100
111
355  
356 2 $self->_set_factory( $factory );
357  
358 2 ▶ if ( $self->setuphandler ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->setuphandler) 2 0 2
359 2 my $setuphandler = $self->setuphandler;
360 2 ▶ if ( $setuphandler->{POSTBACK} and
Branch: 1 branch
BranchTrueFalseTotal
if ($setuphandler->{'POSTBACK'} and ref $setuphandler->{'POSTBACK'} eq 'POE::Session::AnonEvent') { } 0 2 2
Condition33%1/3
$setuphandler->{"POSTBACK"} and ref $setuphandler->{"POSTBACK"} eq "POE::Session::AnonEvent"
!ll&&!rl&&r
200
MC/DC0%0/2
$setuphandler->{"POSTBACK"} and ref $setuphandler->{"POSTBACK"} eq "POE::Session::AnonEvent"
$setuphandler->{"POSTBACK"} ref $setuphandler->{"POSTBACK"} eq "POE::Session::AnonEvent"
Truth table33%1/3
A and B
A= $setuphandler->{"POSTBACK"}B= ref $setuphandler->{"POSTBACK"} eq "POE::Session::AnonEvent"
ABresult
0X0
100
111
361 ref $setuphandler->{POSTBACK} eq 'POE::Session::AnonEvent' ) {
362 0 $setuphandler->{POSTBACK}->( $port, $address );
363 }
364 else {
365 $kernel->post(
366 $setuphandler->{'SESSION'},
367 $setuphandler->{'EVENT'},
368 $port, $address,
369 2 ▶ ) if $setuphandler->{'SESSION'} and $setuphandler->{'EVENT'};
Branch: 1 branch
BranchTrueFalseTotal
if $setuphandler->{"SESSION"} and $setuphandler->{"EVENT"} 2 0 2
Condition33%1/3
$setuphandler->{"SESSION"} and $setuphandler->{"EVENT"}
!ll&&!rl&&r
002
MC/DC0%0/2
$setuphandler->{"SESSION"} and $setuphandler->{"EVENT"}
$setuphandler->{"SESSION"} $setuphandler->{"EVENT"}
Truth table33%1/3
A and B
A= $setuphandler->{"SESSION"}B= $setuphandler->{"EVENT"}
ABresult
0X0
100
111
370 }
371 }
372 }
373  
374 2 return 1;
375 8 };
376  
377 # Got some sort of error from SocketFactory
378 0 ▶event listener_error => sub {
Subroutine listener_error: not called CC=1 SCAR=6.9
379 0 my ($kernel,$self,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,OBJECT,ARG0..ARG3];
380 0 warn
381 "SocketFactory Wheel $wheel_id generated $operation error $errnum: $errstr\n"
382 if DEBUG;
383  
384 0 $self->call( 'start_listener' );
385 0 return 1;
386 8 };
387  
388 # 'STARTLISTEN'
389 # Starts listening on the socket
390 0 ▶event 'STARTLISTEN' => sub {
Subroutine __ANON__: not called CC=1 SCAR=1.2
Subroutine STARTLISTEN: called CC=1 SCAR=1.2
391 0 warn 'STARTLISTEN called, resuming accepts on SocketFactory'
392 if DEBUG;
393 0 $_[OBJECT]->call( 'start_listener', 'noinc' );
394 0 return 1;
395 8 };
396  
397 # 'STOPLISTEN'
398 # Stops listening on the socket
399 0 ▶event 'STOPLISTEN' => sub {
Subroutine STOPLISTEN: not called CC=2 SCAR=17.9
400 0 my $self = $_[OBJECT];
401 0 warn 'STOPLISTEN called, pausing accepts on SocketFactory'
402 if DEBUG;
403 0 ▶ $self->_clear_factory if $self->_factory;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_factory 0 0 0
404 0 return 1;
405 8 };
406  
407 # 'SETHANDLERS'
408 # Sets the HANDLERS
409 0 ▶event 'SETHANDLERS' => sub {
Subroutine SETHANDLERS: not called CC=1 SCAR=6.9
410 0 my ($self,$handlers) = @_[OBJECT,ARG0];
411 0 MassageHandlers($handlers);
412 0 $self->_set_handlers( $handlers );
413 0 return 1;
414 8 };
415  
416 # 'GETHANDLERS'
417 # Gets the HANDLERS
418 0 ▶event 'GETHANDLERS' => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
419 0 my ($kernel,$self,$session,$event ) = @_[KERNEL,OBJECT,ARG0,ARG1];
420 0 ▶ return unless $session and $event;
Branch: 1 branch
BranchTrueFalseTotal
unless $session and $event 0 0 0
Condition0%0/3
$session and $event
!ll&&!rl&&r
000
MC/DC0%0/2
$session and $event
$session $event
Truth table0%0/3
A and B
A= $sessionB= $event
ABresult
0X0
100
111
421 0 require Storable;
422 0 my $handlers = Storable::dclone( $self->handlers );
423 0 delete $_->{'RE'} for @{ $handlers };
424 0 $kernel->post( $session, $event, $handlers );
425 0 return 1;
426 8 };
427  
428 # This subroutine massages the HANDLERS for internal use
429 # Should probably support POSTBACK/CALLBACK
430 7 ▶sub MassageHandlers {
Subroutine MassageHandlers: called CC=15 SCAR=34.9
Pod undocumented
431 7 my $handler = shift;
432  
433 # Make sure it is ref to array
434 7 ▶ if ( !ref $handler or ref($handler) ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $handler or ref $handler ne "ARRAY") 0 7 7
Condition33%1/3
not ref $handler or ref $handler ne "ARRAY"
l!l&&r!l&&!r
007
MC/DC0%0/2
not ref $handler or ref $handler ne "ARRAY"
not ref $handler ref $handler ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not ref $handlerB= ref $handler ne "ARRAY"
ABresult
1X1
011
000
435 0 croak("HANDLERS is not a ref to an array!");
436 }
437  
438 # Massage the handlers
439 7 my $count = 0;
440 7 ▶ while ( $count < scalar(@$handler) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count < scalar @$handler) 22 7 29
441  
442 # Must be ref to hash
443 22 ▶ if ( ref $handler->[$count] and ref( $handler->[$count] ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $handler->[$count] and ref $handler->[$count] eq 'HASH') { } 22 0 22
Condition33%1/3
ref $handler->[$count] and ref $handler->[$count] eq "HASH"
!ll&&!rl&&r
0022
MC/DC0%0/2
ref $handler->[$count] and ref $handler->[$count] eq "HASH"
ref $handler->[$count] ref $handler->[$count] eq "HASH"
Truth table33%1/3
A and B
A= ref $handler->[$count]B= ref $handler->[$count] eq "HASH"
ABresult
0X0
100
111
444  
445 # Make sure all the keys are uppercase
446 $handler->[$count]->{ uc $_ } = delete $handler->[$count]->{$_}
447 22 for keys %{ $handler->[$count] };
448  
449 # Make sure it got the 3 parts necessary
450 22 ▶ if ( !exists $handler->[$count]->{'SESSION'}
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $handler->[$count]{"SESSION"} and defined $handler->[$count]{"SESSION"}) 0 22 22
Condition33%1/3
exists $handler->[$count]{"SESSION"} and defined $handler->[$count]{"SESSION"}
!ll&&!rl&&r
0022
MC/DC0%0/2
exists $handler->[$count]{"SESSION"} and defined $handler->[$count]{"SESSION"}
exists $handler->[$count]{"SESSION"} defined $handler->[$count]{"SESSION"}
Truth table33%1/3
A and B
A= exists $handler->[$count]{"SESSION"}B= defined $handler->[$count]{"SESSION"}
ABresult
0X0
100
111
451 or !defined $handler->[$count]->{'SESSION'} )
452 {
453 0 croak("HANDLER number $count does not have a SESSION argument!");
454 }
455 22 ▶ if ( !exists $handler->[$count]->{'EVENT'}
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $handler->[$count]{"EVENT"} and defined $handler->[$count]{"EVENT"}) 0 22 22
Condition33%1/3
exists $handler->[$count]{"EVENT"} and defined $handler->[$count]{"EVENT"}
!ll&&!rl&&r
0022
MC/DC0%0/2
exists $handler->[$count]{"EVENT"} and defined $handler->[$count]{"EVENT"}
exists $handler->[$count]{"EVENT"} defined $handler->[$count]{"EVENT"}
Truth table33%1/3
A and B
A= exists $handler->[$count]{"EVENT"}B= defined $handler->[$count]{"EVENT"}
ABresult
0X0
100
111
456 or !defined $handler->[$count]->{'EVENT'} )
457 {
458 0 croak("HANDLER number $count does not have an EVENT argument!");
459 }
460 22 ▶ if ( !exists $handler->[$count]->{'DIR'}
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $handler->[$count]{"DIR"} and defined $handler->[$count]{"DIR"}) 0 22 22
Condition33%1/3
exists $handler->[$count]{"DIR"} and defined $handler->[$count]{"DIR"}
!ll&&!rl&&r
0022
MC/DC0%0/2
exists $handler->[$count]{"DIR"} and defined $handler->[$count]{"DIR"}
exists $handler->[$count]{"DIR"} defined $handler->[$count]{"DIR"}
Truth table33%1/3
A and B
A= exists $handler->[$count]{"DIR"}B= defined $handler->[$count]{"DIR"}
ABresult
0X0
100
111
461 or !defined $handler->[$count]->{'DIR'} )
462 {
463 0 croak("HANDLER number $count does not have a DIR argument!");
464 }
465  
466 # Convert SESSION to ID
467 22 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($handler->[$count]{"SESSION"}, "POE::Session")) 0 22 22
468 UNIVERSAL::isa( $handler->[$count]->{'SESSION'}, 'POE::Session' ) )
469 {
470 $handler->[$count]->{'SESSION'} =
471 0 $handler->[$count]->{'SESSION'}->ID;
472 }
473  
474 # Convert DIR to qr// format
475 22 my $regex = undef;
476 22 eval { $regex = qr/$handler->[ $count ]->{'DIR'}/ };
477  
478 # Check for errors
479 22 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 22 22
480 0 croak("HANDLER number $count has a malformed DIR -> $@");
481 }
482 else {
483  
484 # Store it!
485 22 $handler->[$count]->{'RE'} = $regex;
486 }
487 }
488 else {
489 0 croak("HANDLER number $count is not a reference to a HASH!");
490 }
491  
492 # Done with this one!
493 22 $count++;
494 }
495  
496 # Got here, success!
497 7 return 1;
498 }
499  
500 # 'Got_Connection'
501 # The actual manager of connections
502 6 ▶event 'got_connection' => sub {
Subroutine got_connection: called CC=3 SCAR=14.2
503 6 my ( $kernel, $self, $socket ) = @_[KERNEL, OBJECT, ARG0];
504  
505 6 my ( $family, $address, $port, $straddress ) =
506 POE::Component::Server::SimpleHTTP::Connection->get_sockaddr_info(
507 getpeername($socket) );
508  
509 # Should we SSLify it?
510 6 ▶ if ( $self->sslkeycert ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->sslkeycert) 0 6 6
511  
512 # SSLify it!
513 0 eval { $socket = Server_SSLify($socket) };
514 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
515 0 warn "Unable to turn on SSL for connection from $straddress -> $@";
516 0 close $socket;
517 0 return 1;
518 }
519 }
520  
521 # Set up the Wheel to read from the socket
522 6 my $wheel = POE::Wheel::ReadWrite->new(
523 Handle => $socket,
524 Filter => POE::Filter::HTTPD->new(),
525 InputEvent => 'got_input',
526 FlushedEvent => 'got_flush',
527 ErrorEvent => 'got_error',
528 );
529  
530 6 if ( DEBUG and keys %{ $self->_connections } ) {
531  
532 # use Data::Dumper;
533 warn "conn id=", $wheel->ID, " [",
534 join( ', ', keys %{ $self->_connections } ), "]";
535 }
536  
537 # Save this wheel!
538 # 0 = wheel, 1 = Output done?, 2 = SimpleHTTP::Response object, 3 == request, 4 == streaming?
539 6 $self->_requests->{ $wheel->ID } =
540 POE::Component::Server::SimpleHTTP::State->new( wheel => $wheel );
541  
542 # Debug stuff
543 6 if (DEBUG) {
544 warn "Got_Connection completed creation of ReadWrite wheel ( "
545 . $wheel->ID . " )";
546 }
547  
548 # Success!
549 6 return 1;
550 8 };
551  
552 # 'Got_Input'
553 # Finally got input, set some stuff and send away!
554 13 ▶event 'got_input' => sub {
Subroutine __ANON__: called CC=23 SCAR=42.0
555 13 my ($kernel,$self,$request,$id) = @_[KERNEL,OBJECT,ARG0,ARG1];
556 13 my $connection;
557  
558 # This whole thing is a mess. Keep-Alive was bolted on and it
559 # shows. Streaming is unpredictable. There are checks everywhere
560 # because it leaks wheels. *sigh*
561  
562 # Was this request Keep-Alive?
563 13 ▶ if ( $self->_connections->{$id} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_connections->{$id}) 3 10 13
if ($self->_connections->{$id}) 5 9 14
564 3 my $state = delete $self->_connections->{$id};
565 3 $state->reset;
566 0 $connection = $state->connection;
567 3 $state->clear_connection;
568 3 $self->_requests->{$id} = $state;
569 3 warn "Keep-alive id=$id next request..." if DEBUG;
570 }
571  
572 # Quick check to see if the socket died already...
573 # Initially reported by Tim Wood
574 13 ▶ unless ( $self->_requests->{$id}->wheel_alive ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->_requests->{$id}->wheel_alive) 0 13 13
unless ($self->_requests->{$id}->wheel_alive) 5 5 10
575 0 warn 'Got a request, but socket died already!' if DEBUG;
576 # Destroy this wheel!
577 0 $self->_requests->{$id}->close_wheel;
578 0 delete $self->_requests->{$id};
579 0 return;
580 }
581  
582 SWITCH: {
583  
584 13 ▶ last SWITCH if $connection; # connection was kept-alive
Branch: 2 branches
BranchTrueFalseTotal
if $connection 3 10 13
if $connection 0 5 5
585  
586 # Directly access POE::Wheel::ReadWrite's HANDLE_INPUT -> to get the socket itself
587 # Hmm, if we are SSL, then have to do an extra step!
588 10 ▶ if ( $self->sslkeycert ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->sslkeycert) 0 10 10
if ($self->sslkeycert) 0 5 5
589 $connection = POE::Component::Server::SimpleHTTP::Connection->new(
590 SSLify_GetSocket(
591 0 $self->_requests->{$id}->wheel->get_input_handle() )
592 );
593 0 last SWITCH;
594 }
595 $connection = POE::Component::Server::SimpleHTTP::Connection->new(
596 10 $self->_requests->{$id}->wheel->get_input_handle()
597 );
598 }
599  
600 # The HTTP::Response object, the path
601 0 my ( $response, $path, $malformed_req );
602  
603 # Check if it is HTTP::Request or Response
604 # Quoting POE::Filter::HTTPD
605 # The HTTPD filter parses the first HTTP 1.0 request from an incoming stream into an
606 # HTTP::Request object (if the request is good) or an HTTP::Response object (if the
607 # request was malformed).
608  
609 13 ▶ if ( $request->isa('HTTP::Response') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($request->isa('HTTP::Response')) { } 0 13 13
if ($request->isa('HTTP::Response')) { } 0 0 0
610 # Make the request nothing
611 0 $response = $request;
612 0 $request = undef;
613  
614 # Mark that this is a malformed request
615 0 $malformed_req = 1;
616  
617 # Hack it to simulate POE::Component::Server::SimpleHTTP::Response->new( $id, $conn );
618 0 bless( $response, 'POE::Component::Server::SimpleHTTP::Response' );
619 0 $response->_WHEEL( $id );
620  
621 0 $response->set_connection( $connection );
622  
623 # Set the path to an empty string
624 0 $path = '';
625 }
626 else {
627 13 ▶ unless ( $self->proxymode ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->proxymode) { } 0 13 13
if ($self->proxymode) { } 0 5 5
628 # Add stuff it needs!
629 13 my $uri = $request->uri;
630 13 $uri->scheme('http');
631 13 $uri->host( $self->hostname );
632 13 $uri->port( $self->port );
633  
634 # Get the path
635 13 $path = $uri->path();
636 13 ▶ if ( !defined $path or $path eq '' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $path or $path eq "") 0 13 13
if (not defined $path or $path eq "") 0 5 5
Condition33%2/6
not defined $path or $path eq ""
l!l&&r!l&&!r
0013
not defined $path or $path eq ""
l!l&&r!l&&!r
500
MC/DC0%0/2
not defined $path or $path eq ""
not defined $path $path eq ""
MC/DC0%0/2
not defined $path or $path eq ""
not defined $path $path eq ""
Truth table33%1/3
not(A) or B
A= not defined $pathB= $path eq ""
ABresult
1X1
011
000
Truth table33%1/3
not(A) or B
A= not defined $pathB= $path eq ""
ABresult
1X1
011
000
637 # Make it the default handler
638 0 $path = '/';
639 }
640 }
641 else {
642 # We're in PROXYMODE set the path to the full URI
643 0 $path = $request->uri->as_string();
644 }
645  
646 # Get the response
647 13 $response =
648 POE::Component::Server::SimpleHTTP::Response->new( $id, $connection );
649  
650 # Stuff the default headers
651 0 $response->header( %{ $self->headers } )
652 13 ▶ if keys( %{ $self->headers } ) != 0;
Branch: 2 branches
BranchTrueFalseTotal
if keys %{$self->headers;} != 0 0 13 13
if keys %{$self->headers;} != 0 5 0 5
653 }
654  
655 # Check if the SimpleHTTP::Connection object croaked ( happens when sockets just disappear )
656 13 ▶ unless ( defined $response->connection ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $response->connection) 0 13 13
unless (defined $response->connection) 5 0 5
657 # Debug stuff
658 0 warn "could not make connection object" if DEBUG;
659 # Destroy this wheel!
660 0 $self->_requests->{$id}->close_wheel;
661 0 delete $self->_requests->{$id};
662 0 return;
663 }
664  
665 # If we used SSL, turn on the flag!
666 13 ▶ if ( $self->sslkeycert ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->sslkeycert) 0 13 13
if ($self->sslkeycert) 5 0 5
667 0 $response->connection->ssl(1);
668  
669 # Put the cipher type for people who want it
670 $response->connection->sslcipher(
671 0 SSLify_GetCipher( $self->_requests->{$id}->wheel->get_input_handle() )
672 );
673 }
674  
675 13 ▶ if ( !defined( $request ) ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $request) 0 13 13
unless (defined $request) 5 0 5
676 0 $self->_requests->{$id}->close_wheel;
677 0 delete $self->_requests->{$id};
678 0 return;
679 }
680  
681 # Add this response to the wheel
682 13 $self->_requests->{$id}->set_response( $response );
683 13 $self->_requests->{$id}->set_request( $request );
684 13 $response->connection->ID($id);
685  
686 # If they have a log handler registered, send out the needed information
687 # TODO if we received a malformed request, we will not have a request object
688 # We need to figure out what we're doing because they can't always expect to have
689 # a request object, or should we keep it from being ?undef'd?
690  
691 13 ▶ if ( $self->loghandler and scalar keys %{ $self->loghandler } == 2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->loghandler and scalar keys %{$self->loghandler;} == 2) 0 13 13
if ($self->loghandler and scalar keys %{$self->loghandler;} == 2) 5 0 5
Condition33%2/6
$self->loghandler and scalar keys %{$self->loghandler;} == 2
!ll&&!rl&&r
0130
$self->loghandler and scalar keys %{$self->loghandler;} == 2
!ll&&!rl&&r
005
MC/DC0%0/2
$self->loghandler and scalar keys %{$self->loghandler;} == 2
$self->loghandler scalar keys %{$self->loghandler;} == 2
MC/DC0%0/2
$self->loghandler and scalar keys %{$self->loghandler;} == 2
$self->loghandler scalar keys %{$self->loghandler;} == 2
Truth table33%1/3
A and B
A= $self->loghandlerB= scalar keys %{$self->loghandler;} == 2
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $self->loghandlerB= scalar keys %{$self->loghandler;} == 2
ABresult
0X0
100
111
692 my $ok = $kernel->post(
693 $self->loghandler->{'SESSION'},
694 0 $self->loghandler->{'EVENT'},
695 $request, $response->connection->remote_ip()
696 );
697  
698 # Warn if we had a problem dispatching to the log handler above
699 warn(
700 "I had a problem posting to event '",
701 $self->loghandler->{'EVENT'},
702 "' of the log handler alias '",
703 0 ▶ $self->loghandler->{'SESSION'},
Branch: 2 branches
BranchTrueFalseTotal
unless $ok 0 0 0
unless $ok 0 5 5
704 "'. As reported by Kernel: '$!', perhaps the alias is spelled incorrectly for this handler?"
705 ) unless $ok;
706 }
707  
708 # If we received a malformed request then
709 # let's not try to dispatch to a handler
710  
711 13 ▶ if ($malformed_req) {
Branch: 2 branches
BranchTrueFalseTotal
if ($malformed_req) 0 13 13
if ($malformed_req) 5 0 5
712 # Just push out the response we got from POE::Filter::HTTPD saying your request was bad
713 $kernel->post(
714 $self->errorhandler->{SESSION},
715 $self->errorhandler->{EVENT},
716 'BadRequest (by POE::Filter::HTTPD)',
717 $response->connection->remote_ip()
718 0 ▶ ) if $self->errorhandler and $self->errorhandler->{SESSION} and $self->errorhandler->{EVENT};
Branch: 1 branch
BranchTrueFalseTotal
if $self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"} 0 0 0
Condition16%2/12
$self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"}
!ll&&!rl&&r
000
$self->errorhandler and $self->errorhandler->{"SESSION"}
!ll&&!rl&&r
000
$self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"}
!ll&&!rl&&r
500
$self->errorhandler and $self->errorhandler->{"SESSION"}
!ll&&!rl&&r
005
MC/DC0%0/3
$self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"}
$self->errorhandler $self->errorhandler->{"SESSION"} $self->errorhandler->{"EVENT"}
MC/DC0%0/3
$self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"}
$self->errorhandler $self->errorhandler->{"SESSION"} $self->errorhandler->{"EVENT"}
Truth table0%0/4
A and B and C
A= $self->errorhandlerB= $self->errorhandler->{"SESSION"}C= $self->errorhandler->{"EVENT"}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= $self->errorhandlerB= $self->errorhandler->{"SESSION"}C= $self->errorhandler->{"EVENT"}
ABCresult
0XX0
10X0
1100
1111
719 0 $kernel->yield( 'DONE', $response );
720 0 return;
721 }
722  
723 # Find which handler will handle this one
724 13 foreach my $handler ( @{ $self->handlers } ) {
725  
726 # Check if this matches
727 36 ▶ if ( $path =~ $handler->{'RE'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ /$handler->{"RE"}/) 10 26 36
728  
729 # Send this off!
730 my $ok = $kernel->post( $handler->{'SESSION'}, $handler->{'EVENT'}, $request,
731 10 $response, $handler->{'DIR'}, );
732  
733 # Make sure we croak if we have an issue posting
734 10 ▶ croak(
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 10 10
735 "I had a problem posting to event $handler->{'EVENT'} of session $handler->{'SESSION'} for DIR handler '$handler->{'DIR'}'",
736 ". As reported by Kernel: '$!', perhaps the session name is spelled incorrectly for this handler?"
737 ) unless $ok;
738  
739 # All done!
740 10 return;
741 }
742 }
743  
744 # If we reached here, no handler was able to handle it...
745 # Set response code to 404 and tell the client we didn't find anything
746 3 $response->code(404);
747 3 $response->content('404 Not Found');
748 3 $kernel->yield( 'DONE', $response );
749 3 return;
750 8 };
751  
752 # 'Got_Flush'
753 # Finished with a request!
754 13 ▶event 'got_flush' => sub {
Subroutine got_flush: called CC=8 SCAR=25.2
755 13 my ($kernel,$self,$id) = @_[KERNEL,OBJECT,ARG0];
756  
757 13 ▶ return unless defined $self->_requests->{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->_requests->{$id} 0 13 13
758  
759 # Debug stuff
760 13 warn "Got Flush event for wheel ID ( $id )" if DEBUG;
761  
762 13 ▶ if ( $self->_requests->{$id}->streaming ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_requests->{$id}->streaming) 0 13 13
763 # Do the stream !
764 0 warn "Streaming in progress ...!" if DEBUG;
765 0 return;
766 }
767  
768 # Check if we are shutting down
769 13 ▶ if ( $self->_requests->{$id}->done ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_requests->{$id}->done) { } 13 0 13
770  
771 13 ▶ if ( $self->must_keepalive( $id ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->must_keepalive($id)) { } 3 10 13
772 3 warn "Keep-alive id=$id ..." if DEBUG;
773 3 my $state = delete $self->_requests->{$id};
774 3 $state->set_connection( $state->response->connection );
775 3 $state->reset;
776 3 $self->_connections->{$id} = $state;
777 3 delete $self->_chunkcount->{$id};
778 3 delete $self->_responses->{$id};
779 }
780 else {
781 # Shutdown read/write on the wheel
782 10 $self->_requests->{$id}->close_wheel;
783 10 delete $self->_requests->{$id};
784 }
785  
786 }
787 else {
788  
789 # Ignore this, eh?
790 0 if (DEBUG) {
791 warn
792 "Got Flush event for socket ( $id ) when we did not send anything!";
793 }
794 }
795  
796 # Alright, do we have to shutdown?
797 13 ▶ unless ( $self->_factory ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_factory) 0 13 13
798 # Check to see if we have any more requests
799 0 ▶ if ( keys( %{ $self->_requests } ) == 0
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$self->_requests;} == 0 and keys %{$self->_connections;} == 0) 0 0 0
Condition0%0/3
keys %{$self->_requests;} == 0 and keys %{$self->_connections;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
keys %{$self->_requests;} == 0 and keys %{$self->_connections;} == 0
keys %{$self->_requests;} == 0 keys %{$self->_connections;} == 0
Truth table0%0/3
A and B
A= keys %{$self->_requests;} == 0B= keys %{$self->_connections;} == 0
ABresult
0X0
100
111
800 0 and keys( %{ $self->_connections } ) == 0 )
801 {
802 # Shutdown!
803 0 $kernel->yield('SHUTDOWN');
804 }
805 }
806  
807 # Success!
808 13 return 1;
809 8 };
810  
811 # should we keep-alive the connection?
812 13 ▶sub must_keepalive {
Subroutine must_keepalive: called CC=10 SCAR=24.6
Pod undocumented
813 13 my ( $self, $id ) = @_;
814  
815 13 ▶ return unless $self->keepalive;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->keepalive 9 4 13
816  
817 4 my $resp = $self->_requests->{$id}->response;
818 4 my $req = $self->_requests->{$id}->request;
819  
820 # error = close
821 4 ▶ return 0 if $resp->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $resp->is_error 1 3 4
822  
823 # Connection is a comma-seperated header
824 3 ▶ my $conn = lc ($req->header('Connection') || '');
Condition50%1/2
$req->header('Connection') || ''
l!l
30
MC/DC0%0/1
$req->header('Connection') || ''
$req->header('Connection')
Truth table50%1/2
A
A= $req->header('Connection')
Aresult
11
00
825 3 ▶ return 0 if ",$conn," =~ /,\s*close\s*,/;
Branch: 1 branch
BranchTrueFalseTotal
if (",$conn,") =~ /,\s*close\s*,/ 0 3 3
826 3 ▶ $conn = lc ($req->header('Proxy-Connection') || '');
Condition50%1/2
$req->header('Proxy-Connection') || ''
l!l
03
MC/DC0%0/1
$req->header('Proxy-Connection') || ''
$req->header('Proxy-Connection')
Truth table50%1/2
A
A= $req->header('Proxy-Connection')
Aresult
11
00
827 3 ▶ return 0 if ",$conn," =~ /,\s*close\s*,/;
Branch: 1 branch
BranchTrueFalseTotal
if (",$conn,") =~ /,\s*close\s*,/ 0 3 3
828 3 ▶ $conn = lc ($resp->header('Connection') || '');
Condition50%1/2
$resp->header('Connection') || ''
l!l
03
MC/DC0%0/1
$resp->header('Connection') || ''
$resp->header('Connection')
Truth table50%1/2
A
A= $resp->header('Connection')
Aresult
11
00
829 3 ▶ return 0 if ",$conn," =~ /,\s*close\s*,/;
Branch: 1 branch
BranchTrueFalseTotal
if (",$conn,") =~ /,\s*close\s*,/ 0 3 3
830  
831 # HTTP/1.1 = keep
832 3 ▶ return 1 if $req->protocol eq 'HTTP/1.1';
Branch: 1 branch
BranchTrueFalseTotal
if $req->protocol eq "HTTP/1.1" 3 0 3
833 0 return 0;
834 }
835  
836 # 'Got_Error'
837 # Got some sort of error from ReadWrite
838 0 ▶event 'got_error' => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
839 0 my ($kernel,$self,$operation,$errnum,$errstr,$id) = @_[KERNEL,OBJECT,ARG0..ARG3];
840  
841 # Only do this for non-EOF on read
842 #unless ( $operation eq 'read' and $errnum == 0 ) {
843 {
844  
845 # Debug stuff
846 0 warn "Wheel $id generated $operation error $errnum: $errstr\n"
847 if DEBUG;
848  
849 0 my $connection;
850 0 ▶ if ( $self->_connections->{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_connections->{$id}) { } 0 0 0
851 0 my $c = delete $self->_connections->{$id};
852 0 $connection = $c->connection;
853 0 $c->close_wheel;
854 }
855 else {
856  
857 0 ▶ if( defined $self->_requests->{$id}->response ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_requests->{$id}->response) { } 0 0 0
858 0 $connection = $self->_requests->{$id}->response->connection;
859 }
860 else {
861 0 warn "response for $id is undefined" if DEBUG;
862 }
863  
864 # Delete this connection
865 0 $self->_requests->{$id}->close_wheel;
866 }
867  
868 0 delete $self->_requests->{$id};
869 0 delete $self->_responses->{$id};
870  
871 # Mark the client dead
872 0 ▶ $connection->dead(1) if $connection;
Branch: 1 branch
BranchTrueFalseTotal
if $connection 0 0 0
873 }
874  
875 # Success!
876 0 return 1;
877 8 };
878  
879 # 'DONE'
880 # Output to the client!
881 13 ▶event 'DONE' => sub {
Subroutine __ANON__: called CC=17 SCAR=46.9
882 13 my ($kernel,$self,$response) = @_[KERNEL,OBJECT,ARG0];
883  
884 # Check if we got it
885 13 ▶ if ( !defined $response or !UNIVERSAL::isa( $response, 'HTTP::Response' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $response and UNIVERSAL::isa($response, "HTTP::Response")) 0 13 13
Condition33%1/3
defined $response and UNIVERSAL::isa($response, "HTTP::Response")
!ll&&!rl&&r
0013
MC/DC0%0/2
defined $response and UNIVERSAL::isa($response, "HTTP::Response")
defined $response UNIVERSAL::isa($response, "HTTP::Response")
Truth table33%1/3
A and B
A= defined $responseB= UNIVERSAL::isa($response, "HTTP::Response")
ABresult
0X0
100
111
886 0 warn 'Did not get a HTTP::Response object!' if DEBUG;
887 # Abort...
888 0 return;
889 }
890  
891 # Get the wheel ID
892 13 my $id = $response->_WHEEL;
893  
894 # Check if the wheel exists ( sometimes it gets closed by the client, but the application doesn't know that... )
895 13 ▶ unless ( exists $self->_requests->{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->_requests->{$id}) 0 13 13
896  
897 # Debug stuff
898 0 warn
899 'Wheel disappeared, but the application sent us a DONE event, discarding it'
900 if DEBUG;
901  
902 $kernel->post(
903 $self->errorhandler->{SESSION},
904 $self->errorhandler->{EVENT},
905 'Wheel disappeared !'
906 0 ▶ ) if $self->errorhandler and $self->errorhandler->{SESSION} and $self->errorhandler->{EVENT};
Branch: 1 branch
BranchTrueFalseTotal
if $self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"} 0 0 0
Condition0%0/6
$self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"}
!ll&&!rl&&r
000
$self->errorhandler and $self->errorhandler->{"SESSION"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"}
$self->errorhandler $self->errorhandler->{"SESSION"} $self->errorhandler->{"EVENT"}
Truth table0%0/4
A and B and C
A= $self->errorhandlerB= $self->errorhandler->{"SESSION"}C= $self->errorhandler->{"EVENT"}
ABCresult
0XX0
10X0
1100
1111
907  
908 # All done!
909 0 return 1;
910 }
911  
912  
913 # Check if we have already sent the response
914 13 ▶ if ( $self->_requests->{$id}->done ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_requests->{$id}->done) 0 13 13
915 # Tried to send twice!
916 0 die 'Tried to send a response to the same connection twice!';
917 }
918  
919 # Quick check to see if the wheel/socket died already...
920 # Initially reported by Tim Wood
921 13 ▶ unless ( $self->_requests->{$id}->wheel_alive ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_requests->{$id}->wheel_alive) 0 13 13
922 0 warn 'Tried to send data over a closed/nonexistant socket!' if DEBUG;
923 $kernel->post(
924 $self->errorhandler->{SESSION},
925 $self->errorhandler->{EVENT},
926 'Socket closed/nonexistant !'
927 0 ▶ ) if $self->errorhandler and $self->errorhandler->{SESSION} and $self->errorhandler->{EVENT};
Branch: 1 branch
BranchTrueFalseTotal
if $self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"} 0 0 0
Condition0%0/6
$self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"}
!ll&&!rl&&r
000
$self->errorhandler and $self->errorhandler->{"SESSION"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"}
$self->errorhandler $self->errorhandler->{"SESSION"} $self->errorhandler->{"EVENT"}
Truth table0%0/4
A and B and C
A= $self->errorhandlerB= $self->errorhandler->{"SESSION"}C= $self->errorhandler->{"EVENT"}
ABCresult
0XX0
10X0
1100
1111
928 0 return;
929 }
930  
931 # Check if we were streaming.
932  
933 13 ▶ if ( $self->_requests->{$id}->streaming ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_requests->{$id}->streaming) 0 13 13
934 0 $self->_requests->{$id}->set_streaming(0);
935 0 $self->_requests->{$id}->set_done(1); # Finished streaming
936 # TODO: We might not get a flush, trigger it ourselves.
937 0 ▶ if ( !$self->_requests->{$id}->wheel->get_driver_out_messages ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_requests->{$id}->wheel->get_driver_out_messages) 0 0 0
938 0 $kernel->yield( 'got_flush', $id );
939 }
940 0 return;
941 }
942
943  
944 13 $self->fix_headers( $response );
945  
946 # Send it out!
947 13 $self->_requests->{$id}->wheel->put($response);
948  
949 # Mark this socket done
950 13 $self->_requests->{$id}->set_done(1);
951  
952 # Log FINALLY If they have a logFinal handler registered, send out the needed information
953 13 ▶ if ( $self->log2handler and scalar keys %{ $self->log2handler } == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->log2handler and scalar keys %{$self->log2handler;} == 2) 0 13 13
Condition33%1/3
$self->log2handler and scalar keys %{$self->log2handler;} == 2
!ll&&!rl&&r
0130
MC/DC0%0/2
$self->log2handler and scalar keys %{$self->log2handler;} == 2
$self->log2handler scalar keys %{$self->log2handler;} == 2
Truth table33%1/3
A and B
A= $self->log2handlerB= scalar keys %{$self->log2handler;} == 2
ABresult
0X0
100
111
954 0 $! = undef;
955 $kernel->call(
956 $self->log2handler->{'SESSION'},
957 $self->log2handler->{'EVENT'},
958 0 $self->_requests->{$id}->request, $response
959 );
960  
961 # Warn if we had a problem dispatching to the log handler above
962 warn(
963 "I had a problem posting to event '",
964 $self->log2handler->{'EVENT'},
965 "' of the log handler alias '",
966 0 ▶ $self->log2handler->{'SESSION'},
Branch: 1 branch
BranchTrueFalseTotal
if $! 0 0 0
967 "'. As reported by Kernel: '$!', perhaps the alias is spelled incorrectly for this handler?"
968 ) if $!;
969 }
970  
971 # Debug stuff
972 13 warn "Completed with Wheel ID $id" if DEBUG;
973  
974 # Success!
975 13 return 1;
976 8 };
977  
978 # 'STREAM'
979 # Stream output to the client
980 0 ▶event 'STREAM' => sub {
Subroutine STREAM: not called CC=16 SCAR=56.1
981 0 my ($kernel,$self,$response) = @_[KERNEL,OBJECT,ARG0];
982  
983 # Check if we got it
984 0 ▶ unless ( defined $response and UNIVERSAL::isa( $response, 'HTTP::Response' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $response and UNIVERSAL::isa($response, "HTTP::Response")) 0 0 0
Condition0%0/3
defined $response and UNIVERSAL::isa($response, "HTTP::Response")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $response and UNIVERSAL::isa($response, "HTTP::Response")
defined $response UNIVERSAL::isa($response, "HTTP::Response")
Truth table0%0/3
A and B
A= defined $responseB= UNIVERSAL::isa($response, "HTTP::Response")
ABresult
0X0
100
111
985 0 warn 'Did not get a HTTP::Response object!' if DEBUG;
986 # Abort...
987 0 return;
988 }
989  
990 # Get the wheel ID
991 0 my $id = $response->_WHEEL;
992 0 $self->_chunkcount->{$id}++;
993  
994 0 ▶ if ( defined $response->STREAM ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->STREAM) { } 0 0 0
995  
996 # Keep track if we plan to stream ...
997 0 ▶ if ( $self->_responses->{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_responses->{$id}) { } 0 0 0
998 0 warn "Restoring response from HEAP and id $id " if DEBUG;
999 0 $response = $self->_responses->{$id};
1000 }
1001 else {
1002 0 warn "Saving HEAP response to id $id " if DEBUG;
1003 0 $self->_responses->{$id} = $response;
1004 }
1005 }
1006 else {
1007 0 warn
1008 'Can\'t push on a response that has not been not set as a STREAM!'
1009 if DEBUG;
1010 # Abort...
1011 0 return;
1012 }
1013  
1014 # Check if the wheel exists ( sometimes it gets closed by the client, but the application doesn't know that... )
1015 0 ▶ unless ( exists $self->_requests->{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->_requests->{$id}) 0 0 0
1016  
1017 # Debug stuff
1018 0 warn
1019 'Wheel disappeared, but the application sent us a DONE event, discarding it'
1020 if DEBUG;
1021  
1022 $kernel->post(
1023 $self->errorhandler->{SESSION},
1024 $self->errorhandler->{EVENT},
1025 'Wheel disappeared !'
1026 0 ▶ ) if $self->errorhandler and $self->errorhandler->{SESSION} and $self->errorhandler->{EVENT};
Branch: 1 branch
BranchTrueFalseTotal
if $self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"} 0 0 0
Condition0%0/6
$self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"}
!ll&&!rl&&r
000
$self->errorhandler and $self->errorhandler->{"SESSION"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"}
$self->errorhandler $self->errorhandler->{"SESSION"} $self->errorhandler->{"EVENT"}
Truth table0%0/4
A and B and C
A= $self->errorhandlerB= $self->errorhandler->{"SESSION"}C= $self->errorhandler->{"EVENT"}
ABCresult
0XX0
10X0
1100
1111
1027  
1028 # All done!
1029 0 return 1;
1030 }
1031  
1032 # Quick check to see if the wheel/socket died already...
1033 # Initially reported by Tim Wood
1034 0 ▶ unless ( $self->_requests->{$id}->wheel_alive ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_requests->{$id}->wheel_alive) 0 0 0
1035 0 warn 'Tried to send data over a closed/nonexistant socket!' if DEBUG;
1036 $kernel->post(
1037 $self->errorhandler->{SESSION},
1038 $self->errorhandler->{EVENT},
1039 'Socket closed/nonexistant !'
1040 0 ▶ ) if $self->errorhandler and $self->errorhandler->{SESSION} and $self->errorhandler->{EVENT};
Branch: 1 branch
BranchTrueFalseTotal
if $self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"} 0 0 0
Condition0%0/6
$self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"}
!ll&&!rl&&r
000
$self->errorhandler and $self->errorhandler->{"SESSION"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->errorhandler and $self->errorhandler->{"SESSION"} and $self->errorhandler->{"EVENT"}
$self->errorhandler $self->errorhandler->{"SESSION"} $self->errorhandler->{"EVENT"}
Truth table0%0/4
A and B and C
A= $self->errorhandlerB= $self->errorhandler->{"SESSION"}C= $self->errorhandler->{"EVENT"}
ABCresult
0XX0
10X0
1100
1111
1041 0 return;
1042 }
1043  
1044 0 $self->fix_headers( $response, 1 );
1045  
1046 # Sets the correct POE::Filter
1047 0 ▶ unless ( defined $response->IS_STREAMING ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $response->IS_STREAMING) 0 0 0
1048  
1049 # Mark this socket done
1050 0 $self->_requests->{$id}->set_streaming(1);
1051 0 $response->set_streaming(1);
1052 }
1053  
1054 0 if (DEBUG) {
1055 warn "Sending stream via "
1056 . $response->STREAM_SESSION . "/"
1057 . $response->STREAM
1058 . " with id $id \n";
1059 }
1060  
1061 0 ▶ if ( $self->_chunkcount->{$id} > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_chunkcount->{$id} > 1) { } 0 0 0
1062 0 my $wheel = $self->_requests->{ $response->_WHEEL }->wheel;
1063 0 $wheel->set_output_filter( POE::Filter::Stream->new() );
1064 0 $wheel->put( $response->content );
1065 }
1066 else {
1067 0 my $wheel = $self->_requests->{ $response->_WHEEL }->wheel;
1068 0 $wheel->set_output_filter( $wheel->get_input_filter() );
1069 0 $wheel->put($response);
1070 }
1071  
1072 # we send the event to stream with wheels request and response to the session
1073 # that has registered the streaming event
1074 0 ▶ unless ( $response->DONT_FLUSH ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->DONT_FLUSH) 0 0 0
1075 $kernel->post(
1076 $response->STREAM_SESSION, # callback session
1077 $response->STREAM, # callback event
1078 0 $self->_responses->{ $response->_WHEEL }
1079 );
1080 }
1081  
1082 # Success!
1083 0 return 1;
1084 8 };
1085  
1086 # Add required headers to a response
1087 13 ▶sub fix_headers {
Subroutine fix_headers: called CC=11 SCAR=27.4
Pod undocumented
1088 13 my ( $self, $response, $stream ) = @_;
1089  
1090 # Set the date if needed
1091 13 ▶ if ( !$response->header('Date') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->header("Date")) 13 0 13
1092 13 $response->header( 'Date', time2str(time) );
1093 }
1094  
1095 # Set the Content-Length if needed
1096 13 ▶ if ( !$stream and !$self->proxymode
Branch: 1 branch
BranchTrueFalseTotal
if (not $stream || $self->proxymode || defined $response->header("Content-Length") and my $len = length $response->content) 13 0 13
Condition33%3/9
not $stream || $self->proxymode || defined $response->header("Content-Length") and my $len = length $response->content
!ll&&!rl&&r
0013
$stream || $self->proxymode || defined $response->header('Content-Length')
l!l&&r!l&&!r
0013
$stream or $self->proxymode
l!l&&r!l&&!r
0013
MC/DC0%0/4
not $stream || $self->proxymode || defined $response->header("Content-Length") and my $len = length $response->content
$stream $self->proxymode defined $response->header('Content-Length') my $len = length $response->content
Truth table20%1/5
not(A or B || C) and D
A= $streamB= $self->proxymodeC= defined $response->header('Content-Length')D= my $len = length $response->content
ABCDresult
1XXX0
01XX0
001X0
00000
00011
1097 and !defined $response->header('Content-Length')
1098 and my $len = length $response->content )
1099 {
1100 8 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
1101 13 $response->header( 'Content-Length', $len );
1102 }
1103  
1104 # Set the Content-Type if needed
1105 13 ▶ if ( !$response->header('Content-Type') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->header("Content-Type")) 6 7 13
1106 6 $response->header( 'Content-Type', 'text/plain' );
1107 }
1108  
1109 13 ▶ if ( !$response->protocol ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $response->protocol) 13 0 13
1110 13 my $request = $self->_requests->{ $response->_WHEEL }->request;
1111 13 ▶ return unless $request and $request->isa('HTTP::Request');
Branch: 1 branch
BranchTrueFalseTotal
unless $request and $request->isa("HTTP::Request") 0 13 13
Condition33%1/3
$request and $request->isa("HTTP::Request")
!ll&&!rl&&r
0013
MC/DC0%0/2
$request and $request->isa("HTTP::Request")
$request $request->isa("HTTP::Request")
Truth table33%1/3
A and B
A= $requestB= $request->isa("HTTP::Request")
ABresult
0X0
100
111
1112 13 ▶ unless ( $request->method eq 'HEAD' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($request->method eq "HEAD") 13 0 13
1113 13 $response->protocol( $request->protocol );
1114 }
1115 }
1116 }
1117  
1118 # 'CLOSE'
1119 # Closes the connection
1120 0 ▶event 'CLOSE' => sub {
Subroutine CLOSE: not called CC=6 SCAR=37.4
1121 0 my ($kernel,$self,$response) = @_[KERNEL,OBJECT,ARG0];
1122  
1123 # Check if we got it
1124 0 ▶ unless ( defined $response and UNIVERSAL::isa( $response, 'HTTP::Response' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $response and UNIVERSAL::isa($response, "HTTP::Response")) 0 0 0
Condition0%0/3
defined $response and UNIVERSAL::isa($response, "HTTP::Response")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $response and UNIVERSAL::isa($response, "HTTP::Response")
defined $response UNIVERSAL::isa($response, "HTTP::Response")
Truth table0%0/3
A and B
A= defined $responseB= UNIVERSAL::isa($response, "HTTP::Response")
ABresult
0X0
100
111
1125 0 warn 'Did not get a HTTP::Response object!' if DEBUG;
1126 # Abort...
1127 0 return;
1128 }
1129  
1130 # Get the wheel ID
1131 0 my $id = $response->_WHEEL;
1132  
1133 0 ▶ if ( $self->_connections->{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_connections->{$id}) 0 0 0
1134 0 $self->_requests->{$id} = delete $self->_connections->{$id};
1135 }
1136  
1137 # Check if the wheel exists ( sometimes it gets closed by the client, but the application doesn't know that... )
1138 0 ▶ unless ( exists $self->_requests->{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->_requests->{$id}) 0 0 0
1139 0 warn
1140 'Wheel disappeared, but the application sent us a CLOSE event, discarding it'
1141 if DEBUG;
1142 0 return 1;
1143 }
1144  
1145 # Kill it!
1146 0 ▶ $self->_requests->{$id}->close_wheel if $self->_requests->{$id}->wheel_alive;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_requests->{$id}->wheel_alive 0 0 0
1147  
1148 # Delete it!
1149 0 delete $self->_requests->{$id};
1150 0 delete $self->_responses->{$id};
1151  
1152 0 warn 'Delete references to the connection done.' if DEBUG;
1153  
1154 # All done!
1155 0 return 1;
1156 8 };
1157  
1158 # Registers a POE inline state (primarly for streaming)
1159 0 ▶event 'REGISTER' => sub {
Subroutine REGISTER: not called CC=1 SCAR=6.9
1160 0 my ( $session, $state, $code_ref ) = @_[ SESSION, ARG0 .. ARG1 ];
1161 0 warn 'Registering state in POE session' if DEBUG;
1162 0 return $session->register_state( $state, $code_ref );
1163 8 };
1164  
1165 # SETCLOSEHANDLER
1166 2 ▶event 'SETCLOSEHANDLER' => sub {
Subroutine SETCLOSEHANDLER: called CC=7 SCAR=23.2
1167 2 my ($self,$sender) = @_[OBJECT,SENDER ];
1168 2 my ($connection,$state,@params) = @_[ARG0..$#_];
1169  
1170 # turn connection ID into the connection object
1171 2 ▶ unless ( ref $connection ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $connection) 2 0 2
1172 2 my $id = $connection;
1173 2 ▶ if ( $self->_connections->{$id} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_connections->{$id}) { } 0 2 2
elsif ($self->_requests->{$id} and $self->_requests->{$id}->response) { } 2 0 2
1174 0 $connection = $self->_connections->{$id}->connection;
1175 }
1176 ▶ elsif ($self->_requests->{$id}
Condition33%1/3
$self->_requests->{$id} and $self->_requests->{$id}->response
!ll&&!rl&&r
002
MC/DC0%0/2
$self->_requests->{$id} and $self->_requests->{$id}->response
$self->_requests->{$id} $self->_requests->{$id}->response
Truth table33%1/3
A and B
A= $self->_requests->{$id}B= $self->_requests->{$id}->response
ABresult
0X0
100
111
1177 and $self->_requests->{$id}->response )
1178 {
1179 2 $connection = $self->_requests->{$id}->response->connection;
1180 }
1181 2 ▶ unless ( ref $connection ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $connection) 0 2 2
1182 0 die "Can't find connection object for request $id";
1183 }
1184 }
1185  
1186 2 ▶ if ($state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state) { } 2 0 2
1187 2 $connection->_on_close( $sender->ID, $state, @params );
1188 }
1189 else {
1190 0 $connection->_on_close($sender->ID);
1191 }
1192 8 };
1193  
1194 8 ▶no MooseX::POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
1195  
1196 8 __PACKAGE__->meta->make_immutable( );
1197  
1198 8 "Simple In'it";
1199  
1200 __END__
↑ Summary SimpleHTTP/Connection.pm »