| 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.3520'; | |||||||||
| 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 | sub new { | ||||||||||
| 19 | 5 | ▶ | my $class = shift; | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 20 | |||||||||||
| 21 | 5 | ▶ | raise core_handler_PSGI => "Plack::Request is needed by the PSGI handler" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | unless Dancer::ModuleLoader->load('Plack::Request'); | ||||||||||
| 23 | |||||||||||
| 24 | 5 | my $self = {}; | |||||||||
| 25 | 5 | bless $self, $class; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | sub start { | ||||||||||
| 29 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
start: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 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
| |||||||||||
| 34 | 1 | my $method = 'apply_'.$setting; | |||||||||
| 35 | 1 | $app = $self->$method($app); | |||||||||
| 36 | } | ||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 1 | return $app; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | sub apply_plack_middlewares_map { | ||||||||||
| 43 | 0 | ▶ | my ($self, $app) = @_; | ||||||||
|
Subroutine
apply_plack_middlewares_map: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 61 | 0 | return $urlmap->to_app; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | sub apply_plack_middlewares { | ||||||||||
| 65 | 2 | ▶ | my ($self, $app) = @_; | ||||||||
|
Subroutine
apply_plack_middlewares: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||
| 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
| |||||||||||
| 70 | unless Dancer::ModuleLoader->load('Plack::Builder'); | ||||||||||
| 71 | |||||||||||
| 72 | 2 | ▶ | ref $middlewares eq "ARRAY" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | sub init_request_headers { | ||||||||||
| 86 | 2 | ▶ | my ($self, $env) = @_; | ||||||||
|
Subroutine
init_request_headers: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 87 | 2 | my $plack = Plack::Request->new($env); | |||||||||
| 88 | 2 | Dancer::SharedData->headers($plack->headers); | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 4 | 1; | |||||||||
| 92 | |||||||||||
| 93 | __END__ | ||||||||||