Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.2 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Perl Modules

    Apache::ConfigParser 1.01

    Download button

    No screenshots available
    Downloads: 820  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    Good (3.5/5)
    18 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Blair Zajac | More programs
    Perl Artistic License / FREE
    April 29th, 2008, 11:34 GMT
    ROOT / Programming / Perl Modules

     Read user reviews (0)  Refer to a friend  Subscribe

    Apache::ConfigParser description

    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[0]->name;

    # This directive appeared in this file, which may be in an Include'd
    # file.
    my $d_filename = $directives[0]->filename;

    # And it begins on this line number.
    my $d_line_number = $directives[0]->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[0];

    # 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->[0];

    # 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[0];

    # 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.

    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    Apache configuration loader | Apache configuration parser | Perl module | Apache | configuration | parser

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM