1 package Catalyst::Engine::Test;
4 use base 'Catalyst::Engine::CGI::NPH';
13 Catalyst::Engine::Test - Catalyst Test Engine
21 This is the Catalyst engine specialized for testing.
23 =head1 OVERLOADED METHODS
25 This class overloads some methods from C<Catalyst::Engine::CGI::NPH>.
35 my $request = shift || '/';
37 unless ( ref $request ) {
38 $request = URI->new( $request, 'http' );
40 unless ( ref $request eq 'HTTP::Request' ) {
41 $request = HTTP::Request->new( 'GET', $request );
44 local ( *STDIN, *STDOUT );
48 $ENV{CONTENT_TYPE} ||= $request->header('Content-Type') || '';
49 $ENV{CONTENT_LENGTH} ||= $request->header('Content-Length') || '';
50 $ENV{GATEWAY_INTERFACE} ||= 'CGI/1.1';
51 $ENV{HTTP_USER_AGENT} ||= 'Catalyst';
52 $ENV{HTTP_HOST} ||= $request->uri->host || 'localhost';
53 $ENV{QUERY_STRING} ||= $request->uri->query || '';
54 $ENV{REQUEST_METHOD} ||= $request->method;
55 $ENV{PATH_INFO} ||= $request->uri->path || '/';
56 $ENV{SCRIPT_NAME} ||= '/';
57 $ENV{SERVER_NAME} ||= $request->uri->host || 'localhost';
58 $ENV{SERVER_PORT} ||= $request->uri->port;
59 $ENV{SERVER_PROTOCOL} ||= 'HTTP/1.1';
61 for my $field ( $request->header_field_names ) {
62 if ( $field =~ /^Content-(Length|Type)$/ ) {
66 $ENV{ 'HTTP_' . uc($field) } = $request->header($field);
69 if ( $request->content_length ) {
70 my $body = IO::File->new_tmpfile;
71 $body->print( $request->content ) or die $!;
72 $body->seek( 0, SEEK_SET ) or die $!;
73 open( STDIN, "<&=", $body->fileno )
74 or die("Failed to dup \$body: $!");
77 open( STDOUT, '>', \$output );
80 return HTTP::Response->parse($output);
91 Sebastian Riedel, C<sri@cpan.org>
92 Christian Hansen, C<ch@ngmedia.com>
96 This program is free software, you can redistribute it and/or modify it under
97 the same terms as Perl itself.