++ed by:
ADAMJS CURTIS AWNCORP EXC PAWAPAWA

118 PAUSE users
148 non-PAUSE users.

Sebastian Riedel

NAME

Mojolicious::Static - Serve static files

SYNOPSIS

  use Mojolicious::Static;

  my $static = Mojolicious::Static->new;
  push @{$static->classes}, 'MyApp::Foo';
  push @{$static->paths}, '/home/sri/public';

DESCRIPTION

Mojolicious::Static is a dispatcher for static files with Range and If-Modified-Since support.

ATTRIBUTES

Mojolicious::Static implements the following attributes.

classes

  my $classes = $static->classes;
  $static     = $static->classes(['main']);

Classes to use for finding files in DATA sections, first one has the highest precedence, defaults to main.

  # Add another class with static files in DATA section
  push @{$static->classes}, 'Mojolicious::Plugin::Fun';

paths

  my $paths = $static->paths;
  $static   = $static->paths(['/home/sri/public']);

Directories to serve static files from, first one has the highest precedence.

  # Add another "public" directory
  push @{$static->paths}, '/home/sri/public';

METHODS

Mojolicious::Static inherits all methods from Mojo::Base and implements the following ones.

dispatch

  my $success = $static->dispatch(Mojolicious::Controller->new);

Serve static file for Mojolicious::Controller object.

file

  my $asset = $static->file('foo/bar.html');

Get Mojo::Asset::File or Mojo::Asset::Memory object for a file, relative to paths or from classes.

  my $content = $static->file('foo/bar.html')->slurp;

serve

  my $success = $static->serve(Mojolicious::Controller->new, 'foo/bar.html');

Serve a specific file, relative to paths or from classes.

serve_asset

  $static->serve_asset(Mojolicious::Controller->new, Mojo::Asset::File->new);

Serve a Mojo::Asset::File or Mojo::Asset::Memory object with Range and If-Modified-Since support.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.