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 ) = @_;
61 $request = Catalyst::Utils::request($request);
64 'Host' => sprintf( '%s:%d', $request->uri->host, $request->uri->port )
69 PATH_INFO => $request->uri->path || '',
70 QUERY_STRING => $request->uri->query || '',
71 REMOTE_ADDR => '127.0.0.1',
72 REMOTE_HOST => 'localhost',
73 REQUEST_METHOD => $request->method,
74 SERVER_NAME => 'localhost',
75 SERVER_PORT => $request->uri->port,
76 SERVER_PROTOCOL => 'HTTP/1.1',
81 for my $header ( $request->header_field_names ) {
82 my $name = uc $header;
83 $name = 'COOKIE' if $name eq 'COOKIES';
85 $name = 'HTTP_' . $name
86 unless $name =~ m/\A(?:CONTENT_(?:LENGTH|TYPE)|COOKIE)\z/;
87 my $value = $request->header($header);
88 if ( exists $ENV{$name} ) {
89 $ENV{$name} .= "; $value";
98 my $input = $request->content;
99 open STDIN, '<', \$input;
104 open STDOUT, '>', \$output;
107 $class->handle_request;
110 return HTTP::Response->parse($output);
113 =item $self->read_chunk($c, $buffer, $length)
117 sub read_chunk { shift; shift; *STDIN->read(@_); }
127 Sebastian Riedel, <sri@cpan.org>
129 Christian Hansen, <ch@ngmedia.com>
131 Andy Grundman, <andy@hybridized.org>
135 This program is free software, you can redistribute it and/or modify it under
136 the same terms as Perl itself.