O'Reilly logo

Writing Apache Modules with Perl and C by Lincoln Stein, Doug MacEachern

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A.5. The Apache::PerlSections Class

As described in Chapter 7, it's possible to configure the Apache server entirely via Perl scripts embedded in <Perl> sections. The Apache::PerlSections module is a helper class that provides convenient functions for this process. It provides two public functions, dump( ) and store( ).

dump()

Called from within a <Perl> configuration section, dump( ) returns a pretty-printed string containing the current configuration variables. The string can be written out to a file and later brought back in via a require.

Example:

<Perl>
   use Apache::PerlSections ();
   $Port = 8529;
   @DocumentIndex = qw(index.htm index.html);

   print Apache::PerlSections->dump();
</Perl>

This will print out something like this:

package Apache::ReadConfig;
#scalars:

$Port = 8529;

 #arrays:

@DocumentIndex = (
  'index.htm',
  'index.html'
);

# hashes

1;
__END__

Notice that the variables are declared in the Apache::ReadConfig package. We give the reason for this in the next section.

store()

This is identical to dump( ), except that the formatted string is written directly to the file path you specify.

Example:

<Perl>
   .....
   print Apache::PerlSections->store('httpd_config.pl');
</Perl>

If a relative path is given to store(), it will be taken as relative to the current configuration file.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required