blib/lib/Plack/Middleware/Static.pm

filter: Statementstmt 100% 31 / 31 Branchbran 87.5% 7 / 8 Conditioncond 72.7% 8 / 11 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 87.5% 56 / 64 CC 10 SCAR 14.9
CC
10
Cov
92%
_handle_static
7.2
call
4.0
BEGIN
1.0
CRAP 4.4
« blib/lib/Plack/Middleware/Auth/Basic.pm ↑ Summary blib/lib/Plack/Middleware/LighttpdScriptNameFix.pm »
1 package Plack::Middleware::Static;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use parent qw/Plack::Middleware/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Plack::App::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use Plack::Util::Accessor qw( path root encoding pass_through content_type );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 41 ▶sub call {
Subroutine call: called CC=4 SCAR=13.9
Pod documented
10 41 my $self = shift;
11 41 my $env = shift;
12  
13 41 my $res = $self->_handle_static($env);
14 41 ▶ if ($res && not ($self->pass_through and $res->[0] == 404)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res and not $self->pass_through && $res->[0] == 404) 12 29 41
Condition83%5/6
$res and not $self->pass_through && $res->[0] == 404
!ll&&!rl&&r
28112
$self->pass_through && $res->[0] == 404
!ll&&!rl&&r
1201
MC/DC66%2/3
$res and not $self->pass_through && $res->[0] == 404
$res $self->pass_through $res->[0] == 404
Truth table75%3/4
A and not(B && C)
A= $resB= $self->pass_throughC= $res->[0] == 404
ABCresult
0XX0
1110
10X1
1101
15 12 return $res;
16 }
17  
18 29 return $self->app->($env);
19 }
20  
21 41 ▶sub _handle_static {
Subroutine _handle_static: called CC=7 SCAR=19.7
22 41 my($self, $env) = @_;
23  
24 41 ▶ my $path_match = $self->path or return;
Branch: 1 branch
BranchTrueFalseTotal
my $path_match = $self->path or return 41 0 41
25 41 my $path = $env->{PATH_INFO};
26  
27 41 for ($path) {
28 41 ▶ my $matched = 'CODE' eq ref $path_match ? $path_match->($_, $env) : $_ =~ $path_match;
Branch: 1 branch
BranchTrueFalseTotal
'CODE' eq ref $path_match ? : 24 17 41
29 41 ▶ return unless $matched;
Branch: 1 branch
BranchTrueFalseTotal
unless $matched 28 13 41
30 }
31  
32 13 ▶ $self->{file} ||= Plack::App::File->new({ root => $self->root || '.', encoding => $self->encoding, content_type => $self->content_type });
Condition60%3/5
$self->{"file"} ||= "Plack::App::File"->new({"root", $self->root || ".", "encoding", $self->encoding, "content_type", $self->content_type})
l!l&&r!l&&!r
490
$self->root || '.'
l!l
90
MC/DC0%0/2
$self->{"file"} ||= "Plack::App::File"->new({"root", $self->root || ".", "encoding", $self->encoding, "content_type", $self->content_type})
$self->{"file"} "Plack::App::File"->new({"root", $self->root || ".", "encoding", $self->encoding, "content_type", $self->content_type})
MC/DC0%0/1
$self->root || '.'
$self->root
Truth table66%2/3
A ||= B
A= $self->{"file"}B= "Plack::App::File"->new({"root", $self->root || ".", "encoding", $self->encoding, "content_type", $self->content_type})
ABresult
1X1
011
000
Truth table50%1/2
A
A= $self->root
Aresult
11
00
33 13 local $env->{PATH_INFO} = $path; # rewrite PATH
34 13 return $self->{file}->call($env);
35 }
36  
37 5 1;
38 __END__
« blib/lib/Plack/Middleware/Auth/Basic.pm ↑ Summary blib/lib/Plack/Middleware/LighttpdScriptNameFix.pm »