NAME

Dancer2::Plugin::Path::Class - list a directory using Path::Class

VERSION

version 0.06

SYNOPSIS

use Dancer2::Plugin::Path::Class;

get '/img' => sub {
    my $dir = ls(config->{public}, '/img');
    template 'dirlisting';
};

get '/img/**' => sub {
    my ($path) = splat;
    my @splat = @{$path};
    my $dir = ls(config->{public}, '/img', @splat);
    return template 'dirlisting' if -d $dir;
    send_file("$dir", system_path =>1);
};

In your template:

<div><a href="[% vars.ls_cdup %]">
[% vars.ls_cdup %]</a>/[% vars.ls_name %]</div>

[% FOREACH dir IN vars.ls_dirs %] ...

[% FOREACH file IN vars.ls_files %] ...

DESCRIPTION

Dancer2::Plugin::Path::Class exports the ls function returning a Path::Class object. The ls function also sets the following vars:

ls_name

The basename of the path.

ls_cdup

The parent of the request path.

ls_dirs

A list of subdirectories if the path is a directory object. The subdirs are decorated with name, file_count and a list of (sub) subdirs.

ls_files

A list of files or just one file if the path is a file object. The files are decorated with name, date, size and type.

All objects must be readable. Names starting with a dot ('.') or ending with a tilde ('~') are ignored.

AUTHOR

Henk van Oers, HVOERS@cpan.org

CONTRIBUTORS

Peter Mottram

COPYRIGHT and LICENSE

Copyright (c) Henk van Oers. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Path::Class, Dancer2