How to reference %Location outside of <Perl>...</Perl>?

How to reference %Location outside of <Perl>...</Perl>?

am 28.02.2011 22:03:41 von E R

I have the following block in my httpd.conf file which installs
mod-perl handlers for a list of urls:


...
for my $uri (...) {
$Location{$uri} = ...;
}


If I wanted to move this code to a normal perl module, how should I
reference %Location?

Thanks,
ER

Re: How to reference %Location outside of <Perl>...</Perl>?

am 28.02.2011 23:41:28 von Jeff Nokes

--0-103706503-1298932888=:85213
Content-Type: text/plain; charset=us-ascii

I've seen it done where you can make a home-grown module that has a second
package declaration for Apache[2]::ReadConfig. Something like ...


.... in httpd.conf ...


use Some::Module;
Some::Module::my_custom_config();




.... in Module.pm ...

package Some::Module;


sub my_custom_config(;){

package Apache2::ReadConfig;

use strict;
use vars qw(
$ServerName $ServerRoot $DocumentRoot $User $Group
@PerlChildInitHandler @PerlChildExitHandler
%DirectoryMatch %Directory %Location
...
);

for my $uri (...) {
$Location{$uri} ...



You can reference:
http://perl.apache.org/docs/2.0/api/Apache2/PerlSections.htm l for a bit more
info as well.

Going from memory so I could be a bit rusty, but I think it's close. Hope it
helps,
- Jeff



________________________________
From: E R
To: modperl
Sent: Mon, February 28, 2011 1:03:41 PM
Subject: How to reference %Location outside of ...?

I have the following block in my httpd.conf file which installs
mod-perl handlers for a list of urls:


...
for my $uri (...) {
$Location{$uri} = ...;
}


If I wanted to move this code to a normal perl module, how should I
reference %Location?

Thanks,
ER

--0-103706503-1298932888=:85213
Content-Type: text/html; charset=us-ascii

I've seen it done where you can make a home-grown module that has a second package declaration for Apache[2]::ReadConfig.  Something like ...


... in httpd.conf ...

<Perl>
   use Some::Module;
   Some::Module::my_custom_config();
</Perl>



... in Module.pm ...

package Some::Module;


sub my_custom_config(;){

   package Apache2::ReadConfig;
<
div>
   use strict;
   use vars qw(
          $ServerName $ServerRoot $DocumentRoot $User
$Group
          @PerlChildInitHandler @PerlChildExitHandler
          %DirectoryMatch %Directory %Location
          ...
       );

   for my $uri (...) {
      $Location{$uri} ...



You can reference:     for a bit more info as well.

Going from memory so I could be a bit rusty, but I think it's close.  Hope it helps,
- Jeff
="font-family:courier, monaco, monospace, sans-serif;font-size:10pt">
face="Tahoma">
From: E R <pc88mxer@gmail.com>
To: modperl <modperl@perl.apache.org>
Sent: Mon, February 28, 2011 1:03:41 PM
Subject: How to reference %Location outside of <Perl>...</Perl>?


I have the following <Perl> block in my httpd.conf file which installs
mod-perl handlers for a list of urls:

<Perl>
  ...
  for my $uri (...) {
    $Location{$uri} = ...;
  }
</Perl>

If I wanted to move this code to a normal perl module, how should I
reference %Location?

Thanks,
ER




--0-103706503-1298932888=:85213--

Re: How to reference %Location outside of <Perl>...</Perl>?

am 01.03.2011 20:24:16 von E R

On Mon, Feb 28, 2011 at 4:41 PM, Jeff Nokes wrote:
> I've seen it done where you can make a home-grown module that has a secon=
d
> package declaration for Apache[2]::ReadConfig. =A0Something like ...

Thanks, I've found that this works:


use Some::Module;
Some::Module::init(__PACKAGE__);


package Some::Module;

sub init {
my $package =3D shift;
*Redirect =3D *{ $package . "::Redirect" };
push(@Redirect, [ '/to-cnn', 'http://cnn.com' ]);
...
}

Modperl2 uses a different package name for each block.