X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FTest.pm;h=e227bad45f492035b077226fdf34758363129777;hp=3af0f151f677f318a863b412b9482e04597869c5;hb=b5ecfcf07b8ffe7e9984f0279c8781ce51c6ac6a;hpb=b39840dab69d787e608212d070f7ab4a29204f5f diff --git a/lib/Catalyst/Test.pm b/lib/Catalyst/Test.pm index 3af0f15..e227bad 100644 --- a/lib/Catalyst/Test.pm +++ b/lib/Catalyst/Test.pm @@ -6,29 +6,12 @@ use warnings; use Catalyst::Exception; use Catalyst::Utils; use UNIVERSAL::require; -use HTTP::Headers; - -$ENV{CATALYST_ENGINE} = 'Test'; - -# Bypass a HTTP::Headers bug -{ - no warnings 'redefine'; - - sub HTTP::Headers::new { - my $class = shift; - my $self = bless {}, $class; - if (@_) { - while ( my ( $field, $val ) = splice( @_, 0, 2 ) ) { - $self->push_header( $field, $val ); - } - } - return $self; - } -} + +$ENV{CATALYST_ENGINE} ||= 'CGI'; =head1 NAME -Catalyst::Test - Test Catalyst applications +Catalyst::Test - Test Catalyst Applications =head1 SYNOPSIS @@ -46,7 +29,7 @@ Catalyst::Test - Test Catalyst applications # Tests with inline apps need to use Catalyst::Engine::Test package TestApp; - use Catalyst qw[-Engine=Test]; + use Catalyst; sub foo : Global { my ( $self, $c ) = @_; @@ -64,19 +47,17 @@ Catalyst::Test - Test Catalyst applications =head1 DESCRIPTION -Test Catalyst applications. +Test Catalyst Applications. =head2 METHODS -=over 4 - -=item get +=head2 get Returns the content. my $content = get('foo/bar?test=1'); -=item request +=head2 request Returns a C object. @@ -100,8 +81,8 @@ sub import { die if $@ && $@ !~ /^Can't locate /; $class->import; - $request = sub { $class->run(@_) }; - $get = sub { $class->run(@_)->content }; + $request = sub { local_request( $class, @_ ) }; + $get = sub { local_request( $class, @_ )->content }; } no strict 'refs'; @@ -110,9 +91,26 @@ sub import { *{"$caller\::get"} = $get; } +=head2 local_request + +=cut + +sub local_request { + my $class = shift; + + require HTTP::Request::AsCGI; + + my $request = Catalyst::Utils::request( shift(@_) ); + my $cgi = HTTP::Request::AsCGI->new( $request, %ENV )->setup; + + $class->handle_request; + + return $cgi->restore->response; +} + my $agent; -=item remote_request +=head2 remote_request Do an actual remote request using LWP. @@ -123,8 +121,7 @@ sub remote_request { require LWP::UserAgent; my $request = Catalyst::Utils::request( shift(@_) ); - - 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 @@ -149,8 +146,6 @@ sub remote_request { return $agent->request($request); } -=back - =head1 SEE ALSO L.