So I recently decided to convert the config file for a new app I'm working on to JSON. Why? Well for one, it's a lot easier to express perl data structures in, and it's also extremely easy to read. Check it out!
{
"name": "Fnargh",
"Model::Database": {
"connect_info": [
"dbi:SQLite:fnargh.db",
"",
""
]
} ,
"session": {
"flash_to_stash": "1"
}
}
Started off a bit rocky, but thanks to http://www.jsonlint.com I was able to pick at my config file until it was valid. It formats it nicely for you as well!
The best part? You can take the perl data that you use in your Catalyst app, and do something like this:
squishface:~ dhoss$ perl -e "use JSON; print to_json({ my_data => [ 'thing1', 'thing2', 'thing3' ] });"
{"my_data":["thing1","thing2","thing3"]}
JSON formatted for your config!




Hi!
If you use _Config::Any_, you can directly use Perl for configuration files. I tend to do this, as in the default configuration it's less annoying than JSON (fex. it allow comments, comma after in the last key/value pair, to skip using quotes around keys, ...). Your file would just become:
{
name => "Fnargh",
"Model::Database" => {
connect_info => [
"dbi:SQLite:fnargh.db",
"",
"",
],
},
session => {
flash_to_stash: "1",
},
}
And it's more Perlish, of course. ;-)
JSON would be a great config format, if they haden't removed comment support from the spec.
lordthartis: ah! cool! I never thought of that :-)
Marcus: No way, dammit! This displeases me