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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access