table of contents
Mojolicious::Plugin::AssetPack::Pipe(3) | User Contributed Perl Documentation | Mojolicious::Plugin::AssetPack::Pipe(3) |
NAME¶
Mojolicious::Plugin::AssetPack::Pipe - Base class for a pipe
SYNOPSIS¶
Write a custom pipe¶
package MyApp::MyCoolPipe; use Mojo::Base "Mojolicious::Plugin::AssetPack::Pipe"; use Mojolicious::Plugin::AssetPack::Util qw(diag DEBUG); sub process { my ($self, $assets) = @_; # Normally a Mojolicious::Plugin::AssetPack::Store object my $store = $self->assetpack->store; # Loop over Mojolicious::Plugin::AssetPack::Asset objects $assets->each( sub { my ($asset, $index) = @_; # Skip every file that is not css return if $asset->format ne "css"; # Change $attr if this pipe will modify $asset attributes my $attr = $asset->TO_JSON; my $content = $asset->content; # Private name to load/save meta data under $attr->{key} = "coolpipe"; # Return asset if already processed if ($content !~ /white/ and $file = $store->load($attr)) { return $asset->content($file); } # Process asset content diag q(Replace white with red in "%s".), $asset->url if DEBUG; $content =~ s!white!red!g; $asset->content($store->save(\$content, $attr))->minified(1); } ); }
Use the custom pipe¶
use Mojolicious::Lite; plugin AssetPack => {pipes => [qw(MyApp::MyCoolPipe Css)]};
Note that the above will not load the other default pipes, such as Mojolicious::Plugin::AssetPack::Pipe::JavaScript.
DESCRIPTION¶
This is the base class for all pipe classes.
ATTRIBUTES¶
assetpack¶
$obj = $self->assetpack;
Holds a Mojolicious::Plugin::AssetPack object.
topic¶
$str = $self->topic; $self = $self->topic("app.css");
Returns the name of the current asset topic.
METHODS¶
after_process¶
$self->after_process(Mojo::Collection->new);
"process" in Mojolicious::Plugin::AssetPack will call this method before any of the pipe "process" method is called.
Note that this method is not defined in Mojolicious::Plugin::AssetPack::Pipe!
app¶
$obh = $self->app;
Returns the Mojolicious application object.
before_process¶
$self->before_process(Mojo::Collection->new);
"process" in Mojolicious::Plugin::AssetPack will call this method after all of the pipes "process" method is called.
Note that this method is not defined in Mojolicious::Plugin::AssetPack::Pipe!
process¶
$self->process(Mojo::Collection->new);
A method used to process the assets. Each of the element in the collection will be a Mojolicious::Plugin::AssetPack::Asset object or an object with the same API.
This method need to be defined in the subclass.
run¶
$self->run([som_app => @args], \$stdin, \$stdout, ...);
See "run3" in IPC::Run3 for details about the arguments. This method will try to call _install_some_app() unless "som_app" was found in PATH. This method could then try to install the application and must return the path to the installed application.
SEE ALSO¶
- Mojolicious::Plugin::AssetPack
- Mojolicious::Plugin::AssetPack::Asset
- Mojolicious::Plugin::AssetPack::Store
- Mojolicious::Plugin::AssetPack::Util
2024-12-12 | perl v5.40.0 |