You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Autrijus Tang <au...@autrijus.org> on 2002/05/23 18:29:45 UTC

[PATCH] HTML::Mason::ApacheHandler vs. mod_perl2

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;

Re: [PATCH] HTML::Mason::ApacheHandler vs. mod_perl2

Posted by Autrijus Tang <au...@autrijus.org>.
On Thu, May 23, 2002 at 12:10:06PM -0500, Dave Rolsky wrote:
> On Fri, 24 May 2002, Autrijus Tang wrote:
> > 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.
> Actually, I've already done this in the CVS version.  Which version were
> you looking at?  BTW, this patch is not right in a number of ways.

I was looking at the May 15 CVS.

Oh, btw. is the 'cvs' pointer in http://www.masonhq.com/code/download/
intentional in doing 'co masonhq' instead of 'co mason'?

> First, Apache->request is now deprecated (for 2.0), so I stopped using it.
> So is $r->content, I believe.

Understood.

> Second, the patch would break the fixes I did for making "print 'foo'"
> work inside components, at least with 2.0.  Plus there's other things not
> fixed in the patch and changes the patch makes that I'm not sure make
> sense.

Sorry that I wasn't aware of your similiar efforts. Please ignore that patch
then; I'll try to work out another (more sensible) one if there's any other
problems.

> Once there is a working Apache::Request for mod_perl 2.0 I'll make sure
> that that works with Mason.

That would be wonderful. Thank-you.

/Autrijus/

Re: [PATCH] HTML::Mason::ApacheHandler vs. mod_perl2

Posted by Dave Rolsky <au...@urth.org>.
On Fri, 24 May 2002, Autrijus Tang wrote:

> 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.

Actually, I've already done this in the CVS version.  Which version were
you looking at?  BTW, this patch is not right in a number of ways.

First, Apache->request is now deprecated (for 2.0), so I stopped using it.
So is $r->content, I believe.

Second, the patch would break the fixes I did for making "print 'foo'"
work inside components, at least with 2.0.  Plus there's other things not
fixed in the patch and changes the patch makes that I'm not sure make
sense.

Anyway, take a look at the CVS version (the HEAD branch) of
ApacheHandler.pm.  You should be able to get it working with mod_perl 2.0
but you need to use the 'CGI' args_method, which is no longer the default.

Since CGI.pm uses "Apache->request" internally that means you need to add
this to your config:

  PerlOptions +GlobalRequest

Once there is a working Apache::Request for mod_perl 2.0 I'll make sure
that that works with Mason.


-dave

/*==================
www.urth.org
we await the New Sun
==================*/






---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org