Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kentnl/chi-config

Define CHI configuration outside your code
https://github.com/kentnl/chi-config

Last synced: 4 days ago
JSON representation

Define CHI configuration outside your code

Awesome Lists containing this project

README

        

# NAME

CHI::Config - Define CHI configuration outside your code

# VERSION

version 0.001002

# SYNOPSIS

use CHI::Config;

my $config = CHI::Config->new(
defaults => [
# Defaults indeed has to mimic the source file for future purposes
# ie: I plan to make some objects ( such as serializers )
# be configurable as well and they can't really be defined as-is in JSON
{
type => 'driver',
name => 'myproject.roflmayo',
config => {
# Arguments to CHI->new()
},
},
],
);

my $cache = $config->get_cache('myproject.roflmayo');

# Do stuff with $cache and get default behaviour

# User creates ~/.chi/config.json
[
{
'type' : 'driver',
'name' : 'myproject.roflmayo',
'config': {
# CHI CONFIG HERE
},
}
]

my $cache = $config->get_cache('myproject.roflmayo'); # Now gets user defined copy

# CONSTRUCTOR ARGUMENTS

## `config_paths`

_Optional_: An ArrayRef of path prefixes to scan and load.

For instance:

( config_paths => ['./foo'] )

Would automatically attempt to load any files called

foo.yml
foo.json
foo.ini

And load them with the relevant helpers.

See [`Config::Any`](https://metacpan.org/pod/Config::Any) for details on this mechanism.

Paths will be interpreted in the order specified, with the first one
taking precedence over the latter ones for any given driver name,
with `defaults` being taken only if they're needed.

Default paths loaded are as follows:

$ENV{CHI_CONFIG_DIR}/config.*
./chi_config.*
~/.chi/config.*
/etc/chi/config.*

## `config_files`

_Optional_: An ArrayRef of files to scan and load.

If specified, this list entirely overrules that provided by
[`config_paths`](#config_paths)

## `defaults`

_Recommended_: An ArrayRef of defaults in the same notation as the configuration spec.

defaults => [
$entry,
$entry,
$entry,
],

See ["ENTRIES"](#entries)

# METHODS

## `get_cache`

Retrieve an instance of a cache object for consumption.

my $cache = $config->get_cache('myproject.myname');

$cache-># things with CHI

# ENTRIES

Both the internal array based interface and the configuration file
are a list of `Entries`. Design somewhat inspired by `Config::MVP`'s
sequence model, but much more lightweight.

## `driver` entry

These make up the core of a configuration.

{
type => 'driver',

# The following are all passed through to
# CHI::Config::Driver

# STRONGLY recommended
name => 'mynamespace.mycachename',

# RAW CHI arguments
config => {
%CONFIG #
},

# return singleton or new caches?
memoize => 0,
}

See [`CHI::Config::Driver`](https://metacpan.org/pod/CHI::Config::Driver) for details.

## `version` entry

This is a mostly unnecessary element simply designed to give
some kind of informal API in the event there are changes in
how the configuration is parsed.

Currently, Spec version is == `0.1.0`

{
type => 'version',

# Declare a minimum version of CHI::Config
min => 0.001000,

# Declare a maximum version of CHI::Config
max => 1.000000,

# Require exactly specification 0.1.0
spec => '0.1.0',
}

`max` and `min` give range controls on the version of `CHI::Config` itself.

`spec` gives an exact match on the _interface_ provided by `CHI::Config`, and is processed as an exact string match.

Any of the criteria not being satisfied will result in a `croak`

# AUTHOR

Kent Fredric

# COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Kent Fredric .

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