Hi all-

I've written a module that can parse the Apache httpd.conf config file
(and in fact any Apache-like config file). It will take a set of
directive like:

     ServerName         www.mydomain.com
     UseCanonicalName   Off
 
And parse it case-insensitively, returning a ref to a hash:

    my $ac = new Apache::Config;
    my $conf = $ac->readconf($configfile);
    print $conf->{servername};       # = "www.mydomain.com";
    print $conf->{usecanonicalname}; # = 0   (not undef so can test
                                     #        for defined() still)

I am also finishing up the ability to parse within contexts, such as
<Directory> and <Location>. I am still unsure of the interface, I have
two ideas:
 
    1. multi-level hash, i.e.
          $conf->{"directory /"}->{sethandler}
 
    2. individual functions, i.e.
          $conf->directory("/")->{sethandler}

If anyone has any input, I'm all ears. Right now I'm leaning towards the
second one, if I can get it working. The first one is really flexible
and easy, the problem is that it's difficult to search. The second one
helps with this issue, but the downside is that new functions have to be
added if new Apache contexts are defined. I'm trying to play some tricks
with the AutoLoader ala Shell to get new functions defined on the fly.
If anyone has good ideas for a better interface, I'd also like to hear
them.

In any case, I have several questions:
 
    1. Does a module like this exist anywhere?  I saw Doug's
       Apache::httpd_conf, but this only takes care of writing
       a very minimal config file. I looked thru all the
       Apache:: modules but didn't see one.
 
    2. Is the name Apache::Config a good name for this module?
       It seems like the obvious choice to me, and doesn't
       look like it's taken. I've also played around with
       Apache::ConfigFile and Apache::ReadConf, either of
       which I'm open to as well (or other suggestions?).

I'm aware of the Apache and Apache::Constants modules, which do provide
Apache API methods for getting to this data that work great for
mod_perl. My goal with this module was to make it general enough to be
used to parse any Apache-style config file. That way, if you wanted (a)
write a CGI script outside of mod_perl that used httpd.conf data, or (b)
wrote a custom (maybe non-web) app that used an Apache-like config file,
you could get at the data quickly. In this way it would be like
Apache::Session, where it can work either in a CGI or mod_perl context.
 
Thanks for your help and input.

-Nate

Reply via email to