NAME
WebServer::DirIndex::File - A file entry in a directory index
SYNOPSIS
use WebServer::DirIndex::File;
my $file = WebServer::DirIndex::File->new(
url => 'file.txt',
name => 'file.txt',
size => 1234,
mime_type => 'text/plain',
mtime => 'Thu, 01 Jan 2026 00:00:00 GMT',
);
my $parent = WebServer::DirIndex::File->parent_dir;
DESCRIPTION
This module represents a single file entry in a directory index. It stores the five pieces of information needed to render a directory listing row.
CONSTRUCTOR
- new(%args)
-
Creates a new
WebServer::DirIndex::Fileobject. Accepts the following named parameters:- url
-
The URL for the file (possibly URI-escaped).
- name
-
The display name of the file.
- size
-
The file size in bytes, or an empty string for directories and the parent entry.
- mime_type
-
The MIME type of the file,
'directory'for directories, or an empty string for the parent entry. - mtime
-
The last-modified time as a formatted string, or an empty string for the parent entry.
- html_class
-
Optional. The class name to use for HTML templates. Defaults to
WebServer::DirIndex::HTML. Must provide afile_htmlmethod that returns asprintfformat string with five%splaceholders (url, name, size, mime_type, mtime).
- parent_dir
-
A class method that returns a
WebServer::DirIndex::Fileobject representing the parent directory entry (../).
METHODS
- url
-
Returns the URL of the file.
- name
-
Returns the display name of the file.
- size
-
Returns the file size.
- mime_type
-
Returns the MIME type.
- mtime
-
Returns the last-modified time string.
- to_html
-
Returns an HTML table row string representing this file entry, with all fields HTML-escaped, ready for inclusion in a directory index page.
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.