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

Reply via email to