Plankton has asked for the wisdom of the Perl Monks concerning the following question:

Hi Wise Monks,

I have an rather large and complicated httpd.conf file that uses mod_perl <Perl> tags to write a large part of it. I would like to be able to dump out the resulting config as if where normal looking httpd.conf file. I need to be able to reverse engineer and debug this large httpd.conf. I know I can do stuff like ...

Apache::PerlSections->store("httpd_config.pl");
... but that writes the config out as Perl code which is fine but I was hoping the the reverse. I also know that I can check the syntax of my httpd.conf by executing
$ perl -cx httpd.conf
but again I want to end up with output that is just httpd configuration directives without any Perl code left in it.

Does any Monk know of any existing module that does something like this or is there some simple solution I am just not clever enough to see for myself?

Many thanks!

Replies are listed 'Best First'.
Re: Generating an httpd.conf from http://example.com/perl-status
by hsinclai (Deacon) on Mar 11, 2009 at 15:03 UTC
    >>I want to end up with output that is just httpd configuration directives without any Perl code left in it.

    Does this work?
    use strict; use warnings; my $configfile2parse = 'httpd.conf'; my $configfile2check = 'httpd.conf-stripped'; open FH, '<', $configfile2parse or die "cannot open httpd.conf"; my @content = <FH>; close FH; my $opener = qr{<Perl>}; my $closer = qr{</Perl>}; my @httpd_config_only = grep {!(/$opener/sg .. /$closer/sg)} @content; open NH, '>>', $configfile2check or die "cannot open output file"; print NH $_ for @httpd_config_only; close NH; my $result = qx!httpd -S -f /work/$configfile2check!; print $result . $/;

    ... tests ok here - but I hope I understood your original problem correctly. Another consideration might be separating out the perl code from httpd.conf using the Include directive within the config

      Thanks for the reply. I am starting to think there isn't a way to do this and I have stated my question poorly. Your solution works great for removing the text between the <Perl> and </Perl> tags but what I want is to see the resulting configuration generated by the Perl code between the tags. Maybe I could use a eval statement to do this.
        Apologies! I certainly did not get that meaning from your original question.... er.. I now see your dilemma :):)