docs::a...yLoader(3)
hey bestie! π welcome to docs::a...yLoader(3) β the User Contributed Perl Documentation page for ModPerl::RegistryLoader. it's giving "compile scripts at server startup" and honestly? iconic. β¨
π NAME π
ModPerl::RegistryLoader β compile ModPerl::RegistryCooker scripts at server startup. literally that's the whole job, and it ate. π
β¨ Synopsis β¨
okay so first, the group-chat recap. in startup.pl you can do this whole situation:
# in startup.pl
use ModPerl::RegistryLoader ();
use File::Spec ();
# explicit uri => filename mapping
my $rlbb = ModPerl::RegistryLoader->new(
package => 'ModPerl::RegistryBB',
debug => 1, # default 0
);
$rlbb->handler($uri, $filename);
###
# uri => filename mapping using a helper function
sub trans {
my $uri = shift;
$uri =~ s|^/registry/|cgi-bin/|;
return File::Spec->catfile(Apache2::ServerUtil::server_root, $uri);
}
my $rl = ModPerl::RegistryLoader->new(
package => 'ModPerl::Registry',
trans => \&trans,
);
$rl->handler($uri);
###
$rlbb->handler($uri, $filename, $virtual_hostname);
and yes, $rlbb->handler($uri, $filename, $virtual_hostname); is in there too β full mapping, helper-function mapping, and the three-argument preload. no cap. π«Ά
π¦ Description π¦
This module lets you compile scripts that run under packages derived from ModPerl::RegistryCooker at server startup. the script's handler routine gets compiled by the parent server, and then children get a copy β so you're initially sharing the compiled copy with the parent and saving some memory, plus saving the overhead of compiling the script on the first request in every httpd instance. highkey efficient. π₯
heads up bestie: this module is of course useless for those running the ModPerl::PerlRun handler, because scripts get recompiled on each request under that handler. π
π Methods π
β¨ new() β¨
When you make a new ModPerl::RegistryLoader object, you have to specify which ModPerl::RegistryCooker-derived module to use. for example, if a script is going to run under ModPerl::RegistryBB, initialize it like this:
my $rlbb = ModPerl::RegistryLoader->new(
package => 'ModPerl::RegistryBB',
);
If the package is not specified, ModPerl::Registry is assumed:
my $rlbb = ModPerl::RegistryLoader->new();
To turn debugging on, set the debug attribute to a true value:
my $rlbb = ModPerl::RegistryLoader->new(
package => 'ModPerl::RegistryBB',
debug => 1,
);
Instead of specifying a filename explicitly for each uri passed to handler(), you can set the special attribute trans to a subroutine that performs automatic remapping:
my $rlbb = ModPerl::RegistryLoader->new(
package => 'ModPerl::RegistryBB',
trans => \&trans,
);
See the handler() item for an example of using the trans attribute. iykyk. π
πΈ handler() πΈ
$rl->handler($uri, [$filename, [$virtual_hostname]]);
The handler() method takes an argument of uri and optionally of filename and of virtual_hostname.
URI to filename translation normally doesn't happen until HTTP request time, so we're forced to roll our own translation. If the filename is supplied, it's used in translation.
If the filename is omitted and a trans subroutine was not set in new(), the loader will try using the uri relative to the ServerRoot configuration directive. for example:
httpd.conf:
-----------
ServerRoot /usr/local/apache
Alias /registry/ /usr/local/apache/cgi-bin/
startup.pl:
-----------
use ModPerl::RegistryLoader ();
my $rl = ModPerl::RegistryLoader->new(
package => 'ModPerl::Registry',
);
# preload /usr/local/apache/cgi-bin/test.pl
$rl->handler(/registry/test.pl);
To make the loader smarter about the URI->filename translation, you can 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 cgi-bin directory relative to ServerRoot.
httpd.conf:
-----------
ServerRoot /usr/local/apache
Alias /registry/ /usr/local/apache/cgi-bin/
startup.pl:
-----------
{
# test the scripts pre-loading by using trans sub
use ModPerl::RegistryLoader ();
use File::Spec ();
use DirHandle ();
use strict;
my $dir = File::Spec->catdir(Apache2::ServerUtil::server_root,
"cgi-bin");
sub trans {
my $uri = shift;
$uri =~ s|^/registry/|cgi-bin/|;
return File::Spec->catfile(Apache2::ServerUtil::server_root,
$uri);
}
my $rl = ModPerl::RegistryLoader->new(
package => "ModPerl::Registry",
trans => \&trans,
);
my $dh = DirHandle->new($dir) or die $!;
for my $file ($dh->read) {
next unless $file =~ /\.pl$/;
$rl->handler("/registry/$file");
}
}
If the $virtual_hostname argument is passed, it'll be used in the creation of the package name the script will be compiled into for those registry handlers that use the namespace_from_uri() method. see also the notes on $ModPerl::RegistryCooker::NameWithVirtualHost in the ModPerl::RegistryCooker documentation.
Also explained in the ModPerl::RegistryLoader documentation: this only has an effect at run time if $ModPerl::RegistryCooker::NameWithVirtualHost is set to true, otherwise the $virtual_hostname argument is ignored. periodt. π
π§ Implementation Notes π§
ModPerl::RegistryLoader performs a very simple job: at run time it loads and sub-classes the module passed via the package attribute and overrides some of its functions to emulate the run-time environment. this allows you to preload the same script into different registry environments. lowkey clever. β
π Authors π
The original Apache2::RegistryLoader was implemented by Doug MacEachern.
Stas Bekman did the porting to the new registry framework based on ModPerl::RegistryLoader. π
π SEE ALSO π
ModPerl::RegistryCooker, ModPerl::Registry, ModPerl::RegistryBB, ModPerl::PerlRun, Apache(3), mod_perl(3) β go read the whole family, bestie. π«Ά
bye bestie! π signing off from perl v5.42.3, dated 2023-10-21, on the docs::a...yLoader(3) page β stay preloaded and unbothered. πβ¨
π¦ where this page comes from
- nixos 26.05: mod_perl 2.0.13
- nixpkgs unstable: mod_perl 2.0.13
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms