1 package Catalyst::Engine::CGI;
4 use base 'Catalyst::Engine::CGI::Base';
8 __PACKAGE__->mk_accessors('cgi');
12 Catalyst::Engine::CGI - The CGI Engine
16 A script using the Catalyst::Engine::CGI module might look like:
21 use lib '/path/to/MyApp/lib';
26 The application module (C<MyApp>) would use C<Catalyst>, which loads the
27 appropriate engine module.
31 This is the Catalyst engine specialized for the CGI environment (using the
32 C<CGI> and C<CGI::Cookie> modules). Normally Catalyst will select the
33 appropriate engine according to the environment that it detects, however you
34 can force Catalyst to use the CGI engine by specifying the following in your
37 use Catalyst qw(-Engine=CGI);
39 The performance of this way of using Catalyst is not expected to be
40 useful in production applications, but it may be helpful for development.
48 Contains the C<CGI> object.
52 =head1 OVERLOADED METHODS
54 This class overloads some methods from C<Catalyst::Engine::CGI::Base>.
58 =item $c->prepare_body
65 # XXX this is undocumented in CGI.pm. If Content-Type is not
66 # application/x-www-form-urlencoded or multipart/form-data
67 # CGI.pm will read STDIN into a param, POSTDATA.
69 $c->request->body( $c->cgi->param('POSTDATA') );
72 =item $c->prepare_parameters
76 sub prepare_parameters {
81 if ( $c->request->method eq 'POST' ) {
82 for my $param ( $c->cgi->url_param ) {
83 for my $value ( $c->cgi->url_param($param) ) {
84 push ( @params, $param, $value );
89 for my $param ( $c->cgi->param ) {
90 for my $value ( $c->cgi->param($param) ) {
91 push ( @params, $param, $value );
95 $c->request->param(@params);
98 =item $c->prepare_request
102 sub prepare_request {
103 my ( $c, $object ) = @_;
107 if ( defined($object) && ref($object) ) {
109 if ( $object->isa('Apache') ) { # MP 1.3
110 $cgi = CGI->new($object);
113 elsif ( $object->isa('Apache::RequestRec') ) { # MP 1.99
114 $cgi = CGI->new($object);
117 elsif ( $object->isa('Apache2::RequestRec') ) { # MP 2.00
118 $cgi = CGI->new($object);
121 elsif ( $object->isa('CGI') ) {
126 my $class = ref($object);
127 die( qq/Invalid argument $object/ );
131 $c->cgi( $cgi || CGI->new );
134 =item $c->prepare_uploads
138 sub prepare_uploads {
143 for my $param ( $c->cgi->param ) {
145 my @values = $c->cgi->param($param);
147 next unless ref( $values[0] );
149 for my $fh (@values) {
151 next unless my $size = ( stat $fh )[7];
153 my $info = $c->cgi->uploadInfo($fh);
154 my $tempname = $c->cgi->tmpFileName($fh);
155 my $type = $info->{'Content-Type'};
156 my $disposition = $info->{'Content-Disposition'};
157 my $filename = ( $disposition =~ / filename="([^;]*)"/ )[0];
159 my $upload = Catalyst::Request::Upload->new(
160 filename => $filename,
162 tempname => $tempname,
166 push( @uploads, $param, $upload );
170 $c->request->upload(@uploads);
177 L<Catalyst> L<Catalyst::Engine> L<Catalyst::Engine::CGI::Base>.
181 Sebastian Riedel, C<sri@cpan.org>
182 Christian Hansen, C<ch@ngmedia.com>
186 This program is free software, you can redistribute it and/or modify it under
187 the same terms as Perl itself.