diff --git a/lib/Plack/App/Directory.pm b/lib/Plack/App/Directory.pm index 48443ca0..4d3960f0 100644 --- a/lib/Plack/App/Directory.pm +++ b/lib/Plack/App/Directory.pm @@ -10,8 +10,11 @@ use URI::Escape; use Plack::Request; # Stolen from rack/directory.rb -my $dir_file = "%s%s%s%s"; -my $dir_page = <%s%s%s%s"; +} +sub dir_page { + return <<'PAGE'; %s @@ -37,6 +40,16 @@ table { width:100%%; }
PAGE +} + +sub render_file { + my ($self, @f) = @_; + return sprintf $self->dir_file, map { Plack::Util::encode_html($_) } @f; +} +sub render_dir { + my ($self, $path, $files) = @_; + return sprintf $self->dir_page, $path, $path, $files; +} sub should_handle { my($self, $file) = @_; @@ -99,9 +112,9 @@ sub serve_path { my $path = Plack::Util::encode_html("Index of $env->{PATH_INFO}"); my $files = join "\n", map { my $f = $_; - sprintf $dir_file, map Plack::Util::encode_html($_), @$f; + $self->render_file( @$f ); } @files; - my $page = sprintf $dir_page, $path, $path, $files; + my $page = $self->render_dir( $path, $files ); return [ 200, ['Content-Type' => 'text/html; charset=utf-8'], [ $page ] ]; }