1 package Catalyst::Engine::CGI;
4 use base 'Catalyst::Engine::CGI::Base';
10 Catalyst::Engine::CGI - The CGI Engine
14 A script using the Catalyst::Engine::CGI module might look like:
19 use lib '/path/to/MyApp/lib';
24 The application module (C<MyApp>) would use C<Catalyst>, which loads the
25 appropriate engine module.
29 This is the Catalyst engine specialized for the CGI environment (using the
30 C<CGI> and C<CGI::Cookie> modules). Normally Catalyst will select the
31 appropriate engine according to the environment that it detects, however you
32 can force Catalyst to use the CGI engine by specifying the following in your
35 use Catalyst qw(-Engine=CGI);
37 The performance of this way of using Catalyst is not expected to be
38 useful in production applications, but it may be helpful for development.
40 =head1 OVERLOADED METHODS
42 This class overloads some methods from C<Catalyst::Engine::CGI::Base>.
46 =item $c->prepare_body
53 # XXX this is undocumented in CGI.pm. If Content-Type is not
54 # application/x-www-form-urlencoded or multipart/form-data
55 # CGI.pm will read STDIN into a param, POSTDATA.
57 $c->request->body( $c->cgi->param('POSTDATA') );
60 =item $c->prepare_parameters
64 sub prepare_parameters {
69 if ( $c->request->method eq 'POST' ) {
70 for my $param ( $c->cgi->url_param ) {
71 for my $value ( $c->cgi->url_param($param) ) {
72 push ( @params, $param, $value );
77 for my $param ( $c->cgi->param ) {
78 for my $value ( $c->cgi->param($param) ) {
79 push ( @params, $param, $value );
83 $c->request->param(@params);
86 =item $c->prepare_request
92 $c->cgi( $cgi || CGI->new );
93 $c->cgi->_reset_globals;
96 =item $c->prepare_uploads
100 sub prepare_uploads {
105 for my $param ( $c->cgi->param ) {
107 my @values = $c->cgi->param($param);
109 next unless ref( $values[0] );
111 for my $fh (@values) {
113 next unless my $size = ( stat $fh )[7];
115 my $info = $c->cgi->uploadInfo($fh);
116 my $tempname = $c->cgi->tmpFileName($fh);
117 my $type = $info->{'Content-Type'};
118 my $disposition = $info->{'Content-Disposition'};
119 my $filename = ( $disposition =~ / filename="([^;]*)"/ )[0];
121 my $upload = Catalyst::Request::Upload->new(
122 filename => $filename,
124 tempname => $tempname,
128 push( @uploads, $param, $upload );
132 $c->request->upload(@uploads);
139 L<Catalyst> L<Catalyst::Engine> L<Catalyst::Engine::CGI::Base>.
143 Sebastian Riedel, C<sri@cpan.org>
144 Christian Hansen, C<ch@ngmedia.com>
148 This program is free software, you can redistribute it and/or modify it under
149 the same terms as Perl itself.