Engine/ResponseFinalizer.pm

filter: Statementstmt 81.2% 39 / 48 Branchbran 50.0% 11 / 22 Conditioncond 35.2% 6 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 60.9% 64 / 105 SCAR 35.6
CC
19
Cov
64%
finalize
44.6
_finalize_cookies
5.1
BEGIN
1.0
CRAP 35.3
« Engine/Interface/Test.pm ↑ Summary Engine/Interface/POE.pm »
1 package HTTP::Engine::ResponseFinalizer;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use CGI::Simple::Cookie;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub finalize {
9 6 ▶ my ($class, $req, $res) = @_;
Subroutine finalize: called CC=15 SCAR=38.0
Pod undocumented
10 6 ▶ Carp::confess 'argument missing: $res' unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 6 6
11  
12 # protocol
13 6 ▶ $res->protocol( $req->protocol ) unless $res->protocol;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->protocol 0 6 6
14  
15 # Content-Length
16 6 ▶ if ($res->body) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->body) { } 6 0 6
17 # get the length from a filehandle
18 6 ▶ if ((Scalar::Util::blessed($res->body) && $res->body->can('read')) || (ref($res->body) eq 'GLOB')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($res->body) and $res->body->can('read') or ref $res->body eq 'GLOB') { } 0 6 6
Condition33%2/6
builtin::blessed($res->body) and $res->body->can("read") or ref $res->body eq "GLOB"
l!l&&r!l&&!r
006
builtin::blessed($res->body) and $res->body->can("read")
!ll&&!rl&&r
600
MC/DC0%0/3
builtin::blessed($res->body) and $res->body->can("read") or ref $res->body eq "GLOB"
builtin::blessed($res->body) $res->body->can("read") ref $res->body eq "GLOB"
Truth table20%1/5
A and B or C
A= builtin::blessed($res->body)B= $res->body->can("read")C= ref $res->body eq "GLOB"
ABCresult
11X1
0X11
1011
0X00
1000
19 0 my $st_size = 7; # see perldoc -f stat
20 0 ▶ if (my $size = eval { (stat($res->body))[$st_size] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $size = eval { do { (stat $res->body)[$st_size] } }) { } 0 0 0
21 0 $res->content_length($size);
22 } else {
23 0 die "Serving filehandle without a content-length($@)";
24 }
25 } else {
26 3 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 $res->content_length(bytes::length($res->body));
28 }
29 } else {
30 0 $res->content_length(0);
31 }
32  
33 # Errors
34 6 ▶ if ($res->status =~ /^(1\d\d|[23]04)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->status =~ /^(1\d\d|[23]04)$/) 0 6 6
35 0 $res->headers->remove_header("Content-Length");
36 0 $res->body('');
37 }
38  
39 6 ▶ $res->content_type('text/html') unless $res->content_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->content_type 6 0 6
40 6 $res->header(Status => $res->status);
41  
42 6 $class->_finalize_cookies($res);
43  
44 # HTTP/1.1's default Connection: close
45 6 ▶ 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")) 0 6 6
Condition33%2/6
$res->protocol and $res->protocol =~ /1\.1/ and not !!$res->header("Connection")
!ll&&!rl&&r
600
$res->protocol and $res->protocol =~ /1\.1/
!ll&&!rl&&r
060
MC/DC0%0/3
$res->protocol and $res->protocol =~ /1\.1/ and not !!$res->header("Connection")
$res->protocol $res->protocol =~ /1\.1/ not !!$res->header("Connection")
Truth table25%1/4
A and B and not(C)
A= $res->protocolB= $res->protocol =~ /1\.1/C= not !!$res->header("Connection")
ABCresult
0XX0
10X0
1100
1111
46 0 $res->header( Connection => 'close' );
47 }
48  
49 6 ▶ $res->body('') if ((defined $req->method) and ($req->method eq 'HEAD'));
Branch: 1 branch
BranchTrueFalseTotal
if defined $req->method and $req->method eq "HEAD" 0 6 6
Condition33%1/3
defined $req->method and $req->method eq "HEAD"
!ll&&!rl&&r
060
MC/DC0%0/2
defined $req->method and $req->method eq "HEAD"
defined $req->method $req->method eq "HEAD"
Truth table33%1/3
A and B
A= defined $req->methodB= $req->method eq "HEAD"
ABresult
0X0
100
111
50 }
51  
52 sub _finalize_cookies {
53 6 ▶ my ($class, $res) = @_;
Subroutine _finalize_cookies: called CC=5 SCAR=16.2
54  
55 6 my $cookies = $res->cookies;
56 6 my @keys = keys %$cookies;
57 6 ▶ if (@keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keys) 1 5 6
58 1 for my $name (@keys) {
59 1 my $val = $cookies->{$name};
60 my $cookie = (
61 Scalar::Util::blessed($val)
62 ? $val
63 : CGI::Simple::Cookie->new(
64 -name => $name,
65 -value => $val->{value},
66 -expires => $val->{expires},
67 -domain => $val->{domain},
68 -path => $val->{path},
69 1 ▶ -secure => ($val->{secure} || 0)
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($val) ? : 0 1 1
Condition50%1/2
$val->{'secure'} || 0
l!l
01
MC/DC0%0/1
$val->{'secure'} || 0
$val->{'secure'}
Truth table50%1/2
A
A= $val->{'secure'}
Aresult
11
00
70 )
71 );
72  
73 1 $res->headers->push_header('Set-Cookie' => $cookie->as_string);
74 }
75 }
76 }
77  
78 3 1;
« Engine/Interface/Test.pm ↑ Summary Engine/Interface/POE.pm »