blib/lib/Kossy/Response.pm

filter: Statementstmt 96.1% 50 / 52 Branchbran 70.0% 14 / 20 Conditioncond 50.0% 6 / 12 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 81.3% 83 / 102 CC 15 SCAR 15.6
CC
15
Cov
83%
_body
7.6
headers
7.0
finalize
3.0
CRAP 4.8
« blib/lib/Kossy.pm ↑ Summary blib/lib/Kossy/Exception.pm »
1 package Kossy::Response;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use parent qw/Plack::Response/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use HTTP::Headers::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Cookie::Baker;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 our $VERSION = '0.38';
11  
12 sub headers {
13 42 ▶ my $self = shift;
Subroutine headers: called CC=6 SCAR=19.4
Pod documented
14  
15 42 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 21 21 42
16 21 my $headers = shift;
17 21 ▶ if (ref $headers eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $headers eq 'ARRAY') { } 21 0 21
elsif (ref $headers eq 'HASH') { } 0 0 0
18 21 ▶ Carp::carp("Odd number of headers") if @$headers % 2 != 0;
Branch: 1 branch
BranchTrueFalseTotal
if @$headers % 2 != 0 0 21 21
19 21 $headers = HTTP::Headers::Fast->new(@$headers);
20 } elsif (ref $headers eq 'HASH') {
21 0 $headers = HTTP::Headers::Fast->new(%$headers);
22 }
23 21 return $self->{headers} = $headers;
24 } else {
25 21 ▶ return $self->{headers} ||= HTTP::Headers::Fast->new();
Condition66%2/3
$self->{"headers"} ||= "HTTP::Headers::Fast"->new
l!l&&r!l&&!r
1740
MC/DC0%0/2
$self->{"headers"} ||= "HTTP::Headers::Fast"->new
$self->{"headers"} "HTTP::Headers::Fast"->new
Truth table66%2/3
A ||= B
A= $self->{"headers"}B= "HTTP::Headers::Fast"->new
ABresult
1X1
011
000
26 }
27 }
28  
29 sub _body {
30 20 ▶ my $self = shift;
Subroutine _body: called CC=7 SCAR=20.2
31 20 my $body = $self->body;
32 20 ▶ $body = [] unless defined $body;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body 4 16 20
33 20 ▶ if (!ref $body or Scalar::Util::blessed($body) && overload::Method($body, q("")) && !$body->can('getline')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $body or builtin::blessed($body) and overload::Method($body, '""') and not $body->can('getline')) { } 12 8 20
Condition44%4/9
not ref $body or builtin::blessed($body) and overload::Method($body, "\"\"") and not $body->can("getline")
l!l&&r!l&&!r
1208
builtin::blessed($body) and overload::Method($body, "\"\"") and not $body->can("getline")
!ll&&!rl&&r
800
builtin::blessed($body) and overload::Method($body, "\"\"")
!ll&&!rl&&r
800
MC/DC25%1/4
not ref $body or builtin::blessed($body) and overload::Method($body, "\"\"") and not $body->can("getline")
not ref $body builtin::blessed($body) overload::Method($body, "\"\"") not $body->can("getline")
Truth table40%2/5
not(A) or B and C and not(D)
A= not ref $bodyB= builtin::blessed($body)C= overload::Method($body, "\"\"")D= not $body->can("getline")
ABCDresult
1XXX1
01111
00XX0
010X0
01100
34 12 ▶ return [ Encode::encode_utf8($body) ] if Encode::is_utf8($body);
Branch: 1 branch
BranchTrueFalseTotal
if &Encode::is_utf8($body) 3 9 12
35 9 return [ $body ];
36 } else {
37 8 return $body;
38 }
39 }
40  
41 sub finalize {
42 20 ▶ my $self = shift;
Subroutine finalize: called CC=3 SCAR=11.1
Pod documented
43 20 ▶ Carp::croak "missing status" unless $self->status();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status 0 20 20
44 20 my @headers;
45 $self->headers->scan(sub{
46 27 ▶ my ($k,$v) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.2
47 27 ▶ return if $k eq 'X-XSS-Protection';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "X-XSS-Protection" 0 27 27
48 27 $v =~ s/\015\012[\040|\011]+/chr(32)/ge; # replace LWS with a single SP
49 27 $v =~ s/\015|\012//g; # remove CR and LF since the char is invalid here
50 27 push @headers, $k, $v;
51 20 });
52  
53 20 ▶ while (my($name, $val) = each %{$self->cookies}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$self->cookies;}) 1 20 21
54 1 my $cookie = bake_cookie($name, $val);
55 1 push @headers, 'Set-Cookie' => $cookie;
56 }
57  
58 20 push @headers, 'X-XSS-Protection' => 1;
59  
60 return [
61 20 $self->status,
62 \@headers,
63 $self->_body,
64 ];
65 }
66  
67 7 1;
« blib/lib/Kossy.pm ↑ Summary blib/lib/Kossy/Exception.pm »