| 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
| |||||||||||||||||||||||||||||
| 20 | # redirect if waned | ||||||||||||||||||||||||||||
| 21 | 10 | ▶ | if( $self->redirect ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | my $code = ( $env->{REQUEST_METHOD } eq 'HEAD' || | ||||||||||||||||||||||||||||
| 23 | 4 | ▶ | $env->{REQUEST_METHOD } eq 'GET' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$env->{"REQUEST_METHOD"} eq "HEAD" or $env->{"REQUEST_METHOD"} eq "GET"
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"
| |||||||||||||||||||||||||||||
| 24 | ? 301 | ||||||||||||||||||||||||||||
| 25 | : 307; | ||||||||||||||||||||||||||||
| 26 | 4 | my $location = $env->{PATH_INFO}; | |||||||||||||||||||||||||||
| 27 | 4 | ▶ | $location .= "?$env->{QUERY_STRING}" if $env->{QUERY_STRING}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||