| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Plack::Client::Backend::psgi_local; | 
| 2 |  |  |  |  |  |  | BEGIN { | 
| 3 | 4 |  |  | 4 |  | 5834 | $Plack::Client::Backend::psgi_local::VERSION = '0.06'; | 
| 4 |  |  |  |  |  |  | } | 
| 5 | 4 |  |  | 4 |  | 41 | use strict; | 
|  | 4 |  |  |  |  | 13 |  | 
|  | 4 |  |  |  |  | 149 |  | 
| 6 | 4 |  |  | 4 |  | 25 | use warnings; | 
|  | 4 |  |  |  |  | 13 |  | 
|  | 4 |  |  |  |  | 145 |  | 
| 7 |  |  |  |  |  |  | # ABSTRACT: backend for handling local app requests | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 4 |  |  | 4 |  | 28 | use Carp; | 
|  | 4 |  |  |  |  | 10 |  | 
|  | 4 |  |  |  |  | 714 |  | 
| 10 | 4 |  |  | 4 |  | 4052 | use Plack::Middleware::ContentLength; | 
|  | 4 |  |  |  |  | 6661 |  | 
|  | 4 |  |  |  |  | 253 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 4 |  |  | 4 |  | 32 | use base 'Plack::Client::Backend'; | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 2133 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub new { | 
| 17 | 4 |  |  | 4 | 1 | 10 | my $class = shift; | 
| 18 | 4 |  |  |  |  | 15 | my %params = @_; | 
| 19 | 4 |  |  |  |  | 181 | my $self = $class->SUPER::new(@_); | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 4 | 50 |  |  |  | 57 | croak 'apps must be a hashref' | 
| 22 |  |  |  |  |  |  | if ref($params{apps}) ne 'HASH'; | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 4 |  |  |  |  | 316 | $self->{apps} = $params{apps}; | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 4 |  |  |  |  | 41 | return $self; | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 38 |  |  | 38 |  | 195 | sub _apps { shift->{apps} } | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | sub app_for { | 
| 33 | 38 |  |  | 38 | 1 | 77 | my $self = shift; | 
| 34 | 38 |  |  |  |  | 543 | my ($for) = @_; | 
| 35 | 38 |  |  |  |  | 141 | return $self->_apps->{$for}; | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub app_from_request { | 
| 40 | 38 |  |  | 38 | 1 | 86 | my $self = shift; | 
| 41 | 38 |  |  |  |  | 79 | my ($req) = @_; | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 38 |  |  |  |  | 61 | my $app_name; | 
| 44 | 38 | 50 |  |  |  | 215 | if (my $uri = $req->env->{'plack.client.original_uri'}) { | 
| 45 | 38 |  |  |  |  | 549 | $app_name = $uri->authority; | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  | else { | 
| 48 | 0 |  |  |  |  | 0 | $app_name = $req->uri->authority; | 
| 49 | 0 |  |  |  |  | 0 | $app_name =~ s/(.*):.*/$1/; # in case a port was added at some point | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 38 |  |  |  |  | 565 | my $app = $self->app_for($app_name); | 
| 53 | 38 | 50 |  |  |  | 128 | croak "Unknown app: $app_name" unless $app; | 
| 54 | 38 |  |  |  |  | 5365 | return Plack::Middleware::ContentLength->wrap($app); | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | 1; | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | __END__ |