line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Static::Minifier; |
2
|
2
|
|
|
2
|
|
33482
|
use strict; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
90
|
|
3
|
2
|
|
|
2
|
|
58
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
77
|
|
4
|
2
|
|
|
2
|
|
2397
|
use Plack::Util; |
|
2
|
|
|
|
|
16591
|
|
|
2
|
|
|
|
|
85
|
|
5
|
2
|
|
|
2
|
|
985
|
use Plack::Util::Accessor qw/cache/; |
|
2
|
|
|
|
|
270
|
|
|
2
|
|
|
|
|
29
|
|
6
|
2
|
|
|
2
|
|
106
|
use parent 'Plack::Middleware::Static'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
23
|
|
7
|
2
|
|
|
2
|
|
45899
|
use CSS::Minifier::XS qw//; |
|
2
|
|
|
|
|
3395
|
|
|
2
|
|
|
|
|
71
|
|
8
|
2
|
|
|
2
|
|
2006
|
use JavaScript::Minifier::XS qw//; |
|
2
|
|
|
|
|
2075
|
|
|
2
|
|
|
|
|
208
|
|
9
|
2
|
|
|
2
|
|
15
|
use Digest::MD5 qw/md5_hex/; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1403
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub call { |
14
|
10
|
|
|
10
|
1
|
74276
|
my $self = shift; |
15
|
10
|
|
|
|
|
14
|
my $env = shift; |
16
|
|
|
|
|
|
|
|
17
|
10
|
|
|
|
|
40
|
my $res = $self->_handle_static($env); |
18
|
|
|
|
|
|
|
|
19
|
10
|
100
|
100
|
|
|
2223
|
if ($res && $res->[0] == 200) { |
20
|
7
|
|
|
|
|
27
|
my $h = Plack::Util::headers($res->[1]); |
21
|
7
|
100
|
33
|
|
|
230
|
if ( !defined $h->get('Content-Encoding') |
|
|
|
66
|
|
|
|
|
22
|
|
|
|
|
|
|
&& $h->get('Content-Type') |
23
|
|
|
|
|
|
|
&& $h->get('Content-Type') =~ m!/(css|javascript)! ) { |
24
|
5
|
|
|
|
|
662
|
my $ct = $1; |
25
|
5
|
|
|
5
|
|
6
|
my $body; Plack::Util::foreach($res->[2], sub { $body .= $_[0] }); |
|
5
|
|
|
|
|
25
|
|
|
5
|
|
|
|
|
586
|
|
26
|
5
|
|
|
|
|
259
|
my $minified_body; |
27
|
5
|
100
|
|
|
|
17
|
if ($self->cache) { |
28
|
2
|
|
|
|
|
34
|
my $key = md5_hex($env->{PATH_INFO}); |
29
|
2
|
100
|
|
|
|
9
|
unless ( my $cache = $self->cache->get($key) ) { |
30
|
1
|
|
|
|
|
12
|
$minified_body = _minify($ct, \$body); |
31
|
1
|
|
|
|
|
4
|
$self->cache->set($key, @{$minified_body}[0]); |
|
1
|
|
|
|
|
9
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
1
|
|
|
|
|
12
|
$minified_body = [$cache]; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
3
|
|
|
|
|
24
|
$minified_body = _minify($ct, \$body); |
39
|
|
|
|
|
|
|
} |
40
|
5
|
|
|
|
|
19
|
$res->[2] = $minified_body; |
41
|
5
|
|
|
|
|
55
|
$h->set('Content-Length', length $res->[2][0]); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
10
|
100
|
100
|
|
|
601
|
if ($res && not ($self->pass_through and $res->[0] == 404)) { |
|
|
|
100
|
|
|
|
|
46
|
8
|
|
|
|
|
108
|
return $res; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
20
|
return $self->app->($env); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _minify { |
53
|
4
|
|
|
4
|
|
7
|
my ($ct, $body_ref) = @_; |
54
|
4
|
100
|
|
|
|
135
|
return ($ct =~ m!^css!) |
55
|
|
|
|
|
|
|
? [CSS::Minifier::XS::minify($$body_ref)] |
56
|
|
|
|
|
|
|
: [JavaScript::Minifier::XS::minify($$body_ref)]; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |