blib/lib/Plack/Middleware/TrailingSlashKiller.pm

filter: Statementstmt 100% 23 / 23 Branchbran 87.5% 7 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 97.6% 41 / 42 CC 6 SCAR 13.9
CC
6
Cov
97%
call
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
↑ Summary
1 package Plack::Middleware::TrailingSlashKiller;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use parent qw(Plack::Middleware);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Plack::Util::Accessor qw( redirect );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '0.01';
10 1 our %STATUSES = (
11 301 => 'Moved Permanently',
12 307 => 'Temporary Redirect',
13 );
14  
15 17 ▶sub call {
Subroutine call: called CC=6 SCAR=17.9
Pod documented
16 17 my( $self, $env ) = @_;
17  
18 # check for/replace trailing slash
19 17 ▶ if( $env->{PATH_INFO} =~ s{^(.+)/$}{$1} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($env->{"PATH_INFO"} =~ s[^(.+)/$][$1]) 10 7 17
20 # redirect if waned
21 10 ▶ if( $self->redirect ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->redirect) 4 6 10
22 my $code = ( $env->{REQUEST_METHOD } eq 'HEAD' ||
23 4 ▶ $env->{REQUEST_METHOD } eq 'GET' )
Branch: 1 branch
BranchTrueFalseTotal
$env->{'REQUEST_METHOD'} eq 'HEAD' || $env->{'REQUEST_METHOD'} eq 'GET' ? : 2 2 4
Condition100%3/3
$env->{"REQUEST_METHOD"} eq "HEAD" or $env->{"REQUEST_METHOD"} eq "GET"
l!l&&r!l&&!r
112
MC/DC100%2/2
$env->{"REQUEST_METHOD"} eq "HEAD" or $env->{"REQUEST_METHOD"} eq "GET"
$env->{"REQUEST_METHOD"} eq "HEAD" $env->{"REQUEST_METHOD"} eq "GET"
Truth table100%3/3
A or B
A= $env->{"REQUEST_METHOD"} eq "HEAD"B= $env->{"REQUEST_METHOD"} eq "GET"
ABresult
1X1
011
000
24 ? 301
25 : 307;
26 4 my $location = $env->{PATH_INFO};
27 4 ▶ $location .= "?$env->{QUERY_STRING}" if $env->{QUERY_STRING};
Branch: 1 branch
BranchTrueFalseTotal
if $env->{"QUERY_STRING"} 4 0 4
28  
29 4 return [ $code, [ 'Location' => $location ], [ $STATUSES{$code} ] ];
30 }
31 }
32  
33 # return the app's content (with possibly updated PATH_INFO)
34 13 return $self->app->($env);
35 }
36  
37 1 1;
38 __END__
↑ Summary