File Coverage

blib/lib/Mojolicious/Plugin/AssetPack/Pipe/Combine.pm
Criterion Covered Total %
statement 10 23 43.4
branch 1 10 10.0
condition n/a
subroutine 3 4 75.0
pod 1 1 100.0
total 15 38 39.4


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::AssetPack::Pipe::Combine;
2 6     6   36 use Mojo::Base 'Mojolicious::Plugin::AssetPack::Pipe';
  6         11  
  6         32  
3 6     6   781 use Mojolicious::Plugin::AssetPack::Util qw(checksum diag DEBUG);
  6         12  
  6         1955  
4              
5             has enabled => sub { shift->assetpack->minify };
6              
7             sub process {
8 5     5 1 10 my ($self, $assets) = @_;
9 5         22 my $combine = Mojo::Collection->new;
10 5         28 my @other;
11              
12 5 50       29 return unless $self->enabled;
13              
14 0           for my $asset (@$assets) {
15 0 0         if ($asset->isa('Mojolicious::Plugin::AssetPack::Asset::Null')) {
    0          
16 0           next;
17             }
18 0           elsif (grep { $asset->format eq $_ } qw(css js)) {
19 0           push @$combine, $asset;
20             }
21             else {
22 0           push @other, $asset;
23             }
24             }
25              
26             # preserve assets such as images and font files
27 0           @$assets = @other;
28              
29 0 0         if (@$combine) {
30 0           my $checksum = checksum $combine->map('checksum')->join(':');
31 0 0   0     my $content = $combine->map('content')->map(sub { /\n$/ ? $_ : "$_\n" })->join;
  0            
32 0           diag 'Combining assets into "%s" with checksum %s.', $self->topic, $checksum if DEBUG;
33 0           push @$assets,
34             Mojolicious::Plugin::AssetPack::Asset->new(url => $self->topic)
35             ->checksum($checksum)->minified(1)->content($content);
36             }
37             }
38              
39             1;
40              
41             =encoding utf8
42              
43             =head1 NAME
44              
45             Mojolicious::Plugin::AssetPack::Pipe::Combine - Combine multiple assets to one
46              
47             =head1 DESCRIPTION
48              
49             L will take a list of
50             assets and turn them into a single asset.
51              
52             =head1 ATTRIBUTES
53              
54             $bool = $self->enabled;
55              
56             Set this to false to disable combining assets into a single file. The default
57             value will be L.
58              
59             =head1 METHODS
60              
61             =head2 process
62              
63             See L.
64              
65             =head1 SEE ALSO
66              
67             L.
68              
69             =cut