line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Text::Minify; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: remove HTML indentation on the fly |
4
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
9548
|
use v5.9.3; |
|
8
|
|
|
|
|
33
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
41
|
use strict; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
181
|
|
8
|
8
|
|
|
8
|
|
37
|
use warnings; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
213
|
|
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
40
|
use parent qw/ Plack::Middleware /; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
45
|
|
11
|
|
|
|
|
|
|
|
12
|
8
|
|
|
8
|
|
655
|
use Plack::Util; |
|
8
|
|
|
|
|
28
|
|
|
8
|
|
|
|
|
304
|
|
13
|
8
|
|
|
8
|
|
56
|
use Plack::Util::Accessor qw/ path type /; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
62
|
|
14
|
8
|
|
|
8
|
|
4577
|
use Ref::Util qw/ is_arrayref is_coderef /; |
|
8
|
|
|
|
|
12753
|
|
|
8
|
|
|
|
|
645
|
|
15
|
8
|
|
|
8
|
|
3449
|
use Text::Minify::XS v0.6.2 (); |
|
8
|
|
|
|
|
4668
|
|
|
8
|
|
|
|
|
4025
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# RECOMMEND PREREQ: Ref::Util::XS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = 'v0.3.3'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub call { |
22
|
19
|
|
|
19
|
1
|
267936
|
my ($self, $env) = @_; |
23
|
|
|
|
|
|
|
|
24
|
19
|
|
|
|
|
115
|
my $res = $self->app->($env); |
25
|
|
|
|
|
|
|
|
26
|
19
|
100
|
|
|
|
4322
|
return $res if $env->{'psgix.no-minify'}; |
27
|
|
|
|
|
|
|
|
28
|
18
|
|
|
|
|
46
|
my $method = $env->{REQUEST_METHOD}; |
29
|
18
|
100
|
|
|
|
96
|
unless ($method =~ /^(GET|POST)$/) { |
30
|
3
|
|
|
|
|
37
|
return $res; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
15
|
100
|
|
|
|
75
|
if (my $match = $self->path) { |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
28
|
my $path = $env->{PATH_INFO}; |
36
|
|
|
|
|
|
|
|
37
|
4
|
100
|
100
|
|
|
34
|
unless ( ( is_coderef($match) && $match->( $path, $env ) ) |
|
|
|
100
|
|
|
|
|
38
|
|
|
|
|
|
|
|| ( $path =~ $match ) ) |
39
|
|
|
|
|
|
|
{ |
40
|
2
|
|
|
|
|
35
|
return $res; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return Plack::Util::response_cb( |
45
|
|
|
|
|
|
|
$res, |
46
|
|
|
|
|
|
|
sub { |
47
|
13
|
|
|
13
|
|
184
|
my ($res) = @_; |
48
|
|
|
|
|
|
|
|
49
|
13
|
50
|
|
|
|
147
|
return unless is_arrayref($res); |
50
|
|
|
|
|
|
|
|
51
|
13
|
50
|
|
|
|
78
|
return if @$res < 3; |
52
|
|
|
|
|
|
|
|
53
|
13
|
100
|
|
|
|
49
|
return if Plack::Util::status_with_no_entity_body( $res->[0] ); |
54
|
|
|
|
|
|
|
|
55
|
11
|
|
|
|
|
138
|
my $type = Plack::Util::header_get( $res->[1], 'content-type' ); |
56
|
11
|
100
|
|
|
|
215
|
if ( my $match = $self->type ) { |
57
|
|
|
|
|
|
|
return |
58
|
4
|
100
|
100
|
|
|
55
|
unless ( ( is_coderef($match) && $match->( $type, $res ) ) |
|
|
|
100
|
|
|
|
|
59
|
|
|
|
|
|
|
|| ( $type =~ $match ) ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
7
|
100
|
|
|
|
78
|
return unless $type =~ m{^text/}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
7
|
|
|
|
|
40
|
my $body = $res->[2]; |
66
|
7
|
100
|
|
|
|
29
|
if ( is_arrayref($body) ) { # no reason to call a function for each line in the body |
67
|
6
|
|
|
|
|
58
|
$res->[2] = [ Text::Minify::XS::minify( join( "", @$body ) ) ]; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
1
|
|
|
|
|
2
|
my $text = ""; |
71
|
1
|
|
|
|
|
7
|
Plack::Util::foreach( $body, sub { $text .= $_[0] } ); |
|
1
|
|
|
|
|
164
|
|
72
|
1
|
|
|
|
|
81
|
$res->[2] = [ Text::Minify::XS::minify($text) ]; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
7
|
50
|
|
|
|
34
|
if (Plack::Util::header_exists( $res->[1], 'content-length' )) { |
76
|
7
|
|
|
|
|
143
|
Plack::Util::header_set( $res->[1], 'content-length', length( $res->[2][0] ) ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
7
|
|
|
|
|
197
|
return; |
80
|
|
|
|
|
|
|
} |
81
|
13
|
|
|
|
|
181
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |