App::Config::Chronicle - An OO configuration module which can be changed and stored into chronicle database.
my $app_config = App::Config::Chronicle->new;
This module parses configuration files and provides interface to access configuration information.
The configuration file is a YAML file. Here is an example:
system:
description: "Various parameters determining core application functionality"
isa: section
contains:
email:
description: "Dummy email address"
isa: Str
default: "dummy@mail.com"
global: 1
refresh:
description: "System refresh rate"
isa: Num
default: 10
global: 1
admins:
description: "Are we on Production?"
isa: ArrayRef
default: []
Every attribute is very intuitive. If an item is global, you can change its value and the value will be stored into chronicle database by calling the method save_dynamic
.
The maximum length of time (in seconds) that a cached history entry will stay in Redis.
The YAML file that store the configuration
The chronicle store that configurations can be fetch from it. It should be an instance of Data::Chronicle::Reader. But user is free to implement any storage backend he wants if it is implemented with a 'get' method.
The chronicle store that updated configurations can be stored into it. It should be an instance of Data::Chronicle::Writer. But user is free to implement any storage backend he wants if it is implemented with a 'set' method.
The chronicle connection that can notify via callbacks when particular configuration items have a new value set. It should be an instance of Data::Chronicle::Subscriber.
How much time (in seconds) should pass between check_for_update invocations until it actually will do (a bit heavy) lookup for settings in redis.
Default value is 10 seconds
check and load updated settings from chronicle db
Checks at most every refresh_interval
unless forced with
a truthy first argument
Save dynamic settings into chronicle db
Loads setting from chronicle reader and returns the last revision
It is more likely that you want "loaded_revision" in regular use
Returns the revision loaded and served by this instance
This may not reflect the latest stored version in the Chronicle persistence. However, it is the revision of the data which will be returned when querying this instance
######################################################
######################################################
If local_caching is set to the true then key-value pairs stored in Redis will be cached locally.
Calling update_cache will update the local cache with any changes from Redis. refresh_interval defines (in seconds) the minimum time between seqequent updates.
Calls to get on this object will only ever access the cache. Calls to set on this object will immediately update the values in the local cache and Redis.
Loads latest values from data chronicle into local cache.
Calls to this method are rate-limited by refresh_interval
.
Returns the global revision version of the config chronicle. This will correspond to the last time any of values were changed.
Takes a hashref of key->value pairs and atomically sets them in config chronicle
Example: set({key1 => 'value1', key2 => 'value2', key3 => 'value3',...});
Takes either - an arrayref of keys, gets them atomically, and returns a hashref of key->values, including the global_revision under the key '_global_rev'. - a single key (as a string), gets the value, and returns it directly. If a key has an empty value, it will return with undef.
For convenience a get with just a key string will return the value only.
Example: get(['key1','key2','key3',...]); Returns: {'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3',..., '_global_rev' => '<number>'}
Example: get(['key1']); Returns: {'key1' => 'value1', '_global_rev' => '<number>'}
Example: get('key1'); Returns: 'value1'
Retreives a past revision of an app config entry, where $rev is the number of revisions in the past requested. If the optional third argument is true then result of the query will be cached in Redis. This is useful if a certain revision will be needed repeatedly, to avoid excessive database access. By default this argument is 0. All cached revisions will become stale if the key is set with a new value.
Example: get_history('system.email', 0); Retrieves current version get_history('system.email', 1); Retreives previous revision get_history('system.email', 2); Retreives version before previous
Subscribes to changes for the specified $key with the sub $subref called when a new value is set. The chronicle_writer must have publish_on_set enabled.
Stops the sub $subref from being called when $key is set with a new value. The chronicle_writer must have publish_on_set enabled.
Returns a list containing all keys in the config chronicle schema
Returns a list containing only the dynamic keys in the config chronicle schema
Returns a list containing only the static keys in the config chronicle schema
Returns the data type associated with a particular key
Returns the default value associated with a particular key
Returns the default value associated with a particular key
Returns the key type associated with a particular key
Binary.com, <binary at cpan.org>
Please report any bugs or feature requests to bug-app-config at rt.cpan.org
, or through
the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-Config. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc App::Config::Chronicle
You can also look for information at:
-
RT: CPAN's request tracker (report bugs here)
-
AnnoCPAN: Annotated CPAN documentation
-
CPAN Ratings
-
Search CPAN