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/',
);
# Get the list of file entries
my @files = $di->files;
# Generate an HTML directory index page
my $html = $di->to_html('/some/dir/', $pretty);
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::DirIndexobject 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. - html_class
-
Optional. The class name to use for HTML templates. Defaults to
WebServer::DirIndex::HTML. Must providefile_htmlanddir_htmlmethods that returnsprintfformat strings. - css_class
-
Optional. The class name to use for CSS stylesheets. Defaults to
WebServer::DirIndex::CSS. Must provide anew(pretty =$bool)> constructor and acssmethod 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, $pretty)
-
Generates and returns a complete HTML directory index page using WebServer::DirIndex::HTML for templates and WebServer::DirIndex::CSS for styling.
$path_infois the request path info used as the page title and heading. If$prettyis true, an enhanced CSS stylesheet is used.
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.