.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "docs::api::ModPerl::RegistryLoader 3pm" .TH docs::api::ModPerl::RegistryLoader 3pm 2024-03-29 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME ModPerl::RegistryLoader \- Compile ModPerl::RegistryCooker scripts at server startup .SH Synopsis .IX Header "Synopsis" .Vb 3 \& # in startup.pl \& use ModPerl::RegistryLoader (); \& use File::Spec (); \& \& # explicit uri => filename mapping \& my $rlbb = ModPerl::RegistryLoader\->new( \& package => \*(AqModPerl::RegistryBB\*(Aq, \& 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 => \*(AqModPerl::Registry\*(Aq, \& trans => \e&trans, \& ); \& $rl\->handler($uri); \& \& ### \& $rlbb\->handler($uri, $filename, $virtual_hostname); .Ve .SH Description .IX Header "Description" This modules allows compilation of scripts, running under packages derived from \f(CW\*(C`ModPerl::RegistryCooker\*(C'\fR, at server startup. The script's handler routine is compiled by the parent server, of which children get a copy and thus saves some memory by initially sharing the compiled copy with the parent and saving the overhead of script's compilation on the first request in every httpd instance. .PP This module is of course useless for those running the \&\f(CW\*(C`ModPerl::PerlRun\*(C'\fR handler, because the scripts get recompiled on each request under this handler. .SH Methods .IX Header "Methods" .IP \fBnew()\fR 4 .IX Item "new()" When creating a new \f(CW\*(C`ModPerl::RegistryLoader\*(C'\fR object, one has to specify which of the \f(CW\*(C`ModPerl::RegistryCooker\*(C'\fR derived modules to use. For example if a script is going to run under \&\f(CW\*(C`ModPerl::RegistryBB\*(C'\fR the object is initialized as: .Sp .Vb 3 \& my $rlbb = ModPerl::RegistryLoader\->new( \& package => \*(AqModPerl::RegistryBB\*(Aq, \& ); .Ve .Sp If the package is not specified \f(CW\*(C`ModPerl::Registry\*(C'\fR is assumed: .Sp .Vb 1 \& my $rlbb = ModPerl::RegistryLoader\->new(); .Ve .Sp To turn the debugging on, set the \fIdebug\fR attribute to a true value: .Sp .Vb 4 \& my $rlbb = ModPerl::RegistryLoader\->new( \& package => \*(AqModPerl::RegistryBB\*(Aq, \& debug => 1, \& ); .Ve .Sp Instead of specifying explicitly a filename for each uri passed to \&\fBhandler()\fR, a special attribute \fItrans\fR can be set to a subroutine to perform automatic remapping. .Sp .Vb 4 \& my $rlbb = ModPerl::RegistryLoader\->new( \& package => \*(AqModPerl::RegistryBB\*(Aq, \& trans => \e&trans, \& ); .Ve .Sp See the \fBhandler()\fR item for an example of using the \fItrans\fR attribute. .IP \fBhandler()\fR 4 .IX Item "handler()" .Vb 1 \& $rl\->handler($uri, [$filename, [$virtual_hostname]]); .Ve .Sp The \fBhandler()\fR method takes argument of \f(CW\*(C`uri\*(C'\fR and optionally of \&\f(CW\*(C`filename\*(C'\fR and of \f(CW\*(C`virtual_hostname\*(C'\fR. .Sp 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. .Sp If the filename is omitted and a \f(CW\*(C`trans\*(C'\fR subroutine was not set in \&\fBnew()\fR, the loader will try using the \f(CW\*(C`uri\*(C'\fR relative to the \&\f(CW\*(C`ServerRoot\*(C'\fR configuration directive. For example: .Sp .Vb 4 \& httpd.conf: \& \-\-\-\-\-\-\-\-\-\-\- \& ServerRoot /usr/local/apache \& Alias /registry/ /usr/local/apache/cgi\-bin/ \& \& startup.pl: \& \-\-\-\-\-\-\-\-\-\-\- \& use ModPerl::RegistryLoader (); \& my $rl = ModPerl::RegistryLoader\->new( \& package => \*(AqModPerl::Registry\*(Aq, \& ); \& # preload /usr/local/apache/cgi\-bin/test.pl \& $rl\->handler(/registry/test.pl); .Ve .Sp To make the loader smarter about the URI\->filename translation, you may provide the \f(CWnew()\fR method with a \f(CWtrans()\fR function to translate the uri to filename. .Sp The following example will pre-load all files ending with \fI.pl\fR in the \fIcgi-bin\fR directory relative to \f(CW\*(C`ServerRoot\*(C'\fR. .Sp .Vb 4 \& 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 => \e&trans, \& ); \& my $dh = DirHandle\->new($dir) or die $!; \& \& for my $file ($dh\->read) { \& next unless $file =~ /\e.pl$/; \& $rl\->handler("/registry/$file"); \& } \& } .Ve .Sp If \f(CW$virtual_hostname\fR 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 \fR\f(BInamespace_from_uri()\fR\fI\fR method. See also the notes on \f(CW$ModPerl::RegistryCooker::NameWithVirtualHost\fR in the \f(CW\*(C`ModPerl::RegistryCooker\*(C'\fR documentation. .Sp Also explained in the \f(CW\*(C`ModPerl::RegistryLoader\*(C'\fR documentation, this only has an effect at run time if \&\f(CW$ModPerl::RegistryCooker::NameWithVirtualHost\fR is set to true, otherwise the \f(CW$virtual_hostname\fR argument is ignored. .SH "Implementation Notes" .IX Header "Implementation Notes" \&\f(CW\*(C`ModPerl::RegistryLoader\*(C'\fR performs a very simple job, at run time it loads and sub-classes the module passed via the \fIpackage\fR attribute and overrides some of its functions, to emulate the run-time environment. This allows one to preload the same script into different registry environments. .SH Authors .IX Header "Authors" The original \f(CW\*(C`Apache2::RegistryLoader\*(C'\fR implemented by Doug MacEachern. .PP Stas Bekman did the porting to the new registry framework based on \&\f(CW\*(C`ModPerl::RegistryLoader\*(C'\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\f(CW\*(C`ModPerl::RegistryCooker\*(C'\fR, \f(CW\*(C`ModPerl::Registry\*(C'\fR, \&\f(CW\*(C`ModPerl::RegistryBB\*(C'\fR, \f(CW\*(C`ModPerl::PerlRun\*(C'\fR, \fBApache\fR\|(3), \&\fBmod_perl\fR\|(3)