blib/lib/Plack/App/Vhost.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 66.6% 2 / 3 totaltotal 98.0% 49 / 50 CC 5 SCAR 6.2
CC
5
Cov
100%
prepare_app
3.0
call
3.0
BEGIN
1.0
CRAP 1.9
↑ Summary
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
BranchTrueFalseTotal
unless defined $self->vhosts 1 1 2
15 2 ▶ $self->fallback(sub { $self->res_404 }) unless defined $self->fallback;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->fallback 1 1 2
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
BranchTrueFalseTotal
if $env->{"HTTP_HOST"} =~ /$rx/ 2 3 5
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__
↑ Summary