[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cgiapp] CGI::Application::Plugin::Apache and mod_perl 2.0


Hello,

Has anyone yet used CGI::Application under mod_perl 2.0 (without the Apache::compat layer)? I just got it to work, after a bit of work... All I had to do, aside from changes to my own modules, was edit CGI::Application::Plugin::Apache. Now that Apache::Request is available for mod_perl 2.0, it's no longer a nightmare! :-)

I've attached a patch to CAP::Apache version 0.09 that includes my changes, based on "A Reference to mod_perl 1.0 to mod_perl 2.0 Migration"[1]. Here is a summary of my changes, with the relevant sections of that document, for any of you who are interested:

* Changed "use Apache" to "use mod_perl" (not sure if this part is essential, but it's what I've seen used most in the docs) and "use Apache::Constants" to "use Apache::Const" (Migration Reference, sec. 1.6). I also changed the import of Apache::Const to import only the two constants that are used by CAP::Apache.

In _send_headers() sub:
* Changed "REDIRECT" to "HTTP_MOVED_TEMPORARILY" (sec. 1.6.2).
* If there are no headers, call "$q->content_type" instead of "$q->send_http_header" (sec. 1.15.19)

In _handle_cgi_header_props() sub:
* Changed all "$q->header_out()" calls to "$q->headers_out->{...}" (sec. 1.15.14)
* Removed use of $_ in a foreach loop.
* Removed calls to "$q->send_http_header()" (sec. 1.15.19).


Any suggestions or comments? Oh, one caveat: with these changes, I don't think the module will still work under mod_perl 1.0, since I'm not concerned about that any more. It might not be too hard to edit the module so it will work with both, but that is left as an exercise for the reader. ;-)

Thanks,
Chad.

[1] http://perl.apache.org/docs/2.0/user/porting/compat.html


--

C. Chad Wallace
The Lodging Company
http://skihills.com/
OpenPGP Public Key ID: 0x262208A0
--- lib/CGI/Application/Plugin/Apache.pm	(revision 1001)
+++ lib/CGI/Application/Plugin/Apache.pm	(working copy)
@@ -1,10 +1,10 @@
 package CGI::Application::Plugin::Apache;
 use strict;
 use base 'Exporter';
-use Apache;
+use mod_perl;
 use Apache::Request;
 use Apache::Reload;
-use Apache::Constants qw(:common :response);
+use Apache::Const qw(OK HTTP_MOVED_TEMPORARILY);
 use Carp;
 
 $CGI::Application::Plugin::Apache::VERSION = 0.09;
@@ -42,14 +42,14 @@
                                                                                                                                        
     # if we are redirecting try and do it with header_out
     if ( $header_type eq 'redirect' || $header_type eq 'header' ) {
-        $q->status(REDIRECT)
+        $q->status(HTTP_MOVED_TEMPORARILY)
             if($header_type eq 'redirect');
         # if we have any header props then use our CGI compat to handle them
         if( scalar(%props) ) {
             _handle_cgi_header_props($q, %props);
         } else {
             # else use to Apache send the header
-            $q->send_http_header('text/html');
+            $q->content_type('text/html');
         }
     } elsif( $header_type eq 'none' ) {
         # don't do anything here either...
@@ -90,41 +90,40 @@
     $q->content_type($type);
     $q->status($status) if($status);
     if( $target ) {
-        $q->header_out('Window-Target' => $target);
+        $q->headers_out->{'Window-Target'} = $target;
     }
     if ( $p3p ) {
         $p3p = join ' ',@$p3p if ref($p3p) eq 'ARRAY';
-        $q->header_out('P3P' => qq(policyref="/w3c/p3p.xml")); 
-        $q->header_out('CP' => $p3p); 
+        $q->headers_out->{'P3P'} = qq(policyref="/w3c/p3p.xml"); 
+        $q->headers_out->{'CP'} = $p3p; 
     }
     # send all the cookies -- there may be several
     if ( $cookie ) {
         my(@cookie) = ref($cookie) && ref($cookie) eq 'ARRAY' ? @{$cookie} : $cookie;
-        foreach (@cookie) {
+        foreach my $ck (@cookie) {
             my $cs = '';
-            if( UNIVERSAL::isa($_,'CGI::Cookie') || UNIVERSAL::isa($_,'Apache::Cookie') ) {
-                $cs = $_->as_string;
+            if( UNIVERSAL::isa($ck,'CGI::Cookie') || UNIVERSAL::isa($ck,'Apache::Cookie') ) {
+                $cs = $ck->as_string;
             } else {
-                $cs = $_;
+                $cs = $ck;
             }
             $q->headers_out->add('Set-Cookie'  => $cs);
         }
     }
     # if the user indicates an expiration time, then we need an Expires
     if( $expires ) {
-        $q->header_out('Expires' => _expires($expires,'http'));
+        $q->headers_out->{'Expires'} = _expires($expires,'http');
     }
     # if there's a location...this is generally done for redirects but there may be other reasons
     if( $uri ) {
-        $q->header_out('Location' => $uri);
+        $q->headers_out->{'Location'} = $uri;
     }
     if( $attachment ) {
-        $q->header_out('Content-Disposition' => qq(attachment; filename="$attachment"));
+        $q->headers_out->{'Content-Disposition'} = qq(attachment; filename="$attachment");
     }
     foreach my $key (keys %$other) {
-        $q->header_out(ucfirst($key) => $other->{$key});
+        $q->headers_out->{ucfirst($key)} = $other->{$key};
     }
-    $q->send_http_header();
     return '';
 }
 

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed

Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.