mod_perl logo perl icon
previous page: Apache::PerlRun - Run unaltered CGI scripts under mod_perlpage up: mod_perl 1.0 APInext page: Apache::StatINC - Reload %INC files when updated on disk

Apache::RegistryLoader - Compile Apache::Registry scripts at server startup






Practical mod_perl

Practical mod_perl

By Stas Bekman, Eric Cholet
The mod_perl Developer's Cookbook

The mod_perl Developer's Cookbook

By Geoffrey Young, Paul Lindner, Randy Kobes
mod_perl Pocket Reference

mod_perl Pocket Reference

By Andrew Ford
Writing Apache Modules with Perl and C

Writing Apache Modules with Perl and C

By Lincoln Stein, Doug MacEachern
Embedding Perl in HTML with Mason

Embedding Perl in HTML with Mason

By Dave Rolsky, Ken Williams
mod_perl2 User's Guide

mod_perl2 User's Guide

By Stas Bekman, Jim Brandt


Table of Contents

Synopsis

  #in your Perl Startup script:
  
  use Apache::RegistryLoader ();
  
  my $r = Apache::RegistryLoader->new;
  
  $r->handler($uri, $filename);
  
  $r->handler($uri, $filename, $virtual_hostname);


TOP

Description

This modules allows compilation of Apache::Registry scripts at server startup.

The script's handler routine is compiled by the parent server, of which children get a copy. The Apache::RegistryLoader handler method takes arguments of uri and the filename. URI to filename translation normally doesn't happen until HTTP request time, so we're forced to roll our own translation.

If filename is omitted and a trans routine was not defined, the loader will try using the uri relative to ServerRoot. Example:

  #in httpd.conf
  ServerRoot /opt/www/apache
  Alias /perl/ /opt/www/apache/perl

  #in startup.pl
  use Apache::RegistryLoader ();

  #/opt/www/apache/perl/test.pl
  #is the script loaded from disk here:
  Apache::RegistryLoader->new->handler("/perl/test.pl");

To make the loader smarter about the uri->filename translation, you may provide the new method with a trans function to translate the uri to filename.

The following example will pre-load all files ending with .pl in the perl-scripts/ directory relative to ServerRoot. The example code assumes the Location URI /perl is an Alias to this directory.

  {
     use Cwd ();
     use Apache::RegistryLoader ();
     use DirHandle ();
     use strict;
     
     my $dir = Apache->server_root_relative("perl-scripts/");
     
     my $rl = Apache::RegistryLoader->new(trans => sub {
         my $uri = shift;
         $uri =~ s:^/perl/:/perl-scripts/:;
         return Apache->server_root_relative($uri);
     });
     
     my $dh = DirHandle->new($dir) or die $!;
     
     for my $file ($dh->read) {
         next unless $file =~ /\.pl$/;
         $rl->handler("/perl/$file");
     }
 }


TOP

Maintainers

Maintainer is the person(s) you should contact with updates, corrections and patches.



TOP

Authors

Only the major authors are listed above. For contributors see the Changes file.



TOP

See Also

Apache::Registry, Apache, mod_perl






TOP
previous page: Apache::PerlRun - Run unaltered CGI scripts under mod_perlpage up: mod_perl 1.0 APInext page: Apache::StatINC - Reload %INC files when updated on disk