Practical mod_perl / HTML Book /



previous page: 4.4.1. Constructing <Perl> Sections
  
page up: HTML Version of the book
  
next page: 4.4.3. Cheating with Apache->httpd_conf

4.4.2. Breaking Out of <Perl> Sections


Behind the scenes, mod_perl defines a package called Apache::ReadConfig in which it keeps all the variables that you define inside the <Perl> sections. So <Perl>sections aren't the only way to use mod_perl to configure the server: you can also place the Perl code in a separate file that will be called during the configuration parsing with either PerlModule or PerlRequire directives, or from within the startup file. All you have to do is to declare the package Apache::ReadConfig before writing any code in this file.

Using the last example from the previous section, we place the code into a file named apache_config.pl, shown in Example 4-4.

Example 4-4. apache_config.pl

package Apache::ReadConfig;

use Sys::Hostname;
$ServerName = hostname( );
if ($ServerName !~ /^secure/) {
    $UserDir = "public.html";
}
1;

Then we execute it either from httpd.conf:

PerlRequire /home/httpd/perl/lib/apache_config.pl

or from the startup.pl file:

require "/home/httpd/perl/lib/apache_config.pl";

 

Continue to:

  • prev: 4.4.1. Constructing <Perl> Sections
  • Table of Contents
  • next: 4.4.3. Cheating with Apache->httpd_conf







TOP
previous page: 4.4.1. Constructing &lt;Perl&gt; Sections
  
page up: HTML Version of the book
  
next page: 4.4.3. Cheating with Apache-&gt;httpd_conf


Menu

  • HTML Book
  • PDF Book
  • Download Code
  • Table of Contents
  • Errata
  • mod_perl2 User's Guide
  • Sitemap

Search


Add to Google




Creative Commons License


Written by
Eric Cholet (Logilune) and
Stas Bekman (StasoSphere & Free Books).


[ Privacy Policy | Terms of Use | About Us | Search ]

© 2007 StasoSphere.com