Brian Duggan > Clustericious-Config > Clustericious::Config



Annotate this POD

View/Report Bugs
Module Version: 0.13   Source  


Clustericious::Config - configuration files for Clustericious nodes.


 $ cat > ~/etc/MyApp.conf
 % extends_config 'global';
 % extends_config 'hypnotoad', url => 'http://localhost:9999', app => 'MyApp';

 url : http://localhost:9999
 start_mode : hypnotoad
 hypnotoad :
    - heartbeat_timeout : 500

 $ cat > ~/global.conf
 somevar : somevalue

 $ cat > ~/hypnotoad.conf
 listen :
    - <%= $url %>
 pid_file : <%= $ENV{HOME} %>/<%= $app %>/
 env :
    MOJO_HOME : <%= $ENV{HOME} %>/<%= $app %>

Then later in a program somewhere :

 my $c = Clustericious::Config->new("MyApp");
 my $c = Clustericious::Config->new( \$config_string );
 my $c = Clustericious::Config->new( \%config_data_structure );

 print $c->url;
 print $c->{url};

 print $c->hypnotoad->listen;
 print $c->hypnotoad->{listen};
 my %hash = $c->hypnotoad;
 my @ary  = $c->hypnotoad;

 # Supply a default value for a missing configuration parameter :
 $c->url(default => "http://localhost:9999");
 print $c->this_param_is_missing(default => "something_else");

 # Dump out the entire config as yaml
 print $c->dump_as_yaml;


Clustericious::Config reads configuration files which are Mojo::Template's of JSON or YAML files. There should generally be an entry for 'url', which may be used by either a client or a server depending on how this node in the cluster is being used.

After rendering the template and parsing the JSON, the resulting object may be called using method calls or treated as hashes.

Config files are looked for in the following places (in order, where "MyApp" is the name of the app) :


The helper "extends_config" may be used to read default settings from another config file. The first argument to extends_config is the basename of the config file. Additional named arguments may be passed to that config file and used as variables within that file. After reading another file, the hashes are merged (i.e. with Hash::Merge); so values anywhere inside the datastructure may be overridden.

YAML config files must begin with "---", otherwise they are interpreted as JSON.

Clustericious::Config provides a "get_password" function which will prompt for a password if it is needed. It can be used like this :

 password : <%= get_password =%>

This will prompt the user the first time it is encountered.



Create a new Clustericious::Config object. See the SYPNOSIS for possible invocations.


Clustericicious::Config->set_singleton(App => $object);

Cache a config object to be returned by the constructor.


If the environment variable HARNESS_ACTIVE is set, and the current module::build object tells us that the calling module is being tested, then an empty configuration is used. In this situation, however, if $ENV{CLUSTERICIOUS_CONF_DIR} is set and if it is a subdirectory of the current directory, then it will be used. This allows unit tests to provide configuration directories, but avoids using configurations that are outside of the build tree during unit testing.


Brian Duggan

Graham Ollis


This is a beta release. The API may change without notice.


Mojo::Template, Hash::Merge, Clustericious, Clustericious::Client

syntax highlighting: