| 1 | package Plack::Client::Backend::psgi_local; | ||||||||||
| 2 | 5 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 5 | $Plack::Client::Backend::psgi_local::VERSION = '0.06'; | |||||||||
| 4 | } | ||||||||||
| 5 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | # ABSTRACT: backend for handling local app requests | ||||||||||
| 8 | |||||||||||
| 9 | 5 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 5 | ▶ | use Plack::Middleware::ContentLength; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 5 | ▶ | use base 'Plack::Client::Backend'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | 4 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 17 | 4 | my $class = shift; | |||||||||
| 18 | 4 | my %params = @_; | |||||||||
| 19 | 4 | my $self = $class->SUPER::new(@_); | |||||||||
| 20 | |||||||||||
| 21 | croak 'apps must be a hashref' | ||||||||||
| 22 | 4 | ▶ | if ref($params{apps}) ne 'HASH'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | |||||||||||
| 24 | 4 | $self->{apps} = $params{apps}; | |||||||||
| 25 | |||||||||||
| 26 | 4 | return $self; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 38 | ▶ | sub _apps { shift->{apps} } | ||||||||
|
Subroutine
_apps: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | 38 | ▶ | sub app_for { | ||||||||
|
Subroutine
app_for: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 33 | 38 | my $self = shift; | |||||||||
| 34 | 38 | my ($for) = @_; | |||||||||
| 35 | 38 | return $self->_apps->{$for}; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | 38 | ▶ | sub app_from_request { | ||||||||
|
Subroutine
app_from_request: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||
| 40 | 38 | my $self = shift; | |||||||||
| 41 | 38 | my ($req) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 38 | my $app_name; | |||||||||
| 44 | 38 | ▶ | if (my $uri = $req->env->{'plack.client.original_uri'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 38 | $app_name = $uri->authority; | |||||||||
| 46 | } | ||||||||||
| 47 | else { | ||||||||||
| 48 | 0 | $app_name = $req->uri->authority; | |||||||||
| 49 | 0 | $app_name =~ s/(.*):.*/$1/; # in case a port was added at some point | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 38 | my $app = $self->app_for($app_name); | |||||||||
| 53 | 38 | ▶ | croak "Unknown app: $app_name" unless $app; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 38 | return Plack::Middleware::ContentLength->wrap($app); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 5 | 1; | |||||||||
| 58 | |||||||||||
| 59 | __END__ | ||||||||||