The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

GRNOC::Config - The GRNOC Default Config parser

VERSION

Version 1.0.9

SYNOPSIS

A module to allow everyone to access config files in a fairly standard way. Uses XML::XPath and XML::Simple to parse our XML files, and stores all configs it has access to in this module

Setting debug to true will give you extra debugging output (default is off) Setting force_array to true will return everything in an array even if there is only 1 object returned (default is on)

When asking for attributes denoted by '@' it will return only the attribute(s) without the hash

    use GRNOC::Config;

    my $foo = GRNOC::Config->new(config_file => '/etc/grnoc/db.xml', debug => 0, force_array => 0 schema => '/path/to/schema.csd')
    my $db_username = $foo->get("/config/db/credentials");
    print $db_username->{'user'};
    print $db_username->{'password'};

    #just 1 attribute
    my $user = $foo->get("/config/db/credentials[1]/@user");
    my $password = $foo->get("/config/db/credentials[1]/@password");

    #if I have more than 1 result I get an array
    my $hosts = $foo->get("/config/hosts") or die Dumper($foo->get_error());   
    foreach my $host ($hosts){
        print $host->{'hostname'};
    }

    ##turn debugging on
    $foo->{'debug'} = 1;
    
    ##get errors
    print Dumper($foo->get_errors());

    # I always want an array... even if I only get 1 result
    $foo->{'force_array'} = 1;
    $db_username = $foo->get("/config/db/credentials") or die Dumper($foo->get_error());
    print @{db_username}[0]->{'user'}
    print @{db_username}[0]->{'password'}

   $user = $foo->get("/config/db/credentials[1]/@user") or die Dumper($foo->get_error());
   $password = $foo->get("/config/db/credentials[1]/@password") or die Dumper($foo->get_error());
   $user = @{$user}[0];
   $password = @{$password}[0];
 
   my $valid = $foo->validate();

   if(!$valid){
     print STDERR Dumper($foo->get_error());
   }

   my $valid2 = $foo->validate("/path/to/new/schema.xsd");

    ...

getOLD

returns the requested data from the config file must pass in the path of the node/attribute you want from the XML. Attributes are denoted by '@'

to get an attribute the call would look like

    $foo->get("/path/to/@object");

get2

returns the requested data from the config file must pass in the path of the node/attribute you want from the XML. Attributes are denoted by '@'

to get an attribute the call would look like

    $foo->get2("/path/to/@object");

get

returns the requested data from the config file must pass in the path of the node/attribute you want from the XML. Attributes are denoted by '@'

to get an attribute the call would look like

    $foo->get3("/path/to/@object");

update_node

add_node

delete_nodes

delete_node

update_attribute

add_attribute

validate

    my $valid = $config->validate();

    or 
  
    my $valid = $config->validate("/path/to/schema.xsd");

    returns 1 if xml validates
    returns 0 if it fails to valiate
    returns -1 if there is a problem with your schema

get_error

returns any error that is generated from this module

new Creates a new GRNOC::Config object

    my $config = GRNOC::Config->new(config_file => $file, force_array => 0, debug => 0);

    or

    my $config = GRNOC::Config->new( xml_string => $string);