Mojolic...k::Pipe(3)
πΈ Mojolicious::Plugin::AssetPack::Pipe π
okay so first things first, bestie: this page is from the User Contributed Perl Documentation section, and the module's full government name is Mojolicious::Plugin::AssetPack::Pipe. It's the base class for a pipe β like, the mother of all pipes, the blueprint, the main character template. Every pipe in AssetPack inherits from this vibe. π
β¨ NAME β¨
Mojolicious::Plugin::AssetPack::Pipe β the base class for a pipe. That's it, that's the name, no notes. π¦
π§ SYNOPSIS π§
So you wanna write a custom pipe? Periodt, let's go. Write it like this:
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);
}
);
}
and then you use your custom pipe like this, no cap:
use Mojolicious::Lite;
plugin AssetPack => {pipes => [qw(MyApp::MyCoolPipe Css)]};
β οΈ heads up bestie, this is important: the snippet above will not load the other default pipes, such as Mojolicious::Plugin::AssetPack::Pipe::JavaScript. So don't come crying to me when your JS isn't getting piped. You chose the hand-picked list, you get the hand-picked list. π
π DESCRIPTION π
This is the base class for all pipe classes. Every pipe you'll ever meet is a descendant of this one. It's giving founder energy. π
π«Ά ATTRIBUTES π«Ά
β assetpack
$obj = $self->assetpack;
Holds a Mojolicious::Plugin::AssetPack object. That's the whole thing. It's the plug-in handle, your backstage pass. ποΈ
β topic
$str = $self->topic;
$self = $self->topic("app.css");
Returns the name of the current asset topic. You can also set it by passing a value β yes she's a getter and a setter, we love a multi-talented icon. π
π₯ 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.
π plot twist: this method is not defined in Mojolicious::Plugin::AssetPack::Pipe! So if you're counting on it existing here, you're gonna have a bad time.
πΈ app
$obh = $self->app;
Returns the Mojolicious application object. Yes, $obh β that's what the docs say, we don't fix what isn't ours to fix. π
πΈ 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. (Yes, before_process runs after. She's mysterious. She contains multitudes. π)
π same deal as above: 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. Like, you gotta, bestie. Base class isn't gonna do it for you β this one's on you. π«‘
πΈ 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. So it's not just running your stuff β it might install your stuff too. Overachiever behavior, honestly. β¨
π SEE ALSO π
Mojolicious::Plugin::AssetPackMojolicious::Plugin::AssetPack::AssetMojolicious::Plugin::AssetPack::StoreMojolicious::Plugin::AssetPack::Util
okay that's the whole page, you ate that, you're literally an AssetPack pipe developer now π this masterpiece was served up by perl v5.42.0, dated 2024-12-12 β go forth and pipe responsibly, bestie, mwah ππ
π¦ where this page comes from
- opensuse-leap 16.0: perl-Mojolicious-Plugin-AssetPack 2.150.0-bp160.1.11 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms