| 1 | package Plack::App::URLMap; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 36 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 36 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 36 | ▶ | use parent qw(Plack::Component); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 36 | ▶ | use constant DEBUG => $ENV{PLACK_URLMAP_DEBUG} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 36 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 0 | ▶ | sub mount { shift->map(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mount: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 24 | ▶ | sub map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 24 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 24 | my($location, $app) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 24 | my $host; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 24 | ▶ | if ($location =~ m!^https?://(.*?)(/.*)!) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | $host = $1; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | $location = $2; | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 24 | ▶ | if ($location !~ m!^/!) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | Carp::croak("Paths need to start with /"); | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 24 | $location =~ s!/$!!; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 24 | push @{$self->{_mapping}}, [ $host, $location, qr/^\Q$location\E/, $app ]; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 23 | ▶ | sub prepare_app { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_app: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 23 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 31 | # sort by path length | ||||||||||||||||||||||||||||||||||||||||||
| 32 | $self->{_sorted_mapping} = [ | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 64 | map { [ @{$_}[2..5] ] } | |||||||||||||||||||||||||||||||||||||||||
| 34 | 53 | ▶ | sort { $b->[0] <=> $a->[0] || $b->[1] <=> $a->[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Plack::App::URLMap::b->[0] <=> $Plack::App::URLMap::a->[0] || $Plack::App::URLMap::b->[1] <=> $Plack::App::URLMap::a->[1]
MC/DC0%0/2
$Plack::App::URLMap::b->[0] <=> $Plack::App::URLMap::a->[0] || $Plack::App::URLMap::b->[1] <=> $Plack::App::URLMap::a->[1]
$Plack::App::URLMap::b->[0] <=> $Plack::App::URLMap::a->[0]
$Plack::App::URLMap::b->[1] <=> $Plack::App::URLMap::a->[1]
Truth table66%2/3
A || B
A= $Plack::App::URLMap::b->[0] <=> $Plack::App::URLMap::a->[0]B= $Plack::App::URLMap::b->[1] <=> $Plack::App::URLMap::a->[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 23 | ▶ | map { [ ($_->[0] ? length $_->[0] : 0), length($_->[1]), @$_ ] } @{$self->{_mapping}}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 33 | ▶ | sub call { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=11 SCAR=24.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 33 | my ($self, $env) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 33 | my $path_info = $env->{PATH_INFO}; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 33 | my $script_name = $env->{SCRIPT_NAME}; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 33 | my($http_host, $server_name) = @{$env}{qw( HTTP_HOST SERVER_NAME )}; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 33 | ▶ | if ($http_host and my $port = $env->{SERVER_PORT}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$http_host and my $port = $env->{"SERVER_PORT"}
MC/DC0%0/2
$http_host and my $port = $env->{"SERVER_PORT"}
$http_host
my $port = $env->{"SERVER_PORT"}
Truth table33%1/3
A and B
A= $http_hostB= my $port = $env->{"SERVER_PORT"}
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 33 | $http_host =~ s/:\Q$port\E$//; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 33 | for my $map (@{ $self->{_sorted_mapping} }) { | |||||||||||||||||||||||||||||||||||||||||
| 52 | 70 | my($host, $location, $location_re, $app) = @$map; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 70 | my $path = $path_info; # copy | |||||||||||||||||||||||||||||||||||||||||
| 54 | 36 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 70 | DEBUG && warn "Matching request (Host=$http_host Path=$path) and the map (Host=$host Path=$location)\n"; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 70 | ▶ | next unless not defined $host or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not defined $host or $http_host eq $host or $server_name eq $host
not defined $host or $http_host eq $host
MC/DC66%2/3
not defined $host or $http_host eq $host or $server_name eq $host
not defined $host
$http_host eq $host
$server_name eq $host
Truth table75%3/4
not(A) or B or C
A= not defined $hostB= $http_host eq $hostC= $server_name eq $host
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | $http_host eq $host or | ||||||||||||||||||||||||||||||||||||||||||
| 58 | $server_name eq $host; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 54 | ▶ | next unless $location eq '' or $path =~ s!$location_re!!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$location eq "" or $path =~ s/$location_re//
MC/DC100%2/2
$location eq "" or $path =~ s/$location_re//
$location eq ""
$path =~ s/$location_re//
Truth table100%3/3
A or B
A= $location eq ""B= $path =~ s/$location_re//
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 36 | ▶ | next unless $path eq '' or $path =~ m!^/!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$path eq "" or $path =~ m[^/]
MC/DC100%2/2
$path eq "" or $path =~ m[^/]
$path eq ""
$path =~ m[^/]
Truth table100%3/3
A or B
A= $path eq ""B= $path =~ m[^/]
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 33 | DEBUG && warn "-> Matched!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 33 | my $orig_path_info = $env->{PATH_INFO}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 33 | my $orig_script_name = $env->{SCRIPT_NAME}; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 33 | $env->{PATH_INFO} = $path; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 33 | $env->{SCRIPT_NAME} = $script_name . $location; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 33 | ▶ | return $self->response_cb($app->($env), sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 33 | $env->{PATH_INFO} = $orig_path_info; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 33 | $env->{SCRIPT_NAME} = $orig_script_name; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 33 | }); | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | DEBUG && warn "All matching failed.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | return [404, [ 'Content-Type' => 'text/plain' ], [ "Not Found" ]]; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 36 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||||||||||||||||||||||||