The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

DESCRIPTION

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);

ATTRIBUTES

fallback

TODO

METHODS

add

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

can_process

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

checksum

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

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

process

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

Will run the preprocessors added by "add".

map_type

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

remove

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

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

AUTHOR

Jan Henning Thorsen - jhthorsen@cpan.org