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::AssetPack
  • Mojolicious::Plugin::AssetPack::Asset
  • Mojolicious::Plugin::AssetPack::Store
  • Mojolicious::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