Plack::App::Directory::Template - Serve static files from document root with directory index template
version 0.11
use Plack::App::Directory; my $app = Plack::App::Directory->new({ root => "/path/to/htdocs", templates => "/path/to/templates", # optional filter => sub { $_[0]->{files} = [ # hide hidden files grep { $_->{name} =~ qr{^[^.]|^\.+/$} } @{$_[0]->{files}} ]; } })->to_app;
This does what Plack::App::Directory does but with more fancy looking directory index pages. The template is passed to the following variables:
The directory that is listed (absolute server path).
List of files, each with the following properties. The special files . and .. are included on purpose. All directory names end with a slash (/).
.
..
/
Local file name (basename).
URL path of the file.
MIME type of the file.
File status info as given by File::Stat (dev, ino, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime, blksize, and block).
File permissions (given by file.stat.mode & 0777). For instance one can print this in a template with [% file.permission | format("%04o") %].
file.stat.mode & 0777
[% file.permission | format("%04o") %]
Information about the HTTP request as given by Plack::Request. Includes the properties parameters, base, scheme, path, and user.
Most part of the code is copied from Plack::App::Directory.
Document root directory. Defaults to the current directory.
Template directory that must include at least a file named index.html.
index.html
A code reference that is passed a hash reference with the template variables dir and files. The reference can be modified before it is passed to the template, for instance to filter and extend file information.
dir
files
Plack::App::Directory, Plack::Middleware::TemplateToolkit
Jakob Voß
This software is copyright (c) 2013 by Jakob Voß.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
2 POD Errors
The following errors were encountered while parsing the POD:
Expected text after =item, not a bullet
Non-ASCII character seen before =encoding in 'Voß'. Assuming UTF-8
To install Plack::App::Directory::Template, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::App::Directory::Template
CPAN shell
perl -MCPAN -e shell install Plack::App::Directory::Template
For more information on module installation, please visit the detailed CPAN module installation guide.