| 1 | package Plack::Middleware::Redirect; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use parent 'Plack::Middleware'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = "0.01"; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Plack::Util::Accessor qw/url_patterns/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | my $BODY = { | |||||||||||||||||||||||||||
| 14 | 301 => "Moved Permanently", | ||||||||||||||||||||||||||||
| 15 | 302 => "Found" | ||||||||||||||||||||||||||||
| 16 | }; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub prepare_app { | ||||||||||||||||||||||||||
|
Subroutine
prepare_app: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 20 | 0 | my $url_patterns = $self->url_patterns; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | for (my $i = 0; $i < scalar(@$url_patterns); $i += 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | my ($from, $to) = _fetch_url_pattern($url_patterns, $i); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | my $type = ref $from; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | if ($type ne 'Regexp' && $type ne "") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type ne "Regexp" and $type ne ""
MC/DC0%0/2
$type ne "Regexp" and $type ne ""
$type ne "Regexp"
$type ne ""
Truth table0%0/3
A and B
A= $type ne "Regexp"B= $type ne ""
| |||||||||||||||||||||||||||||
| 27 | 0 | croak "$from is invalid parameter"; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | if ($type ne 'Regexp') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 0 | $url_patterns->[$i] = qr/$from/; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub call { | ||||||||||||||||||||||||||
|
Subroutine
call: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 0 | my ($self, $env) = @_; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | my $url_patterns = $self->url_patterns; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | my $path = $env->{PATH_INFO}; | |||||||||||||||||||||||||||
| 42 | 0 | my $body = ""; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | for ( my $i = 0; $i < scalar(@$url_patterns); $i += 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | my ($from, $to) = _fetch_url_pattern($url_patterns, $i); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | next unless $path =~ m#$from#; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | my $type = ref $to; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($type ne 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | my $to = [$to, 301]; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | my ($to_path, $status_code) = @$to; | |||||||||||||||||||||||||||
| 56 | 0 | $type = ref $to_path; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($type eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | $path = &$to_path($env, $from); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||
| 61 | 0 | $path =~ s#$from#"\"$to_path\""#iee; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 0 | my $query = $env->{QUERY_STRING}; | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($query) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $path .= $path =~ /\?/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | ? '&' . $query | ||||||||||||||||||||||||||||
| 67 | : '?' . $query; | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $body = $BODY->{$status_code} || ""; | ||||||||||||||||||||||||||
|
Condition0%0/2
$BODY->{$status_code} || ''
MC/DC0%0/1
$BODY->{$status_code} || ''
$BODY->{$status_code}
Truth table0%0/2
A
A= $BODY->{$status_code}
| |||||||||||||||||||||||||||||
| 70 | 0 | return [$status_code, ['Location' => $path], [$body] ]; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | return $self->app->($env); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub _fetch_url_pattern { | ||||||||||||||||||||||||||
|
Subroutine
_fetch_url_pattern: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 78 | 0 | my ($url_patterns, $i) = @_; | |||||||||||||||||||||||||||
| 79 | 0 | return ($url_patterns->[$i], $url_patterns->[$i+1]); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | 1; | |||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||