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

I am converting some scripts over from cgi to mod_perl with the help of Lincoln/Doug's book. Also doing some hacking to do with user authentication.

From what I can work out, if I make scripts run by giving them a Location directive and providing a handler, I then get the option of authenticating with:

my ($res, $sentPw) = $r->get_basic_auth_pw;

which is neat, as I can then control access to content on any basis I want (rather than per dirctory as with .htaccess). I like it.

But it's actually much easier to port my scripts using Apache::Registry - partly because it fakes the CGI environment, but also because I can just invent a new file extension for my scripts, then rename and retest them one by one - instead of needing to make a <Location> directive per script. Is there then any way to get access back to the request object in the scripts to do basic auth at will?

mod_perl is pretty neat stuff, but it takes some figuring at first ...

Replies are listed 'Best First'.
Re: basic auth under Apache::Registry
by perrin (Chancellor) on Sep 26, 2005 at 20:31 UTC
    There are two ways. The first argument passed to your script will be $r, so you can just do my $r = shift; at the start. Alternatively, you can get $r like this:
    my $r = Apache->request();