| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 21 | my $headers = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 21 | ▶ | if (ref $headers eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 21 | ▶ | Carp::carp("Odd number of headers") if @$headers % 2 != 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 20 | ▶ | if (!ref $body or Scalar::Util::blessed($body) && overload::Method($body, q("")) && !$body->can('getline')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
not ref $body or builtin::blessed($body) and overload::Method($body, "\"\"") and not $body->can("getline")
builtin::blessed($body) and overload::Method($body, "\"\"") and not $body->can("getline")
builtin::blessed($body) and overload::Method($body, "\"\"")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 12 | ▶ | return [ Encode::encode_utf8($body) ] if Encode::is_utf8($body); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||