package Catalyst::Test;
use strict;
+
+use Catalyst::Exception;
+use Catalyst::Utils;
use UNIVERSAL::require;
$ENV{CATALYST_ENGINE} = 'Test';
use Catalyst qw[-Engine=Test];
- __PACKAGE__->action(
- foo => sub {
+ sub foo : Global {
my ( $self, $c ) = @_;
$c->res->output('bar');
- }
- );
+ }
+
+ __PACKAGE__->setup();
package main;
else {
$class->require;
- my $error = $UNIVERSAL::require::ERROR;
- die qq/Couldn't load "$class", "$error"/ if $@;
+
+ if ( $@ ) {
+
+ my $error = $UNIVERSAL::require::ERROR;
+
+ Catalyst::Exception->throw(
+ message => qq/Couldn't load "$class", "$error"/
+ );
+ }
$class->import;
=item remote_request
-Do an actual remote rquest using LWP.
+Do an actual remote request using LWP.
=cut
sub remote_request {
- my $request = shift;
-
- require LWP::UserAgent;
-
- unless ( ref $request ) {
- my $uri =
- ( $request =~ m/http/i )
- ? URI->new($request)
- : URI->new( 'http://localhost' . $request );
+ require LWP::UserAgent;
+
+ my $request = Catalyst::Utils::request( shift(@_) );
- $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
$request->uri->port( $server->port );
$request->uri->path( $server->path . $request->uri->path );
- unless ($agent) {
- $agent = LWP::UserAgent->new(
+ unless ( $agent ) {
- # cookie_jar => {},
+ $agent = LWP::UserAgent->new(
keep_alive => 1,
max_redirect => 0,
timeout => 60,
);
+
$agent->env_proxy;
}