Skip to content

JuneKelly/perl6-config-clever

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
t
 
 
 
 
 
 
 
 
 
 

Config::Clever

A clever, heirarchical config loader for perl6.

Build Status

Config files

Config::Clever.load takes a String environment parameter and loads json files from the config/ directory. The json objects are loaded and merged together in the following order:

  • default.json
  • <environment>.json
  • local-<environment>.json

Calling Config::Clever.load without any parameters will use default as the environment. You can also supply a path to another config directory:

my %config = Config::Clever.load(:environment("staging"), :config-dir("./my/weird/path"));

Example

Imagine we have a directory config, with two files: default.json and development.json.

// default.json
{
    "db": {
        "host": "localhost",
        "port": 27017,
        "user": null,
        "password": null,
        "auth": false
    },
    "logLevel": "DEBUG"
}

// development.json
{
    "db": {
        "user": "apprunner",
        "password": "a_terrible_password",
        "auth": true
    }
}

If we call Config::Clever.load, with "development" as the environment, we'll get a hash which consists of the data from development.json merged on top of the data in default.json.

use v6;
use Config::Clever;

my %config = Config::Clever.load(:environment('development'));
say %config
# %config is a hash equivalent to:
#   {
#       "db": {
#           "host": "localhost",
#           "port": 27017,
#           "user": "apprunner",
#           "password": "a_terrible_password",
#           "auth": true
#       },
#       "logLevel": "DEBUG"
#   }

Todo

  • more tests
  • support more file formats such as ini, yaml and toml

About

A clever, heirarchical config loader for Perl6

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Other 100.0%