line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Static::Minifier; |
2
|
2
|
|
|
2
|
|
62416
|
use strict; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
74
|
|
3
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
72
|
|
4
|
2
|
|
|
2
|
|
493
|
use Plack::Util; |
|
2
|
|
|
|
|
10621
|
|
|
2
|
|
|
|
|
62
|
|
5
|
2
|
|
|
2
|
|
362
|
use Plack::Util::Accessor qw/cache no_minify/; |
|
2
|
|
|
|
|
218
|
|
|
2
|
|
|
|
|
23
|
|
6
|
2
|
|
|
2
|
|
163
|
use parent 'Plack::Middleware::Static'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
7
|
2
|
|
|
2
|
|
17298
|
use CSS::Minifier::XS qw//; |
|
2
|
|
|
|
|
2163
|
|
|
2
|
|
|
|
|
47
|
|
8
|
2
|
|
|
2
|
|
815
|
use JavaScript::Minifier::XS qw//; |
|
2
|
|
|
|
|
1749
|
|
|
2
|
|
|
|
|
62
|
|
9
|
2
|
|
|
2
|
|
12
|
use Digest::MD5 qw/md5_hex/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
907
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub call { |
14
|
11
|
|
|
11
|
1
|
59225
|
my $self = shift; |
15
|
11
|
|
|
|
|
17
|
my $env = shift; |
16
|
|
|
|
|
|
|
|
17
|
11
|
|
|
|
|
34
|
my $res = $self->_handle_static($env); |
18
|
|
|
|
|
|
|
|
19
|
11
|
100
|
100
|
|
|
2189
|
if ($res && $res->[0] == 200) { |
20
|
8
|
|
|
|
|
25
|
my $h = Plack::Util::headers($res->[1]); |
21
|
8
|
100
|
33
|
|
|
225
|
if ( !defined $h->get('Content-Encoding') |
|
|
|
66
|
|
|
|
|
22
|
|
|
|
|
|
|
&& $h->get('Content-Type') |
23
|
|
|
|
|
|
|
&& $h->get('Content-Type') =~ m!/(css|javascript)! ) { |
24
|
6
|
|
|
|
|
393
|
my $ct = $1; |
25
|
6
|
|
|
6
|
|
6
|
my $body; Plack::Util::foreach($res->[2], sub { $body .= $_[0] }); |
|
6
|
|
|
|
|
34
|
|
|
6
|
|
|
|
|
1579
|
|
26
|
6
|
|
|
|
|
235
|
my $minified_body; |
27
|
6
|
100
|
|
|
|
17
|
if ($self->cache) { |
28
|
2
|
|
|
|
|
28
|
my $key = md5_hex($env->{PATH_INFO}); |
29
|
2
|
100
|
|
|
|
6
|
unless ( my $cache = $self->cache->get($key) ) { |
30
|
1
|
|
|
|
|
10
|
$minified_body = $self->_minify($ct, \$body); |
31
|
1
|
|
|
|
|
7
|
$self->cache->set($key, @{$minified_body}[0]); |
|
1
|
|
|
|
|
8
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
1
|
|
|
|
|
7
|
$minified_body = [$cache]; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
4
|
|
|
|
|
25
|
$minified_body = $self->_minify($ct, \$body); |
39
|
|
|
|
|
|
|
} |
40
|
6
|
|
|
|
|
33
|
$res->[2] = $minified_body; |
41
|
6
|
|
|
|
|
47
|
$h->set('Content-Length', length $res->[2][0]); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
11
|
100
|
100
|
|
|
459
|
if ($res && not ($self->pass_through and $res->[0] == 404)) { |
|
|
|
100
|
|
|
|
|
46
|
9
|
|
|
|
|
104
|
return $res; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
20
|
return $self->app->($env); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _minify { |
53
|
5
|
|
|
5
|
|
10
|
my ($self, $ct, $body_ref) = @_; |
54
|
|
|
|
|
|
|
|
55
|
5
|
100
|
|
|
|
10
|
if ($self->no_minify) { |
56
|
1
|
|
|
|
|
5
|
return [$$body_ref]; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
4
|
100
|
|
|
|
2011
|
return ($ct =~ m!^css!) |
60
|
|
|
|
|
|
|
? [CSS::Minifier::XS::minify($$body_ref)] |
61
|
|
|
|
|
|
|
: [JavaScript::Minifier::XS::minify($$body_ref)]; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |