X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FTest.pm;h=b7fdb6df9220e7ff505f493bdfc61e360753ed36;hb=a2f2cde95194a17fe2401ae58c92b5494bac599f;hp=eff1a43c86b6d3b7d6f351f9f2910f6e57ca0b7f;hpb=bea4160a7769e77996d8a820fc2602bd3f0f9029;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Test.pm b/lib/Catalyst/Test.pm index eff1a43..b7fdb6d 100644 --- a/lib/Catalyst/Test.pm +++ b/lib/Catalyst/Test.pm @@ -1,6 +1,9 @@ package Catalyst::Test; use strict; + +use Catalyst::Exception; +use Catalyst::Utils; use UNIVERSAL::require; $ENV{CATALYST_ENGINE} = 'Test'; @@ -27,12 +30,12 @@ Catalyst::Test - Test Catalyst applications use Catalyst qw[-Engine=Test]; - __PACKAGE__->action( - foo => sub { + sub foo : Global { my ( $self, $c ) = @_; $c->res->output('bar'); - } - ); + } + + __PACKAGE__->setup(); package main; @@ -76,9 +79,14 @@ sub import { else { $class->require; - - unless ( $INC{'Test/Builder.pm'} ) { - die qq/Couldn't load "$class", "$@"/ if $@; + + if ( $@ ) { + + my $error = $UNIVERSAL::require::ERROR; + + Catalyst::Exception->throw( + message => qq/Couldn't load "$class", "$error"/ + ); } $class->import; @@ -102,27 +110,15 @@ Do an actual remote rquest using LWP. =cut sub remote_request { - my $request = shift; - - require LWP::UserAgent; - unless ( ref $request ) { + require LWP::UserAgent; + + my $request = Catalyst::Utils::request( shift(@_) ); - my $uri = ( $request =~ m/http/i ) - ? URI->new($request) - : URI->new( 'http://localhost' . $request ); - - $request = $uri->canonical; - } - - unless ( ref $request eq 'HTTP::Request' ) { - $request = HTTP::Request->new( 'GET', $request ); - } - - my $server = URI->new( $ENV{CATALYST_SERVER} ); + my $server = URI->new( $ENV{CATALYST_SERVER} ); if ( $server->path =~ m|^(.+)?/$| ) { - $server->path("$1"); # need to be quoted + $server->path("$1"); # need to be quoted } $request->uri->scheme( $server->scheme ); @@ -130,13 +126,14 @@ sub remote_request { $request->uri->port( $server->port ); $request->uri->path( $server->path . $request->uri->path ); - unless ($agent) { + unless ( $agent ) { + $agent = LWP::UserAgent->new( - # cookie_jar => {}, keep_alive => 1, max_redirect => 0, timeout => 60, ); + $agent->env_proxy; }