Mojolicious::Plugin::AssetPack::Preprocessors - Holds preprocessors for the assetpack


Mojolicious::Plugin::AssetPack::Preprocessors is used to hold a list of preprocessors for a given file type.

Bundled preprocessors

Mojolicious::Plugin::AssetPack will load the preprocessors in the list below, when you try to handle a given file.

NOTE! Some of the preprocessors require optional dependencies to function properly.

Custom preprocessors

You can also define your own preprocessors. Example code:

  package My::Preprocessor;
  use Mojo::Base 'Mojolicious::Plugin::AssetPack::Preprocessor';

  sub process {
    my ($self, $assetpack, $text, $path) = @_;
    $$text = "// yikes!\n" if 5 < rand 10;

  app->asset->preprocessors->add(js => My::Preprocessor->new);



  $self->add($extension => $object);

  $self->add($extension => sub {
    my ($assetpack, $text, $file) = @_;
    $$text =~ s/foo/bar/ if $file =~ /baz/ and $assetpack->minify;

Define a preprocessor which is run on a given file extension. These preprocessors will be chained. The callbacks will be called in the order they where added.

In case of $object, the object need to be able to have the process() method.


  $bool = $self->can_process($extension);

Returns true if there is at least one of the preprocessors added can handle this extensions.

This means that a preprocessor object can be added, but is unable to actually process the asset. This is a helper method, which can be handy in unit tests to check if "sass", "jsx" or other preprocessors are actually installed.


  $str = $self->checksum($extension => \$text, $filename);

Calls the checksum() method in all the preprocessors for the $extension and returns a combined checksum.


DEPRECATED. Default handlers are added on the fly.


  $self->process($extension => $assetpack, \$text, $filename);

Will run the preprocessor callbacks added by "add". The callbacks will be called with the $assetpack object as the first argument.


DEPRECATED: The mapping is already done based on input files.


  $self->remove($extension => $cb);

This method will remove all preprocessors defined for an extension, or just a given $cb.


Jan Henning Thorsen -