Adam Flott > Thorium > Thorium

Download:
Thorium-0.510.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  1
View/Report Bugs
Module Version: 0.510   Source  

NAME ^

Thorium - Configuration management framework

VERSION ^

version 0.510

ABOUT ^

Thorium is a collection of libraries for configuration management. Notable features:

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:

QUICK START ^

The full source code is available in this distributions examples directory.

1. Choose A Namespace

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.

2. Extend Thorium::BuildConf

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.

3. Create conf/presets/defaults.yaml

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.

4. Extend Thorium::Conf

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.

5. Create the configure Script

    #!/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;

6. Run configure

    ./configure

At this point you should see console GUI.

If you go to the Configure option you should see your crust type.

CREDITS ^

Thanks to Sean Quinlan for contributing design and feedback.

AUTHOR ^

Adam Flott <adam@npjh.com>

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: