| 1 | 1 | ▶ | use 5.006; use strict; use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | package Plack::App::Hash; | ||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '1.001'; | |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | BEGIN { require Plack::Component; our @ISA = 'Plack::Component' } | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Plack::Util (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Array::RefElem (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use HTTP::Status (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | #use Digest::SHA; | ||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Plack::Util::Accessor qw( content headers auto_type default_type ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 16 | ▶ | sub prepare_app { | ||||||||||||||||||||||||||||||||
|
Subroutine
prepare_app: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 17 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 18 | 16 | ▶ | require Plack::MIME if $self->auto_type; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 16 | ▶ | sub call { | ||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=16 SCAR=27.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 22 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 23 | 16 | my $env = shift; | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 16 | my $path = $env->{'PATH_INFO'}; | |||||||||||||||||||||||||||||||||
| 26 | 16 | $path =~ s!\A/!!; | |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | 16 | my $content = $self->content; | |||||||||||||||||||||||||||||||||
| 29 | 16 | ▶ | return $self->error( 404 ) unless $content and exists $content->{ $path }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$content and exists $content->{$path}
MC/DC50%1/2
$content and exists $content->{$path}
$content
exists $content->{$path}
Truth table66%2/3
A and B
A= $contentB= exists $content->{$path}
| |||||||||||||||||||||||||||||||||||
| 30 | 15 | ▶ | return $self->error( 500 ) if ref $content->{ $path }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | 14 | ▶ | my $headers = ( $self->headers || $self->headers( {} ) )->{ $path }; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->headers || $self->headers({})
MC/DC0%0/2
$self->headers || $self->headers({})
$self->headers
$self->headers({})
Truth table66%2/3
A || B
A= $self->headersB= $self->headers({})
| |||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | 14 | ▶ | if ( not defined $headers ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 35 | 8 | $headers = []; | |||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||
| 37 | elsif ( not ref $headers ) { | ||||||||||||||||||||||||||||||||||
| 38 | 2 | require JSON::MaybeXS; | |||||||||||||||||||||||||||||||||
| 39 | 2 | $headers = JSON::MaybeXS::decode_json $headers; | |||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | 13 | ▶ | return $self->error( 500 ) if 'ARRAY' ne ref $headers; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||||||||
| 45 | 12 | my $auto = $self->auto_type; | |||||||||||||||||||||||||||||||||
| 46 | 12 | my $default = $self->default_type; | |||||||||||||||||||||||||||||||||
| 47 | 12 | ▶ | last unless $auto or $default; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$auto or $default
MC/DC100%2/2
$auto or $default
$auto
$default
Truth table100%3/3
A or B
A= $autoB= $default
| |||||||||||||||||||||||||||||||||||
| 48 | 5 | ▶ | last if Plack::Util::header_exists $headers, 'Content-Type'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | $auto &&= Plack::MIME->mime_type( $path ); | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$auto &&= "Plack::MIME"->mime_type($path)
MC/DC50%1/2
$auto &&= "Plack::MIME"->mime_type($path)
$auto
"Plack::MIME"->mime_type($path)
Truth table66%2/3
A &&= B
A= $autoB= "Plack::MIME"->mime_type($path)
| |||||||||||||||||||||||||||||||||||
| 50 | 3 | ▶ | push @$headers, 'Content-Type' => $_ for $auto || $default || (); | ||||||||||||||||||||||||||||||||
|
Condition50%3/6
$auto || $default || ()
$auto or $default
MC/DC0%0/3
$auto || $default || ()
$auto
$default
()
Truth table50%2/4
A or B || C
A= $autoB= $defaultC= ()
| |||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | 12 | ▶ | if ( not Plack::Util::header_exists $headers, 'Content-Length' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 54 | 10 | push @$headers, 'Content-Length' => length $content; | |||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 12 | my @body; | |||||||||||||||||||||||||||||||||
| 58 | 12 | Array::RefElem::av_push @body, $content->{ $path }; | |||||||||||||||||||||||||||||||||
| 59 | 12 | return [ 200, $headers, \@body ]; | |||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | 3 | ▶ | sub error { | ||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 63 | 3 | my $status = pop; | |||||||||||||||||||||||||||||||||
| 64 | 3 | my $pkg = __PACKAGE__; | |||||||||||||||||||||||||||||||||
| 65 | 3 | my $body = [ qq(<!DOCTYPE html>\n<title>$pkg $status</title><h1><font face=sans-serif>) . HTTP::Status::status_message $status ]; | |||||||||||||||||||||||||||||||||
| 66 | 3 | return [ $status, [ | |||||||||||||||||||||||||||||||||
| 67 | 'Content-Type' => 'text/html', | ||||||||||||||||||||||||||||||||||
| 68 | 'Content-Length' => length $body->[0], | ||||||||||||||||||||||||||||||||||
| 69 | ], $body ]; | ||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||||||||