line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::DirIndex; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Plack::Middleware::DirIndex::VERSION = '0.01'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Append an index file to request PATH's ending with a / |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
92367
|
use parent qw( Plack::Middleware ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
9
|
1
|
|
|
1
|
|
63
|
use Plack::Util::Accessor qw(dir_index); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Plack::Middleware::DirIndex |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Plack::Builder; |
18
|
|
|
|
|
|
|
use Plack::App::File; |
19
|
|
|
|
|
|
|
use Plack::Middleware::DirIndex; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $app = Plack::App::File->new({ root => './htdocs/' })->to_app; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
builder { |
24
|
|
|
|
|
|
|
enable "Plack::Middleware::DirIndex", dir_index => 'index.html'; |
25
|
|
|
|
|
|
|
$app; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
If $env->{PATH_INFO} ends with a '/' then we will append the dir_index |
31
|
|
|
|
|
|
|
value to it (defaults to index.html) |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub prepare_app { |
36
|
2
|
|
|
2
|
1
|
1862
|
my ($self) = @_; |
37
|
|
|
|
|
|
|
|
38
|
2
|
100
|
|
|
|
9
|
$self->dir_index('index.html') unless $self->dir_index; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub call { |
42
|
5
|
|
|
5
|
1
|
55835
|
my ( $self, $env ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
5
|
100
|
|
|
|
33
|
if ( $env->{PATH_INFO} =~ m{/$} ) { |
45
|
4
|
|
|
|
|
20
|
$env->{PATH_INFO} .= $self->dir_index(); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
5
|
|
|
|
|
40
|
return $self->app->($env); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |