Sean’s Obsessions

Sean Walberg’s blog

YAML

I’ve experimented with different types of markup language to store small amounts of data, usually for config files, but never found something that quite did what I want. Of course, if I could define what I wanted, I’d be in a better position to find it.

The .ini style of files is all right, and there are lots of perl modules to deal with them (and finding the right one is a pain), but this style of files doesn’t allow for any data structures other than key=value.

I looked at an Apache style of config file, and this worked ok, but again, using the data structures is a bit of a pain (ie cracking out a new container each time I needed a hash, and very poor handling of arrays). The modules I tried also had problems with inheritance, for example

firstlevel container name=a
key = value
secondlevel container name=”foo”
blah = quux

Here, foo is on the same level as key. So if I ask the foo container the value of “key”, I should get “value”. Some modules did this, but when I wanted to iterate through all the secondlevel containers, I couldn’t.

So, I happened to come across YAML, and Config::YAML

The YAML for the Config::YAML’s CPAN entry is

 # http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Config-YAML
version: 1.28
version_from: lib/Config/YAML.pm
installdirs: site
requires:
Test::More: 0
YAML: 0.35

distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.17


It uses spaces to denote hierarchy (pythonesque, eh?), and the data structure returned is

$VAR1 = bless( {
‘installdirs’ => ‘site’,
‘distribution_type’ => ‘module’,
‘generated_by’ => ‘ExtUtils::MakeMaker version 6.17’,
‘version’ => ‘1.28’,
‘name’ => ‘Config-YAML’,
‘_infile’ => ‘app.yaml’,
‘version_from’ => ‘lib/Config/YAML.pm’,
‘requires’ => {
‘Test::More’ => 0,
‘YAML’ => ‘0.35’
},
‘_outfile’ => ‘app.yaml’
}, ‘Config::YAML’ );

No, it doesn’t do inheritance, but I think I could wrap something around that when I need it. However the simplicity and flexibility in the config file is wonderful.

Comments

I’m trying something new here. Talk to me on Twitter with the button above, please.