Thorium - Configuration management framework
version 0.503
Thorium is a collection of libraries for configuration management. Notable features:
generate files from templates via Template
enables complex data structures from the YAML backing store
optionally a console GUI to easily adjust configuration
Building complex applications that are highly configurable can be difficult. You want to balance an easy end user configuration with powerful tools. Thorium aims to fill that gap other configuration systems don't.
With Thorium this is possible:
Introduction screen:
Configuration screen:
Changing value screen:
The full source code is available in this distributions examples directory.
We will be extending Thorium::BuildConf and Thorium::Conf. I suggest something unique that won't show up on CPAN. For this example we are going to use Pizza. And our app will be creating a pizza.
Pizza
This example will use a fictional Thorium::BuildConf::Knob for demonstration purposes. You are free and encouraged to create your own specific knobs.
package Pizza::BuildConf; use Moose; use Pizza::BuildConf::Knob::CrustType; extends 'Thorium::BuildConf'; has '+type' => (default => 'Pizza Maker'); has '+files' => ('default' => 'awesome-pizza.tt2'); has '+knobs' => ( 'default' => sub { [ Pizza::BuildConf::Knob::CrustType->new( 'conf_key_name' => 'pizza.crust_type', 'name' => 'Crust type', 'question' => 'What kind of crust do you want?' ) ]; } ); __PACKAGE__->meta->make_immutable; no Moose;
We now have configurable item for the user.
This file will be the base for all configurable data that we will be accessing through a derived Thorium::Conf object. Use YAML::XS compatible syntax.
--- pizza: crust_type: thin
Now in your Template file, awesome-pizza.tt2, you have access to that data via a . separated syntax. For example, to get the crust type you'd use:
.
[% pizza.crust_type %]
You may also alter this data in your own defaults.yaml derived "preset". See Thorium::BuildConf for more.
This will be our class to access to the YAML data we created in Step 3:
package Pizza::Conf; use Moose; extends 'Thorium::Conf'; # core use File::Spec; # CPAN use Dir::Self; has '+component_name' => ('default' => 'pizza-maker'); has '+component_root' => ('default' => File::Spec->catdir(__DIR__, '..', '..')); __PACKAGE__->meta->make_immutable; no Moose;
local.yaml is the resulting saved file of all configuration data. More about overriding defaults in Thorium::Conf.
#!/usr/bin/env perl use strict; use Find::Lib '../lib'; use Find::Lib 'lib'; use Pizza::BuildConf; Pizza::BuildConf->new( 'conf_type' => 'Pizza::Conf', )->run;
./configure
At this point you should see console GUI.
If you go to the Configure option you should see your crust type.
Configure
Adam Flott <adam@npjh.com>
This software is copyright (c) 2011 by Adam Flott <adam@npjh.com>, CIDC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Thorium, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Thorium
CPAN shell
perl -MCPAN -e shell install Thorium
For more information on module installation, please visit the detailed CPAN module installation guide.