| 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::Rewrite; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | our $VERSION = '2.102'; | |||||||||||||||||||||||||||
| 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( request response rules ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Plack::Request (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Plack::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use overload (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 39 | ▶ | sub call { | ||||||||||||||||||||||||||
|
Subroutine
call: called CC=22 SCAR=31.2
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 39 | my $self = shift; | |||||||||||||||||||||||||||
| 16 | 39 | my ( $env ) = @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 39 | my ( $app, $res, $legacy ); | |||||||||||||||||||||||||||
| 19 | 39 | my ( $rules, $modify_cb ) = ( $self->request, $self->response ); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 39 | ▶ | unless ( $rules or $modify_cb ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$rules or $modify_cb
MC/DC100%2/2
$rules or $modify_cb
$rules
$modify_cb
Truth table100%3/3
A or B
A= $rulesB= $modify_cb
| |||||||||||||||||||||||||||||
| 22 | 19 | $rules = $self->rules; | |||||||||||||||||||||||||||
| 23 | 19 | $legacy = 1; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # call rules with $_ aliased to PATH_INFO | ||||||||||||||||||||||||||||
| 27 | 39 | ▶ | ( $res ) = map { scalar $rules->( $env ) } $env->{'PATH_INFO'} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | if $rules; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 39 | ▶ | if ( $legacy ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 19 | ▶ | if ( 'CODE' eq ref $res ) { ( $modify_cb, $res ) = $res } | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 32 | 4 | ▶ | elsif ( 'ARRAY' eq ref $res ) { undef $res if not @$res } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | elsif ( ref $res ) { undef $res } | |||||||||||||||||||||||||||
| 34 | else { | ||||||||||||||||||||||||||||
| 35 | # upgrade scalar to response if it looks like an HTTP status | ||||||||||||||||||||||||||||
| 36 | 9 | ▶ | $res = ( defined $res and $res =~ /\A[1-5][0-9][0-9]\z/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $res and $res =~ /\A[1-5][0-9][0-9]\z/
MC/DC100%2/2
defined $res and $res =~ /\A[1-5][0-9][0-9]\z/
defined $res
$res =~ /\A[1-5][0-9][0-9]\z/
Truth table100%3/3
A and B
A= defined $resB= $res =~ /\A[1-5][0-9][0-9]\z/
| |||||||||||||||||||||||||||||
| 37 | ? [ $res, [], [] ] | ||||||||||||||||||||||||||||
| 38 | : undef; | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | else { | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ( 'CODE' eq ref $res ) { ( $app, $res ) = $res } | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 43 | 10 | ▶ | elsif ( 'ARRAY' eq ref $res ) { @$res = ( 303, [], [] ) if not @$res } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | elsif ( ref $res ) { die 'Unhandled reference type in request rewrite: ', overload::StrVal( $res ), "\n" } | |||||||||||||||||||||||||||
| 45 | 10 | else { undef $res } | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 39 | ▶ | if ( $res ) { # external redirect, or explicit response | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 18 | push @$res, map { [] } @$res .. 2; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 18 | ▶ | if ( $res->[0] =~ /\A3(?:0[0-35-9]|[1-9][0-9])\z/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 11 | my $dest = Plack::Util::header_get( $res->[1], 'Location' ); | |||||||||||||||||||||||||||
| 53 | 11 | ▶ | if ( not $dest ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 9 | $dest = Plack::Request->new( $env )->uri; | |||||||||||||||||||||||||||
| 55 | 9 | Plack::Util::header_set( $res->[1], Location => $dest ); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 11 | ▶ | unless ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
Plack::Util::content_length($res->[2]) or Plack::Util::header_exists($res->[1], "Content-Length")
MC/DC50%1/2
Plack::Util::content_length($res->[2]) or Plack::Util::header_exists($res->[1], "Content-Length")
Plack::Util::content_length($res->[2])
Plack::Util::header_exists($res->[1], "Content-Length")
Truth table66%2/3
A or B
A= Plack::Util::content_length($res->[2])B= Plack::Util::header_exists($res->[1], "Content-Length")
| |||||||||||||||||||||||||||||
| 59 | Plack::Util::content_length( $res->[2] ) | ||||||||||||||||||||||||||||
| 60 | or Plack::Util::header_exists( $res->[1], 'Content-Length' ) | ||||||||||||||||||||||||||||
| 61 | ) { | ||||||||||||||||||||||||||||
| 62 | 9 | my $href = Plack::Util::encode_html( $dest ); | |||||||||||||||||||||||||||
| 63 | 9 | Plack::Util::header_set( $res->[1], qw( Content-Type text/html ) ); | |||||||||||||||||||||||||||
| 64 | 9 | $res->[2] = [ qq'<!DOCTYPE html><title>Moved</title>This resource has moved to <a href="$href">a new address</a>.' ]; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | else { # internal redirect | ||||||||||||||||||||||||||||
| 69 | 21 | ▶ | $app ||= $self->app; | ||||||||||||||||||||||||||
|
Condition33%1/3
$app ||= $self->app
MC/DC0%0/2
$app ||= $self->app
$app
$self->app
Truth table33%1/3
A ||= B
A= $appB= $self->app
| |||||||||||||||||||||||||||||
| 70 | 21 | $res = $app->( $env ); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 39 | ▶ | return $res if not $modify_cb; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 13 | ▶ | Plack::Util::response_cb( $res, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 75 | 13 | my $response = $_[0]; | |||||||||||||||||||||||||||
| 76 | 13 | my $hdrs = Plack::Util::headers( $response->[1] ); | |||||||||||||||||||||||||||
| 77 | 13 | ▶ | $hdrs->{'status'} = sub { @_ ? $response->[0] = $_[0] : $response->[0] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 13 | my ( $result ) = map $modify_cb->( $env ), $hdrs; | |||||||||||||||||||||||||||
| 79 | 13 | ▶ | return 'CODE' eq ref $result ? $result : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 13 | } ); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 3 | 1; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||