Preloading mod_perl Scripts

| | Comments (0)
I was trying to figure out how to preload mod_perl scripts, and I was told by several people to use the PerlRequire directive. The problem is, that's entirely wrong.

PerlRequire just does a require(). But what mod_perl does, via Apache::Registry, is load the text of the script, add some stuff to it, including a new package directive, eval it, and install it into its registry. A require(), or PerlRequire, will not do anything to help here.

The correct answer is Apache::RegistryLoader. I ended up using something like this.

PerlModule Apache::RegistryLoader
<Perl>
my @pls     = qw(names of scripts or something);
my $vhost   = 'hostname.example.com';
my $docroot = '/path/to/scripts';
my $r       = Apache::RegistryLoader->new;
 
for my $u (@pls) {
    my $f = "$docroot/$u.pl";
    $r->handler("/$u.pl", $f, $vhost) if -e $f;
}
</Perl>

I know this is in various FAQs, but 1. my DNS was acting up and I was having trouble getting anywhere, 2. I found plenty of people contradicting the FAQs, and 3. I had to add the virtual host parameter before it would work properly (else it would install the script in a different package than what it would be called as later), which wasn't in the FAQ.

Now Playing: Beyond Beautiful - Aerosmith (Just push play)

use.perl.org

Leave a comment

<pudge/*> (pronounced "PudgeGlob") is thousands of posts over many years by Pudge.

"It is the common fate of the indolent to see their rights become a prey to the active. The condition upon which God hath given liberty to man is eternal vigilance; which condition if he break, servitude is at once the consequence of his crime and the punishment of his guilt."

About this Entry

This page contains a single entry by pudge published on January 16, 2003 6:47 AM.

Why Do You Create? was the previous entry in this site.

Not Over Yet is the next entry in this site.

Find recent content on the main index or look in the archives to find all content.