blib/lib/Plack/Response.pm

filter: Statementstmt 97.7% 85 / 87 Branchbran 87.5% 21 / 24 Conditioncond 87.5% 14 / 16 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 92.0% 23 / 25 Podpod 84.6% 11 / 13 totaltotal 91.9% 159 / 173 CC 20 SCAR 11.2
CC
20
Cov
94%
headers
6.0
_body
6.0
new
4.0
CRAP 3.1
« blib/lib/Plack/App/Cascade.pm ↑ Summary blib/lib/Plack/Middleware/ContentLength.pm »
1 package Plack::Response;
2 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 our $VERSION = '1.0057';
5  
6 19 ▶use Plack::Util::Accessor qw(body status);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 19 ▶use Cookie::Baker ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use HTTP::Headers::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use URI::Escape ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶sub code { shift->status(@_) }
Subroutine code: called CC=1 SCAR=0.0
Pod undocumented
14 6 ▶sub content { shift->body(@_) }
Subroutine content: called CC=1 SCAR=0.0
Pod undocumented
15  
16 41 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
17 41 my($class, $rc, $headers, $content) = @_;
18  
19 41 my $self = bless {}, $class;
20 41 ▶ $self->status($rc) if defined $rc;
Branch: 1 branch
BranchTrueFalseTotal
if defined $rc 32 9 41
21 41 ▶ $self->headers($headers) if defined $headers;
Branch: 1 branch
BranchTrueFalseTotal
if defined $headers 3 38 41
22 41 ▶ $self->body($content) if defined $content;
Branch: 1 branch
BranchTrueFalseTotal
if defined $content 1 40 41
23  
24 41 $self;
25 }
26  
27 65 ▶sub headers {
Subroutine headers: called CC=6 SCAR=18.0
Pod documented
28 65 my $self = shift;
29  
30 65 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 4 61 65
31 4 my $headers = shift;
32 4 ▶ if (ref $headers eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $headers eq 'ARRAY') { } 1 3 4
elsif (ref $headers eq 'HASH') { } 1 2 3
33 1 ▶ Carp::carp("Odd number of headers") if @$headers % 2 != 0;
Branch: 1 branch
BranchTrueFalseTotal
if @$headers % 2 != 0 0 1 1
34 1 $headers = HTTP::Headers::Fast->new(@$headers);
35 } elsif (ref $headers eq 'HASH') {
36 1 $headers = HTTP::Headers::Fast->new(%$headers);
37 }
38 4 return $self->{headers} = $headers;
39 } else {
40 61 ▶ return $self->{headers} ||= HTTP::Headers::Fast->new();
Condition66%2/3
$self->{"headers"} ||= "HTTP::Headers::Fast"->new
l!l&&r!l&&!r
25360
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
41 }
42 }
43  
44 47 ▶sub cookies {
Subroutine cookies: called CC=3 SCAR=11.0
Pod documented
45 47 my $self = shift;
46 47 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 46 47
47 1 $self->{cookies} = shift;
48 } else {
49 46 ▶ return $self->{cookies} ||= +{ };
Condition100%2/2
$self->{"cookies"} ||= {}
l!l
1135
MC/DC100%1/1
$self->{"cookies"} ||= {}
$self->{"cookies"}
Truth table100%2/2
A
A= $self->{"cookies"}
Aresult
11
00
50 }
51 }
52  
53 8 ▶sub header { shift->headers->header(@_) } # shortcut
Subroutine header: called CC=1 SCAR=0.0
Pod documented
54  
55 0 ▶sub content_length {
Subroutine content_length: not called CC=1 SCAR=6.9
Pod documented
56 0 shift->headers->content_length(@_);
57 }
58  
59 10 ▶sub content_type {
Subroutine content_type: called CC=1 SCAR=0.0
Pod documented
60 10 shift->headers->content_type(@_);
61 }
62  
63 0 ▶sub content_encoding {
Subroutine content_encoding: not called CC=1 SCAR=6.9
Pod documented
64 0 shift->headers->content_encoding(@_);
65 }
66  
67 7 ▶sub location {
Subroutine location: called CC=1 SCAR=0.0
Pod documented
68 7 my $self = shift;
69 7 return $self->headers->header('Location' => @_);
70 }
71  
72 3 ▶sub redirect {
Subroutine redirect: called CC=3 SCAR=11.0
Pod documented
73 3 my $self = shift;
74  
75 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 0 3
76 3 my $url = shift;
77 3 ▶ my $status = shift || 302;
Condition100%2/2
shift() || 302
l!l
21
MC/DC100%1/1
shift() || 302
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
78 3 $self->location($url);
79 3 $self->status($status);
80 }
81  
82 3 return $self->location;
83 }
84  
85 36 ▶sub finalize {
Subroutine finalize: called CC=2 SCAR=6.9
Pod documented
86 36 my $self = shift;
87 36 ▶ Carp::croak "missing status" unless $self->status();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status 0 36 36
88  
89 36 my $headers = $self->headers;
90 36 my @headers;
91 17 ▶ $headers->scan(sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
92 17 my ($k,$v) = @_;
93 17 $v =~ s/\015\012[\040|\011]+/chr(32)/ge; # replace LWS with a single SP
94 17 $v =~ s/\015|\012//g; # remove CR and LF since the char is invalid here
95 17 push @headers, $k, $v;
96 36 });
97  
98 36 $self->_finalize_cookies(\@headers);
99  
100 return [
101 36 $self->status,
102 \@headers,
103 $self->_body,
104 ];
105 }
106  
107 1 ▶sub to_app {
Subroutine to_app: called CC=1 SCAR=0.0
Pod documented
108 1 my $self = shift;
109 1 ▶ return sub { $self->finalize };
Subroutine __ANON__: called CC=1 SCAR=0.0
110 }
111  
112  
113 36 ▶sub _body {
Subroutine _body: called CC=6 SCAR=17.9
114 36 my $self = shift;
115 36 my $body = $self->body;
116 36 ▶ $body = [] unless defined $body;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body 16 20 36
117 36 ▶ 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')) { } 15 21 36
Condition88%8/9
not ref $body or builtin::blessed($body) and overload::Method($body, "\"\"") and not $body->can("getline")
l!l&&r!l&&!r
14121
builtin::blessed($body) and overload::Method($body, "\"\"") and not $body->can("getline")
!ll&&!rl&&r
2011
builtin::blessed($body) and overload::Method($body, "\"\"")
!ll&&!rl&&r
2002
MC/DC75%3/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 table80%4/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
118 15 return [ $body ];
119 } else {
120 21 return $body;
121 }
122 }
123  
124 36 ▶sub _finalize_cookies {
Subroutine _finalize_cookies: called CC=2 SCAR=6.9
125 36 my($self, $headers) = @_;
126  
127 36 foreach my $name ( keys %{ $self->cookies } ) {
128 6 my $val = $self->cookies->{$name};
129  
130 6 my $cookie = Cookie::Baker::bake_cookie( $name, $val );
131 6 push @$headers, 'Set-Cookie' => $cookie;
132 }
133 }
134  
135 19 1;
136 __END__
« blib/lib/Plack/App/Cascade.pm ↑ Summary blib/lib/Plack/Middleware/ContentLength.pm »