line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Web::AssetLib::MinifierEngine::Standard; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
11255724
|
use Method::Signatures; |
|
6
|
|
|
|
|
50342
|
|
|
6
|
|
|
|
|
32
|
|
4
|
6
|
|
|
6
|
|
2370
|
use Moose; |
|
6
|
|
|
|
|
289893
|
|
|
6
|
|
|
|
|
35
|
|
5
|
6
|
|
|
6
|
|
25507
|
use Carp; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
307
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
799
|
use Web::AssetLib::Util; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
96
|
|
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
114
|
use v5.14; |
|
6
|
|
|
|
|
13
|
|
10
|
6
|
|
|
6
|
|
25
|
no if $] >= 5.018, warnings => "experimental"; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
59
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
extends 'Web::AssetLib::MinifierEngine'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'minifiers' => ( |
15
|
|
|
|
|
|
|
is => 'rw', |
16
|
|
|
|
|
|
|
isa => 'HashRef', |
17
|
|
|
|
|
|
|
default => sub { |
18
|
|
|
|
|
|
|
my $self = shift; |
19
|
|
|
|
|
|
|
{ js => sub { |
20
|
|
|
|
|
|
|
my $minifier = \&{ $self->javascript_module . '::minify' }; |
21
|
|
|
|
|
|
|
return $minifier->( $_[0] ); |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
css => sub { |
24
|
|
|
|
|
|
|
my $minifier = \&{ $self->css_module . '::minify' }; |
25
|
|
|
|
|
|
|
return $minifier->( $_[0] ); |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
_else => sub { |
28
|
|
|
|
|
|
|
return $_[0]; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has 'javascript_module' => ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
isa => 'Str', |
37
|
|
|
|
|
|
|
lazy_build => 1, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has 'css_module' => ( |
41
|
|
|
|
|
|
|
is => 'rw', |
42
|
|
|
|
|
|
|
isa => 'Str', |
43
|
|
|
|
|
|
|
lazy_build => 1, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
6
|
50
|
|
6
|
|
4156
|
method _build_css_module { |
|
3
|
|
|
3
|
|
6
|
|
|
3
|
|
|
|
|
11
|
|
47
|
3
|
50
|
|
|
|
14
|
return 'CSS::Minifier::XS' if $INC{'CSS/Minifier/XS.pm'}; |
48
|
|
|
|
|
|
|
|
49
|
3
|
50
|
|
|
|
5
|
return 'CSS::Minifier::XS' if eval { require CSS::Minifier::XS; 1; }; |
|
3
|
|
|
|
|
2024
|
|
|
3
|
|
|
|
|
1921
|
|
50
|
0
|
|
|
|
|
0
|
$self->log->warn( |
51
|
|
|
|
|
|
|
'installing CSS::Minifier::XS could yield better performance'); |
52
|
0
|
0
|
|
|
|
0
|
return 'CSS::Minifier' if eval { require CSS::Minifier; 1 }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
53
|
0
|
|
|
|
|
0
|
croak |
54
|
|
|
|
|
|
|
"no css minifier found (requires CSS::Minifier::XS or CSS::Minifier)"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
6
|
50
|
|
6
|
|
3022
|
method _build_javascript_module { |
|
3
|
|
|
3
|
|
7
|
|
|
3
|
|
|
|
|
9
|
|
58
|
3
|
50
|
|
|
|
18
|
return 'JavaScript::Minifier::XS' if $INC{'JavaScript/Minifier/XS.pm'}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return 'JavaScript::Minifier::XS' |
61
|
3
|
50
|
|
|
|
7
|
if eval { require JavaScript::Minifier::XS; 1; }; |
|
3
|
|
|
|
|
1928
|
|
|
3
|
|
|
|
|
2188
|
|
62
|
0
|
|
|
|
|
0
|
$self->log->warn( |
63
|
|
|
|
|
|
|
'installing JavaScript::Minifier::XS could yield better performance'); |
64
|
0
|
0
|
|
|
|
0
|
return 'JavaScript::Minifier' if eval { require JavaScript::Minifier; 1 }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
65
|
0
|
|
|
|
|
0
|
croak |
66
|
|
|
|
|
|
|
"no Javascript minifier found (requires JavaScript::Minifier::XS or JavaScript::Minifier)"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
6
|
50
|
|
6
|
|
16013
|
method minify( :$contents!, :$type ) { |
|
6
|
50
|
|
6
|
|
14
|
|
|
6
|
50
|
|
|
|
44
|
|
|
6
|
|
|
|
|
31
|
|
|
6
|
|
|
|
|
96
|
|
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
23
|
|
|
6
|
|
|
|
|
32
|
|
70
|
6
|
50
|
|
|
|
304
|
if ( $self->minifiers->{$type} ) { |
71
|
6
|
|
|
|
|
207
|
return $self->minifiers->{$type}->($contents); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else { |
74
|
0
|
|
|
|
|
|
$self->minifiers->{'_else'}->($contents); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
6
|
|
|
6
|
|
1065
|
no Moose; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
33
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=pod |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=encoding UTF-8 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 NAME |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Web::AssetLib::MinifierEngine::Standard - basic CSS/Javascript minification engine |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SYNOPSIS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $library = My::AssetLib::Library->new( |
92
|
|
|
|
|
|
|
minifier_engine => [ |
93
|
|
|
|
|
|
|
Web::AssetLib::MinifierEngine::Standard->new() |
94
|
|
|
|
|
|
|
] |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 DESCRIPTION |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Supports types: js, css, stylesheet, javascript. All other types will pass through |
100
|
|
|
|
|
|
|
unchanged. Utilizes either L<CSS::Minifier> and L<JavaScript::Minifier> or |
101
|
|
|
|
|
|
|
L<CSS::Minifier::XS> and L<JavaScript::Minifier::XS> depending on availability. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 USAGE |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
No configuration required. Simply instantiate, and include in your library's |
106
|
|
|
|
|
|
|
list of input engines. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 SEE ALSO |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L<Web::AssetLib::MinifierEngine> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHOR |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Ryan Lang <rlang@cpan.org> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |