blib/lib/Plack/App/GitHubPages/Faux.pm

filter: Statementstmt 100% 38 / 38 Branchbran 100% 12 / 12 Conditioncond 76.9% 10 / 13 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 88.1% 74 / 84 CC 13 SCAR 14.3
CC
13
Cov
95%
locate_file
7.1
serve_path
5.0
should_handle
2.0
CRAP 4.2
↑ Summary
1 1 package Plack::App::GitHubPages::Faux 0.04 {
2  
3 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶ use 5.036;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶ use parent 'Plack::App::File';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: PSGI app to test your GitHub Pages site
10  
11  
12 16 ▶ sub should_handle ($self, $file)
Subroutine should_handle: called CC=2 SCAR=6.9
Pod undocumented
13 {
14 16 ▶ return -f $file || -d $file;
Condition100%3/3
-f $file || -d $file
l!l&&r!l&&!r
583
MC/DC100%2/2
-f $file || -d $file
-f $file -d $file
Truth table100%3/3
A || B
A= -f $fileB= -d $file
ABresult
1X1
011
000
15 }
16  
17 16 ▶ sub locate_file ($self, $env)
Subroutine locate_file: called CC=7 SCAR=19.7
Pod undocumented
18 {
19 16 ▶ my $path_info = $env->{PATH_INFO} // '';
Condition50%1/2
$env->{"PATH_INFO"} // ""
l!l
160
MC/DC0%0/1
$env->{"PATH_INFO"} // ""
$env->{"PATH_INFO"}
Truth table50%1/2
A
A= $env->{"PATH_INFO"}
Aresult
11
00
20  
21 16 ▶ if($path_info ne '' && $path_info !~ m{/$})
Branch: 1 branch
BranchTrueFalseTotal
if ($path_info ne "" and not $path_info =~ m[/$]u) 9 7 16
Condition66%2/3
$path_info ne "" and not $path_info =~ m[/$]u
!ll&&!rl&&r
079
MC/DC50%1/2
$path_info ne "" and not $path_info =~ m[/$]u
$path_info ne "" not $path_info =~ m[/$]u
Truth table66%2/3
A and not(B)
A= $path_info ne ""B= not $path_info =~ m[/$]u
ABresult
0X0
100
111
22 {
23 9 ▶ my $file = ($self->root // '.') . $path_info;
Condition50%1/2
$self->root // "."
l!l
90
MC/DC0%0/1
$self->root // "."
$self->root
Truth table50%1/2
A
A= $self->root
Aresult
11
00
24 9 ▶ if(!-e $file && -f "$file.html")
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $file and -f "$file.html") 2 7 9
Condition100%3/3
not -e $file and -f "$file.html"
!ll&&!rl&&r
522
MC/DC100%2/2
not -e $file and -f "$file.html"
not -e $file -f "$file.html"
Truth table100%3/3
not(A) and B
A= not -e $fileB= -f "$file.html"
ABresult
0X0
100
111
25 {
26 2 local $env->{PATH_INFO} = "$path_info.html";
27 2 return $self->SUPER::locate_file($env);
28 }
29 }
30  
31 14 return $self->SUPER::locate_file($env);
32 }
33  
34 19 ▶ sub serve_path ($self, $env, $path, $fullpath=undef)
Subroutine serve_path: called CC=5 SCAR=16.1
Pod undocumented
35 19 {
36 19 ▶ if(-d $path)
Branch: 1 branch
BranchTrueFalseTotal
if (-d $path) 8 11 19
37 {
38 8 my $uri = $env->{PATH_INFO};
39 8 my $index = path($path)->child('index.html')->stringify;
40 8 ▶ return $self->return_404 unless -f $index;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $index 4 4 8
41 4 ▶ if($uri =~ m{/$})
Branch: 1 branch
BranchTrueFalseTotal
if ($uri =~ m[/$]u) { } 3 1 4
42 {
43 3 $path = $index;
44 }
45 else
46 {
47 return
48 1 [ 301,
49 [
50 'Location' => "$uri/",
51 'Content-Type' => 'text/plain',
52 'Content-Length' => 8,
53 ],
54 [ 'Redirect' ],
55 ];
56 }
57 }
58  
59 14 return $self->SUPER::serve_path($env, $path, $fullpath);
60 }
61  
62 7 ▶ sub return_404 ($self)
Subroutine return_404: called CC=2 SCAR=6.9
Pod undocumented
63 {
64 7 my $file = path($self->root)->child('404.html')->stringify;
65  
66 -f $file
67 7 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
-f $file ? : 6 1 7
68 6 my $res = $self->serve_path(undef, $file);
69 6 $res->[0] = '404';
70 6 $res;
71 }
72 : $self->SUPER::return_404;
73 }
74  
75 }
76  
77 1 1;
78  
79 __END__
↑ Summary