[boulder.pm] config modules?

Rob Nagler nagler at bivio.biz
Fri Aug 23 12:12:50 CDT 2002


Walter Pienciak writes:
> but this time nonprogrammer types will be using it, so . . .

My approach to this has always been to write a simple validator, which
can be as simple as:

perl -w somefile

Another thing I do is insert "use strict" when evaluating the file,
e.g.

    my($config) = eval('use strict; ' . read_file('somefile')) || die($@);

Finally, don't use local vars, e.g. %owners, make the entire file a
hash reference, e.g.

    {
    	owners => {
    	    someresource  => 'somebody at mycompany',
    	    somethingelse => 'someoneelse',
	},
    };

Then you can expand the check above with:

    die("syntax error") unless ref($config) eq 'HASH';

You can parse $@ to clean up the error messages, but I don't believe
you will do any better by using a *.ini or any other format.   Perl's
parser is very good, and any other parser is going to be second-rate,
because it doesn't get nearly the amount of (ab)use that "eval" does.

Rob

P.S. We use this approach at bivio with registered configuration.
     Visit http://petshop.bivio.biz/src?s=Bivio::IO::Config
     for the code and we structure it with:
     http://petshop.bivio.biz/src?s=Bivio::BConf
     recently added a "merge_dir" which searches /etc/bconf.d
     just like bash searches /etc/profile.d.
     





More information about the Boulder-pm mailing list