NAME

Data::Context - Configuration data with context

VERSION

This documentation refers to Data::Context version 0.3.

SYNOPSIS

use Data::Context;

# create a new Data::Context variable
my $dc = Data::Context->new(
     path => [qw{ /path/to/configs /alt/path }],
);

# read a config
my $data = $dc->get(
     'some/config',
     {
         context => 'values',
     }
);

DESCRIPTION

/path/to/file.dc.js:
{
    "PARENT" : "/path/to/default.dc.js:,
    "replace_me" : "#replaced.from.input.variables.0#"
    "structure" : {
        "MODULE": "My::Module",
        "METHOD": "do_stuff",
        ....
    },
    ...
}

Get object Build -> parse file -> if "PARENT" build parent -> merge self and raw parent -> construct instance -> iterate to all values -> if the value is a string of the form "#...#" make sub reference to add to call list -> if the value is a HASHREF & "MODULE" or "METHOD" keys exist add to call list -> cache result

Use object -> clone raw data -> call each method call list -> if return is a CODEREF assume it's an event handler -> else replace data with returned value -> if any event handlers are returned run event loop -> return data

MODULE HASHES { "MODULE" : "My::Module", "METHOD" : "get_data", "NEW" : "new", ... } or { "METHOD" : "do_something", "ORDER" : 1, .... }

1st : calls My::Module->new->get_data (if NEW wasn't present would just call My::Module->get_data) 2nd : calls Data::Context::Actions->do_something

the parameters passed in both cases are $value = the hashref containing the method call $dc = The whole data context raw data $path = A path of how to get to this data $vars = The variables that the get was called with

Data::Context Configuration path string or list of strings containing directory names to be searched config files fallback bool if true if a config isn't found the parent config will be searched for etc fallback_depth If set to a non zero value the fall back will limited to this number of times actions hashref of coderefs, allows simple adding of extra methods to Data::Context::Actions action_class Allows the using of an action class other than Data::Context::Actions. Although it is suggested that the alt class should inherit from Data::Context::Actions file_suffixes HASHREF json => '.dc.json' : JSON::XS js => '.dc.js' : JSON::XS->relaxed yaml => '.dc.yml' : YAML or YAML::XS xml => '.dc.xml' : XML::Simple log logging object, creates own object that just writes to STDERR if not specified debug set the debugging level default is WARN (DEBUG, INFO, WARN, ERROR or FATAL) cache ...

SUBROUTINES/METHODS

new (...)

Parameters to new:

path

The directory path (or a list of paths) where the configuration files can be found

fallback

A bool if set to true will allow the falling back along the path of the config specified.

eg config path = my/config/file

if fallback is false the default search performed (for each directory in $dc->path) is

my/config/file.dc.js
my/config/file.dc.json
my/config/file.dc.yml
my/config/file.dc.xml
my/config/_default.dc.js
my/config/_default.dc.json
my/config/_default.dc.yml
my/config/_default.dc.xml

if fallback is true the search is (just for the .dc.js)

my/config/file.dc.js
my/config/_default.dc.js
my/config.dc.js
my/_default.dc.js
my.dc.js
_default.dc.js
fallback_depth

f fallback is true this if set to a non zero +ve int will limit the number of time a fallback will occur. eg from the above example

fallback_depth = 0 or 2

my/config/file.dc.js
my/config/_default.dc.js
my/config.dc.js
my/_default.dc.js
my.dc.js
_default.dc.js

fallback_depth = 1

my/config/file.dc.js
my/config/_default.dc.js
my/config.dc.js
my/_default.dc.js
actions

A hash ref of code refs to allow the simple adding of default actions. The key can be used in templates METHOD parameter and the code will be called when found.

action_class

If you want to use your own default class for actions (ie you don't want to specify actions and don't want to have to always specify MODULE). Your class should inherit from Data::Context::Action to be safe.

action_method

The default action_method is get_data, through this parameter you may choose a different method name.

file_suffixes

This allows the setting of what file suffixes will be used for loading the various config types. Default:

{
  js   => '.dc.js',
  json => '.dc.json',
  yaml => '.dc.yml',
  xml  => '.dc.xml',
}
file_suffix_order

Specify the order to search for various file types. If you will only use one config type you can specify just that type to speed up the searching. Default: [ js, json, yaml, xml ]

file_default

Sets the name of the default config file name (_default by default). If you unset this value, falling back to a default will be disabled

log

A log object should be compatible with a Catalyst::Log, Log::Log4perl, etc logger object. The default value just writes to STDERR.

debug

When using the default logger for log. This sets the level of logging. 1 = most information, 5 = almost none, default is 3 warnings and higher messages

get ($path, $vars)

Reads the config represented by $path and apply the context variable $vars as dictated by the found config.

get_instance ($path)

Creates (or retrieves from cache) an instance of the config $paht.

DIAGNOSTICS

By default Data::Context writes messages to STDERR (via it's simple log object). More detailed messages can be had by upping the debug level (by lowering the value of debug, 1 out puts all messages, 2 - info and above, 3 - warnings and above, 4 - errors and above, 5 - fatal errors)

CONFIGURATION AND ENVIRONMENT

DEPENDENCIES

Moose, Moose::Util::TypeConstraints

INCOMPATIBILITIES

BUGS AND LIMITATIONS

There are no known bugs in this module.

Please report problems to Ivan Wills (ivan.wills@gmail.com).

Patches are welcome.

AUTHOR

Ivan Wills - (ivan.wills@gmail.com)

LICENSE AND COPYRIGHT

Copyright (c) 2012 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.