blib/lib/Plack/Middleware/Static/Minifier.pm

filter: Statementstmt 100% 54 / 54 Branchbran 100% 14 / 14 Conditioncond 80.0% 12 / 15 MC/DCmcdc 75.0% 6 / 8 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 95.1% 98 / 103 CC 13 SCAR 18.0
CC
13
Cov
96%
call
11.0
_minify
3.0
BEGIN
1.0
CRAP 6.1
↑ Summary
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
BranchTrueFalseTotal
if ($res and $res->[0] == 200) 8 3 11
Condition100%3/3
$res and $res->[0] == 200
!ll&&!rl&&r
128
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
ABresult
0X0
100
111
20 8 my $h = Plack::Util::headers($res->[1]);
21 8 ▶ if ( !defined $h->get('Content-Encoding')
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $h->get("Content-Encoding") and $h->get("Content-Type") and $h->get("Content-Type") =~ m[/(css|javascript)]) 6 2 8
Condition50%3/6
not defined $h->get("Content-Encoding") and $h->get("Content-Type") and $h->get("Content-Type") =~ m[/(css|javascript)]
!ll&&!rl&&r
026
not defined $h->get("Content-Encoding") and $h->get("Content-Type")
!ll&&!rl&&r
008
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)]
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if ($self->cache) { } 2 4 6
28 2 my $key = md5_hex($env->{PATH_INFO});
29 2 ▶ unless ( my $cache = $self->cache->get($key) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cache = $self->cache->get($key)) { } 1 1 2
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
BranchTrueFalseTotal
if ($res and not $self->pass_through && $res->[0] == 404) 9 2 11
Condition100%6/6
$res and not $self->pass_through && $res->[0] == 404
!ll&&!rl&&r
119
$self->pass_through && $res->[0] == 404
!ll&&!rl&&r
811
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
ABCresult
0XX0
1110
10X1
1101
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
BranchTrueFalseTotal
if ($self->no_minify) { } 1 4 5
56 1 return [$$body_ref];
57 }
58 else {
59 4 ▶ return ($ct =~ m!^css!)
Branch: 1 branch
BranchTrueFalseTotal
$ct =~ /^css/ ? : 3 1 4
60 ? [CSS::Minifier::XS::minify($$body_ref)]
61 : [JavaScript::Minifier::XS::minify($$body_ref)];
62 }
63 }
64  
65 2 1;
66  
67 __END__
↑ Summary