creeble has asked for the wisdom of the Perl Monks concerning the following question:

Ug. I'm trying to use Apache::FakeRequest to test some mod_perl. But of course, the most essential object -- the request object -- needs to be created that $self->r->uri and friends work.

I tried creating an HTTP::Request object and initializing it as 'r', blessed every which way, but the FakeRequest object still can't find it:

$r = HTTP::Request->new(GET=>'/Hey'); $fr = Apache::FakeRequest->new('r'=>bless $r, HTTP::Request (or about +a million other different variations) ); $fr->r->uri (or just $fr->r) not found at run time.
Do I have to subclass Apache::FakeRequest to make this work?

Creeble

Edit by tye, change PRE tags to CODE tags, preserve formatting

Replies are listed 'Best First'.
Re: Apache::FakeRequest request object?
by valdez (Monsignor) on Feb 01, 2004 at 09:46 UTC

    I think that you can emulate only methods listed inside Apache::FakeRequest and there isn't a method r; in other words, r is not a method of Apache request. Can you show us some more code? Is it a Apache::Registry script or a plain handler?

    Ciao, Valerio

      I get that r isn't a method of Apache::FakeRequest, I'm trying to make it one somehow. It's a regular PerlHandler that I'm testing, and the first thing that the handler does is assign $self->r to something, which is normally where the HTTP::Request (or Apache::request, I guess) object lives. I'm most confused -- every handler I've ever seen accesses the 'r' (request) method, but Apache::FakeRequest doesn't have one. How can it get one? Creeble

        I'm sorry, but I can't remember any r method of Apache requests... would you be so kind to show me some code? For example, a simple (and stupid) handler would be like the following:

        package myHandler; use Apache::Constants qw(:common); sub handler { my $r = shift; warn "request is ", $r->as_string, "\n"; return DECLINED; }
        In this code $r will contain the Apache request object and, as you can see in Apache request man page, there is no r method...

        Ciao, Valerio