| 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
MC/DC100%2/2
-f $file || -d $file
-f $file
-d $file
Truth table100%3/3
A || B
A= -f $fileB= -d $file
| |||||||||||||||||||||||||||||
| 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"} // ""
MC/DC0%0/1
$env->{"PATH_INFO"} // ""
$env->{"PATH_INFO"}
Truth table50%1/2
A
A= $env->{"PATH_INFO"}
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 16 | ▶ | if($path_info ne '' && $path_info !~ m{/$}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$path_info ne "" and not $path_info =~ m[/$]u
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
| |||||||||||||||||||||||||||||
| 22 | { | ||||||||||||||||||||||||||||
| 23 | 9 | ▶ | my $file = ($self->root // '.') . $path_info; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->root // "."
MC/DC0%0/1
$self->root // "."
$self->root
Truth table50%1/2
A
A= $self->root
| |||||||||||||||||||||||||||||
| 24 | 9 | ▶ | if(!-e $file && -f "$file.html") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not -e $file and -f "$file.html"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 41 | 4 | ▶ | if($uri =~ m{/$}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||