Config-Merge-1.04/000755 000765 000024 00000000000 12376630557 014527 5ustar00clintonstaff000000 000000 Config-Merge-1.04/Changes000644 000765 000024 00000001174 12376630557 016025 0ustar00clintonstaff000000 000000 1.04 25 Aug 2014 Old File::Glob doesn't export :bsd_glob. 1.03 18 Aug 2014 Switch to using bsd_glob to handle spaces in paths on Windows. 1.02 16 Aug 2014 Handle spaces in path names - thanks to oliwel for the patch. 1.01 12 Oct 2010 Removed dependency on Data::Alias - thanks to Graham Barr for the patch. Restructured the module to use the standard CPAN layout with lib/, and switched to Module::Build 1.00 22 Oct 2007 First release of Config::Merge to CPAN. Replaces Config::Loader Config-Merge-1.04/examples/000755 000765 000024 00000000000 12376630557 016345 5ustar00clintonstaff000000 000000 Config-Merge-1.04/lib/000755 000765 000024 00000000000 12376630557 015275 5ustar00clintonstaff000000 000000 Config-Merge-1.04/Makefile.PL000644 000765 000024 00000002632 12376630557 016504 0ustar00clintonstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.020. use strict; use warnings; use ExtUtils::MakeMaker ; my %WriteMakefileArgs = ( "ABSTRACT" => "load a configuration directory tree containing YAML, JSON, XML, Perl, INI or Config::General files", "AUTHOR" => "Clinton Gormley ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Config-Merge", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "Config::Merge", "PREREQ_PM" => { "Config::Any" => "0.07", "File::Glob" => 0, "File::Spec" => 0, "Storable" => 0, "overload" => 0, "strict" => 0, "vars" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "Config::Any" => "0.07", "Test::More" => 0, "YAML" => 0 }, "VERSION" => "1.04", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Config::Any" => "0.07", "File::Glob" => 0, "File::Spec" => 0, "Storable" => 0, "Test::More" => 0, "YAML" => 0, "overload" => 0, "strict" => 0, "vars" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Config-Merge-1.04/MANIFEST000644 000765 000024 00000004473 12376630557 015670 0ustar00clintonstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.020. Changes MANIFEST META.json META.yml Makefile.PL README examples/README examples/advanced.pl examples/advanced/app-(dev1).yaml examples/advanced/app-(dev2).yaml examples/advanced/app.yaml examples/browser.pl examples/config_dev/app.yaml examples/config_dev/app/db.yaml examples/config_dev/app/html_filter.yaml examples/config_dev/forms/search.yaml examples/config_dev/forms/user/edit.yaml examples/config_dev/forms/user/forgotten.yaml examples/config_dev/forms/user/password.yaml examples/config_dev/local.yaml examples/config_prod/app.yaml examples/config_prod/app/db.yaml examples/config_prod/app/html_filter.yaml examples/config_prod/forms/search.yaml examples/config_prod/forms/user/edit.yaml examples/config_prod/forms/user/forgotten.yaml examples/config_prod/forms/user/password.yaml examples/func.pl examples/oo.pl lib/Config/Merge.pm lib/Config/Merge/Perl.pm t/10_oo.t t/20_functional.t t/30_errors.t t/40_advanced.t t/50_spaces_in_path.t t/80_pod.t t/81_pod_coverage.t t/data/array/local.pl t/data/array/main.pl t/data/bad/db.pl t/data/empty/.dummy t/data/errors/array_delete_int/local.pl t/data/errors/array_delete_int/main.pl t/data/errors/array_delete_ref/local.pl t/data/errors/array_delete_ref/main.pl t/data/errors/array_insert_int/local.pl t/data/errors/array_insert_int/main.pl t/data/errors/array_insert_ref/local.pl t/data/errors/array_insert_ref/main.pl t/data/errors/array_merge/local.pl t/data/errors/array_merge/main.pl t/data/load_as/dir-(local)/file.pl t/data/load_as/dir/file.pl t/data/load_as/file-(local).pl t/data/load_as/file.pl t/data/load_as/sub/dir-(aaa)/test.pl t/data/load_as/sub/dir-(bbb)/test.pl t/data/load_as/sub/dir/test.pl t/data/load_as/sub/test-(aaa).pl t/data/load_as/sub/test-(bbb).pl t/data/load_as/sub/test.pl t/data/local/email-(aaa).pl t/data/local/email-(bbb).pl t/data/local/email.pl t/data/local/main.pl t/data/local/override.pl t/data/perl/global.perl t/data/perlmulti/global.perl t/data/perlmulti/global/db.pl t/data/perlmulti/global/db2.pl t/data/perlmulti/global/db3.pl t/data/perlmulti/global/local.pl t/data/perlmulti/local.perl t/data/skip/main/skip_1.pl t/data/skip/main/skip_2.pl t/data/skip/main/skip_not.pl t/data/skip/skip_1/test.pl t/data/skip/skip_2/test.pl t/data/skip/skip_not/test.pl 't/data/with spaces/foo.yaml' Config-Merge-1.04/META.json000644 000765 000024 00000003237 12376630557 016155 0ustar00clintonstaff000000 000000 { "abstract" : "load a configuration directory tree containing YAML, JSON, XML, Perl, INI or Config::General files", "author" : [ "Clinton Gormley " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.020, CPAN::Meta::Converter version 2.140640", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Config-Merge", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "recommends" : { "Config::General" : "0", "Config::Tiny" : "0", "JSON" : "0", "JSON::XS" : "0", "XML::Simple" : "0", "YAML" : "0", "YAML::Syck" : "0" }, "requires" : { "Config::Any" : "0.07", "File::Glob" : "0", "File::Spec" : "0", "Storable" : "0", "overload" : "0", "strict" : "0", "vars" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Config::Any" : "0.07", "Test::More" : "0", "YAML" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/clintongormley/ConfigMerge/issues" }, "repository" : { "type" : "git", "url" : "git://github.com/clintongormley/ConfigMerge.git", "web" : "https://github.com/clintongormley/ConfigMerge" } }, "version" : "1.04" } Config-Merge-1.04/META.yml000644 000765 000024 00000001644 12376630557 016005 0ustar00clintonstaff000000 000000 --- abstract: 'load a configuration directory tree containing YAML, JSON, XML, Perl, INI or Config::General files' author: - 'Clinton Gormley ' build_requires: Config::Any: '0.07' Test::More: '0' YAML: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.020, CPAN::Meta::Converter version 2.140640' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Config-Merge recommends: Config::General: '0' Config::Tiny: '0' JSON: '0' JSON::XS: '0' XML::Simple: '0' YAML: '0' YAML::Syck: '0' requires: Config::Any: '0.07' File::Glob: '0' File::Spec: '0' Storable: '0' overload: '0' strict: '0' vars: '0' warnings: '0' resources: bugtracker: https://github.com/clintongormley/ConfigMerge/issues repository: git://github.com/clintongormley/ConfigMerge.git version: '1.04' Config-Merge-1.04/README000644 000765 000024 00000062022 12376630557 015411 0ustar00clintonstaff000000 000000 NAME Config::Merge - load a configuration directory tree containing YAML, JSON, XML, Perl, INI or Config::General files SYNOPSIS OO style ------------------------------------------------------- use Config::Merge(); my $config = Config::Merge->new('/path/to/config'); @hosts = $config->('db.hosts.session'); $hosts_ref = $config->('db.hosts.session'); @cloned_hosts = $config->clone('db.hosts.session'); ------------------------------------------------------- OR Functional style ------------------------------------------------------- # On startup use Config::Merge('My::Config' => '/path/to/config'); # Then, in any module where you want to use the config package My::Module; use My::Config; @hosts = C('db.hosts.sesssion'); $hosts_ref = C('db.hosts.sesssion'); @cloned_hosts = My::Config::clone('db.hosts.session'); $config = My::Config::object; ------------------------------------------------------- ADVANCED USAGE OO style ------------------------------------------------------- my $config = Config::Merge->new( path => '/path/to/config', skip => sub {} | regex | {} , is_local => sub {} | regex | {} , load_as => sub {} | regex , sort => sub {} , debug => 1 | 0 ); ------------------------------------------------------- Functional style ------------------------------------------------------- use Config::Merge( 'My::Config' => '/path/to/config', { skip => sub {} | regex | {} , is_local => sub {} | regex | {} , load_as => sub {} | regex , sort => sub {} , debug => 1 | 0 } ); # Also, you can subclass these: package My::Config; sub skip { ... } ------------------------------------------------------- DESCRIPTION Config::Merge is a configuration module which has six goals: * Flexible storage Store all configuration in your format(s) of choice (YAML, JSON, INI, XML, Perl, Config::General / Apache-style config) broken down into individual files in a configuration directory tree, for easy maintenance. See "CONFIG TREE LAYOUT" * Flexible access Provide a simple, easy to read, concise way of accessing the configuration values (similar to Template). See "ACCESSING CONFIG DATA" * Minimal maintenance Specify the location of the configuration files only once per application, so that it requires minimal effort to relocate. See "USING Config::Merge" * Easy to alter development environment Provide a way for overriding configuration values on a development machine, so that differences between the dev environment and the live environment do not get copied over accidentally. See "OVERRIDING CONFIG LOCALLY" * Minimise memory use Load all config at startup so that (eg in the mod_perl environment) the data is shared between all child processes. See "MINIMISING MEMORY USE" * Flexible implementation You may want to use a different schema for your configuration files, so you can pass in (or subclass) methods for determining how your files are merged. See "ADVANCED USAGE". USING "Config::Merge" There are two ways to use "Config::Merge": OO STYLE use Config::Merge(); my $config = Config::Merge->new('/path/to/config'); @hosts = $config->('db.hosts.session'); $hosts_ref = $config->('db.hosts.session'); @cloned_hosts = $config->clone('db.hosts.session'); Also, see "ADVANCED USAGE". YOUR OWN CONFIG CLASS (functional style) The following code: # On startup use Config::Merge('My::Config' => '/path/to/config'); * auto-generates the class "My::Config" * loads the configuration data in '/path/to/config' * creates the subs "My::Config::C", "My::Config::clone" and "My::Config::object". Then when you want your application to have access to your configuration data, you add this (eg in your class "My::Module"): package My::Module; use My::Config; # Note, no () This exports the sub "C" into your current package, which allows you to access your configuation data as follows: @hosts = C('db.hosts.sesssion'); $hosts_ref = C('db.hosts.sesssion'); @cloned_hosts = My::Config::clone('db.hosts.session'); $config = My::Config::object; CONFIG TREE LAYOUT Config::Merge reads the data from any number (and type) of config files stored in a directory tree. File names and directory names are used as keys in the configuration hash. It uses file extensions to decide what type of data the file contains, so: YAML : .yaml .yml JSON : .json .jsn XML : .xml INI : .ini Perl : .perl .pl Config::General : .conf .cnf When loading your config data, Config::Merge starts at the directory specified at startup (see "USING Config::Merge") and looks through all the sub-directories for files ending in one of the above extensions. The name of the file or subdirectory is used as the first key. So: global/ db.yaml: username : admin hosts: - host1 - host2 password: host1: password1 host2: password2 would be loaded as : $Config = { global => { db => { username => 'admin', password => { host1 => 'password1', host2 => 'password2'}, hosts => ['host1','host2'], } } } Subdirectories are processed before the current directory, so you can have a directory and a config file with the same name, and the values will be merged into a single hash, so for instance, you can have: confdir: syndication/ --data_types/ --traffic.yaml --headlines.yaml --data_types.ini syndication.conf The config items in syndication.conf will be added to (or overwrite) the items loaded into the syndication namespace via the subdirectory called syndication. OVERRIDING CONFIG LOCALLY The situation often arises where it is necessary to specify different config values on different machines. For instance, the database host on a dev machine may be different from the host on the live application. Also, see "ADVANCED USAGE" which provides you with other means to merge local data. Instead of changing this data during dev and then having to remember to change it back before putting the new code live, we have a mechanism for overriding config locally in a "local.*" file and then, as long as that file never gets uploaded to live, you are protected. You can put a file called "local.*" (where * is any of the recognised extensions) in any sub-directory, and the data in this file will be merged with the existing data. Just make sure that the "local.*" files are never checked into your live code. For instance, if we have: confdir: db.yaml local.yaml and db.yaml has : connections: default_settings: host: localhost table: abc password: 123 And in local.yaml: db: connections: default_settings: password: 456 the resulting configuration will look like this: db: connections: default_settings: host: localhost table: abc password: 456 ACCESSING CONFIG DATA All configuration data is loaded into a single hash, eg: $config = { db => { hosts => { session => ['host1','host2','host3'], images => ['host1','host2','host3'], etc... } } } If you want to access it via standard Perl dereferences, you can just ask for the hash: OO: $data_ref = $config->(); $hosts_ref = $data_ref->{db}{hosts}{session}; $host_1 = $data_ref->{db}{hosts}{session}[0]; Functional: $data_ref = C(); $hosts_ref = $data_ref->{db}{hosts}{session}; $host_1 = $data_ref->{db}{hosts}{session}[0]; However, "Config::Merge" also provides an easy to read dot-notation in the style of Template Toolkit: "('key1.key2.keyn')". A key can be the key of a hash or the index of an array. The return value is context sensitive, so if called in list context, a hash ref or array ref will be dereferenced. OO: @hosts = $config->('db.hosts.session'); $hosts_ref = $config->('db.hosts.session'); $host_1 = $config->('db.hosts.session.0'); Functional: @hosts = C('db.hosts.session'); $hosts_ref = C('db.hosts.session'); $host_1 = C('db.hosts.session.0'); These lookups are memo'ised, so lookups are fast. If the specified key is not found, then an error is thrown. MINIMISING MEMORY USE The more configuration data you load, the more memory you use. In order to keep the memory use as low as possible for mod_perl (or other forking applications), the configuration data should be loaded at startup in the parent process. As long as the data is never changed by the children, the configuration hash will be stored in shared memory, rather than there being a separate copy in each child process. (See ) METHODS "new()" $conf = Config::Merge->new($config_dir); new() instantiates a config object, loads the config from the directory specified, and returns the object. "C()" $val = $config->C('key1.key2.keyn'); $val = $config->C('key1.key2.keyn',$hash_ref); "Config::Merge" objects are overloaded so that this also works: $val = $config->('key1.key2.keyn'); $val = $config->('key1.key2.keyn',$hash_ref); Or, if used in the functional style (see "USING Config::Merge"): $val = C('key1.key2.keyn'); $val = C('key1.key2.keyn',$hash_ref); "key1" etc can be keys in a hash, or indexes of an array. "C('key1.key2.keyn')" returns everything from "keyn" down, so you can use the return value just as you would any normal Perl variable. The return values are context-sensitive, so if called in list context, an array ref or hash ref will be returned as lists. Scalar values, code refs, regexes and blessed objects will always be returned as themselves. So for example: $password = C('database.main.password'); $regex = C('database.main.password_regex'); @countries = C('lists.countries'); $countries_array_ref = C('lists.countries'); etc If called with a hash ref as the second parameter, then that hash ref will be examined, rather than the $config data. "clone()" This works exactly the same way as "C()" but it performs a deep clone of the data before returning it. This means that the returned data can be changed without affecting the data stored in the $conf object; The data is deep cloned, using Storable, so the bigger the data, the more performance hit. That said, Storable's dclone is very fast. "register_loader()" Config::Merge->register_loader( 'Config::Merge::XYZ'); Config::Merge->register_loader( 'Config::Merge::XYZ' => 'xyz','xxx'); By default, "Config::Merge" uses the "Config::Any" plugins to support YAML, JSON, INI, XML, Perl and Config::General configuration files, using the standard file extensions to recognise the file type. (See "CONFIG TREE LAYOUT"). If you would like to change the handler for an extension (eg, you want ".conf" and ".cnf" files to be treated as YAML), do the following: Config::Merge->register_loader ('Config::Any::YAML' => 'conf', 'cnf'); If you would like to add a new config style, then your module should have two methods: "extensions()" (which returns a list of the extensions it handles), and "load()" which accepts the name of the file to load, and returns a hash ref containing the data in the file. See Config::Any for details. Alternatively, you can specify the extensions when you load it: Config::Merge->register_loader ('My::Merge' => 'conf', 'cnf'); "load_config()" $config->load_config(); Will reload the config files located in the directory specified at object creation (see "new()"). BEWARE : If you are using this in a mod_perl environment, you will lose the benefit of shared memory by calling this in a child process - each child will have its own copy of the data. See "MINIMISING MEMORY USE". Returns the config hash ref. "clear_cache()" $config->clear_cache(); Config data is generally not supposed to be changed at runtime. However, if you do make changes, you may get inconsistent results, because lookups are cached. For instance: print $config->C('db.hosts.session'); # Caches this lookup > "host1 host2 host3" $data = $config->C('db.hosts'); $data->{session} = 123; print $config->C('db.hosts.session'); # uses cached value > "host1 host2 host3" $config->clear_cache(); print $config->C('db.hosts.session'); # uses actual value > "123" "import()" "import()" will normally be called automatically when you "use Config::Merge". However, you may want to do this: use Config::Merge(); Config::Merge->register_loader('My::Plugin' => 'ext'); Config::Merge->import('My::Config' => '/path/to/config/dir'); If called with two params: $config_class and $config_dir, it generates the new class (which inherits from Config::Merge) specified in $config_class, creates a new object of that class and creates 4 subs: "C()" As a function: C('keys...') is the equivalent of: $config->C('keys...'); "clone()" As a function: clone('keys...') is the equivalent of: $config->clone('keys...'); "object()" $config = My::Config->object(); Returns the $config object, "import()" When you use your generated config class, it exports the "C()" sub into your package: use My::Config; $hosts = C('db.hosts.session'); ADVANCED USAGE The items in the section allow you to customise how Config::Merge loads your data. You may never need them. You can: * Override array values * Skip the loading of parts of your config tree * Specify which files / dirs are local * Specify how to translate a file / dir name into a key * Change order in which files are loaded * See debug output Overriding array values Overriding hash values is easy, however arrays are more complex. it may be simpler to copy and paste and edit the array you want to change locally. However, if your array is too long, and you want to make small changes, then you can use the following: In the main config: { cron => [qw( job1 job2 job3 job4)] } In the local file { cron => { '3' => 'newjob4', # changes 'job4' -> 'newjob4' '!' => { # signals an array override '-' => [1], # deletes 'job2' '+' => ['job5'], # appends 'job5' OR '+' => { # inserts 'job3a' after 'job3' 2 => 'job3a' } } } * The override has to be a hash, with at least this structure "{ '!' => {} }" to signal an array override * Any other keys with integers are treated as indexes and are used to change the value at that index in the original array * The '-' key should contain an array ref, with the indexes of the elements to remove from the array. * If the '+' key contains an array ref, then its contents are appended to the original array. * If the '+' key contains a hash ref, then each value is inserted into the original array at the index given in the key * Indexes are zero based, just as in Perl. "skip()" $c = Config::Merge->new( path => '/path/to/config', skip => qr/regex/, | [ qr/regex1/, qr/regex2/...] | { name1 => 1, name2 => 2} | sub {} ); "skip()" allows you to skip the loading of parts of your config tree. For instance, if you don't need a list of cron jobs when running your web server, you can skip it. The decision is made based on the path to that value, eg 'app.db.hosts' rather than on filenames. Also, the check is only performed for each new directory or filename - it doesn't check the data within each file. To use "skip()", you can either subclass it, or pass in a parameter to new: "qr/regex/" or "[qr/regex1/, qr/regex2]" Each regex will be checked against the key path, and if it matches then the loading of that tree will be skipped "{key_path => 1}" If the key path exists in the hash, then loading will be skipped "sub {}" or subclassed "skip" sub { my ($self,$key_path) = @_; ...make decision... return 1 | 0; } "is_local()" $c = Config::Merge->new( path => '/path/to/config', is_local => qr/regex/, | [ qr/regex1/, qr/regex2/...] | { name1 => 1, name2 => 2} | sub {} ); "is_local()" indicates whether a file or dir should be considered part of the main config (and thus loaded normally) or part of the local config (and thus merged into the main config). The decision is made based on the name of the file / dir, without any extension. To use "is_local()", you can either subclass it, or pass in a parameter to new: "qr/regex/" or "[qr/regex1/, qr/regex2]" Each regex will be checked against the file/dir name, and if it matches then that tree will be merged "{filename => 1, dirname => 1}" If the file/dir name exists in the hash, then that tree will be merged "sub {}" or subclassed "is_local" sub { my ($self,$name) = @_; ...make decision... return 1 | 0; } See "EXAMPLE USING is_local() AND load_as()". "load_as()" $c = Config::Merge->new( path => '/path/to/config', load_as => qr/(regex)/, | sub {} ); "load_as()" returns the name of the key to use when loading the file / dir. By default, it returns the $name for main config files, or '' for local files. The decision is made based on the name of the file / dir, without any extension. If "load_as()" returns an empty string, then each key in the file/tree is merged separately. This is how the "local.*" files work by default. See "OVERRIDING CONFIG LOCALLY". For instance: main.yaml: key1: value key2: value db.yaml: key3: value key4: value local.yaml: main: key1: new_value db: key4: new_value To use "load_as()", you can either subclass it, or pass in a parameter to new: "qr/(regex)/" The regex will be checked against the file/dir name, and if it matches then it returns the string captured in the regex, otherwise it returns the original name. "sub {}" or subclassed "is_local" sub { my ($self,$name,$is_local) = @_; ...make decision... return 'string'; # string is used as the keyname return ''; # acts like local.* (see above) return undef; # don't load this file/dir } Also, see "EXAMPLE USING is_local() AND load_as()". EXAMPLE USING "is_local()" AND "load_as()" For instance, instead of using "local.*" files, you may want to keep versioned copies of local configs for different machines, and so use: app.yaml app-(dev1.domain.com).yaml app-(dev2.domain.com).yaml You would implement this as follows: my $config = Config::Merge->new( path => '/path/to/config', # If matches 'xxx-(yyy)' is_local => sub { my ( $self, $name ) = @_; return $name=~/- [(] .+ [)]/x ? 1 : 0; }, # If local and matches 'xxx-(hostname)', return xxx load_as => sub { my ( $self, $name, $is_local ) = @_; if ($is_local) { if ( $name=~/(.*) - [(] ($hostname) [)] /x ) { return $1; } return undef; } return $name; } ); See "examples/advanced.pl" for a working illustration. "sort()" $c = Config::Merge->new( path => '/path/to/config', sort => sub {} ); By default, directory entries are sorted alphabetically, with directories before filenames. This would be the order for these directory entries: api/ api-(dev1)/ api.yaml api-(dev1).yaml To override this, you can subclass "sort()" or pass it in as a parameter to new: sub { my ($self,$names_array_ref) = @_ ...sort... return $names_array_ref; } "debug()" my $config = Config::Merge->new( path => '/path/to/config', debug => 1 | 0 ); If "debug" is true, then Config::Merge prints out an explanation of what it is doing on STDERR. SEE ALSO Storable, Config::Any, Config::Any::YAML, Config::Any::JSON, Config::Any::INI, Config::Any::XML, Config::Any::General THANKS Thanks to Hasanuddin Tamir [HASANT] for vacating the Config::Merge namespace, which allowed me to rename Config::Loader to the more meaningful Config::Merge. His version of Config::Merge can be found in . Thanks to Joel Bernstein and Brian Cassidy for the interface to the various configuration modules. Also to Ewan Edwards for his suggestions about how to make Config::Merge more flexible. BUGS No bugs have been reported. Please report any bugs or feature requests to . AUTHOR Clinton Gormley, COPYRIGHT Copyright (C) 2007-2010 by Clinton Gormley LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available. Config-Merge-1.04/t/000755 000765 000024 00000000000 12376630557 014772 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/10_oo.t000644 000765 000024 00000007240 12376630557 016077 0ustar00clintonstaff000000 000000 use strict; use warnings FATAL => 'all', NONFATAL => 'redefine'; use File::Spec; use Test::More 'tests' => 30; BEGIN { use_ok('Config::Merge'); } my $config; ok( $config = Config::Merge->new( get_path('empty') ), 'OO - Load empty dir' ); ok( $config = Config::Merge->new( get_path('perl') ), 'OO - Load perl dir' ); is( $config->C('global.domain'), 'www.test.com', 'OO - Simple lookup' ); is( $config->('global.domain'), 'www.test.com', 'OO - Overload lookup' ); is_deeply( scalar $config->C('global.db.hosts.session'), [qw(host1 host2 host3)], 'OO - Array ref lookup' ); is_deeply( [ $config->C('global.db.hosts.session') ], [qw(host1 host2 host3)], 'OO - Array lookup' ); is( $config->C('global.db.hosts.image.1'), 'host5', 'OO - Array element lookup' ); ok( $config = Config::Merge->new( get_path('perlmulti') ), 'OO - Load perl dir' ); my @list; ok( @list = $config->C('global.testsub'), 'OO - Retrieve code'); is( scalar @list, 1, 'OO - CODE ref list context'); is( ref $list[0], 'CODE', 'OO - CODE ref'); is( ref scalar $config->C('global.testsub'), 'CODE', 'OO - CODE ref scalar context'); ok( @list = $config->C('global.testregex'), 'OO - Retrieve regepx'); is( scalar @list, 1, 'OO - Regexp ref list context'); is( ref $list[0], 'Regexp', 'OO - Regexp ref'); is( ref scalar $config->C('global.testregex'), 'Regexp', 'OO - Regexp ref scalar context'); ok( @list = $config->C('global.testobj'), 'OO - Retrieve object'); is( scalar @list, 1, 'OO - Object list context'); is( ref $list[0], 'ABC', 'OO - Object ref'); is( ref scalar $config->C('global.testobj'), 'ABC', 'OO - Object scalar context'); is( $config->C('global.db.hosts.image.1'), 'host5', 'OO - Directory lookup' ); is( $config->C('global.db.hosts.image.1'), 'host5', 'OO - Directory lookup' ); is( defined eval{$config->C('global.db3.hosts.image.1')} ? 1 : 0, 0, 'OO - Directory lookup - fail overwritten' ); is( $config->C('global.db3.different'), 'data', 'OO - Directory lookup - succeed overwritten' ); is( $config->C('global.engine'), 'Oracle', 'OO - Local override' ); is( $config->C('global.db2.hosts.session.0'), 'local1', 'OO - Local override deep' ); $config->clear_cache(); my $data = $config->C('global.db.hosts'); $data->{session} = '123'; is( $config->C('global.db.hosts.session'), '123', 'OO - Overwrite original' ); $data = $config->clone('global.db.hosts'); $data->{image} = '123'; isnt( $config->C('global.db.hosts.image'), '123', 'OO - Overwrite clone' ); $config->load_config(); isnt( $config->C('global.db.hosts.session'), '123', 'OO - Reload data' ); #=================================== sub get_path { #=================================== my ($vol,$path) = File::Spec->splitpath( File::Spec->rel2abs($0) ); $path = File::Spec->catdir( File::Spec->splitdir($path), 'data',@_ ); return File::Spec->catpath($vol,$path,''); } Config-Merge-1.04/t/20_functional.t000644 000765 000024 00000007272 12376630557 017632 0ustar00clintonstaff000000 000000 use strict; use warnings; use File::Spec; use Test::More 'tests' => 31; my $path; BEGIN { my $vol; ($vol,$path) = File::Spec->splitpath( File::Spec->rel2abs($0) ); $path = File::Spec->catdir( File::Spec->splitdir($path), 'data','perlmulti' ); $path = File::Spec->catpath($vol,$path,''); } BEGIN { use_ok('Config::Merge', 'My' => $path); } BEGIN { use_ok('My'); } is( C('global.domain'), 'www.test.com', 'Func - Simple lookup' ); is_deeply( scalar C('global.db.hosts.session'), [qw(host1 host2 host3)], 'Func - Array ref lookup' ); is_deeply( [ C('global.db.hosts.session') ], [qw(host1 host2 host3)], 'Func - Array lookup' ); is( C('global.db.hosts.image.1'), 'host5', 'Func - Array element lookup' ); my @list; ok( @list = C('global.testsub'), 'Func - Retrieve coderef'); is( scalar @list, 1, 'Func - CODE ref list context'); is( ref $list[0], 'CODE', 'Func - CODE ref'); is( ref scalar C('global.testsub'), 'CODE', 'Func - CODE ref scalar context'); ok( @list = C('global.testregex'), 'Func - Retrieve regexp'); is( scalar @list, 1, 'Func - Regexp ref list context'); is( ref $list[0], 'Regexp', 'Func - Regexp ref'); is( ref scalar C('global.testregex'), 'Regexp', 'Func - Regexp ref scalar context'); ok( @list = C('global.testobj'), 'Func - Retrieve object'); is( scalar @list, 1, 'Func - Object list context'); is( ref $list[0], 'ABC', 'Func - Object ref'); is( ref scalar C('global.testobj'), 'ABC', 'Func - Object scalar context'); is( C('global.db.hosts.image.1'), 'host5', 'Func - Directory lookup' ); is( defined eval{C('global.db3.hosts.image.1')} ? 1 : 0, 0, 'Func - Directory lookup - fail overwritten' ); is( C('global.db3.different'), 'data', 'Func - Directory lookup - succeed overwritten' ); is( C('global.engine'), 'Oracle', 'Func - Local override' ); is( C('global.db2.hosts.session.0'), 'local1', 'Func - Local override deep' ); my $config = My->object(); is( $config->C('global.domain'), 'www.test.com', 'Func - object->C lookup' ); is( $config->('global.domain'), 'www.test.com', 'Func - overload lookup' ); $config->clear_cache(); my $data = C('global.db.hosts'); $data->{session} = '123'; is( C('global.db.hosts.session'), '123', 'Func - Overwrite original' ); $data = My::clone('global.db.hosts'); $data->{image} = '123'; isnt( C('global.db.hosts.image'), '123', 'Func - Overwrite clone' ); My::object->load_config(); isnt( C('global.db.hosts.session'), '123', 'Func - Reload data' ); is ($config, My::object(), 'Func - reload object same'); $config->clear_cache(); $data = $config->C('global.db.hosts'); $data->{session} = '123'; is( $config->C('global.db.hosts.session'), '123', 'Func - Object overwrite original' ); $data = $config->clone('global.db.hosts'); $data->{image} = '123'; isnt( $config->C('global.db.hosts.image'), '123', 'Func - Object overwrite clone' ); Config-Merge-1.04/t/30_errors.t000644 000765 000024 00000005572 12376630557 017006 0ustar00clintonstaff000000 000000 use strict; use warnings; use File::Spec; use Test::More 'tests' => 17; BEGIN { use_ok('Config::Merge'); } my $config; eval { $config = Config::Merge->new()}; like( $@, qr/Configuration directory not specified/, 'New - no directory' ); eval { $config = Config::Merge->new(get_path('none'))}; like( $@, qr/not readable/, 'New - directory not readable' ); eval { $config = Config::Merge->new(get_path('bad'))}; like( $@, qr/Error loading config/, 'New - Error loading config' ); $config = Config::Merge->new(get_path('perl')); eval { $config->('global.nonexistent')}; like( $@, qr/Invalid key/, 'Invalid key' ); eval {Config::Merge->register_loader()}; like( $@, qr/No loader class/, 'No loader class' ); eval {Config::Merge->register_loader('Config::Merge::None')}; like( $@, qr{Can't locate Config/Merge/None.pm}, 'Bad loader class' ); eval {Config::Merge->import(get_path('perl'))}; like( $@, qr{USAGE}, 'Bad import' ); eval { $config = Config::Merge->new(path => get_path('perl'), load_as => sub {return ''})}; like( $@, qr/load_as\(\) cannot return ''/, "New - main load_as '' " ); eval { $config = Config::Merge->new(path => get_path('errors','array_merge'))}; like( $@, qr/Array override for key/, "Array override" ); eval { $config = Config::Merge->new(path => get_path('errors','array_delete_ref'))}; like( $@, qr/Index delete.*array ref/, "Array delete ref" ); ok ($config = Config::Merge->new(path => get_path('errors','array_delete_int')), 'Array delete int' ); eval { $config = Config::Merge->new(path => get_path('errors','array_insert_ref'))}; like( $@, qr/Array add .*ref/, "Array insert ref" ); ok ($config = Config::Merge->new(path => get_path('errors','array_insert_int')), 'Array insert int' ); eval { $config = Config::Merge->new(path => get_path('empty'), load_as =>{})}; like( $@, qr/load_as\(\) cannot be a hashref/, "Load_as hash ref" ); eval { $config = Config::Merge->new(path => get_path('empty'), load_as => [])}; like( $@, qr/single regex/, "Load_as array ref" ); eval { $config = Config::Merge->new(path => get_path('empty'), is_local => 'abc')}; like( $@, qr/not a regular expression/, "Not regex" ); #=================================== sub get_path { #=================================== my ($vol,$path) = File::Spec->splitpath( File::Spec->rel2abs($0) ); $path = File::Spec->catdir( File::Spec->splitdir($path), 'data',@_ ); return File::Spec->catpath($vol,$path,''); } Config-Merge-1.04/t/40_advanced.t000644 000765 000024 00000017317 12376630557 017240 0ustar00clintonstaff000000 000000 use strict; use warnings; use File::Spec; use Test::More 'tests' => 80; BEGIN { use_ok('Config::Merge'); } my ($c,$C); my $path = get_path('skip'); ## SKIP ok($c = Config::Merge->new(path => $path, skip => qr{skip_\d}), 'new - skip - regex' ); $C=$c->(); ok( exists $C->{skip_not}, 'skip - dir - regex - 1' ); ok( ! exists $C->{skip_1}, 'skip - dir - regex - 2' ); ok( exists $C->{main}{skip_not}, 'skip - file - regex - 1' ); ok(! exists $C->{main}{skip_1}, 'skip - file - regex - 2' ); ok($c = Config::Merge->new(path => $path, skip => [qr{skip_1}, qr{skip_2}]), 'new - skip - regexen' ); $C=$c->(); ok( exists $C->{skip_not}, 'skip - dir - regexen - 1' ); ok( ! exists $C->{skip_1}, 'skip - dir - regexen - 2' ); ok( exists $C->{main}{skip_not}, 'skip - file - regexen - 1' ); ok(! exists $C->{main}{skip_1}, 'skip - file - regexen - 2' ); ok($c = Config::Merge->new(path => $path, skip => {'skip_1' => 1,'main.skip_1' => 1}), 'new - skip - hash' ); $C=$c->(); ok( exists $C->{skip_not}, 'skip - dir - hash - 1' ); ok( ! exists $C->{skip_1}, 'skip - dir - hash - 2' ); ok( exists $C->{main}{skip_not}, 'skip - file - hash - 1' ); ok(! exists $C->{main}{skip_1}, 'skip - file - hash - 2' ); ok($c = Config::Merge->new(path => $path, skip => sub { my ($self,$filename) = @_; return 1 if $filename=~/skip_1/; return 0; }), 'new - skip - sub' ); $C=$c->(); ok( exists $C->{skip_not}, 'skip - dir - sub - 1' ); ok( ! exists $C->{skip_1}, 'skip - dir - sub - 2' ); ok( exists $C->{main}{skip_not}, 'skip - file - sub - 1' ); ok(! exists $C->{main}{skip_1}, 'skip - file - sub - 2' ); ## LOAD_AS for main config $path = get_path('load_as'); ok($c = Config::Merge->new(path => $path), 'new - main load_as - none' ); is($c->C('file.a'), 1, 'main load_as - none - 1' ); is($c->C('file-(local).a'), 4, 'main load_as - none - 2' ); is($c->C('dir.file.a'), 1, 'main load_as - none - 3' ); is($c->C('dir-(local).file.a'), 4, 'main load_as - none - 4' ); is($c->C('sub.test.foo'), 'test', 'main load_as - none - 5' ); is($c->C('sub.test.bar'), 'test', 'main load_as - none - 6' ); is($c->C('sub.test-(aaa).foo'), 'test-(aaa)', 'main load_as - none - 7' ); is($c->C('sub.test-(bbb).foo'), 'test-(bbb)', 'main load_as - none - 8' ); is($c->C('sub.dir.test.foo'), 'test', 'main load_as - none - 9' ); is($c->C('sub.dir.test.bar'), 'test', 'main load_as - none - 10' ); is($c->C('sub.dir-(aaa).test.foo'), 'test-(aaa)', 'main load_as - none - 11' ); is($c->C('sub.dir-(bbb).test.foo'), 'test-(bbb)', 'main load_as - none - 12' ); ok($c = Config::Merge->new(path => $path, load_as => qr/(.*)-\(local\)/), 'new - load_as - regex' ); $C=$c->(); is($c->C('file.a'), '4', 'load_as - regex - 1' ); is($c->C('file.d'), '5', 'load_as - regex - 2' ); is($c->C('file.b'), '2', 'load_as - regex - 3' ); is($c->C('dir.file.a'), '4', 'load_as - regex - 4' ); is($c->C('dir.file.d'), '5', 'load_as - regex - 5' ); ok (!exists $C->{dir}{file}{b}, 'load_as - regex - 6' ); ok($c = Config::Merge->new(path => $path, load_as => sub { my ($self,$name) = @_; if ($name=~/(.*)-[(](\w+)[)]/) { return $2 eq 'aaa' ? $1 : undef; } return $name; }), 'new - load_as - sub' ); $C=$c->(); is($c->C('sub.test.foo'), 'test-(aaa)', 'load_as - sub - 1' ); is($c->C('sub.test.bar'), 'test', 'load_as - sub - 2' ); is($c->C('sub.dir.test.foo'), 'test-(aaa)', 'load_as - sub - 3' ); ok (!exists $C->{sub}{dir}{test}{bar}, 'load_as - sub - 4' ); ok (!exists $C->{sub}{'test-(aaa)'}, 'load_as - sub - 5' ); ok (!exists $C->{sub}{'test-(bbb)'}, 'load_as - sub - 6' ); ok (!exists $C->{sub}{'dir-(aaa)'}, 'load_as - sub - 7' ); ok (!exists $C->{sub}{'dir-(bbb)'}, 'load_as - sub - 7' ); ## SORT ok($c = Config::Merge->new(path => $path, load_as => qr/(.*)-\(local\)/, sort => sub {return [sort @{$_[1]}]}), 'new - load_as - regex' ); is($c->C('file.a'), '1', 'sort' ); ## IS_LOCAL $path=get_path('local'); ok($c = Config::Merge->new(path => $path), 'new - is_local - none' ); is ($c->C('main.db.servers.server1.host'), 'host1', 'is_local - none - 1' ); is ($c->C('main.db.servers.list.0'), 'server1', 'is_local - none - 2' ); ok($c = Config::Merge->new(path => $path, is_local => qr{override}), 'new - is_local - regex - ..' ); is ($c->C('main.db.servers.server1.host'), 'host4', 'is_local - regex - .. - 1' ); is ($c->C('main.db.servers.list.0'), 'server3', 'is_local - regex - .. - 2' ); ok($c = Config::Merge->new(path => $path, is_local => {override => 1}), 'new - is_local - hash - ..' ); is ($c->C('main.db.servers.server1.host'), 'host4', 'is_local - hash - .. - 1' ); is ($c->C('main.db.servers.list.0'), 'server3', 'is_local - hash - .. - 2' ); ok($c = Config::Merge->new(path => $path, is_local => sub { return $_[1] eq 'override'}), 'new - is_local - sub - ..' ); is ($c->C('main.db.servers.server1.host'), 'host4', 'is_local - sub - .. - 1' ); is ($c->C('main.db.servers.list.0'), 'server3', 'is_local - sub - .. - 2' ); ok($c = Config::Merge->new(path => $path, is_local => qr{-[(].+[)]}, load_as => qr{(.*)-[(].+[)]}), 'new - is_local - regex - key' ); is ($c->C('email.address.sig'), 'Us', 'is_local - regex - key - 1' ); is ($c->C('email.address.from'), 'dev@', 'is_local - regex - key - 2' ); is ($c->C('email.address.headers.0'), 'ddd', 'is_local - regex - key - 3' ); is ($c->C('email.address.subject'), 'DEV', 'is_local - regex - key - 4' ); ok($c = Config::Merge->new(path => $path, is_local => qr{-[(].+[)]}, load_as => sub { my $name = $_[1]; if ($name=~/(.*)-[(](.*)[)]/) { return $2 eq 'aaa' ? $1 : undef; } return $name;} ), 'new - is_local - sub - key' ); is ($c->C('email.address.sig'), 'Us', 'is_local - sub - key - 1' ); is ($c->C('email.address.from'), 'dev@', 'is_local - sub - key - 2' ); is ($c->C('email.address.headers.0'), 'ddd', 'is_local - sub - key - 3' ); is ($c->C('email.address.subject'), 'HELP', 'is_local - sub - key - 4' ); $path = get_path('array'); ok($c = Config::Merge->new(path => $path), 'new - array merge' ); is_deeply( scalar $c->C('main.foo'), [qw(a b d f h i Z k l m)], 'array merge - 1' ); is_deeply( scalar $c->C('main.bar'), [qw(a b Z d Y f h i j), undef, undef, 'X',undef, 'W'], 'array merge - 2' ); is_deeply( scalar $c->C('main.baz'), [qw(x y z)], 'array merge - 3' ); ## EXPLAIN my ($debug, $olderr); open $olderr, '>&', \*STDERR or die "Can't dup STDERR: $!"; close STDERR or die "Can't close STDERR : $!"; open STDERR, '>>', \$debug or die "Can't open STDERR to debug : $!"; ok($c = Config::Merge->new(path => $path, debug => 1), 'new - debug' ); open STDERR, '>&', $olderr or die "Can't dup OLDERR: $!"; like($debug, qr/Entering dir/, 'debug' ); #=================================== sub get_path { #=================================== my ($vol,$path) = File::Spec->splitpath( File::Spec->rel2abs($0) ); $path = File::Spec->catdir( File::Spec->splitdir($path), 'data',@_ ); return File::Spec->catpath($vol,$path,''); } 1;Config-Merge-1.04/t/50_spaces_in_path.t000644 000765 000024 00000000776 12376630557 020455 0ustar00clintonstaff000000 000000 use strict; use warnings; use File::Spec; use Test::More 'tests' => 3; my $path; BEGIN { my $vol; ($vol,$path) = File::Spec->splitpath( File::Spec->rel2abs($0) ); $path = File::Spec->catdir( File::Spec->splitdir($path), 'data','with spaces' ); $path = File::Spec->catpath($vol,$path,''); } BEGIN { use_ok('Config::Merge', 'My' => $path); } BEGIN { use_ok('My'); } is( C('foo.bar'), 'baz', 'With spaces' ); Config-Merge-1.04/t/80_pod.t000644 000765 000024 00000000201 12376630557 016241 0ustar00clintonstaff000000 000000 use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Config-Merge-1.04/t/81_pod_coverage.t000644 000765 000024 00000000316 12376630557 020124 0ustar00clintonstaff000000 000000 use Test::More; eval "use Test::Pod::Coverage tests=>1"; plan skip_all => "Test::Pod::Coverage required for testing POD coverage" if $@; pod_coverage_ok( "Config::Merge", "Config::Merge is covered" ); Config-Merge-1.04/t/data/000755 000765 000024 00000000000 12376630557 015703 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/array/000755 000765 000024 00000000000 12376630557 017021 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/bad/000755 000765 000024 00000000000 12376630557 016431 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/empty/000755 000765 000024 00000000000 12376630557 017041 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/errors/000755 000765 000024 00000000000 12376630557 017217 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/load_as/000755 000765 000024 00000000000 12376630557 017305 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/local/000755 000765 000024 00000000000 12376630557 016775 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/perl/000755 000765 000024 00000000000 12376630557 016645 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/perlmulti/000755 000765 000024 00000000000 12376630557 017720 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/skip/000755 000765 000024 00000000000 12376630557 016651 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/with spaces/000755 000765 000024 00000000000 12376630557 020115 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/with spaces/foo.yaml000644 000765 000024 00000000012 12376630557 021555 0ustar00clintonstaff000000 000000 bar: baz Config-Merge-1.04/t/data/skip/main/000755 000765 000024 00000000000 12376630557 017575 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/skip/skip_1/000755 000765 000024 00000000000 12376630557 020037 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/skip/skip_2/000755 000765 000024 00000000000 12376630557 020040 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/skip/skip_not/000755 000765 000024 00000000000 12376630557 020477 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/skip/skip_not/test.pl000644 000765 000024 00000000006 12376630557 022007 0ustar00clintonstaff000000 000000 'foo' Config-Merge-1.04/t/data/skip/skip_2/test.pl000644 000765 000024 00000000006 12376630557 021350 0ustar00clintonstaff000000 000000 'foo' Config-Merge-1.04/t/data/skip/skip_1/test.pl000644 000765 000024 00000000006 12376630557 021347 0ustar00clintonstaff000000 000000 'foo' Config-Merge-1.04/t/data/skip/main/skip_1.pl000644 000765 000024 00000000006 12376630557 021314 0ustar00clintonstaff000000 000000 'foo' Config-Merge-1.04/t/data/skip/main/skip_2.pl000644 000765 000024 00000000006 12376630557 021315 0ustar00clintonstaff000000 000000 'foo' Config-Merge-1.04/t/data/skip/main/skip_not.pl000644 000765 000024 00000000006 12376630557 021754 0ustar00clintonstaff000000 000000 'foo' Config-Merge-1.04/t/data/perlmulti/global/000755 000765 000024 00000000000 12376630557 021160 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/perlmulti/global.perl000644 000765 000024 00000000512 12376630557 022042 0ustar00clintonstaff000000 000000 { domain => 'www.test.com', db3 => { different => 'data', }, engine => 'MySQL', testsub => sub {'test'}, testregex => qr/test/, testobj => bless({},'ABC'), list => { a => 'b'}, array => [1,2,3,4], } Config-Merge-1.04/t/data/perlmulti/local.perl000644 000765 000024 00000000154 12376630557 021676 0ustar00clintonstaff000000 000000 { global => { engine => 'Oracle', array => { key => 'value' }, } } Config-Merge-1.04/t/data/perlmulti/global/db.pl000644 000765 000024 00000000203 12376630557 022075 0ustar00clintonstaff000000 000000 { hosts => { session => [qw(host1 host2 host3)], image => [qw(host4 host5 host6)], }, }, Config-Merge-1.04/t/data/perlmulti/global/db2.pl000644 000765 000024 00000000200 12376630557 022154 0ustar00clintonstaff000000 000000 { hosts => { session => [qw(host1 host2 host3)], image => [qw(host4 host5 host6)], }, } Config-Merge-1.04/t/data/perlmulti/global/db3.pl000644 000765 000024 00000000200 12376630557 022155 0ustar00clintonstaff000000 000000 { hosts => { session => [qw(host1 host2 host3)], image => [qw(host4 host5 host6)], }, } Config-Merge-1.04/t/data/perlmulti/global/local.pl000644 000765 000024 00000000104 12376630557 022602 0ustar00clintonstaff000000 000000 { db2 => { hosts => { session =>[qw(local1)]}}} Config-Merge-1.04/t/data/perl/global.perl000644 000765 000024 00000000340 12376630557 020766 0ustar00clintonstaff000000 000000 { db => { hosts => { session => [qw(host1 host2 host3)], image => [qw(host4 host5 host6)], }, engine => 'MySQL', }, domain => 'www.test.com', } Config-Merge-1.04/t/data/local/email-(aaa).pl000644 000765 000024 00000000126 12376630557 021261 0ustar00clintonstaff000000 000000 { address => { from => 'dev@', headers => [qw(ddd )], }, } Config-Merge-1.04/t/data/local/email-(bbb).pl000644 000765 000024 00000000066 12376630557 021267 0ustar00clintonstaff000000 000000 { address => { subject => 'DEV', }, } Config-Merge-1.04/t/data/local/email.pl000644 000765 000024 00000000223 12376630557 020416 0ustar00clintonstaff000000 000000 { address => { sig => 'Us', from => 'help@', subject => 'HELP', headers => [qw(aaa bbb ccc )], }, } Config-Merge-1.04/t/data/local/main.pl000644 000765 000024 00000000471 12376630557 020260 0ustar00clintonstaff000000 000000 { db => { servers => { server1 => { host => 'host1', user => 'user1', }, server2 => { host => 'host2', user => 'user2', }, list => [qw(server1 server2)], } } } Config-Merge-1.04/t/data/local/override.pl000644 000765 000024 00000000575 12376630557 021160 0ustar00clintonstaff000000 000000 { main => { db => { servers => { server1 => { host => 'host4', user => 'user4', }, server3 => { host => 'host3', user => 'user3', }, list => [qw(server3)], } } } } Config-Merge-1.04/t/data/load_as/dir/000755 000765 000024 00000000000 12376630557 020063 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/load_as/dir-(local)/000755 000765 000024 00000000000 12376630557 021274 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/load_as/file-(local).pl000644 000765 000024 00000000040 12376630557 021764 0ustar00clintonstaff000000 000000 { 'a' => 4, 'd' => 5, } Config-Merge-1.04/t/data/load_as/file.pl000644 000765 000024 00000000056 12376630557 020562 0ustar00clintonstaff000000 000000 { 'a' => 1, 'b' => 2, 'c' => 3, } Config-Merge-1.04/t/data/load_as/sub/000755 000765 000024 00000000000 12376630557 020076 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/load_as/sub/dir/000755 000765 000024 00000000000 12376630557 020654 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/load_as/sub/dir-(aaa)/000755 000765 000024 00000000000 12376630557 021515 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/load_as/sub/dir-(bbb)/000755 000765 000024 00000000000 12376630557 021520 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/load_as/sub/test-(aaa).pl000644 000765 000024 00000000032 12376630557 022246 0ustar00clintonstaff000000 000000 { foo => 'test-(aaa)' } Config-Merge-1.04/t/data/load_as/sub/test-(bbb).pl000644 000765 000024 00000000032 12376630557 022251 0ustar00clintonstaff000000 000000 { foo => 'test-(bbb)' } Config-Merge-1.04/t/data/load_as/sub/test.pl000644 000765 000024 00000000047 12376630557 021413 0ustar00clintonstaff000000 000000 { foo => 'test', bar => 'test' } Config-Merge-1.04/t/data/load_as/sub/dir-(bbb)/test.pl000644 000765 000024 00000000032 12376630557 023027 0ustar00clintonstaff000000 000000 { foo => 'test-(bbb)' } Config-Merge-1.04/t/data/load_as/sub/dir-(aaa)/test.pl000644 000765 000024 00000000032 12376630557 023024 0ustar00clintonstaff000000 000000 { foo => 'test-(aaa)' } Config-Merge-1.04/t/data/load_as/sub/dir/test.pl000644 000765 000024 00000000047 12376630557 022171 0ustar00clintonstaff000000 000000 { foo => 'test', bar => 'test' } Config-Merge-1.04/t/data/load_as/dir-(local)/file.pl000644 000765 000024 00000000040 12376630557 022542 0ustar00clintonstaff000000 000000 { 'a' => 4, 'd' => 5, } Config-Merge-1.04/t/data/load_as/dir/file.pl000644 000765 000024 00000000056 12376630557 021340 0ustar00clintonstaff000000 000000 { 'a' => 1, 'b' => 2, 'c' => 3, } Config-Merge-1.04/t/data/errors/array_delete_int/000755 000765 000024 00000000000 12376630557 022531 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/errors/array_delete_ref/000755 000765 000024 00000000000 12376630557 022513 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/errors/array_insert_int/000755 000765 000024 00000000000 12376630557 022573 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/errors/array_insert_ref/000755 000765 000024 00000000000 12376630557 022555 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/errors/array_merge/000755 000765 000024 00000000000 12376630557 021514 5ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/errors/array_merge/local.pl000644 000765 000024 00000000104 12376630557 023136 0ustar00clintonstaff000000 000000 {main => { foo => { '!' => {}, 'abc' => 'bar', } } } Config-Merge-1.04/t/data/errors/array_merge/main.pl000644 000765 000024 00000000032 12376630557 022770 0ustar00clintonstaff000000 000000 { foo => [ 1, 2, 3, 4 ] } Config-Merge-1.04/t/data/errors/array_insert_ref/local.pl000644 000765 000024 00000000114 12376630557 024200 0ustar00clintonstaff000000 000000 {main => { foo => { '!' => { '+' => 'abc', }, } } } Config-Merge-1.04/t/data/errors/array_insert_ref/main.pl000644 000765 000024 00000000032 12376630557 024031 0ustar00clintonstaff000000 000000 { foo => [ 1, 2, 3, 4 ] } Config-Merge-1.04/t/data/errors/array_insert_int/local.pl000644 000765 000024 00000000123 12376630557 024216 0ustar00clintonstaff000000 000000 {main => { foo => { '!' => { '+' => {'abc' => 1}, }, } } } Config-Merge-1.04/t/data/errors/array_insert_int/main.pl000644 000765 000024 00000000032 12376630557 024047 0ustar00clintonstaff000000 000000 { foo => [ 1, 2, 3, 4 ] } Config-Merge-1.04/t/data/errors/array_delete_ref/local.pl000644 000765 000024 00000000114 12376630557 024136 0ustar00clintonstaff000000 000000 {main => { foo => { '!' => { '-' => 'abc', }, } } } Config-Merge-1.04/t/data/errors/array_delete_ref/main.pl000644 000765 000024 00000000032 12376630557 023767 0ustar00clintonstaff000000 000000 { foo => [ 1, 2, 3, 4 ] } Config-Merge-1.04/t/data/errors/array_delete_int/local.pl000644 000765 000024 00000000116 12376630557 024156 0ustar00clintonstaff000000 000000 {main => { foo => { '!' => { '-' => ['abc'], }, } } } Config-Merge-1.04/t/data/errors/array_delete_int/main.pl000644 000765 000024 00000000032 12376630557 024005 0ustar00clintonstaff000000 000000 { foo => [ 1, 2, 3, 4 ] } Config-Merge-1.04/t/data/empty/.dummy000644 000765 000024 00000000000 12376630557 020163 0ustar00clintonstaff000000 000000 Config-Merge-1.04/t/data/bad/db.pl000644 000765 000024 00000000173 12376630557 017354 0ustar00clintonstaff000000 000000 hosts => { session => [qw(host1 host2 host3)], image => [qw(host4 host5 host6)], , Config-Merge-1.04/t/data/array/local.pl000644 000765 000024 00000001051 12376630557 020445 0ustar00clintonstaff000000 000000 { main => { foo => { '!' => { '-' => [2,4,6], '+' => [qw(k l m)], }, '9' => 'Z', }, bar => { '!' => { '-' => [2,4,6,20], '+' => { 2 => 'Z', 5 => 'Y', 12 => 'X', 14 => 'W', }, }, }, baz => [qw( x y z )], } } Config-Merge-1.04/t/data/array/main.pl000644 000765 000024 00000000177 12376630557 020307 0ustar00clintonstaff000000 000000 { foo => [qw( a b c d e f g h i j )], bar => [qw( a b c d e f g h i j )], baz => [qw( a b c d e f g h i j )], } Config-Merge-1.04/lib/Config/000755 000765 000024 00000000000 12376630557 016502 5ustar00clintonstaff000000 000000 Config-Merge-1.04/lib/Config/Merge/000755 000765 000024 00000000000 12376630557 017541 5ustar00clintonstaff000000 000000 Config-Merge-1.04/lib/Config/Merge.pm000644 000765 000024 00000115251 12376630557 020104 0ustar00clintonstaff000000 000000 package Config::Merge; use strict; use warnings FATAL => 'all', NONFATAL => 'redefine'; use File::Spec(); use File::Glob 'bsd_glob'; use Storable(); use overload ( '&{}' => sub { my $self = shift; return sub { $self->C(@_) } }, 'fallback' => 1 ); use vars qw($VERSION); $VERSION = '1.04'; =head1 NAME Config::Merge - load a configuration directory tree containing YAML, JSON, XML, Perl, INI or Config::General files =head1 SYNOPSIS OO style ------------------------------------------------------- use Config::Merge(); my $config = Config::Merge->new('/path/to/config'); @hosts = $config->('db.hosts.session'); $hosts_ref = $config->('db.hosts.session'); @cloned_hosts = $config->clone('db.hosts.session'); ------------------------------------------------------- OR Functional style ------------------------------------------------------- # On startup use Config::Merge('My::Config' => '/path/to/config'); # Then, in any module where you want to use the config package My::Module; use My::Config; @hosts = C('db.hosts.sesssion'); $hosts_ref = C('db.hosts.sesssion'); @cloned_hosts = My::Config::clone('db.hosts.session'); $config = My::Config::object; ------------------------------------------------------- ADVANCED USAGE OO style ------------------------------------------------------- my $config = Config::Merge->new( path => '/path/to/config', skip => sub {} | regex | {} , is_local => sub {} | regex | {} , load_as => sub {} | regex , sort => sub {} , debug => 1 | 0 ); ------------------------------------------------------- Functional style ------------------------------------------------------- use Config::Merge( 'My::Config' => '/path/to/config', { skip => sub {} | regex | {} , is_local => sub {} | regex | {} , load_as => sub {} | regex , sort => sub {} , debug => 1 | 0 } ); # Also, you can subclass these: package My::Config; sub skip { ... } ------------------------------------------------------- =head1 DESCRIPTION Config::Merge is a configuration module which has six goals: =over =item * Flexible storage Store all configuration in your format(s) of choice (YAML, JSON, INI, XML, Perl, Config::General / Apache-style config) broken down into individual files in a configuration directory tree, for easy maintenance. See L =item * Flexible access Provide a simple, easy to read, concise way of accessing the configuration values (similar to L