You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Gene Dascher <ge...@multiservice.com> on 2001/03/12 13:35:01 UTC
Apache request object
How can I access the Apache Request object from a Perl package that I am
calling from a Perl Authorization handler?
Example:
Package TestPackage.pm
-------------------
Package Apache::TestPackage.pm
@EXPORT qw ($home_url);
my $home_url = "http:" . "//" . $ENV{'SERVER_NAME'};
1;
-------------------
Handler TestHandler.pm
-------------------
Package Apache::TestHandler.pm
use Apache::TestPackage.pm
sub handler()
{
my $r = shift;
$r->log_error("Home URL = $home_url");
return OK;
}
1;
---------------------
When I use the handler above, the $home_url does not print out because the
$ENV{'SERVER_NAME'} has not been set at the time that the TestHandler is
called.
I tried using the following code in TestPackage.pm:
my $r = Apache->request();
my $s = $r->server;
but the error I get is: Can't call method "server" on an undefined value.
I also tried using the server_name() function from CGI, but that also relies
on the $ENV{'SERVER_NAME'} as well. I get $home_url = "localhost" when I
call that function from the Package.
Thanks,
Gene Dascher
Re: Apache request object
Posted by Perrin Harkins <pe...@primenet.com>.
On Mon, 12 Mar 2001, Gene Dascher wrote:
> How can I access the Apache Request object from a Perl package that I am
> calling from a Perl Authorization handler?
$r is the first argument passed to your handler.
my $r = shift;
> I tried using the following code in TestPackage.pm:
>
> my $r = Apache->request();
> my $s = $r->server;
>
> but the error I get is: Can't call method "server" on an undefined value.
That should work as well, although it's slower. Something might be wrong
with your build if this is failing.
- Perrin