1Mojolicious::Plugin::AsUsseetrPaCcokn:t:rSitbourtee(d3M)PoejrolliDcoicouumse:n:tPaltuigoinn::AssetPack::Store(3)
2
3
4
6 Mojolicious::Plugin::AssetPack::Store - Storage for assets
7
9 use Mojolicious::Lite;
10
11 # Load plugin and pipes in the right order
12 plugin AssetPack => {pipes => \@pipes};
13
14 # Change where assets can be found
15 app->asset->store->paths([
16 app->home->rel_file("some/directory"),
17 "/some/other/directory",
18 ]);
19
20 # Change where assets are stored
21 app->asset->store->paths->[0] = app->home->rel_file("some/directory");
22
23 # Define asset
24 app->asset->process($moniker => @assets);
25
26 # Retrieve a Mojolicious::Plugin::AssetPack::Asset object
27 my $asset = app->asset->store->asset("some/file.js");
28
30 Mojolicious::Plugin::AssetPack::Store is an object to manage cached
31 assets on disk.
32
33 The idea is that a Mojolicious::Plugin::AssetPack::Pipe object can
34 store an asset after it is processed. This will speed up development,
35 since only changed assets will be processed and it will also allow
36 processing tools to be optional in production environment.
37
38 This module will document meta data about each asset which is saved to
39 disk, so it can be looked up later as a unique item using "load".
40
42 Mojolicious::Plugin::AssetPack::Store inherits all attributes from
43 Mojolicious::Static implements the following new ones.
44
45 asset_class
46 $str = $self->asset_class;
47 $self = $self->asset_class("Mojolicious::Plugin::AssetPack::Asset");
48
49 Holds the classname of which new assets will be constructed from.
50
51 default_headers
52 $hash_ref = $self->default_headers;
53 $self = $self->default_headers({"Cache-Control" => "max-age=31536000"});
54
55 Used to set headers used by "serve_asset".
56
57 fallback_headers
58 $hash_ref = $self->fallback_headers;
59 $self = $self->fallback_headers({"Cache-Control" => "max-age=300"});
60
61 Used to set headers used by "serve_fallback_for_assets".
62
63 This is currently an EXPERIMENTAL feature.
64
65 fallback_templates
66 $hash_ref = $self->fallback_templates;
67 $self = $self->fallback_templates->{"css"} = Mojo::Template->new;
68
69 Used to set up templates used by "serve_fallback_for_assets".
70
71 This is currently an EXPERIMENTAL feature.
72
73 paths
74 $paths = $self->paths;
75 $self = $self->paths([$app->home->rel_file("assets")]);
76
77 See "paths" in Mojolicious::Static for details.
78
79 retry_delay
80 my $delay = $self->retry_delay;
81 $self = $self->retry_delay(0.5);
82
83 Delay in seconds between download attempts for assets that need to be
84 fetched, defaults to 3.
85
86 retries
87 my $retries = $self->retries;
88 $self = $self->retries(5);
89
90 Number of times asset downloads will be attempted for assets that need
91 to be fetched, defaults to 0.
92
93 ua
94 $ua = $self->ua;
95
96 See "ua" in Mojolicious::Plugin::AssetPack.
97
99 Mojolicious::Plugin::AssetPack::Store inherits all attributes from
100 Mojolicious::Static implements the following new ones.
101
102 asset
103 $asset = $self->asset($url, $paths);
104
105 Returns a Mojolicious::Plugin::AssetPack::Asset object or undef unless
106 $url can be found in $paths. $paths default to "paths" in
107 Mojolicious::Static. $paths and $url can be...
108
109 • helper://some.mojo.helper/some_identifier?format=css
110
111 Will call a helper registered under the name "csome.mojo.helper",
112 with the query parameters as arguments. Example:
113
114 $output = $c->some->mojo->helper(some_identifier => {format => "css"});
115
116 $output can be a scalar containing the asset content or a hash-ref
117 with arguments passed on to Mojolicious::Plugin::AssetPack::Asset.
118 Note that "format" need to be present in the URL or the returning
119 hash-ref for this to work.
120
121 This feature is currently EXPERIMENTAL. Let me know if you use
122 it/find it interesting.
123
124 • http://example.com/foo/bar
125
126 An absolute URL will be downloaded from web, unless the host is
127 "local": "local" is a special host which will run the request through
128 the current Mojolicious application.
129
130 • foo/bar
131
132 An relative URL will be looked up using "file" in
133 Mojolicious::Static.
134
135 Note that assets from web will be cached locally, which means that you
136 need to delete the files on disk to download a new version.
137
138 load
139 $bool = $self->load($asset, \%attr);
140
141 Used to load an existing asset from disk. %attr will override the way
142 an asset is looked up. The example below will ignore minified and
143 rather use the value from %attr:
144
145 $bool = $self->load($asset, {minified => $bool});
146
147 persist
148 $self = $self->persist;
149
150 Used to save the internal state of the store to disk.
151
152 This method is EXPERIMENTAL, and may change without warning.
153
154 save
155 $bool = $self->save($asset, \%attr);
156
157 Used to save an asset to disk. %attr are usually the same as "TO_JSON"
158 in Mojolicious::Plugin::AssetPack::Asset and used to document metadata
159 about the $asset so it can be looked up using "load".
160
161 serve_asset
162 $self = $self->serve_asset($c, $asset);
163
164 Override "serve_asset" in Mojolicious::Static with the functionality to
165 set response headers first, from "default_headers".
166
167 Will call "render" in Mojolicious::Plugin::AssetPack::Asset if
168 available, after setting Content-Type header and other
169 "default_headers".
170
171 serve_fallback_for_assets
172 $self = $self->serve_fallback_for_assets($c, $topic, $assets);
173
174 Used to serve a fallback response for given $topic and a
175 Mojo::Collection of "Mojolicious::Plugin::AssetPack::Asset" objects.
176
177 Will set the headers in "fallback_headers" and then either render
178 either a template matching the extension from $topic from
179 "fallback_templates", a 302 redirect to the actual asset, or a 404 Not
180 Found.
181
182 This is currently an EXPERIMENTAL feature.
183
185 Mojolicious::Plugin::AssetPack.
186
187
188
189perl v5.36.0 2023-M0o2j-o0l5icious::Plugin::AssetPack::Store(3)