| 1 | package Plack::App::Vhost; | ||||||||||
| 2 | 2 | ▶ | use 5.008005; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | our $VERSION = "0.01"; | |||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use parent qw/Plack::Component/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use Plack::Util::Accessor qw/vhosts fallback/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use List::Util 1.28 qw/pairs/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | sub prepare_app { | ||||||||
|
Subroutine
prepare_app: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 13 | 2 | my $self = shift; | |||||||||
| 14 | 2 | ▶ | $self->vhosts([]) unless defined $self->vhosts; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 2 | ▶ | $self->fallback(sub { $self->res_404 }) unless defined $self->fallback; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | 4 | ▶ | sub call { | ||||||||
|
Subroutine
call: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 19 | 4 | my ($self, $env) = @_; | |||||||||
| 20 | |||||||||||
| 21 | 4 | for my $vhost (pairs @{ $self->vhosts }) { | |||||||||
| 22 | 5 | my ($rx, $app) = @$vhost; | |||||||||
| 23 | 5 | ▶ | return $app->($env) if $env->{HTTP_HOST} =~ $rx; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 2 | return $self->fallback->($env); | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 1 | ▶ | sub res_404 { | ||||||||
|
Subroutine
res_404: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 30 | 1 | my $self = shift; | |||||||||
| 31 | 1 | return [404, ['Content-Type' => 'text/plain', 'Content-Length' => 9], ['not found']]; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 2 | 1; | |||||||||
| 35 | __END__ | ||||||||||