blib/lib/Plack/App/Hash.pm

filter: Statementstmt 100% 55 / 55 Branchbran 100% 18 / 18 Conditioncond 66.6% 12 / 18 MC/DCmcdc 36.3% 4 / 11 Subroutinesub 100% 11 / 11 Podpod 66.6% 2 / 3 totaltotal 87.9% 102 / 116 CC 17 SCAR 23.1
CC
17
Cov
93%
call
16.3
prepare_app
2.0
BEGIN
1.0
CRAP 10.1
↑ Summary
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
BranchTrueFalseTotal
if $self->auto_type 3 13 16
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
BranchTrueFalseTotal
unless $content and exists $content->{$path} 1 15 16
Condition66%2/3
$content and exists $content->{$path}
!ll&&!rl&&r
0115
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}
ABresult
0X0
100
111
30 15 ▶ return $self->error( 500 ) if ref $content->{ $path };
Branch: 1 branch
BranchTrueFalseTotal
if ref $content->{$path} 1 14 15
31  
32 14 ▶ my $headers = ( $self->headers || $self->headers( {} ) )->{ $path };
Condition66%2/3
$self->headers || $self->headers({})
l!l&&r!l&&!r
1310
MC/DC0%0/2
$self->headers || $self->headers({})
$self->headers $self->headers({})
Truth table66%2/3
A || B
A= $self->headersB= $self->headers({})
ABresult
1X1
011
000
33  
34 14 ▶ if ( not defined $headers ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $headers) { } 8 6 14
elsif (not ref $headers) { } 2 4 6
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
BranchTrueFalseTotal
if "ARRAY" ne ref $headers 1 12 13
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
BranchTrueFalseTotal
unless $auto or $default 7 5 12
Condition100%3/3
$auto or $default
l!l&&r!l&&!r
327
MC/DC100%2/2
$auto or $default
$auto $default
Truth table100%3/3
A or B
A= $autoB= $default
ABresult
1X1
011
000
48 5 ▶ last if Plack::Util::header_exists $headers, 'Content-Type';
Branch: 1 branch
BranchTrueFalseTotal
if Plack::Util::header_exists($headers, "Content-Type") 2 3 5
49 3 ▶ $auto &&= Plack::MIME->mime_type( $path );
Condition66%2/3
$auto &&= "Plack::MIME"->mime_type($path)
!ll&&!rl&&r
102
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)
ABresult
0X0
100
111
50 3 ▶ push @$headers, 'Content-Type' => $_ for $auto || $default || ();
Condition50%3/6
$auto || $default || ()
l!l&&r!l&&!r
300
$auto or $default
l!l&&r!l&&!r
210
MC/DC0%0/3
$auto || $default || ()
$auto $default ()
Truth table50%2/4
A or B || C
A= $autoB= $defaultC= ()
ABCresult
1XX1
01X1
0011
0000
51 }
52  
53 12 ▶ if ( not Plack::Util::header_exists $headers, 'Content-Length' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Plack::Util::header_exists($headers, "Content-Length")) 10 2 12
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__
↑ Summary