perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Colin Wetherbee <>
Subject [mp2] The right way to use CGI parameters in a handler
Date Mon, 11 Jun 2007 02:14:41 GMT

It's been about four years since I've used mod_perl to any great extent, 
and I'm afraid I'm somewhat rusty.  I'm trying to create a handler that 
can parse CGI parameters, but I'm unsure of the most modern way of doing 

I know Apache2::Request is supposed to be able to grab CGI parameters; 
is that "better" than using  How about these APR modules that 
seem to wind their way into the framework?

When I tried creating an Apache2::Request->new($r) object to use to get 
CGI parameters, I found that everything I tried to print after the 
object's instantiation wouldn't show up anywhere.  All the pages served 
were zero bytes, and I couldn't even print to STDERR.

Here's a simple handler I wrote.  It works, but I'm afraid I might be 
doing something incorrectly by mixing Apache2 and CGI.  I'm wondering 
how it would look if someone who was more up-to-date on mod_perl wrote 
it? :)

use Apache2::Const -compile => qw(OK);
use CGI;

sub handler
   my ($r) = @_;

   my $cgi = CGI->new($r);


   if (defined $cgi->param('foo'))
     print 'foo: ' . $cgi->param('foo') . "<br />\n";

   return Apache2::Const::OK;

Thanks. :)


View raw message