PSGIHandler/Streamy.pm

filter: Statementstmt 100% 38 / 38 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 92.4% 49 / 53 CC 6 SCAR 9.8
CC
6
Cov
93%
__ANON__
4.1
__ANON__
3.0
handle_psgi
1.0
CRAP 2.7
↑ Summary PSGIHandler.pm »
1 package HTML::Mason::PSGIHandler::Streamy;
2 {
3 3 $HTML::Mason::PSGIHandler::Streamy::VERSION = '0.53';
4 }
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 require HTML::Mason::PSGIHandler; # XXX: this is fucked
9 3 ▶use base qw( HTML::Mason::PSGIHandler );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 12 ▶sub handle_psgi {
Subroutine handle_psgi: called CC=1 SCAR=0.0
Pod undocumented
12 12 my $self = shift;
13 12 my $env = shift;
14  
15 my $p = {
16 comp => $env->{PATH_INFO},
17 12 cgi => CGI::PSGI->new($env),
18 };
19  
20 12 my $r = $self->create_delayed_object('cgi_request', cgi => $p->{cgi});
21 12 $self->interp->set_global('$r', $r);
22  
23 12 my $headers_sent;
24 my $responder;
25 12 my $writer;
26  
27 $self->interp->out_method(
28 11 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=14.1
29 # XXX: the original code from HTTP::Server::Simple::Mason
30 # has the following comment. need to verify memory usage
31 # without the following hack.
32  
33 # We use instance here because if we store $request we get a
34 # circular reference and a big memory leak.
35 11 my $m = HTML::Mason::Request->instance;
36 11 my $r = $m->cgi_request;
37 11 ▶ unless ($headers_sent) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($headers_sent) 11 0 11
38 11 ▶ die "PANIC: responder not configured yet" unless $responder;
Branch: 1 branch
BranchTrueFalseTotal
unless $responder 0 11 11
39 11 $writer = $responder->([$r->psgi_header()]);
40 11 $headers_sent = 1;
41 }
42  
43 11 $writer->write($_) for @_;
44 12 });
45  
46 12 $self->interp->delayed_object_params('request', cgi_request => $r);
47  
48 12 my %args = $self->request_args($r);
49  
50 12 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
51 12 $responder = shift;
52 12 my @result = $self->invoke_mason(\%args, $p);
53 12 ▶ die if $@; # XXX: format 500?
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 12 12
54 12 ▶ unless ($writer) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($writer) 1 11 12
55 1 return $responder->([$r->psgi_header(-Status => $result[0]), []]);
56 }
57 11 undef $responder;
58 11 $writer->close();
59 11 undef $writer;
60 }
61  
62 12 }
63  
64 3 1;
↑ Summary PSGIHandler.pm »