| 1 | package Plack::Test::MockHTTP; | ||||||||||
| 2 | 62 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 62 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 62 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 62 | ▶ | use HTTP::Request; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 62 | ▶ | use HTTP::Response; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 62 | ▶ | use HTTP::Message::PSGI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 62 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 119 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 12 | 119 | my($class, $app) = @_; | |||||||||
| 13 | 119 | bless { app => $app }, $class; | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 287 | ▶ | sub request { | ||||||||
|
Subroutine
request: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 17 | 287 | my($self, $req) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 287 | ▶ | $req->uri->scheme('http') unless defined $req->uri->scheme; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 287 | ▶ | $req->uri->host('localhost') unless defined $req->uri->host; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 287 | my $env = $req->to_psgi; | |||||||||
| 22 | |||||||||||
| 23 | 287 | ▶ | my $res = try { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 287 | HTTP::Response->from_psgi($self->{app}->($env)); | |||||||||
| 25 | 23 | ▶ | } catch { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 23 | HTTP::Response->from_psgi([ 500, [ 'Content-Type' => 'text/plain' ], [ $_ ] ]); | |||||||||
| 27 | 287 | }; | |||||||||
| 28 | |||||||||||
| 29 | 287 | $res->request($req); | |||||||||
| 30 | 287 | return $res; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 62 | 1; | |||||||||
| 34 | |||||||||||
| 35 | __END__ | ||||||||||