Engine/ResponseFinalizer.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 24 / 24 Conditioncond 100% 20 / 20 MC/DCmcdc 100% 10 / 10 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 99.1% 111 / 112 CC 21 SCAR 24.4
CC
21
Cov
100%
finalize
17.0
_finalize_cookies
5.0
BEGIN
1.0
CRAP 11.4
« Engine/Interface/ServerSimple.pm ↑ Summary Engine/Role/RequestBuilder/ParseEnv.pm »
1 package HTTP::Engine::ResponseFinalizer;
2 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 32 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 32 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 32 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 32 ▶use CGI::Simple::Cookie;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 66 ▶sub finalize {
Subroutine finalize: called CC=17 SCAR=28.3
Pod undocumented
9 66 my ($class, $req, $res, $interface) = @_;
10 66 ▶ Carp::confess 'argument missing: $res' unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 6 60 66
11  
12 # protocol
13 60 ▶ $res->protocol( $req->protocol ) unless $res->protocol;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->protocol 52 8 60
14  
15 # Content-Length
16 59 ▶ if ($res->body) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->body) { } 52 7 59
17 # get the length from a filehandle
18 52 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (ref $res->body eq 'GLOB' or builtin::blessed($res->body) and $res->body->can('getline') || $res->body->can('read')) { } 8 44 52
Condition100%9/9
ref $res->body eq "GLOB" or builtin::blessed($res->body) and $res->body->can("getline") || $res->body->can("read")
l!l&&r!l&&!r
3544
builtin::blessed($res->body) and $res->body->can("getline") || $res->body->can("read")
!ll&&!rl&&r
4315
$res->body->can("getline") or $res->body->can("read")
l!l&&r!l&&!r
411
MC/DC100%4/4
ref $res->body eq "GLOB" or builtin::blessed($res->body) and $res->body->can("getline") || $res->body->can("read")
ref $res->body eq "GLOB" builtin::blessed($res->body) $res->body->can("getline") $res->body->can("read")
Truth table100%5/5
A or B and C or D
A= ref $res->body eq "GLOB"B= builtin::blessed($res->body)C= $res->body->can("getline")D= $res->body->can("read")
ABCDresult
1XXX1
011X1
01011
00XX0
01000
19 ref($res->body) eq 'GLOB' ||
20 ( Scalar::Util::blessed($res->body) && ($res->body->can('getline') || $res->body->can('read')) )
21 ) {
22 8 my $st_size = 7; # see perldoc -f stat
23 8 my $size = eval { (stat($res->body))[$st_size] };
24 8 ▶ if (defined $size) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $size) { } 5 3 8
elsif (not $interface->can_has_streaming) { } 2 1 3
25 5 $res->content_length($size);
26 } elsif (!$interface->can_has_streaming) { # can_has_streaming for PSGI streaming response
27 2 die "Serving filehandle without a content-length($@)";
28 }
29 } else {
30 32 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 44 $res->content_length(bytes::length($res->body));
32 }
33 } else {
34 7 $res->content_length(0);
35 }
36  
37 # Errors
38 57 ▶ if ($res->status =~ /^(1\d\d|[23]04)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->status =~ /^(1\d\d|[23]04)$/) 1 56 57
39 1 $res->headers->remove_header("Content-Length");
40 1 $res->body('');
41 }
42  
43 57 ▶ $res->content_type('text/html') unless $res->content_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->content_type 54 3 57
44 57 $res->header(Status => $res->status);
45  
46 57 $class->_finalize_cookies($res);
47  
48 # HTTP/1.1's default Connection: close
49 57 ▶ if ($res->protocol && $res->protocol =~ m!1\.1! && !!!$res->header('Connection')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->protocol and $res->protocol =~ /1\.1/ and not !!$res->header("Connection")) 8 49 57
Condition100%6/6
$res->protocol and $res->protocol =~ /1\.1/ and not !!$res->header("Connection")
!ll&&!rl&&r
4818
$res->protocol and $res->protocol =~ /1\.1/
!ll&&!rl&&r
34149
MC/DC100%3/3
$res->protocol and $res->protocol =~ /1\.1/ and not !!$res->header("Connection")
$res->protocol $res->protocol =~ /1\.1/ not !!$res->header("Connection")
Truth table100%4/4
A and B and not(C)
A= $res->protocolB= $res->protocol =~ /1\.1/C= not !!$res->header("Connection")
ABCresult
0XX0
10X0
1100
1111
50 8 $res->header( Connection => 'close' );
51 }
52  
53 57 ▶ $res->body('') if ((defined $req->method) and ($req->method eq 'HEAD'));
Branch: 1 branch
BranchTrueFalseTotal
if defined $req->method and $req->method eq "HEAD" 1 56 57
Condition100%3/3
defined $req->method and $req->method eq "HEAD"
!ll&&!rl&&r
2541
MC/DC100%2/2
defined $req->method and $req->method eq "HEAD"
defined $req->method $req->method eq "HEAD"
Truth table100%3/3
A and B
A= defined $req->methodB= $req->method eq "HEAD"
ABresult
0X0
100
111
54 }
55  
56 57 ▶sub _finalize_cookies {
Subroutine _finalize_cookies: called CC=5 SCAR=16.1
57 57 my ($class, $res) = @_;
58  
59 57 my $cookies = $res->cookies;
60 57 my @keys = keys %$cookies;
61 57 ▶ if (@keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keys) 2 55 57
62 2 for my $name (@keys) {
63 5 my $val = $cookies->{$name};
64 my $cookie = (
65 Scalar::Util::blessed($val)
66 ? $val
67 : CGI::Simple::Cookie->new(
68 -name => $name,
69 -value => $val->{value},
70 -expires => $val->{expires},
71 -domain => $val->{domain},
72 -path => $val->{path},
73 5 ▶ -secure => ($val->{secure} || 0)
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($val) ? : 2 3 5
Condition100%2/2
$val->{'secure'} || 0
l!l
12
MC/DC100%1/1
$val->{'secure'} || 0
$val->{'secure'}
Truth table100%2/2
A
A= $val->{'secure'}
Aresult
11
00
74 )
75 );
76  
77 5 $res->headers->push_header('Set-Cookie' => $cookie->as_string);
78 }
79 }
80 }
81  
82 32 1;
« Engine/Interface/ServerSimple.pm ↑ Summary Engine/Role/RequestBuilder/ParseEnv.pm »