NAME

WebServer::DirIndex::HTML - HTML rendering for directory index pages

SYNOPSIS

use WebServer::DirIndex::HTML;

my $html      = WebServer::DirIndex::HTML->new;
my $file_tmpl = $html->file_html;   # non-icon template
my $dir_tmpl  = $html->dir_html;

my $html_icons = WebServer::DirIndex::HTML->new(icons => 1);
my $file_tmpl_icons = $html_icons->file_html;  # icon template
my $dir_tmpl_icons  = $html_icons->dir_html;

DESCRIPTION

This module provides HTML template strings used to render a directory index page. The actual rendering is performed by WebServer::DirIndex.

CONSTRUCTOR

new(%args)

Creates a new WebServer::DirIndex::HTML object. Accepts the following optional named parameter:

icons

If true, file_html and dir_html return icon-aware templates (with a Font Awesome icon column). Defaults to false.

METHODS

file_html

Returns a sprintf format string used to render a single file row. When icons is true, returns the icon-aware template (6 %s placeholders: icon_class, url, name, size, mime_type, mtime). Otherwise returns the standard template (5 %s placeholders: url, name, size, mime_type, mtime).

dir_html

Returns a sprintf format string used to render the full directory index page. When icons is true, returns the icon-aware template (with Font Awesome CDN link and icon column header). Otherwise returns the standard template. Both variants have 4 %s placeholders: page title, inline css, page heading, file rows.

file_html_icons

Returns the icon-aware sprintf format string for a single file row, regardless of the icons field. Contains 6 %s placeholders: icon_class, url, name, size, mime_type, mtime.

dir_html_icons

Returns the icon-aware sprintf format string for the full directory index page, regardless of the icons field. Includes a Font Awesome CDN link and icon column header. Contains 4 %s placeholders: page title, inline css, page heading, file rows.

SUBCLASSING

You can subclass this module to provide custom HTML templates. Override file_html and/or dir_html by declaring new fields with the :reader attribute in your subclass.

Pass your subclass name as the html_class parameter when constructing WebServer::DirIndex or WebServer::DirIndex::File. The icons parameter is passed to the constructor automatically.

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
WebServer::DirIndex::CSS
Plack::App::DirectoryIndex