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 ua
80 $ua = $self->ua;
81
82 See "ua" in Mojolicious::Plugin::AssetPack.
83
85 Mojolicious::Plugin::AssetPack::Store inherits all attributes from
86 Mojolicious::Static implements the following new ones.
87
88 asset
89 $asset = $self->asset($url, $paths);
90
91 Returns a Mojolicious::Plugin::AssetPack::Asset object or undef unless
92 $url can be found in $paths. $paths default to "paths" in
93 Mojolicious::Static. $paths and $url can be...
94
95 • helper://some.mojo.helper/some_identifier?format=css
96
97 Will call a helper registered under the name "csome.mojo.helper",
98 with the query parameters as arguments. Example:
99
100 $output = $c->some->mojo->helper(some_identifier => {format => "css"});
101
102 $output can be a scalar containing the asset content or a hash-ref
103 with arguments passed on to Mojolicious::Plugin::AssetPack::Asset.
104 Note that "format" need to be present in the URL or the returning
105 hash-ref for this to work.
106
107 This feature is currently EXPERIMENTAL. Let me know if you use
108 it/find it interesting.
109
110 • http://example.com/foo/bar
111
112 An absolute URL will be downloaded from web, unless the host is
113 "local": "local" is a special host which will run the request through
114 the current Mojolicious application.
115
116 • foo/bar
117
118 An relative URL will be looked up using "file" in
119 Mojolicious::Static.
120
121 Note that assets from web will be cached locally, which means that you
122 need to delete the files on disk to download a new version.
123
124 load
125 $bool = $self->load($asset, \%attr);
126
127 Used to load an existing asset from disk. %attr will override the way
128 an asset is looked up. The example below will ignore minified and
129 rather use the value from %attr:
130
131 $bool = $self->load($asset, {minified => $bool});
132
133 persist
134 $self = $self->persist;
135
136 Used to save the internal state of the store to disk.
137
138 This method is EXPERIMENTAL, and may change without warning.
139
140 save
141 $bool = $self->save($asset, \%attr);
142
143 Used to save an asset to disk. %attr are usually the same as "TO_JSON"
144 in Mojolicious::Plugin::AssetPack::Asset and used to document metadata
145 about the $asset so it can be looked up using "load".
146
147 serve_asset
148 $self = $self->serve_asset($c, $asset);
149
150 Override "serve_asset" in Mojolicious::Static with the functionality to
151 set response headers first, from "default_headers".
152
153 Will call "render" in Mojolicious::Plugin::AssetPack::Asset if
154 available, after setting Content-Type header and other
155 "default_headers".
156
157 serve_fallback_for_assets
158 $self = $self->serve_fallback_for_assets($c, $topic, $assets);
159
160 Used to serve a fallback response for given $topic and a
161 Mojo::Collection of "Mojolicious::Plugin::AssetPack::Asset" objects.
162
163 Will set the headers in "fallback_headers" and then either render
164 either a template matching the extension from $topic from
165 "fallback_templates", a 302 redirect to the actual asset, or a 404 Not
166 Found.
167
168 This is currently an EXPERIMENTAL feature.
169
171 Mojolicious::Plugin::AssetPack.
172
173
174
175perl v5.32.1 2021-M0o1j-o2l7icious::Plugin::AssetPack::Store(3)