DOKK / manpages / debian 11 / libmojolicious-plugin-assetpack-perl / Mojolicious::Plugin::AssetPack::Pipe.3pm.en
Mojolicious::Plugin::AssetPack::Pipe(3pm) User Contributed Perl Documentation Mojolicious::Plugin::AssetPack::Pipe(3pm)

Mojolicious::Plugin::AssetPack::Pipe - Base class for a 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 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.

This is the base class for all pipe classes.

  $obj = $self->assetpack;

Holds a Mojolicious::Plugin::AssetPack object.

  $str = $self->topic;
  $self = $self->topic("app.css");

Returns the name of the current asset topic.

  $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!

  $obh = $self->app;

Returns the Mojolicious application object.

  $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!

  $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.

  $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.

  • Mojolicious::Plugin::AssetPack
  • Mojolicious::Plugin::AssetPack::Asset
  • Mojolicious::Plugin::AssetPack::Store
  • Mojolicious::Plugin::AssetPack::Util
2021-02-20 perl v5.32.1