1 package Catalyst::Engine::Test;
4 use base 'Catalyst::Engine::CGI';
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>.
41 =item finalize_headers
45 sub finalize_headers {
46 my ( $self, $c ) = @_;
47 my $protocol = $c->request->protocol;
48 my $status = $c->response->status;
49 my $message = status_message($status);
50 print "$protocol $status $message\n";
51 $c->response->headers->date(time);
52 $self->NEXT::finalize_headers($c);
60 my ( $self, $class, $request ) = @_;
62 $request = Catalyst::Utils::request($request);
65 'Host' => sprintf( '%s:%d', $request->uri->host, $request->uri->port )
70 PATH_INFO => $request->uri->path || '',
71 QUERY_STRING => $request->uri->query || '',
72 REMOTE_ADDR => '127.0.0.1',
73 REMOTE_HOST => 'localhost',
74 REQUEST_METHOD => $request->method,
75 SERVER_NAME => 'localhost',
76 SERVER_PORT => $request->uri->port,
77 SERVER_PROTOCOL => 'HTTP/1.1',
82 for my $header ( $request->header_field_names ) {
83 my $name = uc $header;
84 $name = 'COOKIE' if $name eq 'COOKIES';
86 $name = 'HTTP_' . $name
87 unless $name =~ m/\A(?:CONTENT_(?:LENGTH|TYPE)|COOKIE)\z/;
88 my $value = $request->header($header);
89 if ( exists $ENV{$name} ) {
90 $ENV{$name} .= "; $value";
99 my $input = $request->content;
100 open STDIN, '<', \$input;
105 open STDOUT, '>', \$output;
108 $class->handle_request;
111 return HTTP::Response->parse($output);
114 =item $self->read_chunk($c, $buffer, $length)
118 sub read_chunk { shift; shift; *STDIN->read(@_); }
128 Sebastian Riedel, <sri@cpan.org>
130 Christian Hansen, <ch@ngmedia.com>
132 Andy Grundman, <andy@hybridized.org>
136 This program is free software, you can redistribute it and/or modify it under
137 the same terms as Perl itself.