Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: How to get the value of <Location> directive (mod_perl)?

by ChemBoy (Priest)
on Dec 10, 2006 at 18:17 UTC ( [id://588918] : note . print w/replies, xml ) Need Help??

in reply to How to get the value of <Location> directive (mod_perl)?

I'm not sure this is what you're after, but it seems like it might be a problem I had recently: if your module is handling all of the requests below a certain root URI, and you're taking actions based on the path after that root, how do you know (without hardcoding it or some other such evil tactic) how much of the uri is what you're supposed to be processing?

My solution, which may or may not have been a good one, was to do the Apache configuration in Perl. The root URL for each handler is set in a constants file, and the configuration section refers to that constant when setting up the server. (I can't remember precisely the syntax, but it's roughly $Location{$MY::ROOT_URL} = { PerlResponseHandler=>'My::Apache::Handler', SetHandler=>"perl-script'};) Then the handler itself refers to that same constant when determining its root path: (my $path = $r->uri) =~ s/^\Q$MY::ROOT_URL//;.

If that wasn't the problem you were trying to solve, my apologies, but it seemed like a decent shot. :-)

If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders

Replies are listed 'Best First'.
Re^2: How to get the value of <Location> directive (mod_perl)?
by Burak (Chaplain) on Dec 10, 2006 at 19:14 UTC
    It looks like you've revealed my evil action :) But, it seems like your method will also need hardcoding at least in two places. I'm currently using PerlSetVar to set the location:
    <Location /foo> SetHandler perl-script PerlSetVar NAME "/foo" PerlHandler My::Apache::Handler </Location>
    It looks like Apache2::Directive may help, but I still need to know what the location is:
    use Apache2::Directive (); my $tree = Apache2::Directive::conftree(); my $node = $tree->lookup('Location', '/foo/');