0

My requirement is as below.

if the requested url is like

http://localhost/mod_perl/TopModule/ActualModule/method1

Then I should call TopModule::ActualModule->method1 ()

How can I configure Apache to do this ?

Kishore Relangi
  • 1,928
  • 16
  • 18

1 Answers1

0

The URL part behind the script name is passed to your perl program in $ENV{PATH_INFO}. So you could create a perl script that you call modulerunner, which you can call with an URL like 'http://whatever.host/modulerunner/Top/Actual/method' :

my $arg=$ENV{PATH_INFO};        <-- contains Top/Actual/method
my @arg=split("/", $arg);       <-- [ "Top", "Actual", "method" ]
my $method=pop @arg;            <-- removes "method", "Top" and "Actual" remain in @arg
my $modules=join("::", @arg);   <-- "Top::Actual"
my $call="$modules->$method()"; <-- "Top::Actual->method()"
eval $call;                     <-- actually execute the method

However, i would NOT AT ALL recommend this - it opens way too many security holes, allowing your web site visitors to call any perl function in any module. So, except you're doing this on your own server that isn't connected to anything else, i'd just go for a very boring if-then-cascade.

$p=$ENV{PATH_INFO};
if     ($p eq "Top/Actual/method") { Top::Actual->method(); }
elseif ($p eq "Other/Module/function" { Other::Module->function(); }
else {
    print "<font color=red>Don't try to hack me this way, you can't.</font>\n";
}

Oh, and don't use the <font> tag ony anything productive either ;)

Guntram Blohm
  • 9,667
  • 2
  • 24
  • 31