M J wrote:
I’m very disappointed regarding the mod_perl 2 documentation and changes
that have been made.
I’m searching for several hours already how can I read the query params
using only mod_perl2 API.
I had problem installing libapreq2-2.06-dev and I’m tired to debug that
library.
I want to use mod_perl2 API to do the simplest job possible: read the
parameters sent using GET or POST. I am looping around and I did not find a
clear example or explanation regarding this.
I can use $r->args() but then I need to split that string in order to
get my param value. I doubt that this is a good solution.
The reference you are looking for is here:
http://perl.apache.org/docs/2.0/user/porting/compat.html#C__r_E_gt_args__in_an_Array_Context
It's buried a bit deep, so maybe a cooking recipe or two could be added
- this seems to be a common issue for mp2.
If you can't install libapreq2, there are still several options. You
could use CGI which has compatible with mod_perl2. If you are looking
for some sample code maybe this will work (untested). It logs the
arguments received to the apache error log.
----------------------------------------
Your request:
http://servername/postaway/?param=value
or the equivalent POST
----------------------------
In your httpd.conf:
LoadModule perl_module modules/mod_perl.so
PerRequire "/path/to/startup.pl"
<Location /postaway>
SetHandler perl-script
PerlResponseHandler My::CGI
</Location>
----------------------
In startup.pl
use strict;
use warnings;
use lib 'path/to/my/lib'
use CGI;
use Apache2::Const ();
use Apache2::Log ();
use Apache2::RequestRec (); # Not sure if you need the next two
# explicitly but I think CGI may require it
use Apache2::RequestUtil ();
--------------------
In lib/My/CGI.pm
package My::CGI;
use strict;
use warnings;
use Apache2::Const -compile => qw( OK );
use Apache2::Log;
use Apache2::RequestRec;
use Apache2::RequestUtil;
use CGI;
sub handler {
my $r = shift;
my $cgi = CGI->new;
my $q = $cgi->query;
foreach my $name ( $q->param ) {
$r->log->info("Passed a param named $name with value " .
$q->param($name));
}
return Apache2::Const::OK;
}
P.S.
With the modification that you made for mod_perl2 you will loose a lot
of perl programmer and I doubt that you will get new ones.
M J