File Coverage

blib/lib/Plack/App/GitHubPages/Faux.pm
Criterion Covered Total %
statement 44 44 100.0
branch 8 8 100.0
condition 3 3 100.0
subroutine 9 9 100.0
pod 0 3 0.0
total 64 67 95.5


line stmt bran cond sub pod time code
1             package Plack::App::GitHubPages::Faux 0.03 {
2              
3 1     1   203538 use strict;
  1         5  
  1         25  
4 1     1   12 use warnings;
  1         2  
  1         21  
5 1     1   20 use 5.020;
  1         2  
6 1     1   4 use parent 'Plack::App::File';
  1         2  
  1         6  
7 1     1   17029 use experimental qw( signatures postderef );
  1         3749  
  1         4  
8 1     1   928 use Path::Tiny qw( path );
  1         10326  
  1         372  
9              
10             # ABSTRACT: PSGI app to test your GitHub Pages site
11              
12              
13 13         21 sub should_handle ($self, $file)
14 13     13 0 148146 {
  13         18  
  13         15  
15 13   100     348 return -f $file || -d $file;
16             }
17              
18 16         20 sub serve_path ($self, $env, $path, $fullpath=undef)
  16         29  
  16         22  
19 16     16 0 345 {
  16         24  
  16         17  
20 16 100       149 if(-d $path)
21             {
22 8         22 my $uri = $env->{PATH_INFO};
23 8         26 my $index = path($path)->child('index.html')->stringify;
24 8 100       590 return $self->return_404 unless -f $index;
25 4 100       22 if($uri =~ m{/$})
26             {
27 3         6 $path = $index;
28             }
29             else
30             {
31             return
32 1         18 [ 301,
33             [
34             'Location' => "$uri/",
35             'Content-Type' => 'text/plain',
36             'Content-Length' => 8,
37             ],
38             [ 'Redirect' ],
39             ];
40             }
41             }
42              
43 11         56 return $self->SUPER::serve_path($env, $path, $fullpath);
44             }
45              
46             sub return_404 ($self)
47 6     6 0 50 {
  6         11  
  6         8  
48 6         20 my $file = path($self->root)->child('404.html')->stringify;
49              
50             -f $file
51 6 100       450 ? do {
52 5         23 my $res = $self->serve_path(undef, $file);
53 5         684 $res->[0] = '404';
54 5         33 $res;
55             }
56             : $self->SUPER::return_404;
57             }
58              
59             }
60              
61             1;
62              
63             __END__