The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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.

METHODS

new( %options )

%options may include:

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

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.

make_route()

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

make_handler

Returns a Neaf-compatible hander sub.

DEPRECATED Use make_route instead.