as i alluded to
yesterday earlier this month, i’m trying to whip up a little app that can run this here blog in a way that’s slightly more pleasing to me (because i figure the best way to get more updates here is to remove the things that make me go ‘ugh’ when i think about updating…) i’ve had the mental model for how it should work for the past couple of years and i’m just starting to get the first bits of that down, and i’ve run into my first yak of the project: config file handling.
i’ve got a couple of other sites where i’d like to put content that’s not quite the same as the content here, and i’m pretty sure i’m going to want to use this tool i’m writing for that once it’s done. so i don’t want to hardcode a bunch of stuff into the app, i want to be able to have a config file, or maybe even more than one config file.
now, i’m writing this thing in perl. i have a lot of opinions about a lot of perl modules, but i don’t yet have a strong opinion about the best config-handling module. looking at CPAN, i see there are quite a few configuration related modules (searching for ‘config::’ in the module namespace gets pretty close to 1000 hits).
i guess i’m going to start pawing through all those modules, just to see what i see that fits my requirements:
- it should support a plain-text-ish key/value sort of syntax
- it would be nice if it supported YAML syntax too because if things start to get hairy that’s probably the config format i’m going to reach for
- ini format can hang for all i care
- some sort of self-referential variable interpolation would be nice
- it would be even nicer if that _didn’t_ involve full-blown perl evaluation
- it would be quite nice if the thing took a stab at figuring out where the config file was without having to be explicitly told
- but of course if it’s explicitly pointed at a particular file it should STFU and use what it’s given
- i’d prefer to have getter methods automagickly appear based on what’s in the config, rather than having to supply arguments to some ‘get()’ or ‘param()’ method
- in the long run something that’s designed out of the gate for subclassing is probably a better bet
so that’s what i’ll be hunting up on the CPAN — should you happen to have any yak razors or shaving soap handy, do let me know…
Update: wrote the above, never did get around to cleaning it up to post it, and have finally — through some combination of YAGNI and POGE have decided to go with Config::Singleton, which hits the following of the above criteria:
- auto-discovery of config files (by checking in a pre-defined list of locations which can be overridden)
- auto-getter methods
- used by subclassing the base module into your namespace, which (partially and very kludgeably) works around the self-referential variable interpolation thing
so, anyway… onward.