blib/lib/Dancer/Handler/PSGI.pm

filter: Statementstmt 84.2% 59 / 70 Branchbran 35.7% 5 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.7% 15 / 16 Podpod 0.0% 0 / 5 totaltotal 75.2% 79 / 105 CC 12 SCAR 23.9
CC
12
Cov
76%
apply_plack_middlewares_map
42.0
apply_plack_middlewares
4.1
start
3.0
CRAP 10.9
« lib/Dancer/FileUtils.pm ↑ Summary lib/Dancer.pm »
1 package Dancer::Handler::PSGI;
2 4 our $AUTHORITY = 'cpan:SUKRIA';
3 #ABSTRACT: a PSGI handler for Dancer applications
4 4 $Dancer::Handler::PSGI::VERSION = '1.3522';
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use base 'Dancer::Handler';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use Dancer::Deprecation;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Dancer::GetOpt;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Dancer::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Dancer::ModuleLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Dancer::SharedData;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Dancer::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Dancer::Exception qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
19 5 my $class = shift;
20  
21 5 ▶ raise core_handler_PSGI => "Plack::Request is needed by the PSGI handler"
Branch: 1 branch
BranchTrueFalseTotal
unless "Dancer::ModuleLoader"->load("Plack::Request") 0 5 5
22 unless Dancer::ModuleLoader->load('Plack::Request');
23  
24 5 my $self = {};
25 5 bless $self, $class;
26 }
27  
28 1 ▶sub start {
Subroutine start: called CC=3 SCAR=11.0
Pod undocumented
29 1 my $self = shift;
30 1 my $app = $self->psgi_app();
31  
32 1 foreach my $setting (qw/plack_middlewares plack_middlewares_map/) {
33 2 ▶ if (Dancer::Config::setting($setting)) {
Branch: 1 branch
BranchTrueFalseTotal
if (Dancer::Config::setting($setting)) 1 1 2
34 1 my $method = 'apply_'.$setting;
35 1 $app = $self->$method($app);
36 }
37 }
38  
39 1 return $app;
40 }
41  
42 0 ▶sub apply_plack_middlewares_map {
Subroutine apply_plack_middlewares_map: not called CC=6 SCAR=37.4
Pod undocumented
43 0 my ($self, $app) = @_;
44  
45 0 my $mw_map = Dancer::Config::setting('plack_middlewares_map');
46  
47 0 foreach my $req (qw(Plack::App::URLMap Plack::Builder)) {
48 0 ▶ raise core_handler_PSGI => "$req is needed to use apply_plack_middlewares_map"
Branch: 1 branch
BranchTrueFalseTotal
unless "Dancer::ModuleLoader"->load($req) 0 0 0
49 unless Dancer::ModuleLoader->load($req);
50 }
51  
52 0 my $urlmap = Plack::App::URLMap->new;
53  
54 0 ▶ while ( my ( $path, $mw ) = each %$mw_map ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$mw_map) 0 0 0
55 0 my $builder = Plack::Builder->new();
56 0 $builder->add_middleware(@$_) for @$mw;
57 0 $urlmap->map( $path => $builder->to_app($app) );
58 }
59  
60 0 ▶ $urlmap->map('/' => $app) unless $mw_map->{'/'};
Branch: 1 branch
BranchTrueFalseTotal
unless $mw_map->{"/"} 0 0 0
61 0 return $urlmap->to_app;
62 }
63  
64 2 ▶sub apply_plack_middlewares {
Subroutine apply_plack_middlewares: called CC=4 SCAR=14.0
Pod undocumented
65 2 my ($self, $app) = @_;
66  
67 2 my $middlewares = Dancer::Config::setting('plack_middlewares');
68  
69 2 ▶ raise core_handler_PSGI => "Plack::Builder is needed for middlewares support"
Branch: 1 branch
BranchTrueFalseTotal
unless "Dancer::ModuleLoader"->load("Plack::Builder") 0 2 2
70 unless Dancer::ModuleLoader->load('Plack::Builder');
71  
72 2 ▶ ref $middlewares eq "ARRAY"
Branch: 1 branch
BranchTrueFalseTotal
ref $middlewares eq "ARRAY" or &raise("core_handler_PSGI", "'plack_middlewares' setting must be an ArrayRef") 2 0 2
73 or raise core_handler_PSGI => "'plack_middlewares' setting must be an ArrayRef";
74  
75 2 my $builder = Plack::Builder->new();
76  
77 2 for my $mw (@$middlewares) {
78 2 Dancer::Logger::core "add middleware " . $mw->[0];
79 2 $builder->add_middleware(@$mw)
80 }
81  
82 2 return $builder->to_app($app);
83 }
84  
85 2 ▶sub init_request_headers {
Subroutine init_request_headers: called CC=1 SCAR=0.0
Pod undocumented
86 2 my ($self, $env) = @_;
87 2 my $plack = Plack::Request->new($env);
88 2 Dancer::SharedData->headers($plack->headers);
89 }
90  
91 4 1;
92  
93 __END__
« lib/Dancer/FileUtils.pm ↑ Summary lib/Dancer.pm »