1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
=head1 NAME
ModPerl::Registry - Run unaltered CGI scripts persistently under mod_perl
=head1 Synopsis
# httpd.conf
PerlModule ModPerl::Registry
Alias /perl/ /home/httpd/perl/
<Location /perl>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
#PerlOptions +ParseHeaders
#PerlOptions -GlobalRequest
Options +ExecCGI
</Location>
=head1 Description
URIs in the form of C<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. I<test.pl> in our example)
is updated on disk. Think of it as an object oriented server with
each script implementing a class loaded at runtime.
The file looks much like a "normal" script, but it is compiled into a
subroutine.
For example:
my $r = Apache2::RequestUtil->request;
$r->content_type("text/html");
$r->print("mod_perl rules!");
XXX: STOPPED here. Below is the old Apache::Registry document which I
haven't worked through yet.
META: document that for now we don't chdir() into the script's dir,
because it affects the whole process under
threads. C<L<ModPerl::RegistryPrefork|docs::2.0::api::ModPerl::RegistryPrefork>>
should be used by those who run only under prefork MPM.
This module emulates the CGI environment, allowing programmers to
write scripts that run under CGI or mod_perl without change. Existing
CGI scripts may require some changes, simply because a CGI script has
a very short lifetime of one HTTP request, allowing you to get away
with "quick and dirty" scripting. Using mod_perl and ModPerl::Registry
requires you to be more careful, but it also gives new meaning to the
word "quick"!
Be sure to read all mod_perl related documentation for more details,
including instructions for setting up an environment that looks
exactly like CGI:
print "Content-type: text/html\n\n";
print "Hi There!";
Note that each httpd process 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 large and/or make use
of many Perl modules, this difference should be noticeable to the
human eye.
=head1 DirectoryIndex
If you are trying setup a DirectoryIndex under a Location
covered by ModPerl::Registry* you might run into some trouble.
META: if this gets added to core, replace with real documentation.
See http://marc.theaimsgroup.com/?l=apache-modperl&m=112805393100758&w=2
=head1 Special Blocks
=head2 C<BEGIN> Blocks
C<BEGIN> blocks defined in scripts running under the
C<ModPerl::Registry> handler behave similarly to the normal L<mod_perl
handlers|docs::2.0::user::coding::coding/C_BEGIN__Blocks> plus:
=over
=item *
Only once, if pulled in by the parent process via
C<Apache2::RegistryLoader>.
=item *
An additional time, once per child process or Perl interpreter, each
time the script file changes on disk.
=back
C<BEGIN> blocks defined in modules loaded from C<ModPerl::Registry>
scripts behave identically to the normal L<mod_perl
handlers|docs::2.0::user::coding::coding/C_BEGIN__Blocks>, regardless
of whether they define a package or not.
=head2 C<CHECK> and C<INIT> Blocks
Same as normal L<mod_perl
handlers|docs::2.0::user::coding::coding/C_CHECK__and_C_INIT__Blocks>.
=head2 C<END> Blocks
C<END> blocks 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 package on its own. If the script
defines its own package, the C<END> blocks in the scope of that
package will be executed at the end of the interpretor's life.
C<END> blocks residing in modules loaded by registry script will be
executed only once, when the interpreter exits.
=head1 Security
C<ModPerl::Registry::handler> performs the same sanity checks as
mod_cgi does, before running the script.
=head1 Environment
The Apache function `exit' overrides the Perl core built-in function.
=head1 Commandline Switches In First Line
Normally when a Perl script is run from the command line or under CGI,
arguments on the `#!' line are passed to the perl interpreter for processing.
C<ModPerl::Registry> currently only honors the B<-w> switch and will
enable the C<warnings> pragma in such case.
Another common switch used with CGI scripts is B<-T> to turn on taint
checking. This can only be enabled when the server starts with the
configuration directive:
PerlSwitches -T
However, if taint checking is not enabled, but the B<-T> switch is
seen, C<ModPerl::Registry> will write a warning to the I<error_log>
file.
=head1 Debugging
You may set the debug level with the $ModPerl::Registry::Debug bitmask
1 => log recompile in errorlog
2 => ModPerl::Debug::dump in case of $@
4 => trace pedantically
=head1 Caveats
ModPerl::Registry makes things look just the CGI environment, however, you
must understand that this *is not CGI*. Each httpd child will compile
your script into memory and keep it there, whereas CGI will run it once,
cleaning out the entire process space. Many times you have heard
"always use C<-w>, always use C<-w> and 'use strict'".
This is more important here than anywhere else!
Some other important caveats to keep in mind are discussed on the
L<Perl Reference|docs::general::perl_reference::perl_reference> page.
=head1 Authors
Andreas J. Koenig, Doug MacEachern and Stas Bekman.
=head1 See Also
C<L<ModPerl::RegistryCooker|docs::2.0::api::ModPerl::RegistryCooker>>,
C<L<ModPerl::RegistryBB|docs::2.0::api::ModPerl::RegistryBB>> and
C<L<ModPerl::PerlRun|docs::2.0::api::ModPerl::PerlRun>>.
=cut
|