Added Catalyst::Exception
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / CGI.pm
index 9305c1b..11d8ebf 100644 (file)
@@ -3,8 +3,27 @@ package Catalyst::Engine::CGI;
 use strict;
 use base 'Catalyst::Engine::CGI::Base';
 
+use Catalyst::Exception;
 use CGI;
 
+our @compile = qw[
+    delete
+    http
+    new_MultipartBuffer
+    param
+    parse_keywordlist
+    read_from_client
+    read_multipart
+    tmpFileName
+    uploadInfo
+    url_param
+    user_agent
+];
+
+CGI->compile(@compile);
+
+__PACKAGE__->mk_accessors('cgi');
+
 =head1 NAME
 
 Catalyst::Engine::CGI - The CGI Engine
@@ -27,15 +46,17 @@ appropriate engine module.
 =head1 DESCRIPTION
 
 This is the Catalyst engine specialized for the CGI environment (using the
-C<CGI> 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:
+C<CGI> and C<CGI::Cookie> modules).
+
+=head1 METHODS
+
+=over 4
 
-    use Catalyst qw(-Engine=CGI);
+=item $c->cgi
 
-The performance of this way of using Catalyst is not expected to be
-useful in production applications, but it may be helpful for development.
+Contains the C<CGI> object.
+
+=back
 
 =head1 OVERLOADED METHODS
 
@@ -88,9 +109,38 @@ sub prepare_parameters {
 =cut
 
 sub prepare_request {
-    my ( $c, $cgi ) = @_;
+    my ( $c, $object ) = @_;
+
+    my $cgi;
+
+    if ( defined($object) && ref($object) ) {
+
+        if ( $object->isa('Apache') ) {                   # MP 1.3
+            $cgi = CGI->new($object);
+        }
+
+        elsif ( $object->isa('Apache::RequestRec') ) {    # MP 1.99
+            $cgi = CGI->new($object);
+        }
+
+        elsif ( $object->isa('Apache2::RequestRec') ) {   # MP 2.00
+            $cgi = CGI->new($object);
+        }
+
+        elsif ( $object->isa('CGI') ) {
+            $cgi = $object;
+        }
+
+        else {
+            my $class = ref($object);
+            
+            Catalyst::Exception->throw(
+                message => qq/Unknown object '$object'/
+            );
+        }
+    }
+
     $c->cgi( $cgi || CGI->new );
-    $c->cgi->_reset_globals;
 }
 
 =item $c->prepare_uploads