1 package Catalyst::Engine::CGI;
4 use base 'Catalyst::Engine::CGI::Base';
6 use Catalyst::Exception;
23 CGI->compile(@compile);
25 __PACKAGE__->mk_accessors('cgi');
29 Catalyst::Engine::CGI - The CGI Engine
33 A script using the Catalyst::Engine::CGI module might look like:
38 use lib '/path/to/MyApp/lib';
43 The application module (C<MyApp>) would use C<Catalyst>, which loads the
44 appropriate engine module.
48 This is the Catalyst engine specialized for the CGI environment (using the
49 C<CGI> and C<CGI::Cookie> modules).
57 Contains the C<CGI> object.
61 =head1 OVERLOADED METHODS
63 This class overloads some methods from C<Catalyst::Engine::CGI::Base>.
67 =item $c->prepare_body
74 # XXX this is undocumented in CGI.pm. If Content-Type is not
75 # application/x-www-form-urlencoded or multipart/form-data
76 # CGI.pm will read STDIN into a param, POSTDATA.
78 $c->request->body( $c->cgi->param('POSTDATA') );
81 =item $c->prepare_parameters
85 sub prepare_parameters {
90 if ( $c->request->method eq 'POST' ) {
91 for my $param ( $c->cgi->url_param ) {
92 for my $value ( $c->cgi->url_param($param) ) {
93 push ( @params, $param, $value );
98 for my $param ( $c->cgi->param ) {
99 for my $value ( $c->cgi->param($param) ) {
100 push ( @params, $param, $value );
104 $c->request->param(@params);
107 =item $c->prepare_request
111 sub prepare_request {
112 my ( $c, $object ) = @_;
116 if ( defined($object) && ref($object) ) {
118 if ( $object->isa('Apache') ) { # MP 1.3
119 $cgi = CGI->new($object);
122 elsif ( $object->isa('Apache::RequestRec') ) { # MP 1.99
123 $cgi = CGI->new($object);
126 elsif ( $object->isa('Apache2::RequestRec') ) { # MP 2.00
127 $cgi = CGI->new($object);
130 elsif ( $object->isa('CGI') ) {
135 my $class = ref($object);
137 Catalyst::Exception->throw(
138 message => qq/Unknown object '$object'/
143 $c->cgi( $cgi || CGI->new );
146 =item $c->prepare_uploads
150 sub prepare_uploads {
155 for my $param ( $c->cgi->param ) {
157 my @values = $c->cgi->param($param);
159 next unless ref( $values[0] );
161 for my $fh (@values) {
163 next unless my $size = ( stat $fh )[7];
165 my $info = $c->cgi->uploadInfo($fh);
166 my $tempname = $c->cgi->tmpFileName($fh);
167 my $type = $info->{'Content-Type'};
168 my $disposition = $info->{'Content-Disposition'};
169 my $filename = ( $disposition =~ / filename="([^;]*)"/ )[0];
171 my $upload = Catalyst::Request::Upload->new(
172 filename => $filename,
174 tempname => $tempname,
178 push( @uploads, $param, $upload );
182 $c->request->upload(@uploads);
189 L<Catalyst> L<Catalyst::Engine> L<Catalyst::Engine::CGI::Base>.
193 Sebastian Riedel, C<sri@cpan.org>
194 Christian Hansen, C<ch@ngmedia.com>
198 This program is free software, you can redistribute it and/or modify it under
199 the same terms as Perl itself.