Mojolicious::Plugin::AssetPack::Store - Storage for assets
use Mojolicious::Lite; # Load plugin and pipes in the right order plugin AssetPack => {pipes => \@pipes}; # Change where assets can be found app->asset->store->paths([ app->home->rel_file("some/directory"), "/some/other/directory", ]); # Change where assets are stored app->asset->store->paths->[0] = app->home->rel_file("some/directory"); # Define asset app->asset->process($moniker => @assets); # Retrieve a Mojolicious::Plugin::AssetPack::Asset object my $asset = app->asset->store->asset("some/file.js");
Mojolicious::Plugin::AssetPack::Store is an object to manage cached assets on disk.
The idea is that a Mojolicious::Plugin::AssetPack::Pipe object can store an asset after it is processed. This will speed up development, since only changed assets will be processed and it will also allow processing tools to be optional in production environment.
This module will document meta data about each asset which is saved to disk, so it can be looked up later as a unique item using "load".
Mojolicious::Plugin::AssetPack::Store inherits all attributes from Mojolicious::Static implements the following new ones.
$hash_ref = $self->default_headers; $self = $self->default_headers({"Cache-Control" => "max-age=31536000"});
Used to set default headers used by "serve_asset".
$ua = $self->ua;
See "ua" in Mojolicious::Plugin::AssetPack.
$asset = $self->asset($url, $paths);
Retuns a Mojolicious::Plugin::AssetPack::Asset object or undef unless $url can be found in $paths. $paths default to "paths" in Mojolicious::Static. $paths and $url can be...
$url
$paths
http://example.com/foo/bar
An absolute URL will be downloaded from web, unless the host is "local": "local" is a special host which will run the request through the current Mojolicious application.
foo/bar
An relative URL will be looked up using "file" in Mojolicious::Static.
Note that assets from web will be cached locally, which means that you need to delete the files on disk to download a new version.
$bool = $self->load($asset, \%attr);
Used to load an existing asset from disk. %attr will override the way an asset is looked up. The example below will ignore minified and rather use the value from %attr:
%attr
$bool = $self->load($asset, {minified => $bool});
$bool = $self->save($asset, \%attr);
Used to save an asset to disk. %attr are usually the same as "TO_JSON" in Mojolicious::Plugin::AssetPack::Asset and used to document metadata about the $asset so it can be looked up using "load".
$asset
Override "serve_asset" in Mojolicious::Static with the functionality to set response headers first, from "default_headers".
Mojolicious::Plugin::AssetPack.
To install Mojolicious::Plugin::AssetPack, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::AssetPack
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::AssetPack
For more information on module installation, please visit the detailed CPAN module installation guide.