improved Catalyst::Test::request
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / CGI.pm
index 44d1903..1a9d04a 100644 (file)
@@ -18,27 +18,58 @@ Catalyst::Engine::CGI - The CGI Engine
 
 =head1 SYNOPSIS
 
-See L<Catalyst>.
+A script using the Catalyst::Engine::CGI module might look like:
+
+    #!/usr/bin/perl -w
+
+    use strict;
+    use lib '/path/to/MyApp/lib';
+    use MyApp;
+
+    MyApp->run;
+
+The application module (C<MyApp>) would use C<Catalyst>, which loads the
+appropriate engine module.
 
 =head1 DESCRIPTION
 
-This is the CGI engine for Catalyst.
+This is the Catalyst engine specialized for the CGI environment (using the
+C<CGI::Simple> and C<CGI::Cookie> modules).  Normally Catalyst will select the
+appropriate engine according to the environment that it detects, however you
+can force Catalyst to use the CGI engine by specifying the following in your
+application module:
+
+    use Catalyst qw(-Engine=CGI);
 
-=head2 METHODS
+Catalyst::Engine::CGI generates a full set of HTTP headers, which means that
+applications using the engine must be be configured as "Non-parsed Headers"
+scripts (at least when running under Apache).  To configure this under Apache
+name the starting with C<nph->.
 
-=head3 run
+The performance of this way of using Catalyst is not expected to be
+useful in production applications, but it may be helpful for development.
+
+=head1 METHODS
+
+=over 4
+
+=item $c->run
 
 To be called from a CGI script to start the Catalyst application.
 
-=head3 cgi
+=item $c->cgi
 
 This config parameter contains the C<CGI::Simple> object.
 
-=head2 OVERLOADED METHODS
+=back
+
+=head1 OVERLOADED METHODS
 
 This class overloads some methods from C<Catalyst>.
 
-=head3 finalize_headers
+=over 4
+
+=item $c->finalize_headers
 
 =cut
 
@@ -64,7 +95,9 @@ sub finalize_headers {
     print $c->cgi->header(%headers);
 }
 
-=head3 finalize_output
+=item $c->finalize_output
+
+Prints the response output to STDOUT.
 
 =cut
 
@@ -73,13 +106,25 @@ sub finalize_output {
     print $c->response->output;
 }
 
-=head3 prepare_cookies
+=item $c->prepare_connection
+
+=cut
+
+sub prepare_connection {
+    my $c = shift;
+    $c->req->hostname( $c->cgi->remote_host );
+    $c->req->address( $c->cgi->remote_addr );
+}
+
+=item $c->prepare_cookies
+
+Sets up cookies.
 
 =cut
 
 sub prepare_cookies { shift->req->cookies( { CGI::Cookie->fetch } ) }
 
-=head3 prepare_headers
+=item $c->prepare_headers
 
 =cut
 
@@ -90,9 +135,11 @@ sub prepare_headers {
         ( my $field = $header ) =~ s/^HTTPS?_//;
         $c->req->headers->header( $field => $c->cgi->http($header) );
     }
+    $c->req->headers->header( 'Content-Type'   => $c->cgi->content_type );
+    $c->req->headers->header( 'Content-Length' => $c->cgi->content_length );
 }
 
-=head3 prepare_parameters
+=item $c->prepare_parameters
 
 =cut
 
@@ -106,7 +153,7 @@ sub prepare_parameters {
     $c->req->parameters( {%vars} );
 }
 
-=head3 prepare_path
+=item $c->prepare_path
 
 =cut
 
@@ -127,13 +174,13 @@ sub prepare_path {
     $c->req->base( $base->as_string );
 }
 
-=head3 prepare_request
+=item $c->prepare_request
 
 =cut
 
 sub prepare_request { shift->cgi( CGI::Simple->new ) }
 
-=head3 prepare_uploads
+=item $c->prepare_uploads
 
 =cut
 
@@ -150,6 +197,8 @@ sub prepare_uploads {
 
 sub run { shift->handler }
 
+=back
+
 =head1 SEE ALSO
 
 L<Catalyst>.
@@ -166,4 +215,3 @@ the same terms as Perl itself.
 =cut
 
 1;
-## Please see file perltidy.ERR