Config::RecurseINI

Config::RecurseINI

Config::RecurseINI - some extras on top of Config::Tiny

Synopsys

use Config::RecurseINI 'someapp' => qw(config);

my $dbname = config('database','dbname');
my %dbconfig = config('database');

Description

Config::RecuseINI adds two main things on top of Config::Tiny:

  • Config Inheritance
  • Config Discovery

Config Inheritance

You can define one section as being the same as other section with some extras (or overrides):

[dabatase]
hostname=127.0.0.1
username=dbuser
password=passwd

[database:users]
_isa=database
dbname=user

[database:posts]
_isa=database
dbname=posts

when calling config(‘database:users’) config::RecurseINI will return

{  hostname  => '127.0.0.1',
  username  => 'dbuser',
  password  => 'passwd',
  dbname    => 'user',
}

Config Discovery

Config::RecurseINI looks for the config file - see bellow config-name - in several places, in order:

  • $HOME/ if the env variable $HOME is defined, it will look for a file named .config-name

  • $HOME/.config/

  • /etc/

  • …/config/

if $0 is in a …/bin/ or …/?bin/ directory, it looks for a config file in a config directory in the parent of that directory.

config-name

the first time you use Config::RecurseINI you can define what is the name of the config file if that is not given, the basename of $0 will be used

example:

use Config::RecurseINI ‘someapp’ => qw(config);

either way, that will be only the basename of the config file, and the name will be appended with .ini or .conf - both will be search for, in that order.

Methods

config($section[, $key])

config can take one or two parameters - the first will return a full config section, while the second will return the value of a specific config key in that section.

In case of usage with only one parameter, config will return an HASH or an hashref, depending on context.

debug

Config::RecurseINI uses several different ways to define what debug level will be used: env $DEBUG, the parameter --debug or the debug key in the root of your config file.

verbose

the same as with debug, $VERBOSE, --verbose and verbose key in the root section.

BUG REPORTS and FEATURE REQUESTS

Please report any bugs or request features in:

COPYRIGHT and LICENSE

Copyright (C) 2016 by theMage

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.22.1 or, at your option, any later version of Perl 5 you may have available.

Alternativally, you can also redistribute it and/or modify it under the terms of the GPL 2.0 licence (or any future version of it).