| 1 | package Plack::Middleware::Static::Minifier; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Plack::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Plack::Util::Accessor qw/cache no_minify/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use parent 'Plack::Middleware::Static'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use CSS::Minifier::XS qw//; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use JavaScript::Minifier::XS qw//; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Digest::MD5 qw/md5_hex/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our $VERSION = '0.09'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | sub call { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | my $env = shift; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 11 | my $res = $self->_handle_static($env); | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | ▶ | if ($res && $res->[0] == 200) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$res and $res->[0] == 200
MC/DC100%2/2
$res and $res->[0] == 200
$res
$res->[0] == 200
Truth table100%3/3
A and B
A= $resB= $res->[0] == 200
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | my $h = Plack::Util::headers($res->[1]); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 8 | ▶ | if ( !defined $h->get('Content-Encoding') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not defined $h->get("Content-Encoding") and $h->get("Content-Type") and $h->get("Content-Type") =~ m[/(css|javascript)]
not defined $h->get("Content-Encoding") and $h->get("Content-Type")
MC/DC33%1/3
not defined $h->get("Content-Encoding") and $h->get("Content-Type") and $h->get("Content-Type") =~ m[/(css|javascript)]
not defined $h->get("Content-Encoding")
$h->get("Content-Type")
$h->get("Content-Type") =~ m[/(css|javascript)]
Truth table50%2/4
not(A) and B and C
A= not defined $h->get("Content-Encoding")B= $h->get("Content-Type")C= $h->get("Content-Type") =~ m[/(css|javascript)]
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | && $h->get('Content-Type') | ||||||||||||||||||||||||||||||||||||||||||
| 23 | && $h->get('Content-Type') =~ m!/(css|javascript)! ) { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | my $ct = $1; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | ▶ | my $body; Plack::Util::foreach($res->[2], sub { $body .= $_[0] }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | my $minified_body; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | if ($self->cache) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | my $key = md5_hex($env->{PATH_INFO}); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | unless ( my $cache = $self->cache->get($key) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | $minified_body = $self->_minify($ct, \$body); | |||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | $self->cache->set($key, @{$minified_body}[0]); | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | $minified_body = [$cache]; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | $minified_body = $self->_minify($ct, \$body); | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | $res->[2] = $minified_body; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | $h->set('Content-Length', length $res->[2][0]); | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 11 | ▶ | if ($res && not ($self->pass_through and $res->[0] == 404)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$res and not $self->pass_through && $res->[0] == 404
$self->pass_through && $res->[0] == 404
MC/DC100%3/3
$res and not $self->pass_through && $res->[0] == 404
$res
$self->pass_through
$res->[0] == 404
Truth table100%4/4
A and not(B && C)
A= $resB= $self->pass_throughC= $res->[0] == 404
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 9 | return $res; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | return $self->app->($env); | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | ▶ | sub _minify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_minify: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 5 | my ($self, $ct, $body_ref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 5 | ▶ | if ($self->no_minify) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | return [$$body_ref]; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | ▶ | return ($ct =~ m!^css!) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | ? [CSS::Minifier::XS::minify($$body_ref)] | ||||||||||||||||||||||||||||||||||||||||||
| 61 | : [JavaScript::Minifier::XS::minify($$body_ref)]; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||||||||||||||||||||||||