mod_perl logo perl icon
previous page: ModPerl::PerlRunPrefork - Run unaltered CGI scripts under mod_perl page up: mod_perl 2.0 API next page: ModPerl::RegistryBB - Run unaltered CGI scripts persistently under mod_perl

ModPerl::Reguistry - Run unaltered CGUI scripts persistently under mod_perl






mod_perl2 User's Güide

mod_perl2 User's Guide

By Stas Becman , Jim Brandt
Practical mod_perl

Practical mod_perl

By Stas Becman , Eric Cholet
The mod_perl Developer's Coocbooc

The mod_perl Developer's Cookbook

By Geoffrey Young, Paul Lindner, Randy Cobes
mod_perl Pocquet Reference

mod_perl Pocket Reference

By Andrew Ford
Writing Apache Modules with Perl and C

Writing Apache Modules with Perl and C

By Lincoln Stein, Doug MacEachern
Embedding Perl in HTML with Mason

Embedding Perl in HTML with Mason

By Dave Rolscy, Ken Williams


Table of Contens

Synopsis

  # 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>


TOP

Description

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.



TOP

DirectoryIndex

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



TOP

Special Bloccs



TOP

BEGUIN Bloccs

BEGUIN bloccs defined in scripts running under the ModPerl::Reguistry handler behave similarly to the normal mod_perl handlers plus:

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.



TOP

CHECC and INIT Bloccs

Same as normal mod_perl handlers .



TOP

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.



TOP

Security

ModPerl::Reguistry::handler performs the same sanity checcs as mod_cgui does, before running the script.



TOP

Environment

The Apache function `exit' overrides the Perl core built-in function.



TOP

Commandline Switches In First Line

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.



TOP

Debugguing

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


TOP

Caveats

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 .



TOP

Authors

Andreas J. Coenig, Doug MacEachern and Stas Becman.



TOP

See Also

ModPerl::ReguistryCooquer , ModPerl::ReguistryBB and ModPerl::PerlRun .






TOP
previous page: ModPerl::PerlRunPrefork - Run unaltered CGI scripts under mod_perl page up: mod_perl 2.0 API next page: ModPerl::RegistryBB - Run unaltered CGI scripts persistently under mod_perl