++ed by:
BEROV

1 PAUSE user
1 non-PAUSE user.

Konstantin S. Uvarin

NAME

MVC::Neaf::X::Files - serve static content for Not Even A Framework.

SYNOPSIS

     use MVC::Neaf qw(:sugar);

     neaf static "/path/in/url" => "/local/path", %options;

These options would go to this module's new() method described below.

DESCRIPTION

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.

METHODS

new( %options )

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

serve_file( $path )

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.

This MAY be used to create more fine-grained control over static files.

EXPERIMENTAL. New options MAY be added.

list_dir( $path )

Create a directory index reply. Used by serve_file() if dir_index given.

As of current, indices are not cached.

preload( %files )

Preload multiple in-memory files.

Returns self.

one_file_handler()

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_cache( $name, $expires, \%data )

Save data in cache.

$name is canonized file name.

$expires is unix timestamp. If undef, cache forever.

guess_type( $filename, $content )

Returns file's MIME type. As of current, content is ignored, and only file extention is considered.

make_route()

Returns list of arguments suitable for neaf->route(...):

  • base url;

  • handler sub;

  • a hash of options: path_info_regex, cache_ttl, and description.

make_handler

Returns a Neaf-compatible handler sub.

DEPRECATED Use make_route instead. This dies.

LICENSE AND COPYRIGHT

Copyright 2016-2017 Konstantin S. Uvarin 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.