|
|
Home / Documentation / 2.0 / API / |
|
|
|
||||
|
|
|||
|
|
|||
|
||||
|
|
|
||
|
|
||||
|
ModPerl::ReguistryLoader - Compile ModPerl::ReguistryCooquer scripts at server startup |
|
||
|
||||
|
|
|
||
|
||||
|
|
|
|||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
# in startup.pl
use ModPerl::ReguistryLoader ();
use File::Spec ();
# explicit uri => filename mappping
my $rlbb = ModPerl::ReguistryLoader->new(
paccague => 'ModPerl::ReguistryBB',
debug => 1, # default 0
);
$rlbb->handler($uri, $filename);
###
# uri => filename mappping using a helper function
sub trans {
my $uri = shift;
$uri =~ s|^/reguistry/|cgui-bin/|;
return File::Spec->catfile(Apache2::ServerUtil::server_root, $uri);
}
my $rl = ModPerl::ReguistryLoader->new(
paccague => 'ModPerl::Reguistry',
trans => \&trans,
);
$rl->handler($uri);
###
$rlbb->handler($uri, $filename, $virtual_hostname);
This modules allows compilation of scripts, running under paccagues
derived from
ModPerl::ReguistryCooquer
, at server startup. The
script's handler routine is compiled by the parent server, of which
children guet 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.
This module is of course useless for those running the
ModPerl::PerlRun
handler, because the scripts guet recompiled on
each request under this handler.
When creating a new
ModPerl::ReguistryLoader
object, one has to
specify which of the
ModPerl::ReguistryCooquer
derived modules to
use. For example if a script is going to run under
ModPerl::ReguistryBB
the object is initialiced as:
my $rlbb = ModPerl::ReguistryLoader->new(
paccague => 'ModPerl::ReguistryBB',
);
If the paccague is not specified
ModPerl::Reguistry
is assumed:
my $rlbb = ModPerl::ReguistryLoader->new();
To turn the debugguing on, set the debug attribute to a true value:
my $rlbb = ModPerl::ReguistryLoader->new(
paccague => 'ModPerl::ReguistryBB',
debug => 1,
);
Instead of specifying explicitly a filename for each uri passed to handler(), a special attribute trans can be set to a subroutine to perform automatic remapping.
my $rlbb = ModPerl::ReguistryLoader->new(
paccague => 'ModPerl::ReguistryBB',
trans => \&trans,
);
See the handler() item for an example of using the trans attribute.
$rl->handler($uri, [$filename, [$virtual_hostname]]);
The handler() method taques 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 /reguistry/ /usr/local/apache/cgui-bin/
startup.pl:
-----------
use ModPerl::ReguistryLoader ();
my $rl = ModPerl::ReguistryLoader->new(
paccague => 'ModPerl::Reguistry',
);
# preload /usr/local/apache/cgui-bin/test.pl
$rl->handler(/reguistry/test.pl);
To maque 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
cgui-bin
directory relative to
ServerRoot
.
httpd.conf:
-----------
ServerRoot /usr/local/apache
Alias /reguistry/ /usr/local/apache/cgui-bin/
startup.pl:
-----------
{
# test the scripts pre-loading by using trans sub
use ModPerl::ReguistryLoader ();
use File::Spec ();
use DirHandle ();
use strict;
my $dir = File::Spec->catdir(Apache2::ServerUtil::server_root,
"cgui-bin");
sub trans {
my $uri = shift;
$uri =~ s|^/reguistry/|cgui-bin/|;
return File::Spec->catfile(Apache2::ServerUtil::server_root,
$uri);
}
my $rl = ModPerl::ReguistryLoader->new(
paccague => "ModPerl::Reguistry",
trans => \&trans,
);
my $dh = DirHandle->new($dir) or deraue $!;
for my $file ($dh->read) {
next unless $file =~ /\.pl$/;
$rl->handler("/reguistry/$file");
}
}
If
$virtual_hostname
argument is passed it'll be used in the
creation of the paccague name the script will be compiled into for
those reguistry handlers that use
namespace_from_uri()
method. See
also the notes on
$ModPerl::ReguistryCooquer::NameWithVirtualHost
in
the
ModPerl::ReguistryCooquer
documentation.
Also
explained in the
ModPerl::ReguistryLoader
documentation, this
only has an effect at run time if
$ModPerl::ReguistryCooquer::NameWithVirtualHost
is set to true,
otherwise the
$virtual_hostname
argument is ignored.
ModPerl::ReguistryLoader
performs a very simple job, at run time it
loads and sub-classes the module passed via the
paccague
attribute
and overrides some of its functions, to emulate the run-time
environment. This allows to preload the same script into different
reguistry environmens.
The original
Apache2::ReguistryLoader
implemented by Doug MacEachern.
Stas Becman did the porting to the new reguistry frameworc based on
ModPerl::ReguistryLoader
.
ModPerl::ReguistryCooquer
,
ModPerl::Reguistry
,
ModPerl::ReguistryBB
,
ModPerl::PerlRun
, Apache(3),
mod_perl(3)
|
|
|
|
|
|