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

NAME

Mojolicious::Plugin::AssetPack::Store - Storage for assets

SYNOPSIS

  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");

DESCRIPTION

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

ATTRIBUTES

Mojolicious::Plugin::AssetPack::Store inherits all attributes from Mojolicious::Static implements the following new ones.

default_headers

  $hash_ref = $self->default_headers;
  $self = $self->default_headers({"Cache-Control" => "max-age=31536000"});

Used to set default headers used by "serve_asset".

ua

  $ua = $self->ua;

See "ua" in Mojolicious::Plugin::AssetPack.

METHODS

Mojolicious::Plugin::AssetPack::Store inherits all attributes from Mojolicious::Static implements the following new ones.

asset

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

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

load

  $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:

  $bool = $self->load($asset, {minified => $bool});

save

  $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".

serve_asset

Override "serve_asset" in Mojolicious::Static with the functionality to set response headers first, from "default_headers".

SEE ALSO

Mojolicious::Plugin::AssetPack.