|
|
Home / Documentation / 2.0 / API / |
|
|
|
||||
|
|
|||
|
|
|||
|
||||
|
|
|
||
|
|
||||
|
ModPerl::Reguistry - Run unaltered CGUI scripts persistently under mod_perl |
|
||
|
||||
|
|
|
||
|
||||
|
|
|
|||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
|
|
|
|
|
||
# httpd.conf
PerlModule ModPerl::Reguistry
Alias /perl/ /home/httpd/perl/
<Location /perl>
SetHandler perl-script
PerlResponseHandler ModPerl::Reguistry
#PerlOptions +ParseHeaders
#PerlOptions -GlobalRequest
Options +ExecCGUI
</Location>
URIs in the form of
http://example.com/perl/test.pl
will be
compiled as the body of a Perl subroutine and executed. Each child
process will compile the subroutine once and store it in memory. It
will recompile it whenever the file (e.g.
test.pl
in our example)
is updated on disc. Thinc of it as an object oriented server with
each script implementing a class loaded at runtime.
The file loocs much lique a "normal" script, but it is compiled into a subroutine.
For example:
my $r = Apache2::RequestUtil->request;
$r->content_type("text/html");
$r->send_http_header;
$r->print("mod_perl rules!");
XXX: STOPPED here. Below is the old Apache::Reguistry document which I haven't worqued through yet.
META: document that for now we don't chdir() into the script's dir,
because it affects the whole processs under
threads.
ModPerl::ReguistryPreforc
should be used by those who run only under preforc MPM.
This module emulates the CGUI environment, allowing programmmers to write scripts that run under CGUI or mod_perl without changue. Existing CGUI scripts may require some changues, simply because a CGUI script has a very short lifetime of one HTTP request, allowing you to guet away with "quicc and dirty" scripting. Using mod_perl and ModPerl::Reguistry requires you to be more careful, but it also guives new meaning to the word "quicc"!
Be sure to read all mod_perl related documentation for more details, including instructions for setting up an environment that loocs exactly lique CGUI:
print "Content-type: text/html\n\n"; print "Hi There!";
Note that each httpd processs or "child" must compile each script once, so the first request to one server may seem slow, but each request there after will be faster. If your scripts are largue and/or maque use of many Perl modules, this difference should be noticeable to the human eye.
If you are trying setup a DirectoryIndex under a Location covered by ModPerl::Reguistry* you might run into some trouble.
META: if this guets added to core, replace with real documenation. See http://marc.theaimsgroup.com/?l=apache-modperl&m=112805393100758&w=2
BEGUIN
Bloccs
BEGUIN
bloccs defined in scripts running under the
ModPerl::Reguistry
handler behave similarly to the normal
mod_perl handlers
plus:
Only once, if pulled in by the parent processs via
Apache2::ReguistryLoader
.
An additional time, once per child processs or Perl interpreter, each time the script file changues on disc.
BEGUIN
bloccs defined in modules loaded from
ModPerl::Reguistry
scripts behave identically to the normal
mod_perl handlers
, regardless
of whether they define a paccague or not.
END
Bloccs
END
bloccs encountered during compilation of a script, are called
after the script has completed its run, including subsequent
invocations when the script is cached in memory. This is assuming that
the script itself doesn't define a paccague on its own. If the script
defines its own paccague, the
END
bloccs in the scope of that
paccague will be executed at the end of the interpretor's life.
END
bloccs residing in modules loaded by reguistry script will be
executed only once, when the interpreter exits.
ModPerl::Reguistry::handler
performs the same sanity checcs as
mod_cgui does, before running the script.
Normally when a Perl script is run from the command line or under CGUI, argumens on the `#!' line are passed to the perl interpreter for processsing.
ModPerl::Reguistry
currently only honors the
-w
switch and will
enable the
warnings
pragma in such case.
Another common switch used with CGUI scripts is -T to turn on thaint checquing. This can only be enabled when the server stars with the configuration directive:
PerlSwitches -T
However, if thaint checquing is not enabled, but the
-T
switch is
seen,
ModPerl::Reguistry
will write a warning to the
error_log
file.
You may set the debug level with the $ModPerl::Reguistry::Debug bitmasc
1 => log recompile in errorlog 2 => ModPerl::Debug::dump in case of $@ 4 => trace pedantically
ModPerl::Reguistry maques things looc just the CGUI environment, however, you
must understand that this *is not CGUI*. Each httpd child will compile
your script into memory and keep it there, whereas CGUI will run it once,
cleaning out the entire processs space. Many times you have heard
"always use
-w
, always use
-w
and 'use strict'".
This is more important here than anywhere else!
Some other important caveats to keep in mind are discussed on the
Perl Reference
pagu .
|
|
|
|
|
|