| 1 | 1 | ▶ | 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::App::Hostname; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '1.002'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | BEGIN { require Plack::Component; our @ISA = 'Plack::Component' } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Plack::Util::Accessor qw( custom_matcher missing_header_app default_app ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | sub map_hosts_to { | ||||||||||||||||||||||||||
|
Subroutine
map_hosts_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 12 | 5 | my $app = shift; | |||||||||||||||||||||||||||
| 13 | 5 | @{ $self->{'_app_for_host'} }{ map { lc } @_ } = ( $app ) x @_; | |||||||||||||||||||||||||||
| 14 | 5 | $self->{'_num_wildcards'} += grep { /\A\*\*\./ } @_; | |||||||||||||||||||||||||||
| 15 | 5 | return $self; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | sub unmap_host { | ||||||||||||||||||||||||||
|
Subroutine
unmap_host: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 20 | 2 | delete @{ $self->{'_app_for_host'} }{ map { lc } @_ }; | |||||||||||||||||||||||||||
| 21 | 2 | $self->{'_num_wildcards'} -= grep { /\A\*\*\./ } @_; | |||||||||||||||||||||||||||
| 22 | 2 | return $self; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | sub unmap_app { | ||||||||||||||||||||||||||
|
Subroutine
unmap_app: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 27 | 1 | ▶ | my $map = $self->{'_app_for_host'} ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"_app_for_host"} ||= {}
MC/DC0%0/1
$self->{"_app_for_host"} ||= {}
$self->{"_app_for_host"}
Truth table50%1/2
A
A= $self->{"_app_for_host"}
| |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | while ( my ( $host, $host_app ) = each %$map ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 6 | ▶ | next if not grep { $host_app == $_ } @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 6 | delete $map->{ $host }; | |||||||||||||||||||||||||||
| 31 | 6 | ▶ | --$self->{'_num_wildcards'} if $host =~ /\A\*\*\./; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 1 | return $self; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 21 | ▶ | sub matching { | ||||||||||||||||||||||||||
|
Subroutine
matching: called CC=9 SCAR=22.5
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 21 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | 21 | my $host = lc $_[0]; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 21 | my $map = $self->{'_app_for_host'}; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 21 | ▶ | return $_ for $map->{ $host } || (); | ||||||||||||||||||||||||||
|
Condition66%2/3
$map->{$host} || ()
MC/DC50%1/2
$map->{$host} || ()
$map->{$host}
()
Truth table66%2/3
A || B
A= $map->{$host}B= ()
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 11 | ▶ | if ( $self->{'_num_wildcards'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 4 | my @part = split /\./, $host, 16; | |||||||||||||||||||||||||||
| 46 | 4 | for my $pattern ( map { shift @part; join '.', '**', @part } 1 .. $#part ) { | |||||||||||||||||||||||||||
| 47 | 19 | ▶ | return $_ for $map->{ $pattern } || (); | ||||||||||||||||||||||||||
|
Condition66%2/3
$map->{$pattern} || ()
MC/DC0%0/2
$map->{$pattern} || ()
$map->{$pattern}
()
Truth table66%2/3
A || B
A= $map->{$pattern}B= ()
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 9 | ▶ | return undef unless my $cb = $self->custom_matcher; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | return scalar $cb->() for $host; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 1 | our $sadtrombone = [ | |||||||||||||||||||||||||||
| 57 | 400, | ||||||||||||||||||||||||||||
| 58 | [qw( Content-Type text/html )], | ||||||||||||||||||||||||||||
| 59 | ['<!DOCTYPE html><title>Bad Request</title><center style="font-family: sans-serif"><h1>Bad Request</h1><p>Unknown host or domain'], | ||||||||||||||||||||||||||||
| 60 | ]; | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 24 | ▶ | sub call { | ||||||||||||||||||||||||||
|
Subroutine
call: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 24 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | 24 | my ( $env ) = @_; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 24 | my $host = $env->{'HTTP_HOST'}; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 24 | ▶ | my $app = defined $host | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->matching($host) || $self->default_app
MC/DC100%2/2
$self->matching($host) || $self->default_app
$self->matching($host)
$self->default_app
Truth table100%3/3
A || B
A= $self->matching($host)B= $self->default_app
| |||||||||||||||||||||||||||||
| 69 | ? ( $host =~ s/:$env->{'SERVER_PORT'}\z//, $self->matching( $host ) || $self->default_app ) | ||||||||||||||||||||||||||||
| 70 | : $self->missing_header_app; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 24 | ▶ | return 'CODE' eq ref $app ? &$app : $app || $sadtrombone; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$app or $Plack::App::Hostname::sadtrombone
MC/DC0%0/2
$app or $Plack::App::Hostname::sadtrombone
$app
$Plack::App::Hostname::sadtrombone
Truth table66%2/3
A or B
A= $appB= $Plack::App::Hostname::sadtrombone
| |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | 1; | |||||||||||||||||||||||||||