Skip to content
dod38fr edited this page Mar 24, 2012 · 1 revision

Debian perl team gen-itp

This small program uses Config::Model and Debian::Dpkg::Copyright configuration model to extract informations from debian/copyright file. see gen-itp on Debian's repo

Configuration tool refactoring example by gkr

Here's a mail telling how Config::Model was used to refactor existing configuration tools in Perl. Some punctuation and blank lines were added to improve the flow of this text. The full name and mail address of gkr is withheld on his request.

I took over a perl script that was responsible to pull data from several sources and push it after validation and re-packaging including some meta data into one of our production systems.

The script was never intended to be used for more then a few month. But as things go, we were still using it after a few years. Only now for a lot more sources. Since all the configuration of sources and meta data were contained as a single hash in this script, it became very unwieldy. Although the configuration seldom changed, once it got added it was not an option to keep it like this especially as we decided to prepare a Debian package for faster installation and version tracking. So I had to re-work it and was looking for some library that was allowing me to define how the configuration has to look like, providing sensible hard coded and computed defaults for some of the values.

This was when I found Config::Model on CPan. It was, after some digging into the documentation, quite simple to define a rough first version of the complete config, including global default values as ini file and very simple to read in and write out. A more advanced version was not working because the Config::Model in Debian squeeze did not provide needed features.

Switching to yaml as configuration file format not only increased readability but also worked with the standard Squeeze package. Consistency is checked automatically inside the model so broken configurations are more unlikely in the future.

Of course I had some work re-factoring the original source but Config::Model allowed an easy addition of a value-checked and documented configuration file. To access the Config::Model::Instance I added small wrapper packages that allowed an easy access of the config elements by name to make the source easier to understand. The re-factoring needed for creating a Debian package for the Script - which is now a set of modules and a small executable - was simple once I had Config::Model working, since I was able to add new configuration items effortlessly and remove a lot of hard coded parameters.

I don't use the cli tool yet for configuration editing but that's going to be the next step.

The author wishes to thank gkr for this feedback