1 package Catalyst::Engine::CGI;
4 use base 'Catalyst::Engine::CGI::Base';
22 CGI->compile(@compile);
24 __PACKAGE__->mk_accessors('cgi');
28 Catalyst::Engine::CGI - The CGI Engine
32 A script using the Catalyst::Engine::CGI module might look like:
37 use lib '/path/to/MyApp/lib';
42 The application module (C<MyApp>) would use C<Catalyst>, which loads the
43 appropriate engine module.
47 This is the Catalyst engine specialized for the CGI environment (using the
48 C<CGI> and C<CGI::Cookie> modules).
56 Contains the C<CGI> object.
60 =head1 OVERLOADED METHODS
62 This class overloads some methods from C<Catalyst::Engine::CGI::Base>.
66 =item $c->prepare_body
73 # XXX this is undocumented in CGI.pm. If Content-Type is not
74 # application/x-www-form-urlencoded or multipart/form-data
75 # CGI.pm will read STDIN into a param, POSTDATA.
77 $c->request->body( $c->cgi->param('POSTDATA') );
80 =item $c->prepare_parameters
84 sub prepare_parameters {
89 if ( $c->request->method eq 'POST' ) {
90 for my $param ( $c->cgi->url_param ) {
91 for my $value ( $c->cgi->url_param($param) ) {
92 push ( @params, $param, $value );
97 for my $param ( $c->cgi->param ) {
98 for my $value ( $c->cgi->param($param) ) {
99 push ( @params, $param, $value );
103 $c->request->param(@params);
106 =item $c->prepare_request
110 sub prepare_request {
111 my ( $c, $object ) = @_;
115 if ( defined($object) && ref($object) ) {
117 if ( $object->isa('Apache') ) { # MP 1.3
118 $cgi = CGI->new($object);
121 elsif ( $object->isa('Apache::RequestRec') ) { # MP 1.99
122 $cgi = CGI->new($object);
125 elsif ( $object->isa('Apache2::RequestRec') ) { # MP 2.00
126 $cgi = CGI->new($object);
129 elsif ( $object->isa('CGI') ) {
134 my $class = ref($object);
135 die( qq/Invalid argument $object/ );
139 $c->cgi( $cgi || CGI->new );
142 =item $c->prepare_uploads
146 sub prepare_uploads {
151 for my $param ( $c->cgi->param ) {
153 my @values = $c->cgi->param($param);
155 next unless ref( $values[0] );
157 for my $fh (@values) {
159 next unless my $size = ( stat $fh )[7];
161 my $info = $c->cgi->uploadInfo($fh);
162 my $tempname = $c->cgi->tmpFileName($fh);
163 my $type = $info->{'Content-Type'};
164 my $disposition = $info->{'Content-Disposition'};
165 my $filename = ( $disposition =~ / filename="([^;]*)"/ )[0];
167 my $upload = Catalyst::Request::Upload->new(
168 filename => $filename,
170 tempname => $tempname,
174 push( @uploads, $param, $upload );
178 $c->request->upload(@uploads);
185 L<Catalyst> L<Catalyst::Engine> L<Catalyst::Engine::CGI::Base>.
189 Sebastian Riedel, C<sri@cpan.org>
190 Christian Hansen, C<ch@ngmedia.com>
194 This program is free software, you can redistribute it and/or modify it under
195 the same terms as Perl itself.