1 package Catalyst::Engine::Test;
4 use base 'Catalyst::Engine::CGI::NPH';
13 Catalyst::Engine::Test - Catalyst Test Engine
17 A script using the Catalyst::Engine::Test module might look like:
22 $ENV{CATALYST_ENGINE} = 'Test';
26 use lib '/path/to/MyApp/lib';
29 MyApp->run('/a/path');
33 This is the Catalyst engine specialized for testing.
35 =head1 OVERLOADED METHODS
37 This class overloads some methods from C<Catalyst::Engine::CGI::NPH>.
47 my $request = shift || '/';
49 unless ( ref $request ) {
50 $request = URI->new( $request, 'http' );
52 unless ( ref $request eq 'HTTP::Request' ) {
53 $request = HTTP::Request->new( 'GET', $request );
56 local ( *STDIN, *STDOUT );
60 $ENV{CONTENT_TYPE} ||= $request->header('Content-Type') || '';
61 $ENV{CONTENT_LENGTH} ||= $request->header('Content-Length') || '';
62 $ENV{GATEWAY_INTERFACE} ||= 'CGI/1.1';
63 $ENV{HTTP_USER_AGENT} ||= 'Catalyst';
64 $ENV{HTTP_HOST} ||= $request->uri->host || 'localhost';
65 $ENV{QUERY_STRING} ||= $request->uri->query || '';
66 $ENV{REQUEST_METHOD} ||= $request->method;
67 $ENV{PATH_INFO} ||= $request->uri->path || '/';
68 $ENV{SCRIPT_NAME} ||= '/';
69 $ENV{SERVER_NAME} ||= $request->uri->host || 'localhost';
70 $ENV{SERVER_PORT} ||= $request->uri->port;
71 $ENV{SERVER_PROTOCOL} ||= 'HTTP/1.1';
73 for my $field ( $request->header_field_names ) {
74 if ( $field =~ /^Content-(Length|Type)$/ ) {
78 $ENV{ 'HTTP_' . uc($field) } = $request->header($field);
81 if ( $request->content_length ) {
82 my $body = IO::File->new_tmpfile;
83 $body->print( $request->content ) or die $!;
84 $body->seek( 0, SEEK_SET ) or die $!;
85 open( STDIN, "<&=", $body->fileno )
86 or die("Failed to dup \$body: $!");
89 open( STDOUT, '>', \$output );
92 return HTTP::Response->parse($output);
103 Sebastian Riedel, C<sri@cpan.org>
104 Christian Hansen, C<ch@ngmedia.com>
108 This program is free software, you can redistribute it and/or modify it under
109 the same terms as Perl itself.