Config-Versioned
view release on metacpan or search on metacpan
lib/Config/Versioned.pm view on Meta::CPAN
## Config::Versioned
##
## Written 2011-2012 by Scott T. Hardin for the OpenXPKI project
## Copyright (C) 2010-2012 by The OpenXPKI Project
##
## Was based on the CPAN module App::Options, but the import() stuff
## bit me so we're turning into a Moose.
##
## vim: syntax=perl
package Config::Versioned;
use Moose;
use namespace::autoclean;
=head1 NAME
Config::Versioned - Simple, versioned access to configuration data
=cut
our $VERSION = '1.01';
use Carp;
use Config::Std;
use Data::Dumper;
use DateTime;
use Git::PurePerl;
use Path::Class;
has 'path' => ( is => 'ro', isa => 'ArrayRef', default => sub { [qw( . )] } );
has 'filename' => ( is => 'ro', isa => 'Str' );
has 'dbpath' =>
( is => 'ro', default => 'cfgver.git', required => 1 );
has 'author_name' => ( is => 'ro', isa => 'Str', default => "process: $@" );
has 'author_mail' => (
is => 'ro',
isa => 'Str',
default => $ENV{GIT_AUTHOR_EMAIL} || $ENV{USER} . '@localhost'
);
has 'autocreate' => ( is => 'ro', isa => 'Bool', default => 0 );
has 'commit_time' => ( is => 'ro', isa => 'DateTime' );
has 'comment' => ( is => 'rw', isa => 'Str' );
has 'delimiter' => ( is => 'ro', isa => 'Str', default => '.' );
has 'delimiter_regex' =>
( is => 'ro', isa => 'RegexpRef', default => sub { qr{ \. }xms } );
has 'log_get_callback' => ( is => 'ro' );
has '_git' => ( is => 'rw' );
has 'debug' => ( is => 'rw', isa => 'Int', default => 0 );
# a reference to the singleton Config::Versioned object that parsed the command line
#my ($default_option_processor);
#my (%path_is_secure);
=head1 SYNOPSIS
use Config::Versioned;
my $cfg = Config::Versioned->new();
my $param1 = $cfg->get('subsystem1.group.param1');
my $old1 = $cfg->get('subsystem1.group.param1', $version);
my @keys = $cfg->list('subsys1.db');
=head1 DESCRIPTION
Config::Versioned allows an application to access configuration parameters
not only by parameter name, but also by version number. This allows for
the configuration subsystem to store previous versions of the configuration
parameters. When requesting the value for a specific attribute, the programmer
specifies whether to fetch the most recent value or a previous value.
This is useful for long-running tasks such as in a workflow-based application
where task-specific values (e.g.: profiles) are static over the life of a
workflow, while global values (e.g.: name of an LDAP server to be queried)
should always be the most recent.
Config::Versioned handles the versions by storing the configuration data
in an internal Git repository. Each import of configuration files into
the repository is documented with a commit. When a value is fetched, it is
this commit that is referenced directly when specifying the version.
The access to the individual attributes is via a named-parameter scheme, where
the key is a dot-separated string.
Currently, C<Config::Std> is used for the import of the data files into the
internal Git repository. Support for other configuration modules (e.g.:
C<Config::Any>) is planned.
=head1 METHODS
( run in 0.617 second using v1.01-cache-2.11-cpan-39bf76dae61 )