NAME

Plack::App::Directory::Template - Serve static files from document root with directory index template

VERSION

version 0.21

SYNOPSIS

use Plack::App::Directory::Template;

my $template = "/path/to/templates"; # or \$template_string

my $app = Plack::App::Directory::Template->new(
    root      => "/path/to/htdocs",
    templates => $template, # optional
    filter    => sub {
         # hide hidden files
         $_[0]->{name} =~ qr{^[^.]|^\.+/$} ? $_[0] : undef;
    }
)->to_app;

DESCRIPTION

This does what Plack::App::Directory does but with more fancy looking directory index pages. The template is passed to the following variables:

dir

The directory that is listed (absolute server path).

files

List of files, each with the following properties. All directory names end with a slash (/). The special directory ./ is included and ../ as well, unless the root directory is listed.

file.name

Local file name (basename).

file.url

URL path of the file.

file.mime_type

MIME type of the file.

file.stat

File status info as given by File::Stat (dev, ino, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime, blksize, and block).

file.permission

File permissions (given by file.stat.mode & 0777). For instance one can print this in a template with [% file.permission | format("%04o") %].

request

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.

CONFIGURATION

root

Document root directory. Defaults to the current directory.

templates

Template directory that must include at least a file named index.html or template given as string reference.

filter

A code reference that is called for each file before files are passed as template variables One can use such filter to omit selected files and to modify or extend file objects.

METHODS

template_vars($dir, \@files)

This method is internally used to construct a hash reference with template variables (dir and files) from the directory and an unfiltered list of files. It is documented here as possible hook for subclasses that add more template variables.

SEE ALSO

Plack::App::Directory, Plack::Middleware::TemplateToolkit

AUTHOR

Jakob Voß

COPYRIGHT AND LICENSE

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.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 161:

Expected text after =item, not a bullet