lib/DNStools/Config.pm
branchhs12
changeset 80 fc2156761c29
parent 75 4c0f518fd1be
child 85 c47953192c5c
equal deleted inserted replaced
79:ac04894f45c1 80:fc2156761c29
     1 package DNStools::Config;
     1 package DNStools::Config;
       
     2 
     2 use strict;
     3 use strict;
     3 use warnings;
     4 use warnings;
     4 
     5 
     5 use base "Exporter";
     6 use base "Exporter";
     6 
     7 
    13     my @configs = @_;
    14     my @configs = @_;
    14     my %config;
    15     my %config;
    15 
    16 
    16     # the first config FILE
    17     # the first config FILE
    17     my ($_) = grep { -f } @configs;
    18     my ($_) = grep { -f } @configs;
       
    19 
       
    20     die "no config file found, searched for @configs\n" if not $_;
    18     open(my $cf, $_) or die "Can't open $_: $!\n";
    21     open(my $cf, $_) or die "Can't open $_: $!\n";
    19 
    22 
    20     while (<$cf>) {
    23     while (<$cf>) {
    21         s/#.*//;
    24         s/#.*//;
    22         s/\s//g;
    25         s/\s//g;
    32     }
    35     }
    33     return %config;
    36     return %config;
    34 }
    37 }
    35 
    38 
    36 1;
    39 1;
       
    40 
       
    41 __END__
       
    42 
       
    43 =head1 NAME
       
    44 
       
    45     DNStools::Config - config parser
       
    46 
       
    47 =head1 SYNOPSIS
       
    48 
       
    49     use DNStools::Config qw(get_config);
       
    50     %config = get_config($file1, $file2, ...);
       
    51 
       
    52 =head1 DESCRIPTION
       
    53 
       
    54 Simple config file parser. The format is simple:
       
    55 
       
    56     key = value
       
    57 
       
    58 All spaces are ignored.
       
    59 
       
    60 =head1 FUNCTIONS
       
    61 
       
    62 =over
       
    63 
       
    64 =item B<get_config>(I<list of config files>)
       
    65 
       
    66 Read the first file of the list (or dies if none of the files is found).
       
    67 Returns a hash with the config keys and values.
       
    68 
       
    69 =back
       
    70 
       
    71 =cut
       
    72 
       
    73 
       
    74