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::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.

METHODS

files

Returns the list of file entries for the directory. Each entry is an arrayref of [$url, $name, $size, $mime_type, $mtime]. The first entry is always the parent directory (../).

to_html($path_info, $pretty)

Generates and returns a complete HTML directory index page by delegating to WebServer::DirIndex::HTML. $path_info is the request path info used as the page title and heading. If $pretty is 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.

SEE ALSO

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