blib/lib/Plack/App/URLMap.pm

filter: Statementstmt 93.6% 59 / 63 Branchbran 81.2% 13 / 16 Conditioncond 77.7% 14 / 18 MC/DCmcdc 54.5% 6 / 11 Subroutinesub 90.9% 10 / 11 Podpod 100% 4 / 4 totaltotal 86.1% 106 / 123 CC 16 SCAR 17.7
CC
16
Cov
89%
call
11.2
map
3.0
prepare_app
3.0
CRAP 5.9
« blib/lib/Plack/Middleware/LogDispatch.pm ↑ Summary blib/lib/Plack/Middleware/StackTrace.pm »
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
BranchTrueFalseTotal
$ENV{'PLACK_URLMAP_DEBUG'} ? : 0 36 36
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
BranchTrueFalseTotal
if ($location =~ m[^https?://(.*?)(/.*)]) 4 20 24
17 4 $host = $1;
18 4 $location = $2;
19 }
20  
21 24 ▶ if ($location !~ m!^/!) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($location =~ m[^/]) 0 24 24
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]
l!l&&r!l&&!r
27260
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]
ABresult
1X1
011
000
35 23 ▶ map { [ ($_->[0] ? length $_->[0] : 0), length($_->[1]), @$_ ] } @{$self->{_mapping}},
Branch: 1 branch
BranchTrueFalseTotal
$_->[0] ? : 15 49 64
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
BranchTrueFalseTotal
if ($http_host and my $port = $env->{"SERVER_PORT"}) 33 0 33
Condition33%1/3
$http_host and my $port = $env->{"SERVER_PORT"}
!ll&&!rl&&r
0033
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless not defined $host or $http_host eq $host or $server_name eq $host 16 54 70
Condition83%5/6
not defined $host or $http_host eq $host or $server_name eq $host
l!l&&r!l&&!r
54016
not defined $host or $http_host eq $host
l!l&&r!l&&!r
48616
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
ABCresult
1XX1
01X1
0011
0000
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
BranchTrueFalseTotal
unless $location eq "" or $path =~ s/$location_re// 18 36 54
Condition100%3/3
$location eq "" or $path =~ s/$location_re//
l!l&&r!l&&!r
171918
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//
ABresult
1X1
011
000
60 36 ▶ next unless $path eq '' or $path =~ m!^/!;
Branch: 1 branch
BranchTrueFalseTotal
unless $path eq "" or $path =~ m[^/] 3 33 36
Condition100%3/3
$path eq "" or $path =~ m[^/]
l!l&&r!l&&!r
11223
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[^/]
ABresult
1X1
011
000
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__
« blib/lib/Plack/Middleware/LogDispatch.pm ↑ Summary blib/lib/Plack/Middleware/StackTrace.pm »