Mojolicious::Static - Serve static files
use Mojolicious::Static; my $static = Mojolicious::Static->new; push @{$static->classes}, 'MyApp::Foo'; push @{$static->paths}, '/home/sri/public';
Mojolicious::Static is a static file server with Range and If-Modified-Since support.
Range
If-Modified-Since
Mojolicious::Static implements the following attributes.
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.
DATA
main
# Add another class with static files in DATA section push @{$static->classes}, 'Mojolicious::Plugin::Fun';
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';
Mojolicious::Static inherits all methods from Mojo::Base and implements the following new ones.
my $bool = $static->dispatch(Mojolicious::Controller->new);
Serve static file for Mojolicious::Controller object.
my $asset = $static->file('images/logo.png'); my $asset = $static->file('../lib/MyApp.pm');
Build Mojo::Asset::File or Mojo::Asset::Memory object for a file, relative to "paths" or from "classes". Note that this method does not protect from traversing to parent directories.
my $content = $static->file('foo/bar.html')->slurp;
my $bool = $static->serve(Mojolicious::Controller->new, 'images/logo.png'); my $bool = $static->serve(Mojolicious::Controller->new, '../lib/MyApp.pm');
Serve a specific file, relative to "paths" or from "classes". Note that this method does not protect from traversing to parent directories.
$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.
Mojolicious, Mojolicious::Guides, http://mojolicio.us.
To install Mojolicious, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious
CPAN shell
perl -MCPAN -e shell install Mojolicious
For more information on module installation, please visit the detailed CPAN module installation guide.