AssetPack/Pipe/JavaScript.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 43 CC 6 SCAR 34.7
CC
6
Cov
0%
process
42.0
BEGIN
2.0
BEGIN
2.0
CRAP 32.0
1 package Mojolicious::Plugin::AssetPack::Pipe::JavaScript;
2 use Mojo::Base 'Mojolicious::Plugin::AssetPack::Pipe';
3  
4 use Mojolicious::Plugin::AssetPack::Util qw(diag load_module DEBUG);
5  
6 sub process {
7 my ($self, $assets) = @_;
8 my $store = $self->assetpack->store;
9 my $file;
10  
11 return unless $self->assetpack->minify;
12 return $assets->each(sub {
13 my ($asset, $index) = @_;
14 my $attrs = $asset->TO_JSON;
15 $attrs->{key} = 'js-min';
16 $attrs->{minified} = 1;
17 return if $asset->format ne 'js' or $asset->minified;
18 return $asset->content($file)->minified(1) if $file = $store->load($attrs);
19 return unless length(my $js = $asset->content);
20 load_module 'JavaScript::Minifier::XS';
21 diag 'Minify "%s" with checksum %s.', $asset->url, $asset->checksum if DEBUG;
22 $js = JavaScript::Minifier::XS::minify($js);
23 $asset->content($store->save(\$js, $attrs))->minified(1);
24 });
25 }
26  
27 1;
28  
29 =encoding utf8
30  
31 =head1 NAME
32  
33 Mojolicious::Plugin::AssetPack::Pipe::JavaScript - Minify JavaScript
34  
35 =head1 DESCRIPTION
36  
37 L<Mojolicious::Plugin::AssetPack::Pipe::JavaScript> will minify your "js"
38 assets if L<Mojolicious::Plugin::AssetPack/minify> is true and the asset is
39 not already minified.
40  
41 =head1 METHODS
42  
43 =head2 process
44  
45 See L<Mojolicious::Plugin::AssetPack::Pipe/process>.
46  
47 =head1 SEE ALSO
48  
49 L<Mojolicious::Plugin::AssetPack>.
50  
51 =cut