blib/lib/Plack/App/DirectoryIndex.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 80.0% 8 / 10 Conditioncond 75.0% 6 / 8 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 87.1% 54 / 62 CC 9 SCAR 18.4
CC
9
Cov
90%
serve_path
9.3
BEGIN
1.0
BEGIN
1.0
CRAP 6.3
↑ Summary
1 package Plack::App::DirectoryIndex;
2  
3 1 ▶use parent qw[Plack::App::Directory];
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Plack::Util::Accessor qw[dir_index icons pretty];
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use WebServer::DirIndex;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.2.4';
12  
13 # NOTE: Copied from Plack::App::Directory as that module makes it
14 # impossible to override the HTML.
15  
16 5 ▶sub serve_path {
Subroutine serve_path: called CC=9 SCAR=22.3
Pod undocumented
17 5 my $self = shift;
18 5 my ($env, $dir) = @_;
19  
20 5 ▶ my $dir_index = $self->dir_index // 'index.html';
Condition100%2/2
$self->dir_index // "index.html"
l!l
41
MC/DC100%1/1
$self->dir_index // "index.html"
$self->dir_index
Truth table100%2/2
A
A= $self->dir_index
Aresult
11
00
21  
22 5 ▶ if (-d $dir and $dir_index and -f "$dir$dir_index") {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dir and $dir_index and -f "$dir$dir_index") 3 2 5
Condition66%4/6
-d $dir and $dir_index and -f "$dir$dir_index"
!ll&&!rl&&r
203
-d $dir and $dir_index
!ll&&!rl&&r
023
MC/DC33%1/3
-d $dir and $dir_index and -f "$dir$dir_index"
-d $dir $dir_index -f "$dir$dir_index"
Truth table50%2/4
A and B and C
A= -d $dirB= $dir_indexC= -f "$dir$dir_index"
ABCresult
0XX0
10X0
1100
1111
23 3 $dir .= $dir_index;
24 }
25  
26 5 ▶ if (-f $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $dir) 3 2 5
27 3 return $self->SUPER::serve_path($env, $dir);
28 }
29
30 2 my $dir_url = $env->{SCRIPT_NAME} . $env->{PATH_INFO};
31
32 2 ▶ if ($dir_url !~ m{/$}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dir_url =~ m[/$]) 0 2 2
33 0 return $self->return_dir_redirect($env);
34 }
35  
36 2 my %dir_index_args = (
37 dir => $dir,
38 dir_url => $dir_url,
39 );
40  
41 2 ▶ $dir_index_args{pretty} = $self->pretty if defined $self->pretty;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->pretty 0 2 2
42 2 ▶ $dir_index_args{icons} = $self->icons if defined $self->icons;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->icons 1 1 2
43
44 2 my $di = WebServer::DirIndex->new(%dir_index_args);
45 2 my $page = $di->to_html($env->{PATH_INFO});
46  
47 2 return [ 200, ['Content-Type' => 'text/html; charset=utf-8'], [ $page ] ];
48 }
49  
50 1 1;
51  
52 __END__
↑ Summary