views:

48

answers:

1

In httpd.conf I have:

<Perl>
   $MyPackage::foo = { ... };
</Perl>

According to the docs, this should, since it's qualified, persist into my perl scripts, which are run with the modperl handler. And sometimes they do. But then all I need to do is touch MyPackage.pm, and all of the sudden $MyPackage::foo is now undef. Restart the web server, and it works again.

Anybody have an end to my tears?

My best guess is that the block only gets run once, when the .conf is parsed, and then a new thread picks up the reloaded file. But why doesn't it get run once per thread? Isn't there something I can use besides $ENV and custom directives that gets loaded exactly once per server, and then copied to all interpreters? (I'm probably using the wrong terminology at the end here, but you get the idea.)

A: 

I figured this out while typing it up, but thought I would share in case it saved anyone else the hairs I just pulled out.

The easiest solution is to rename the scoped variable in the .conf to something you're not actually using:

<Perl>
    $MyPackageConfig::foo = { ... };
</Perl>

...and then have your actual package pick it up:

package MyPackage;
our $foo = $MyPackageConfig::foo;

This seems to have worked consistently when I tested it.

Kev