Created
March 10, 2011 03:11
-
-
Save hdp/863516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $root = '.'; | |
my @indexes = qw(index.html); | |
use strict; | |
use warnings; | |
use Plack::App::File; | |
use Plack::App::Cascade; | |
sub directory_indexes { | |
my ($root, @indexes) = @_; | |
my $file = Plack::App::File->new(root => $root)->to_app; | |
my $serve_index = sub { | |
my ($index) = @_; | |
return sub { | |
my $env = shift; | |
my $path = $env->{PATH_INFO}; | |
local $env->{PATH_INFO} = "$path/$index"; | |
return $file->($env); | |
}; | |
}; | |
my $cascade = Plack::App::Cascade->new; | |
for my $index (@indexes) { | |
$cascade->add($serve_index->($index)); | |
} | |
$cascade->add($file); | |
return $cascade->to_app; | |
} | |
directory_indexes($root, @indexes); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment