An improved Perl API for cme and Config::Model
While hacking on a script to update build dependencies on a Debian package, it occured to me that using Config::Model in a Perl program should be no more complicated than using cme from a shell script. That was an itch that I scratched immediately.
For instance, the following program is enough to update popcon’s configuration file:
use strict; # let's not forget best practices ;-) use warnings; use Config::Model qw(cme); # cme function must be imported cme('popcon')->modify("PARTICIPATE=yes");
my $instance = cme('popcon'); $instance->load("PARTICIPATE=yes"); $instance->apply_fixes; $instance->say_changes; $instance->save;
When run as root, the script above shows:
Changes applied to popcon configuration: - PARTICIPATE: 'no' -> 'yes'
If need be, you can also retrieve the root node of the configuration tree to use Config;:Model::Node methods:
my $root_node = cme('popcon')->config_root; say "is popcon active ? ",$root_node->fetch_element_value('PARTICIPATE');
In summary, using cme in a Perl program is now as easy as using cme from a shell script.
To provide feedback, comments, ideas, patches or to report problems, please follow the instructions from CONTRIBUTING page on github.
All the best