Hi Monks! I have a quick question regarding configuration files

I almost always use Apache style configuration files in partnership with Config::General in my scripts

The thing is, i always end up writing lengthy subroutines or methods to check that the config file is in the correct format or has the data i'm expecting before i use it. I've been known to make this the majority of the length of my script!

Is this madness? What is the general opinion on checking config files are as expected?

Error out upon trying to use an aspect of the configuration if its wrong?

Completely check that everything is in place with the config so you have complete confidence in moving on and using the config data?

Are there any modules out there to help with this or do i just accept that the end user might completely screw up the config data/format and just bail with an error when i don't get what i expect?

Cheers!

Edit for Completeness!

Thanks for all the replies, i looked into Config::Validator but i couldn't work out how to do it should the config have unknown values in it

So long story short, i ended up creating a child class of Config::General and having a "CFG_check_cfg" method which runs all the other little standalone checks i wrote.

The Package being:

package ConfigObjects; use strict; use warnings; use Exporter 'import'; use parent 'Config::General'; our $VERSION='0.1'; our @EXPORT_OK=qw(CFG_check_cfg); # Main config checker sub CFG_check_cfg { my $self=shift; my $return=1; # True by default (all good) $return&=CFG_check1($self); $return&=CFG_check2($self); return $return; } # Unit checks: sub CFG_check1 { my $self=shift; return (#Some property of the $self->{config} data structure); } 1; __END__

Then i call the config parser in the main script like:

my $cfg_obj=ConfigObjects->new(-ConfigFile => $opt_config_file); pod2usage(-verbose => 1, -exitval => 1, -msg => "ERROR: Config file ha +s errors") unless ($cfg_obj->CFG_check_cfg);

Any feedback would be very much appreciated. Particularly if doing it this way is madness!!


In reply to Data checking configuration files by Amblikai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.