Sebastian Riedel > Mojo > MojoX::Dispatcher::Static

Download:
Mojo-0.9002.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Source   Latest Release: Mojo-0.999913

NAME ^

MojoX::Dispatcher::Static - Serve Static Files

SYNOPSIS ^

    use MojoX::Dispatcher::Static;

    my $dispatcher = MojoX::Dispatcher::Static->new(
            prefix => '/images',
            root   => '/ftp/pub/images'
    );
    my $success = $dispatcher->dispatch($c);

DESCRIPTION ^

MojoX::Dispatcher::Static is a dispatcher for static files.

ATTRIBUTES

prefix

    my $prefix  = $dispatcher->prefix;
    $dispatcher = $dispatcher->prefix('/static');

Returns the path prefix if called without arguments. Returns the invocant if called with arguments. If defined, files will only get served for url paths beginning with this prefix.

types

    my $types   = $dispatcher->types;
    $dispatcher = $dispatcher->types(MojoX::Types->new);

Returns a Mojo::Types object if called without arguments. Returns the invocant if called with arguments. If no type can be determined, text/plain will be used.

root

    my $root    = $dispatcher->root;
    $dispatcher = $dispatcher->root('/foo/bar/files');

Returns the root directory from which files get served if called without arguments. Returns the invocant if called with arguments.

METHODS ^

MojoX::Dispatcher::Static inherits all methods from Mojo::Base and implements the follwing the ones.

dispatch

    my $success = $dispatcher->dispatch($c);

Returns true if a file matching the request could be found and a response be prepared. Returns false otherwise. Expects a MojoX::Context object as first argument.

serve

    my $success = $dispatcher->serve($c, 'foo/bar.html');

Returns true if a readable file could be found under root and a response be prepared. Returns false otherwise. Expects a MojoX::Context object and a path as arguments. If no type can be determined, text/plain will be used. A Last-Modified header will always be set according to the last modified time of the file.

serve_404

    my $success = $dispatcher->serve_404($c);
    my $success = $dispatcher->serve_404($c, '404.html');

serve_500

    my $success = $dispatcher->serve_500($c);
    my $success = $dispatcher->serve_500($c, '500.html');

serve_error

    my $success = $dispatcher->serve_error($c, 404);
    my $success = $dispatcher->serve_error($c, 404, '404.html');