| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 1 |  |  | 1 |  | 40561 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 50 |  | 
| 2 | 1 |  |  | 1 |  | 6 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 79 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | package Plack::Test::ExternalServer; # git description: 0.01-3-g19ad453 | 
| 5 |  |  |  |  |  |  | # ABSTRACT: Run HTTP tests on external live servers | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = '0.02'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 8 | use URI; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 66 |  | 
| 10 | 1 |  |  | 1 |  | 5 | use Carp (); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 15 |  | 
| 11 | 1 |  |  | 1 |  | 881 | use LWP::UserAgent; | 
|  | 1 |  |  |  |  | 18869 |  | 
|  | 1 |  |  |  |  | 293 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | #pod =head1 SYNOPSIS | 
| 14 |  |  |  |  |  |  | #pod | 
| 15 |  |  |  |  |  |  | #pod     $ PLACK_TEST_IMPL=Plack::Test::ExternalServer \ | 
| 16 |  |  |  |  |  |  | #pod       PLACK_TEST_EXTERNALSERVER_URI=http://myhost.example/myapp/ \ | 
| 17 |  |  |  |  |  |  | #pod       perl my_plack_test.t | 
| 18 |  |  |  |  |  |  | #pod | 
| 19 |  |  |  |  |  |  | #pod =head1 DESCRIPTION | 
| 20 |  |  |  |  |  |  | #pod | 
| 21 |  |  |  |  |  |  | #pod This module allows your to run your Plack::Test tests against an external | 
| 22 |  |  |  |  |  |  | #pod server instead of just against a local application through either mocked HTTP | 
| 23 |  |  |  |  |  |  | #pod or a locally spawned server. | 
| 24 |  |  |  |  |  |  | #pod | 
| 25 |  |  |  |  |  |  | #pod See L on how to write tests that can use this module. | 
| 26 |  |  |  |  |  |  | #pod | 
| 27 |  |  |  |  |  |  | #pod =head1 ENVIRONMENT VARIABLES | 
| 28 |  |  |  |  |  |  | #pod | 
| 29 |  |  |  |  |  |  | #pod =over 4 | 
| 30 |  |  |  |  |  |  | #pod | 
| 31 |  |  |  |  |  |  | #pod =item PLACK_TEST_EXTERNALSERVER_URI | 
| 32 |  |  |  |  |  |  | #pod | 
| 33 |  |  |  |  |  |  | #pod The value of this variable will be used as the base uri for requests to the | 
| 34 |  |  |  |  |  |  | #pod external server. | 
| 35 |  |  |  |  |  |  | #pod | 
| 36 |  |  |  |  |  |  | #pod =back | 
| 37 |  |  |  |  |  |  | #pod | 
| 38 |  |  |  |  |  |  | #pod =head1 SEE ALSO | 
| 39 |  |  |  |  |  |  | #pod | 
| 40 |  |  |  |  |  |  | #pod L | 
| 41 |  |  |  |  |  |  | #pod | 
| 42 |  |  |  |  |  |  | #pod L | 
| 43 |  |  |  |  |  |  | #pod | 
| 44 |  |  |  |  |  |  | #pod L | 
| 45 |  |  |  |  |  |  | #pod | 
| 46 |  |  |  |  |  |  | #pod =begin Pod::Coverage | 
| 47 |  |  |  |  |  |  | #pod | 
| 48 |  |  |  |  |  |  | #pod test_psgi | 
| 49 |  |  |  |  |  |  | #pod | 
| 50 |  |  |  |  |  |  | #pod =end Pod::Coverage | 
| 51 |  |  |  |  |  |  | #pod | 
| 52 |  |  |  |  |  |  | #pod =cut | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | sub test_psgi { | 
| 55 | 2 |  |  | 2 | 0 | 63576 | my %args = @_; | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 2 | 50 |  |  |  | 23 | my $client = delete $args{client} or Carp::croak 'client test code needed'; | 
| 58 | 2 |  | 33 |  |  | 25 | my $ua     = delete $args{ua} || LWP::UserAgent->new; | 
| 59 | 2 |  | 66 |  |  | 3314 | my $base   = $ENV{PLACK_TEST_EXTERNALSERVER_URI} || delete $args{uri}; | 
| 60 | 2 | 50 |  |  |  | 35 | $base   = URI->new($base) if $base; | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | $client->(sub { | 
| 63 | 2 |  |  | 2 |  | 388 | my ($req) = shift->clone; | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 2 | 50 |  |  |  | 515 | if ($base) { | 
| 66 | 2 |  |  |  |  | 22 | my $uri = $req->uri->clone; | 
| 67 | 2 |  |  |  |  | 27 | $uri->scheme($base->scheme); | 
| 68 | 2 |  |  |  |  | 211 | $uri->host($base->host); | 
| 69 | 2 |  |  |  |  | 219 | $uri->port($base->port); | 
| 70 | 2 |  |  |  |  | 144 | $uri->path($base->path . $uri->path); | 
| 71 | 2 |  |  |  |  | 88 | $req->uri($uri); | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  |  | 
| 74 | 2 |  |  |  |  | 53 | return $ua->request($req); | 
| 75 | 2 |  |  |  |  | 6727 | }); | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | 1; | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | __END__ |