Config::FromHash - Read config files containing hashes

Requires Perl 5.10.1 Travis status


Version 0.0800, released 2015-10-27.


    # in config file
        thing => 'something',
        things => ['lots', 'of', 'things'],
        deep => {
            ocean => 'submarine',

    # somewhere else
    use Config::FromHash;

    my $config = Config::FromHash->new(filename => 'path/to/theconfig.conf', data => { deep => { ocean => 'thing' });

    # prints 'submarine'
    print $config->get('deep/ocean');


Config::FromHash is yet another config file handler. This one reads config files that contain a Perl hash.

The following options are available

    my $config = Config::FromHash->new(
        filename => 'path/to/config.file',
        filenames => ['path/to/highest_priority_config.file', 'path/to/might_be_overwritten.file'],
        environment => 'production',
        environments => ['production', 'standard'],
        data => { default => { data => ['structure'] } },
        require_all_files => 1,


Optional. If it exists its value is used as the default settings and will be overwritten if the same setting exists in a config file.

filename or filenames

Optional. filenames is an alias for filename. It reads better to use filenames if you have many config files.

Files are parsed left to right. That is, as soon as a setting is found in a file (while reading left to right) that setting is not overwritten.

environment or environments

Optional. environments is an alias for environment It reads better to use environment if you have many environments.

If this is set its value is inserted into all config file names, just before the final dot.

Environments are read left to right. All files from each environment is read before moving on to the next environment. See Examples below.

An environment can be undef.


Default: 0

If set to a true value Config::FromHash will die if any config file doesn't exist. Otherwise it will silently skip such files.


Default: qr{/}

The separator used to split the argument to get():

    my $config = Config::FromHash->new(sep => qr{\.}, data => { some => { nested => { data => { is => 'deep' }}}});

    # prints 'deep'
    print $config->get('');



Returns the value that exists at $path. $path is translated into hash keys, and is separated by /.


Returns the entire hash after all config files have been read.


Returns a list of parsed config files. Mostly useful as a debuging tool, especially if require_all_files is false, and the contents of $self->data doesn't match expectations.


     my $config = Config::FromHash->new(
        filename => '/path/to/config.file',
        data => { some => 'setting' },

Will read


And any setting that exists in data that has not yet been set will be set.

    my $config = Config::FromHash->new(
        filenames => ['/path/to/highest_priority_config.file', '/path/to/might_be_overwritten.file'],
        environments => ['production', 'standard', undef],
        data => { default => { data => ['structure'] } },

The following files are read (with decreasing priority)


And then any setting that exists in data that has not yet been set will be set.

    my $config->new(data => { hello => 'world', can => { find => ['array', 'refs'] });

    # $hash becomes { hello => 'world', can => { find => ['array', 'refs'] }
    my $hash = $config->data;

    # prints 'refs';
    print $config->get('can/find')->[1];




Erik Carlsson <>


This software is copyright (c) 2015 by Erik Carlsson <>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.