MVC::Neaf::X::Files - serve static content for Not Even A Framework.
use MVC::Neaf; neaf static "/path/in/url" => "/local/path", %options;
These options would go to this module's new() method described below.
Serving static content in production via a perl application framework is a bad idea. However, forcing the user to run a separate web-server just to test their CSS, JS, and images is an even worse one.
So this module is here to fill the gap in MVC::Neaf.
%options may include:
root - where to search for files. May point to asingle file, too. (Required).
buffer - buffer size for serving files. Currently this is also the size below which in-memory caching is on, but this MAY change in the future.
cache_ttl - if given, files below the buffer size will be stored in memory for cache_ttl seconds. EXPERIMENTAL. Cache API is not yet established.
in_memory = { name => [ "content", "type" ] }
Serve some files from memory. Content-type defaults to text/plain.
EXPERIMENTAL. Name and signature MAY change in the future.
Create a Neaf-compatible response using given path. The response is like follows:
{ -content => (file content), -headers => (length, name etc), -type => (content-type), -continue => (serve the rest of the file, if needed), };
Will die 404; if file is not there.
die 404;
This MAY be used to create more fine-grained control over static files.
EXPERIMENTAL. New options MAY be added.
Create a directory index reply. Used by serve_file() if dir_index given.
As of current, indices are not cached.
Preload multiple in-memory files.
Returns self.
Returns a simple closure that accepts a MVC::Neaf::Request and serves the requested path as is, relative to the X::Files objects's root, or from cache.
EXPERIMENTAL. This is used internally by Neaf, name & meaning may change.
Save data in cache.
$name is canonized file name.
$expires is unix timestamp. If undef, cache forever.
Returns file's MIME type. As of current, content is ignored, and only file extention is considered.
Returns list of arguments suitable for neaf->route(...):
neaf->route(...)
base url;
handler sub;
a hash of options: path_info_regex, cache_ttl, and description.
Returns a Neaf-compatible handler sub.
DEPRECATED Use make_route instead. This dies.
This module is part of MVC::Neaf suite.
Copyright 2016-2023 Konstantin S. Uvarin khedin@cpan.org.
khedin@cpan.org
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install MVC::Neaf, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MVC::Neaf
CPAN shell
perl -MCPAN -e shell install MVC::Neaf
For more information on module installation, please visit the detailed CPAN module installation guide.