| 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
| |||||||||||
| 38 | 11 | ▶ | die "PANIC: responder not configured yet" unless $responder; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 54 | 12 | ▶ | unless ($writer) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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; | |||||||||