File Coverage

blib/lib/HTTP/Engine/Interface/PSGI.pm
Criterion Covered Total %
statement 17 18 94.4
branch 5 6 83.3
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 27 31 87.1


line stmt bran cond sub pod time code
1             package HTTP::Engine::Interface::PSGI;
2             use HTTP::Engine::Interface
3             builder => 'CGI',
4             writer => {
5             around => {
6 2         24 finalize => sub { _finalize(@_) },
7             },
8             },
9 2     2   7853 ;
  2         6  
  2         28  
10              
11 1     1 0 4 sub can_has_streaming { 1 }
12              
13             sub run {
14 2     2 0 246 my($self, $env) = @_;
15              
16             # get PSGI response arrayrey. generated by _finalize
17 2         17 $self->handle_request(
18             _connection => {
19             env => $env,
20             input_handle => $env->{'psgi.input'},
21             output_handle => undef,
22             },
23             );
24             }
25              
26             # generate PSGI response
27             # hack to HTTP::Engine::Role::ResponseWriter::Finalize
28             sub _finalize {
29 2     2   4 my($next, $writer, $req, $res) = @_;
30 2         2 my @headers; $res->headers->scan(sub {
31 7     7   129 my ($k, $v) = @_;
32             # PSGI spec says "The header MUST NOT contain a Status key".
33 7 100       19 if ($k eq 'Status') {
34 2 50       10 return if $res->code eq $v;
35 0         0 die "Do not set Status header with HTTP::Engine::Interface::PSGI.";
36             }
37 5         16 push @headers, $k, $v;
38 2         24 });
39 2         20 my $body = $res->body;
40 2 100       9 $body = [ $body ] unless ref($body);
41 2         7 [ $res->code, \@headers, $body ];
42             }
43              
44             __INTERFACE__
45              
46             __END__