You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Charlie Katz <ck...@cfa.harvard.edu> on 2011/10/25 19:43:51 UTC

$r vs. Apache2::RequestUtil->request

Hi, I'm confused about something.  I am cleaning up some legacy Perl code in
our application, and I find a number of our custom Perl modules have
functions which require $r be passed to them solely for use in logging (e.g.
$r->log->error()). I want to remove that requirement, so I am changing
things around so that the code uses Apache2::RequestUtil::request to get the
request object when needed.  This is working fine, except when I use the
object retrieved that way, the $r->log methods fail to write to the server
log.   In addition, I see that the original $r and the new one from
A::RU::request are different:

use Data::Dumper;
print STDERR Dumper($r);
print STDERR Dumper(Apache2::RequestUtil->request);

yields

$VAR1 = bless( do{\(my $o = 158143776)}, 'Apache2::Request' );
$VAR1 = bless( do{\(my $o = 158116376)}, 'Apache2::RequestRec' );

Can someone help me understand this difference, and how to use the object
retrieved from A::RU::request to access the Apache2::Log methods?  Why isn't
the original $r an Apache2::RequestRec object?

This is Perl 5.14.2, mod_perl 2.0.5

Thanks.

Charlie Katz

Re: $r vs. Apache2::RequestUtil->request

Posted by Fred Moyer <fr...@redhotpenguin.com>.
Apache2::Request is a Perl module which is part of the libapreq Apache
software project.  You have to install apreq (
http://httpd.apache.org/apreq/ ) and then load the shared object in
httpd.conf via LoadModule.  It contains many convenience methods that
CGI.pm normally provides.

Apache2::RequestUtil is part of the mod_perl2 core.

If you are using $r->log then you need to 'use Apache2::Log;' in
either startup.pl or your module.

Hope that helps.

On Tue, Oct 25, 2011 at 11:53 AM, Charlie Katz <ck...@cfa.harvard.edu> wrote:
> Okay, never mind.  The Apache2::Log methods are in fact working for me.
>  Stupid error.
> I am still curious about the difference between the Apache2::Request object
> which is the default request record accessor, and the Apache2::RequestRec
> object which comes out of Apache2::RequestUtil::request.
>
> On Tue, Oct 25, 2011 at 1:43 PM, Charlie Katz <ck...@cfa.harvard.edu> wrote:
>>
>> Hi, I'm confused about something.  I am cleaning up some legacy Perl code
>> in our application, and I find a number of our custom Perl modules have
>> functions which require $r be passed to them solely for use in logging (e.g.
>> $r->log->error()). I want to remove that requirement, so I am changing
>> things around so that the code uses Apache2::RequestUtil::request to get the
>> request object when needed.  This is working fine, except when I use the
>> object retrieved that way, the $r->log methods fail to write to the server
>> log.   In addition, I see that the original $r and the new one from
>> A::RU::request are different:
>> use Data::Dumper;
>> print STDERR Dumper($r);
>> print STDERR Dumper(Apache2::RequestUtil->request);
>> yields
>> $VAR1 = bless( do{\(my $o = 158143776)}, 'Apache2::Request' );
>> $VAR1 = bless( do{\(my $o = 158116376)}, 'Apache2::RequestRec' );
>> Can someone help me understand this difference, and how to use the object
>> retrieved from A::RU::request to access the Apache2::Log methods?  Why isn't
>> the original $r an Apache2::RequestRec object?
>> This is Perl 5.14.2, mod_perl 2.0.5
>> Thanks.
>> Charlie Katz
>
>

Re: $r vs. Apache2::RequestUtil->request

Posted by Charlie Katz <ck...@cfa.harvard.edu>.
Okay, never mind.  The Apache2::Log methods are in fact working for me.
 Stupid error.

I am still curious about the difference between the Apache2::Request object
which is the default request record accessor, and the Apache2::RequestRec
object which comes out of Apache2::RequestUtil::request.


On Tue, Oct 25, 2011 at 1:43 PM, Charlie Katz <ck...@cfa.harvard.edu> wrote:

> Hi, I'm confused about something.  I am cleaning up some legacy Perl code
> in our application, and I find a number of our custom Perl modules have
> functions which require $r be passed to them solely for use in logging (e.g.
> $r->log->error()). I want to remove that requirement, so I am changing
> things around so that the code uses Apache2::RequestUtil::request to get the
> request object when needed.  This is working fine, except when I use the
> object retrieved that way, the $r->log methods fail to write to the server
> log.   In addition, I see that the original $r and the new one from
> A::RU::request are different:
>
> use Data::Dumper;
> print STDERR Dumper($r);
> print STDERR Dumper(Apache2::RequestUtil->request);
>
> yields
>
> $VAR1 = bless( do{\(my $o = 158143776)}, 'Apache2::Request' );
> $VAR1 = bless( do{\(my $o = 158116376)}, 'Apache2::RequestRec' );
>
> Can someone help me understand this difference, and how to use the object
> retrieved from A::RU::request to access the Apache2::Log methods?  Why isn't
> the original $r an Apache2::RequestRec object?
>
> This is Perl 5.14.2, mod_perl 2.0.5
>
> Thanks.
>
> Charlie Katz
>
>