NAME

WebServer::DirIndex - Directory index data for web server listings

SYNOPSIS

use WebServer::DirIndex;

my $di = WebServer::DirIndex->new(
  dir     => '/path/to/dir',
  dir_url => '/some/dir/',
  icons   => 1,          # optional, defaults to 1 (enabled)
  pretty  => 0,          # optional, defaults to 0 (standard CSS)
);

# Get the list of file entries
my @files = $di->files;

# Generate an HTML directory index page
my $html = $di->to_html('/some/dir/');

DESCRIPTION

This module reads a filesystem directory and builds the data required to render a directory index page for a web server. It provides access to the list of file entries and can generate an HTML page via WebServer::DirIndex::HTML.

CONSTRUCTOR

new(%args)

Creates a new WebServer::DirIndex object and reads the directory. Accepts the following named parameters:

dir

The filesystem path to the directory to index.

dir_url

The URL path corresponding to the directory (e.g. /some/dir/). Used to construct file URLs.

icons

Optional. When true, each file row includes a Font Awesome icon chosen based on the file's MIME type, and the rendered page links to the Font Awesome CDN stylesheet. Set to a false value to disable icons entirely. If not supplied (or explicitly set to undef), icons are enabled when pretty is true and enabled by default otherwise. Pass 0 to explicitly disable icons even when pretty is true.

pretty

Optional. When true, to_html uses an enhanced CSS stylesheet for a more attractive appearance. Defaults to false.

html_class

Optional. The class name to use for HTML templates. Defaults to WebServer::DirIndex::HTML. Must provide file_html and dir_html methods that return sprintf format strings.

css_class

Optional. The class name to use for CSS stylesheets. Defaults to WebServer::DirIndex::CSS. Must provide a new(pretty => $bool) constructor and a css method that returns a stylesheet string.

METHODS

files

Returns the list of file entries for the directory. Each entry is a WebServer::DirIndex::File object. The first entry is always the parent directory (../).

to_html($path_info)

Generates and returns a complete HTML directory index page using WebServer::DirIndex::HTML for templates and WebServer::DirIndex::CSS for styling. $path_info is the request path info used as the page title and heading. The pretty and icons options are set at construction time.

AUTHOR

Dave Cross <dave@perlhacks.com>

COPYRIGHT

Copyright (c) 2026 Magnum Solutions Limited. All rights reserved.

LICENCE

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

SEE ALSO

WebServer::DirIndex::File
WebServer::DirIndex::HTML
WebServer::DirIndex::CSS
Plack::App::DirectoryIndex