.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mojolicious::Plugin::AssetPack::Store 3pm" .TH Mojolicious::Plugin::AssetPack::Store 3pm "2023-02-04" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojolicious::Plugin::AssetPack::Store \- Storage for assets .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojolicious::Lite; \& \& # Load plugin and pipes in the right order \& plugin AssetPack => {pipes => \e@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"); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojolicious::Plugin::AssetPack::Store is an object to manage cached assets on disk. .PP 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. .PP 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 \*(L"load\*(R". .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojolicious::Plugin::AssetPack::Store inherits all attributes from Mojolicious::Static implements the following new ones. .SS "asset_class" .IX Subsection "asset_class" .Vb 2 \& $str = $self\->asset_class; \& $self = $self\->asset_class("Mojolicious::Plugin::AssetPack::Asset"); .Ve .PP Holds the classname of which new assets will be constructed from. .SS "default_headers" .IX Subsection "default_headers" .Vb 2 \& $hash_ref = $self\->default_headers; \& $self = $self\->default_headers({"Cache\-Control" => "max\-age=31536000"}); .Ve .PP Used to set headers used by \*(L"serve_asset\*(R". .SS "fallback_headers" .IX Subsection "fallback_headers" .Vb 2 \& $hash_ref = $self\->fallback_headers; \& $self = $self\->fallback_headers({"Cache\-Control" => "max\-age=300"}); .Ve .PP Used to set headers used by \*(L"serve_fallback_for_assets\*(R". .PP This is currently an \s-1EXPERIMENTAL\s0 feature. .SS "fallback_templates" .IX Subsection "fallback_templates" .Vb 2 \& $hash_ref = $self\->fallback_templates; \& $self = $self\->fallback_templates\->{"css"} = Mojo::Template\->new; .Ve .PP Used to set up templates used by \*(L"serve_fallback_for_assets\*(R". .PP This is currently an \s-1EXPERIMENTAL\s0 feature. .SS "paths" .IX Subsection "paths" .Vb 2 \& $paths = $self\->paths; \& $self = $self\->paths([$app\->home\->rel_file("assets")]); .Ve .PP See \*(L"paths\*(R" in Mojolicious::Static for details. .SS "retry_delay" .IX Subsection "retry_delay" .Vb 2 \& my $delay = $self\->retry_delay; \& $self = $self\->retry_delay(0.5); .Ve .PP Delay in seconds between download attempts for assets that need to be fetched, defaults to \f(CW3\fR. .SS "retries" .IX Subsection "retries" .Vb 2 \& my $retries = $self\->retries; \& $self = $self\->retries(5); .Ve .PP Number of times asset downloads will be attempted for assets that need to be fetched, defaults to \f(CW0\fR. .SS "ua" .IX Subsection "ua" .Vb 1 \& $ua = $self\->ua; .Ve .PP See \*(L"ua\*(R" in Mojolicious::Plugin::AssetPack. .SH "METHODS" .IX Header "METHODS" Mojolicious::Plugin::AssetPack::Store inherits all attributes from Mojolicious::Static implements the following new ones. .SS "asset" .IX Subsection "asset" .Vb 1 \& $asset = $self\->asset($url, $paths); .Ve .PP Returns a Mojolicious::Plugin::AssetPack::Asset object or undef unless \&\f(CW$url\fR can be found in \f(CW$paths\fR. \f(CW$paths\fR default to \&\*(L"paths\*(R" in Mojolicious::Static. \f(CW$paths\fR and \f(CW$url\fR can be... .IP "\(bu" 2 helper://some.mojo.helper/some_identifier?format=css .Sp Will call a helper registered under the name \f(CW\*(C`csome.mojo.helper\*(C'\fR, with the query parameters as arguments. Example: .Sp .Vb 1 \& $output = $c\->some\->mojo\->helper(some_identifier => {format => "css"}); .Ve .Sp \&\f(CW$output\fR can be a scalar containing the asset content or a hash-ref with arguments passed on to Mojolicious::Plugin::AssetPack::Asset. Note that \&\f(CW\*(C`format\*(C'\fR need to be present in the \s-1URL\s0 or the returning hash-ref for this to work. .Sp This feature is currently \s-1EXPERIMENTAL.\s0 Let me know if you use it/find it interesting. .IP "\(bu" 2 http://example.com/foo/bar .Sp An absolute \s-1URL\s0 will be downloaded from web, unless the host is \*(L"local\*(R": \&\*(L"local\*(R" is a special host which will run the request through the current Mojolicious application. .IP "\(bu" 2 foo/bar .Sp An relative \s-1URL\s0 will be looked up using \*(L"file\*(R" in Mojolicious::Static. .PP 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. .SS "load" .IX Subsection "load" .Vb 1 \& $bool = $self\->load($asset, \e%attr); .Ve .PP Used to load an existing asset from disk. \f(CW%attr\fR will override the way an asset is looked up. The example below will ignore minified and rather use the value from \f(CW%attr\fR: .PP .Vb 1 \& $bool = $self\->load($asset, {minified => $bool}); .Ve .SS "persist" .IX Subsection "persist" .Vb 1 \& $self = $self\->persist; .Ve .PP Used to save the internal state of the store to disk. .PP This method is \s-1EXPERIMENTAL,\s0 and may change without warning. .SS "save" .IX Subsection "save" .Vb 1 \& $bool = $self\->save($asset, \e%attr); .Ve .PP Used to save an asset to disk. \f(CW%attr\fR are usually the same as \&\*(L"\s-1TO_JSON\*(R"\s0 in Mojolicious::Plugin::AssetPack::Asset and used to document metadata about the \f(CW$asset\fR so it can be looked up using \*(L"load\*(R". .SS "serve_asset" .IX Subsection "serve_asset" .Vb 1 \& $self = $self\->serve_asset($c, $asset); .Ve .PP Override \*(L"serve_asset\*(R" in Mojolicious::Static with the functionality to set response headers first, from \*(L"default_headers\*(R". .PP Will call \*(L"render\*(R" in Mojolicious::Plugin::AssetPack::Asset if available, after setting Content-Type header and other \*(L"default_headers\*(R". .SS "serve_fallback_for_assets" .IX Subsection "serve_fallback_for_assets" .Vb 1 \& $self = $self\->serve_fallback_for_assets($c, $topic, $assets); .Ve .PP Used to serve a fallback response for given \f(CW$topic\fR and a Mojo::Collection of \f(CW\*(C`Mojolicious::Plugin::AssetPack::Asset\*(C'\fR objects. .PP Will set the headers in \*(L"fallback_headers\*(R" and then either render either a template matching the extension from \f(CW$topic\fR from \*(L"fallback_templates\*(R", a 302 redirect to the actual asset, or a 404 Not Found. .PP This is currently an \s-1EXPERIMENTAL\s0 feature. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious::Plugin::AssetPack.