Apache::ConfigParser

Apache::ConfigParser is a Perl module that can load Apache configuration files.
Download

Apache::ConfigParser Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Blair Zajac
  • Publisher web site:
  • http://search.cpan.org/~bzajac/Apache-ConfigParser-1.01/lib/Apache/ConfigParser.pm

Apache::ConfigParser Tags


Apache::ConfigParser Description

Apache::ConfigParser is a Perl module that can load Apache configuration files. Apache::ConfigParser is a Perl module that can load Apache configuration files.SYNOPSIS use Apache::ConfigParser; # Create a new empty parser. my $c1 = Apache::ConfigParser->new; # Load an Apache configuration file. my $rc = $c1->parse_file('/etc/httpd/conf/httpd.conf'); # If there is an error in parsing the configuration file, then $rc # will be false and an error string will be available. if (not $rc) { print $c1->errstr, "n"; } # Get the root of a tree that represents the configuration file. # This is an Apache::ConfigParser::Directive object. my $root = $c1->root; # Get all of the directives and starting of context's. my @directives = $root->daughters; # Get the first directive's name. my $d_name = $directives->name; # This directive appeared in this file, which may be in an Include'd # file. my $d_filename = $directives->filename; # And it begins on this line number. my $d_line_number = $directives->line_number; # Find all the CustomLog entries, regardless of context. my @custom_logs = $c1->find_down_directive_names('CustomLog'); # Get the first CustomLog. my $custom_log = $custom_logs; # Get the value in string form. $custom_log_args = $custom_log->value; # Get the value in array form already split. my @custom_log_args = $custom_log->get_value_array; # Get the same array but a reference to it. my $customer_log_args = $custom_log->value_array_ref; # The first value in a CustomLog is the filename of the log. my $custom_log_file = $custom_log_args->; # Get the original value before the path has been made absolute. @custom_log_args = $custom_log->get_orig_value_array; $customer_log_file = $custom_log_args; # Here is a more complete example to load an httpd.conf file and add # a new VirtualHost directive to it. # # The Apache::ConfigParser object contains a reference to a # Apache::ConfigParser::Directive object, which can be obtained by # using Apache::ConfigParser->root. The root node is a # Apache::ConfigParser::Directive which ISA Tree::DAG_Node (that is # Apache::ConfigParser::Directive's @ISA contains Tree::DAG_Node). # So to get the root node and add a new directive to it, it could be # done like this: my $c = Apache::ConfigParser->new; my $rc = $c->parse_file('/etc/httpd.conf'); my $root = $c->root; my $new_virtual_host = $root->new_daughter; $new_virtual_host->name('VirtualHost'); $new_virtual_host->value('*'); # The VirtualHost is called a "context" that contains other # Apache::ConfigParser::Directive's: my $server_name = $new_virtual_host->new_daughter; $server_name->name('ServerName'); $server_name->value('my.hostname.com');The Apache::ConfigParser module is used to load an Apache configuration file to allow programs to determine Apache's configuration directives and contexts. The resulting object contains a tree based structure using the Apache::ConfigParser::Directive class, which is a subclass of Tree::DAG_node, so all of the methods that enable tree based searches and modifications from Tree::DAG_Node are also available. The tree structure is used to represent the ability to nest sections, such as < VirtualHost >, < Directory >, etc.Apache does a great job of checking Apache configuration files for errors and this modules leaves most of that to Apache. This module does minimal configuration file checking. The module currently checks for:Start and end context names match The module checks if the start and end context names match. If the end context name does not match the start context name, then it is ignored. The module does not even check if the configuration contexts have valid names. Requirements: · Perl


Apache::ConfigParser Related Software