| 1 | 3 | ▶ | use 5.006; use strict; use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | package Plack::Middleware::Precompressed; | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 3 | our $VERSION = '1.104'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | ▶ | BEGIN { require Plack::Middleware; our @ISA = 'Plack::Middleware' } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 3 | ▶ | use Plack::Util::Accessor qw( match rules env_keys ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 3 | ▶ | use Plack::MIME (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 3 | ▶ | use Plack::Util (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 3 | ▶ | use Array::RefElem (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 7 | ▶ | sub rewrite { | ||||||||||||||||||
|
Subroutine
rewrite: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 15 | 7 | my $self = shift; | |||||||||||||||||||
| 16 | 7 | my ( $env ) = @_; | |||||||||||||||||||
| 17 | 7 | my $rules = $self->rules; | |||||||||||||||||||
| 18 | 7 | ▶ | $rules ? $rules->( defined $env ? $env : () ) : ( $_ .= '.gz' ); | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 14 | ▶ | sub call { | ||||||||||||||||||
|
Subroutine
call: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||
| 22 | 14 | my $self = shift; | |||||||||||||||||||
| 23 | 14 | my ( $env ) = @_; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 14 | my $encoding; | |||||||||||||||||||
| 26 | 14 | my $path = $env->{'PATH_INFO'}; | |||||||||||||||||||
| 27 | 14 | ▶ | my $have_match = $self->match ? $path =~ $self->match : 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | # the `deflate` encoding is unreliably messy so we won't support it | ||||||||||||||||||||
| 30 | # c.f. http://zoompf.com/2012/02/lose-the-wait-http-compression | ||||||||||||||||||||
| 31 | 14 | ▶ | if ( $have_match ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | ( $encoding ) = | ||||||||||||||||||||
| 33 | 8 | ▶ | grep { $_ eq 'gzip' or $_ eq 'x-gzip' } | ||||||||||||||||||
|
Condition33%1/3
$_ eq 'gzip' || $_ eq 'x-gzip'
MC/DC0%0/2
$_ eq 'gzip' || $_ eq 'x-gzip'
$_ eq 'gzip'
$_ eq 'x-gzip'
Truth table33%1/3
A || B
A= $_ eq 'gzip'B= $_ eq 'x-gzip'
| |||||||||||||||||||||
| 34 | 8 | map { s!\s+!!g; split /,/, lc } | |||||||||||||||||||
| 35 | 10 | grep { defined } | |||||||||||||||||||
| 36 | 10 | $env->{'HTTP_ACCEPT_ENCODING'}; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 14 | my $res = do { | |||||||||||||||||||
| 40 | 14 | ▶ | my $keys = $self->env_keys || []; | ||||||||||||||||||
|
Condition100%2/2
$self->env_keys || []
MC/DC100%1/1
$self->env_keys || []
$self->env_keys
Truth table100%2/2
A
A= $self->env_keys
| |||||||||||||||||||||
| 41 | 14 | ▶ | local @$env{ 'PATH_INFO', @$keys } = ( $path, @$env{ @$keys } ) if $encoding; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 14 | ▶ | if ( $encoding ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 8 | my %pass_env; | |||||||||||||||||||
| 44 | 8 | Array::RefElem::hv_store %pass_env, $_, $env->{ $_ } for @$keys; | |||||||||||||||||||
| 45 | 8 | $self->rewrite( \%pass_env ) for $env->{'PATH_INFO'}; | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | 14 | ▶ | delete local $env->{'HTTP_ACCEPT_ENCODING'} if $encoding; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 14 | $self->app->( $env ); | |||||||||||||||||||
| 49 | }; | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 14 | ▶ | return $res unless $have_match; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 10 | my $is_fail; | |||||||||||||||||||
| 54 | 10 | ▶ | my $final_res = Plack::Util::response_cb( $res, sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 55 | 10 | my $res = shift; | |||||||||||||||||||
| 56 | 10 | $is_fail = $res->[0] != 200; | |||||||||||||||||||
| 57 | 10 | ▶ | return if $is_fail; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 6 | push @{ $res->[1] }, 'Vary', 'Accept-Encoding'; | |||||||||||||||||||
| 59 | 6 | ▶ | if ( $encoding ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 5 | my $mime = Plack::MIME->mime_type( $path ); | |||||||||||||||||||
| 61 | 5 | ▶ | Plack::Util::header_set( $res->[1], 'Content-Type', $mime ) if $mime; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 5 | push @{ $res->[1] }, 'Content-Encoding', $encoding; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | 6 | return; | |||||||||||||||||||
| 65 | 10 | } ); | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 10 | ▶ | return $is_fail ? $self->app->( $env ) : $final_res; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 3 | 1; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||