Updated Changes and MANIFEST
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / CGI.pm
index 9305c1b..1a8f37c 100644 (file)
@@ -5,6 +5,8 @@ use base 'Catalyst::Engine::CGI::Base';
 
 use CGI;
 
+__PACKAGE__->mk_accessors('cgi');
+
 =head1 NAME
 
 Catalyst::Engine::CGI - The CGI Engine
@@ -37,6 +39,16 @@ application module:
 The performance of this way of using Catalyst is not expected to be
 useful in production applications, but it may be helpful for development.
 
+=head1 METHODS
+
+=over 4
+
+=item $c->cgi
+
+Contains the C<CGI> object.
+
+=back
+
 =head1 OVERLOADED METHODS
 
 This class overloads some methods from C<Catalyst::Engine::CGI::Base>.
@@ -88,9 +100,35 @@ 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);
+            die( qq/Invalid argument $object/ );
+        }
+    }
+
     $c->cgi( $cgi || CGI->new );
-    $c->cgi->_reset_globals;
 }
 
 =item $c->prepare_uploads