NAME

Thorium::Conf - Configuration class

VERSION

version 0.510

SYNOPSIS

Extending:

package Some::App::Conf;

use Moose;

extends 'Thorium::Conf';

has '+component_name' => ('default' => 'someapp');
has '+component' => ('default' => [ '/file1.yaml', '/file2.yaml' ]);

1;

But you may also use it directly:

use Thorium::Conf;

my $conf = Thorium::Conf->new('from' => '/that/app.yaml');

print $conf->data('some.key');

...

DESCRIPTION

Thorium::Conf is an extendable class for handling configuration data in YAML http://yaml.org format through YAML::XS.

Data is accessed through a string interface that maps directly to the key names of a hash. Data is loaded in the order of (first to last): global, system, component, env_var, from. With each overriding data from the previous, e.g. component's a key would override systems's a key. All data is marked read-only to prevent accidental modification, but there is an interface to control this.

In nearly all cases you should sub-class and override the component_name and component attributes. See the "SYNOPSIS" for an example. component maps to the base file name that will be found in the system location (as set by _system_directory_root). Therefore, if your component name is someapp, then you'd expect the system wide file to reside in /etc/thorium/conf/someapp.yaml.

/etc/thorium/conf/thorium.yaml is the universally global file all Thorium::Conf and sub-classed objects read (when it exists).

ROLES

Thorium::Roles::Logging

ATTRIBUTES

Optional Attributes

  • _system_directory_root (ro, Str) - Directory root where global files are located. Changing this is not recommended. Defaults to '/etc/thorium/conf'.

  • component (ro, Maybe[ArrayRef|Str]) - Component specific file(s) to read from. Extended classes should set this.

  • component_name (ro, Str) - File name base that might be stored in the _system_directory_root. When extending please provide this.

  • env_var (ro, Maybe[Str]) - Full path to the environmental set file.

  • env_var_name (ro, Maybe[Str]) - Name of the environment variable. Defaults to 'THORIUM_CONF_FILE'.

  • from (ro, Maybe[ArrayRef|Str]) - A string or list containing the full path of files to read from.

  • global (ro, Maybe[Str]) - Global configuration file read by all configuration objects. Defaults to '/etc/thorium/conf/thorium.yaml'.

  • system (ro, Maybe[Str]) - Full path to the components system wide file.

PUBLIC API METHODS

  • data([ $key ])

    If $key is specified, return that specific data, otherwise return all data.

    Note: by default all configuration data is marked read only and can not be changed.

  • reload()

    Re-reads all data from files.

  • save($filename)

    Writes the data to the full file path from $filename.

  • set($key, $value)

    Change $key to $value. $key is the same format as data().

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.