1 package Catalyst::Engine::Test;
4 use base 'Catalyst::Engine::CGI';
12 Catalyst::Engine::Test - Catalyst Test Engine
16 A script using the Catalyst::Engine::Test module might look like:
21 $ENV{CATALYST_ENGINE} = 'Test';
25 use lib '/path/to/MyApp/lib';
28 MyApp->run('/a/path');
32 This is the Catalyst engine specialized for testing.
34 =head1 OVERLOADED METHODS
36 This class overloads some methods from C<Catalyst::Engine::CGI>.
40 =item finalize_headers
44 sub finalize_headers {
45 my ( $self, $c ) = @_;
46 my $protocol = $c->request->protocol;
47 my $status = $c->response->status;
48 my $message = status_message($status);
49 print "$protocol $status $message\n";
50 $c->response->headers->date(time);
51 $self->NEXT::finalize_headers($c);
59 my ( $self, $class, $request ) = @_;
62 unless ( ref $request ) {
63 if ( $request =~ m/http/i ) {
64 $request = URI->new($request)->canonical;
67 $request = URI->new( 'http://localhost' . $request )->canonical;
70 unless ( ref $request eq 'HTTP::Request' ) {
71 $request = HTTP::Request->new( 'GET', $request );
75 'Host' => sprintf( '%s:%d', $request->uri->host, $request->uri->port )
80 PATH_INFO => $request->uri->path || '',
81 QUERY_STRING => $request->uri->query || '',
82 REMOTE_ADDR => '127.0.0.1',
83 REMOTE_HOST => 'localhost',
84 REQUEST_METHOD => $request->method,
85 SERVER_NAME => 'localhost',
86 SERVER_PORT => $request->uri->port,
87 SERVER_PROTOCOL => 'HTTP/1.1',
92 for my $header ( $request->header_field_names ) {
93 my $name = uc $header;
94 $name = 'COOKIE' if $name eq 'COOKIES';
96 $name = 'HTTP_' . $name
97 unless $name =~ m/\A(?:CONTENT_(?:LENGTH|TYPE)|COOKIE)\z/;
98 my $value = $request->header($header);
99 if ( exists $ENV{$name} ) {
100 $ENV{$name} .= "; $value";
103 $ENV{$name} = $value;
109 my $input = $request->content;
110 open STDIN, '<', \$input;
115 open STDOUT, '>', \$output;
118 $class->handle_request;
121 return HTTP::Response->parse($output);
124 =item $self->read_chunk($c, $buffer, $length)
128 sub read_chunk { shift; shift; *STDIN->read(@_); }
138 Sebastian Riedel, <sri@cpan.org>
140 Christian Hansen, <ch@ngmedia.com>
142 Andy Grundman, <andy@hybridized.org>
146 This program is free software, you can redistribute it and/or modify it under
147 the same terms as Perl itself.