Acess current request using static method

Acess current request using static method

am 07.01.2009 18:40:16 von Michael Ludwig

In 2.0, is there a way to access the current request object using one of
the classes in the following fashion?

my $r = Apache2::RequestRec->current(); # INVALID!

So you could access the request object from a function without passing
the request in as a parameter.

Background is, I want to access Apache functionality in a function that
is called from XSL.

Writing this, it occurred to me that it can be done as follows:

use Apache2::Util;
....

sub handler {
...
my $strftime_1 = sub {
Apache2::Util::ht_time( $r->pool, $_[0], '%Y-%m-%d %H:%M', 0);
};
my $strftime_2 = sub {
Apache2::Util::ht_time( $r->pool, $_[0], '%H:%M', 0);
};

my $prsr = XML::LibXML->new;
my $xsl = XML::LibXSLT->new;
XML::LibXSLT->register_function('urn:perl', 'strftime-1', $strftime_1);
XML::LibXSLT->register_function('urn:perl', 'strftime-2', $strftime_2);
...
}

This works. So I don't have to load the POSIX module to get strftime.

Anyway, is there a way to do what I asked?

Michael Ludwig

Re: Acess current request using static method

am 07.01.2009 19:26:57 von Mark Hedges

On Wed, 7 Jan 2009, Michael Ludwig wrote:
> In 2.0, is there a way to access the current request object using one of
> the classes in the following fashion?
>
> my $r = Apache2::RequestRec->current(); # INVALID!
>

From `man Apache2::RequestUtil`:

# get the global request object (requires PerlOptions +GlobalRequest)
$r = Apache2::RequestUtil->request;

Is that what you want?

Mark

Re: Acess current request using static method

am 07.01.2009 22:02:35 von Philip Gollucci

sub list : method {
my $class = shift;
my $r = shift;
my $req = APR::Request::Apache2->handle($r);


OR

sub list {
my $r = shift;
my $req = APR::Request::Apache2->handle($r);




--
------------------------------------------------------------ ------------
1024D/DB9B8C1C B90B FBC3 A3A1 C71A 8E70 3F8C 75B8 8FFB DB9B 8C1C
Philip M. Gollucci (pgollucci@p6m7g8.com) c: 703.336.9354
Consultant - P6M7G8 Inc. http://p6m7g8.net
Senior Sys Admin - RideCharge, Inc. http://ridecharge.com
Contractor - PositiveEnergyUSA http://positiveenergyusa.com
ASF Member - Apache Software Foundation http://apache.org
FreeBSD Committer - FreeBSD Foundation http://freebsd.org

Work like you don't need the money,
love like you'll never get hurt,
and dance like nobody's watching.

Re: Acess current request using static method

am 08.01.2009 09:33:34 von Michael Ludwig

Mark Hedges schrieb:
> On Wed, 7 Jan 2009, Michael Ludwig wrote:
>> In 2.0, is there a way to access the current request object using one
>> of the classes in the following fashion?
>>
>> my $r = Apache2::RequestRec->current(); # INVALID!
>
>>From `man Apache2::RequestUtil`:
>
> # get the global request object (requires PerlOptions +GlobalRequest)
> $r = Apache2::RequestUtil->request;
>
> Is that what you want?

Yes, that's exactly what I was looking for! Thanks Mark, Philip, Steven
(your reply was off-list).

Michael