perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Autrijus Tang <autri...@autrijus.org>
Subject [PATCH] HTML::Mason::ApacheHandler vs. mod_perl2
Date Thu, 23 May 2002 16:29:45 GMT
Greetings. Below is what I've done to port Mason(CVS version)'s
ApacheHandler to Apache2; it deals mostly with the args-parsing
incompatibilities and changed method names.

I think some of these chunks will need some work to maintain
mod_perl 1.x compatibility, but as I don't have version 1 right
now, here's the preliminary results.

Thanks,
/Autrijus/

--- /home/autrijus/mason/dist/lib/HTML/Mason/ApacheHandler.pm	Tue Apr 16 12:56:02 2002
+++ RT/MasonApacheHandler.pm	Fri May 24 00:05:50 2002
@@ -492,7 +507,7 @@
     }
 
     # If we're running as superuser, change file ownership to http user & group
-    if (!($> || $<) && $self->interp->files_written)
+    if (!($> || $<) && $self->interp->files_written and Apache->server->can('uid'))
     {
 	chown Apache->server->uid, Apache->server->gid, $self->interp->files_written
 	    or system_error( "Can't change ownership of files written by interp object: $!\n" );
@@ -696,7 +711,7 @@
     #
     my (%args, $cgi_object);
     if ($self->args_method eq 'mod_perl') {
-	$r = Apache::Request->new($r);
+	$r = Apache->request($r);
 	%args = $self->_mod_perl_args($r);
     } else {
 	$cgi_object = CGI->new;
@@ -719,7 +734,7 @@
     # we call the version of the sub that sends its output to the
     # right place.
     #
-    my $print = \&Apache::print;
+    my $print = Apache->request->can('print');
 
     # Craft the request's out method to handle http headers, content
     # length, and HEAD requests.
@@ -780,9 +795,29 @@
     my ($self, $apr, $request) = @_;
 
     my %args;
-    foreach my $key ( $apr->param ) {
-	my @values = $apr->param($key);
-	$args{$key} = @values == 1 ? $values[0] : \@values;
+    
+    if ($apr->can('param')) {
+        foreach my $key ( $apr->param ) {
+	    my @values = $apr->param($key);
+	    $args{$key} = @values == 1 ? $values[0] : \@values;
+        }
+    }
+    else {
+        require CGI::Util;
+
+        my (@pairs) = split(/[&;]/, scalar $apr->args);
+        
+        foreach (@pairs) {
+	    my ($param, $value) = split('=', $_, 2);
+	    next unless defined $param;
+	    $value = '' unless defined $value;
+	    $param = CGI::Util::unescape($param);
+	    $value = CGI::Util::unescape($value);
+	    $args{$param} = $value;
+        }
+
+        my @contents = Apache->request->content;
+        %args = (@contents, %args) if @contents and ($#contents or $contents[0]);
     }
 
     return %args;

Mime
View raw message