1docs::api::ModPerl::RegUissetrryC(o3n)tributed Perl Docudmoecnst:a:taipoin::ModPerl::Registry(3)
2
3
4
6 ModPerl::Registry - Run unaltered CGI scripts persistently under
7 mod_perl
8
10 # httpd.conf
11 PerlModule ModPerl::Registry
12 Alias /perl/ /home/httpd/perl/
13 <Location /perl>
14 SetHandler perl-script
15 PerlResponseHandler ModPerl::Registry
16 #PerlOptions +ParseHeaders
17 #PerlOptions -GlobalRequest
18 Options +ExecCGI
19 </Location>
20
22 URIs in the form of "http://example.com/perl/test.pl" will be compiled
23 as the body of a Perl subroutine and executed. Each child process will
24 compile the subroutine once and store it in memory. It will recompile
25 it whenever the file (e.g. test.pl in our example) is updated on disk.
26 Think of it as an object oriented server with each script implementing
27 a class loaded at runtime.
28
29 The file looks much like a "normal" script, but it is compiled into a
30 subroutine.
31
32 For example:
33
34 my $r = Apache2::RequestUtil->request;
35 $r->content_type("text/html");
36 $r->send_http_header;
37 $r->print("mod_perl rules!");
38
39 XXX: STOPPED here. Below is the old Apache::Registry document which I
40 haven't worked through yet.
41
42 META: document that for now we don't chdir() into the script's dir,
43 because it affects the whole process under threads. "ModPerl::Reg‐
44 istryPrefork" should be used by those who run only under prefork MPM.
45
46 This module emulates the CGI environment, allowing programmers to write
47 scripts that run under CGI or mod_perl without change. Existing CGI
48 scripts may require some changes, simply because a CGI script has a
49 very short lifetime of one HTTP request, allowing you to get away with
50 "quick and dirty" scripting. Using mod_perl and ModPerl::Registry
51 requires you to be more careful, but it also gives new meaning to the
52 word "quick"!
53
54 Be sure to read all mod_perl related documentation for more details,
55 including instructions for setting up an environment that looks exactly
56 like CGI:
57
58 print "Content-type: text/html\n\n";
59 print "Hi There!";
60
61 Note that each httpd process or "child" must compile each script once,
62 so the first request to one server may seem slow, but each request
63 there after will be faster. If your scripts are large and/or make use
64 of many Perl modules, this difference should be noticeable to the human
65 eye.
66
68 If you are trying setup a DirectoryIndex under a Location covered by
69 ModPerl::Registry* you might run into some trouble.
70
71 META: if this gets added to core, replace with real documenation. See
72 http://marc.theaimsgroup.com/?l=apache-modperl&m=112805393100758&w=2
73
75 "BEGIN" Blocks
76
77 "BEGIN" blocks defined in scripts running under the "ModPerl::Registry"
78 handler behave similarly to the normal mod_perl handlers plus:
79
80 · Only once, if pulled in by the parent process via "Apache2::Reg‐
81 istryLoader".
82
83 · An additional time, once per child process or Perl interpreter,
84 each time the script file changes on disk.
85
86 "BEGIN" blocks defined in modules loaded from "ModPerl::Registry"
87 scripts behave identically to the normal mod_perl handlers, regardless
88 of whether they define a package or not.
89
90 "CHECK" and "INIT" Blocks
91
92 Same as normal mod_perl handlers.
93
94 "END" Blocks
95
96 "END" blocks encountered during compilation of a script, are called
97 after the script has completed its run, including subsequent invoca‐
98 tions when the script is cached in memory. This is assuming that the
99 script itself doesn't define a package on its own. If the script
100 defines its own package, the "END" blocks in the scope of that package
101 will be executed at the end of the interpretor's life.
102
103 "END" blocks residing in modules loaded by registry script will be exe‐
104 cuted only once, when the interpreter exits.
105
107 "ModPerl::Registry::handler" performs the same sanity checks as mod_cgi
108 does, before running the script.
109
111 The Apache function `exit' overrides the Perl core built-in function.
112
114 Normally when a Perl script is run from the command line or under CGI,
115 arguments on the `#!' line are passed to the perl interpreter for pro‐
116 cessing.
117
118 "ModPerl::Registry" currently only honors the -w switch and will enable
119 the "warnings" pragma in such case.
120
121 Another common switch used with CGI scripts is -T to turn on taint
122 checking. This can only be enabled when the server starts with the
123 configuration directive:
124
125 PerlSwitches -T
126
127 However, if taint checking is not enabled, but the -T switch is seen,
128 "ModPerl::Registry" will write a warning to the error_log file.
129
131 You may set the debug level with the $ModPerl::Registry::Debug bitmask
132
133 1 => log recompile in errorlog
134 2 => ModPerl::Debug::dump in case of $@
135 4 => trace pedantically
136
138 ModPerl::Registry makes things look just the CGI environment, however,
139 you must understand that this *is not CGI*. Each httpd child will com‐
140 pile your script into memory and keep it there, whereas CGI will run it
141 once, cleaning out the entire process space. Many times you have heard
142 "always use "-w", always use "-w" and 'use strict'". This is more
143 important here than anywhere else!
144
146 Andreas J. Koenig, Doug MacEachern and Stas Bekman.
147
149 "ModPerl::RegistryCooker", "ModPerl::RegistryBB" and "ModPerl::Perl‐
150 Run".
151
152
153
154perl v5.8.8 2006-11-19 docs::api::ModPerl::Registry(3)