Config-Any-0.32/000755 000765 000024 00000000000 13077221024 013647 5ustar00gknopstaff000000 000000 Config-Any-0.32/Changes000644 000765 000024 00000012525 13077220723 015154 0ustar00gknopstaff000000 000000 Revision history for Config-Any 0.32 - 2017-04-23 - allow YAML::Syck to fail its error tests - improved diagnostics in YAML test - include a full list of modules used in JSON documentation - be less strict checking error messages in tests - add test to report optional prereq versions 0.31 - 2017-04-23 - test cleanups - better diagnostics for test failures - don't run pod tests on user machines - handle unsupported Config::General versions better - refactored module loading - include optional prereqs in suggests - pod cleanups 0.30 - 2017-03-28 - don't use YAML::Syck on perl 5.8.8 or below, where it is broken - ensure tarball does not contain SCHILY headers 0.29 - 2017-02-27 - allow loading relative perl files even under taint mode (RT#120371) - throw errors when attempting to load perl files that do not exist 0.28 - 2017-02-21 - support Cpanel::JSON::XS and JSON::MaybeXS for loading JSON - decode UTF-8 config files properly - load perl files directly, never possibly searching @INC 0.27 2016-03-31 - depend on Module::Pluggable::Object directly instead of assuming it is bundled with Module::Pluggable (RT #113148) 0.26 2015-04-29 - fix error reporting from code applied in 0.25 (RT #104079) 0.25 2015-04-23 - do not clobber $@ (RT #103061) 0.24 2013-09-10 - remove 4-year-old warning about YAML::XS not being installed - add JSON::PP to list of available JSON parsers (RT #86959) 0.23 2011-07-13 - fix test suite's method of checking availability of plugins 0.22 2011-07-04 - add XML::NamespaceSupport to XML format deps, silence YAML warnings in tests (caelum) 0.21 2011-05-25 - fix t/64-extfail.t to pass when t/lib is in @INC 0.20 2010-08-06 - enable -ForceArray option by default for Config::General (caelum) 0.19 2010-02-15 - add JSON::DWIW to the top of the JSON loaders list (caelum) - remove need for caching in Perl loader by using do() instead of require() (caelum) 0.18 2009-11-16 - ensure XML loader's _coerce() method checks specifically for HASH refs - add YAML::XS to the top of the YAML loaders list 0.17 2009-02-05 - ensure require() happens against plugin specified in force_plugins. - add JSON::XS to the top of the JSON loaders list 0.16 2008-11-17 - fix up branches test which did not handle the errors thrown by changes from the last release (RT #40948) - fix up error message for "any of" (RT #40972) 0.15 2008-11-12 - when use_ext is true, we will check to see if there are no supported modules for a particular file. instead of the file being skipped, an error will be thrown (RT #38927). - also, when use_ext is true, a fatal error will be thrown if there are no loaders available that understand the file extension. - officially support multiple loaders per extension - add a Config::Any::Base for all loaders to inherit from, plus add a new dependency mechanism: requires_any_of() and requires_all_of(). - filter out loaders that don't inherit from Config::Any::Base (RT #40830) 0.14 2008-08-06 - skip xml failure tests if XML::LibXML < 1.59 is installed, it seems to parse anything you throw at it (Matt S. Trout) 0.13 2008-08-05 - show actual parse error when parse fails (Marcus Ramberg) - ensure Config::Tiny parse errors are trapped - added tests for each format to ensure they throw parse errors - added a caveat regarding XML::Simple's strict mode (Peter Corlett) - added a flatten_to_hash option to return a simple key-value hashref instead of the default "arrayref of hashrefs" (Pedro Figueiredo) 0.12 2008-04-07 - ensure Perl loader dies on a failed require() (RT #32995) 0.11 2008-01-28 - fix subsection parsing for existing keys in INI files (RT #32726) - use from_json() if JSON version 2.x is available - refactor the test suite slightly 0.10 2007-12-11 - promote dev release to stable 0.09_02 2007-11-13 - require version 0.70 of YAML::Syck for multi-document loading 0.09_01 2007-11-13 - code and pod cleanups - use_ext is now on by default - when use_ext is on, if a loader throws an error, we throw an error - fix case where use_ext is defined and false, but was behaving like use_ext => 1 - allow loaders to return multiple documents as an array - each plugin now has an is_supported() method which helps us figure out if the right modules are available 0.08 2007-08-23 - pass config options to each parser - fix for loading the same perl config twice (RT #28812) 0.07 2007-02-26 - promote 0.06_01 to non-dev. 0.06_01 2007-02-25 - fixed bug [rt.cpan.org #25143] make tests fails + t/61_features.t had 1 more test added than was set to skip if the INI parser was not installed. Fixed by s/9/10/ on the skip() line. 0.06 2007-02-22 - removed reference to Test::Exception, bumped version number 0.05 2007-02-21 - added support for (requested by Evan Kaufman): + 'force_plugins => [ qw(Config::Any::Foo Config::Any::Blah) ]' parameter to load_(files|stems) + $Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY - boolean, defaulting to on, controlling whether to map spaces in INI section headings to nested hashrefs 0.04 2006-08-07 - Initial CPAN-worthy release with proper test suite Config-Any-0.32/lib/000755 000765 000024 00000000000 13077221024 014415 5ustar00gknopstaff000000 000000 Config-Any-0.32/maint/000755 000765 000024 00000000000 13077221024 014757 5ustar00gknopstaff000000 000000 Config-Any-0.32/Makefile.PL000644 000765 000024 00000006210 13072437363 015632 0ustar00gknopstaff000000 000000 use strict; use warnings FATAL => 'all'; use 5.006; my %META = ( name => 'Config-Any', license => 'perl_5', prereqs => { test => { requires => { 'Test::More' => 0, } }, runtime => { requires => { 'Module::Pluggable::Object' => '3.6', }, suggests => { 'Config::General' => '2.47', 'Config::Tiny' => 0, 'Cpanel::JSON::XS' => 0, 'XML::Simple' => 0, 'XML::NamespaceSupport' => 0, 'YAML::XS' => 0, }, }, develop => { requires => { 'Config::General' => '2.47', 'Config::Tiny' => 0, 'Cpanel::JSON::XS' => 0, 'XML::Simple' => 0, 'XML::NamespaceSupport' => 0, 'YAML::XS' => 0, 'Test::Pod' => 0, 'Test::Pod::Coverage' => 0, }, }, }, resources => { repository => { url => 'git://git.shadowcat.co.uk/p5sagit/Config-Any.git', web => 'http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/Config-Any.git;a=summary', type => 'git', }, bugtracker => { web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=Config-Any', mailto => 'bug-Config-Any@rt.cpan.org', }, license => [ 'http://dev.perl.org/licenses/' ], }, no_index => { directory => [ 't', 'xt' ] }, x_authority => 'cpan:RATAXIS', ); my %MM_ARGS = ( PREREQ_PM => { (eval { require Config::General } ? ('Config::General' => '2.47') : ()), }, ); ## BOILERPLATE ############################################################### require ExtUtils::MakeMaker; (do './maint/Makefile.PL.include' or die $@) unless -f 'META.yml'; # have to do this since old EUMM dev releases miss the eval $VERSION line my $eumm_version = eval $ExtUtils::MakeMaker::VERSION; my $mymeta = $eumm_version >= 6.57_02; my $mymeta_broken = $mymeta && $eumm_version < 6.57_07; ($MM_ARGS{NAME} = $META{name}) =~ s/-/::/g; ($MM_ARGS{VERSION_FROM} = "lib/$MM_ARGS{NAME}.pm") =~ s{::}{/}g; $META{license} = [ $META{license} ] if $META{license} && !ref $META{license}; $MM_ARGS{LICENSE} = $META{license}[0] if $META{license} && $eumm_version >= 6.30; $MM_ARGS{NO_MYMETA} = 1 if $mymeta_broken; $MM_ARGS{META_ADD} = { 'meta-spec' => { version => 2 }, %META } unless -f 'META.yml'; for (qw(configure build test runtime)) { my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES'; my $r = $MM_ARGS{$key} = { %{$META{prereqs}{$_}{requires} || {}}, %{delete $MM_ARGS{$key} || {}}, }; defined $r->{$_} or delete $r->{$_} for keys %$r; } $MM_ARGS{MIN_PERL_VERSION} = delete $MM_ARGS{PREREQ_PM}{perl} || 0; delete $MM_ARGS{MIN_PERL_VERSION} if $eumm_version < 6.47_01; $MM_ARGS{BUILD_REQUIRES} = {%{$MM_ARGS{BUILD_REQUIRES}}, %{delete $MM_ARGS{TEST_REQUIRES}}} if $eumm_version < 6.63_03; $MM_ARGS{PREREQ_PM} = {%{$MM_ARGS{PREREQ_PM}}, %{delete $MM_ARGS{BUILD_REQUIRES}}} if $eumm_version < 6.55_01; delete $MM_ARGS{CONFIGURE_REQUIRES} if $eumm_version < 6.51_03; ExtUtils::MakeMaker::WriteMakefile(%MM_ARGS); ## END BOILERPLATE ########################################################### Config-Any-0.32/MANIFEST000644 000765 000024 00000002261 13077221024 015001 0ustar00gknopstaff000000 000000 Changes lib/Config/Any.pm lib/Config/Any/Base.pm lib/Config/Any/General.pm lib/Config/Any/INI.pm lib/Config/Any/JSON.pm lib/Config/Any/Perl.pm lib/Config/Any/XML.pm lib/Config/Any/YAML.pm maint/Makefile.PL.include Makefile.PL MANIFEST This list of files t/00-report-prereqs.t t/10-branches.t t/20-parse.t t/50-general.t t/51-ini.t t/52-json.t t/53-perl.t t/54-xml.t t/55-yaml.t t/61-features.t t/62-multi.t t/63-unsupported.t t/64-extfail.t t/65-force_plugins.t t/conf/conf.conf t/conf/conf.extfail t/conf/conf.foo t/conf/conf.ini t/conf/conf.json t/conf/conf.pl t/conf/conf.unsupported t/conf/conf.xml t/conf/conf.yml t/conf/conf2.ini t/conf/conf_arrayref.xml t/conf/single_element_arrayref.conf t/conf/subsections.ini t/invalid/conf.conf t/invalid/conf.ini t/invalid/conf.json t/invalid/conf.pl t/invalid/conf.xml t/invalid/conf.yml t/lib/Config/Any/Unsupported.pm t/multi/conf.yml t/perl-taint.t t/supported/conf.pl xt/author/pod-coverage.t xt/author/pod.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) README README file (added by Distar) Config-Any-0.32/META.json000644 000765 000024 00000003761 13077221024 015277 0ustar00gknopstaff000000 000000 { "abstract" : "Load configuration from different file formats, transparently", "author" : [ "Joel Bernstein " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Config-Any", "no_index" : { "directory" : [ "t", "xt" ] }, "prereqs" : { "build" : {}, "configure" : {}, "develop" : { "requires" : { "Config::General" : "2.47", "Config::Tiny" : "0", "Cpanel::JSON::XS" : "0", "Test::Pod" : "0", "Test::Pod::Coverage" : "0", "XML::NamespaceSupport" : "0", "XML::Simple" : "0", "YAML::XS" : "0" } }, "runtime" : { "requires" : { "Module::Pluggable::Object" : "3.6" }, "suggests" : { "Config::General" : "2.47", "Config::Tiny" : "0", "Cpanel::JSON::XS" : "0", "XML::NamespaceSupport" : "0", "XML::Simple" : "0", "YAML::XS" : "0" } }, "test" : { "requires" : { "Test::More" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-Config-Any@rt.cpan.org", "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=Config-Any" }, "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://git.shadowcat.co.uk/p5sagit/Config-Any.git", "web" : "http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/Config-Any.git;a=summary" } }, "version" : "0.32", "x_authority" : "cpan:RATAXIS", "x_serialization_backend" : "JSON::PP version 2.27300" } Config-Any-0.32/META.yml000644 000765 000024 00000001374 13077221024 015125 0ustar00gknopstaff000000 000000 --- abstract: 'Load configuration from different file formats, transparently' author: - 'Joel Bernstein ' build_requires: Test::More: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Config-Any no_index: directory: - t - xt requires: Module::Pluggable::Object: '3.6' resources: bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=Config-Any license: http://dev.perl.org/licenses/ repository: git://git.shadowcat.co.uk/p5sagit/Config-Any.git version: '0.32' x_authority: cpan:RATAXIS x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Config-Any-0.32/README000644 000765 000024 00000017025 13077221024 014534 0ustar00gknopstaff000000 000000 NAME Config::Any - Load configuration from different file formats, transparently SYNOPSIS use Config::Any; my $cfg = Config::Any->load_stems({stems => \@filepath_stems, ... }); # or my $cfg = Config::Any->load_files({files => \@filepaths, ... }); for (@$cfg) { my ($filename, $config) = %$_; $class->config($config); warn "loaded config from file: $filename"; } DESCRIPTION Config::Any provides a facility for Perl applications and libraries to load configuration data from multiple different file formats. It supports XML, YAML, JSON, Apache-style configuration, Windows INI files, and even Perl code. The rationale for this module is as follows: Perl programs are deployed on many different platforms and integrated with many different systems. Systems administrators and end users may prefer different configuration formats than the developers. The flexibility inherent in a multiple format configuration loader allows different users to make different choices, without generating extra work for the developers. As a developer you only need to learn a single interface to be able to use the power of different configuration formats. INTERFACE load_files( \%args ) Config::Any->load_files( { files => \@files } ); Config::Any->load_files( { files => \@files, filter => \&filter } ); Config::Any->load_files( { files => \@files, use_ext => 1 } ); Config::Any->load_files( { files => \@files, flatten_to_hash => 1 } ); "load_files()" attempts to load configuration from the list of files passed in the "files" parameter, if the file exists. If the "filter" parameter is set, it is used as a callback to modify the configuration data before it is returned. It will be passed a single hash-reference parameter which it should modify in-place. If the "use_ext" parameter is defined, the loader will attempt to parse the file extension from each filename and will skip the file unless it matches a standard extension for the loading plugins. Only plugins whose standard extensions match the file extension will be used. For efficiency reasons, its use is encouraged, but be aware that you will lose flexibility -- for example, a file called "myapp.cfg" containing YAML data will not be offered to the YAML plugin, whereas "myapp.yml" or "myapp.yaml" would be. When the "flatten_to_hash" parameter is defined, the loader will return a hash keyed on the file names, as opposed to the usual list of single-key hashes. "load_files()" also supports a 'force_plugins' parameter, whose value should be an arrayref of plugin names like "Config::Any::INI". Its intended use is to allow the use of a non-standard file extension while forcing it to be offered to a particular parser. It is not compatible with 'use_ext'. You can supply a "driver_args" hashref to pass special options to a particular parser object. Example: Config::Any->load_files( { files => \@files, driver_args => { General => { -LowerCaseNames => 1 } } ) load_stems( \%args ) Config::Any->load_stems( { stems => \@stems } ); Config::Any->load_stems( { stems => \@stems, filter => \&filter } ); Config::Any->load_stems( { stems => \@stems, use_ext => 1 } ); Config::Any->load_stems( { stems => \@stems, flatten_to_hash => 1 } ); "load_stems()" attempts to load configuration from a list of files which it generates by combining the filename stems list passed in the "stems" parameter with the potential filename extensions from each loader, which you can check with the "extensions()" classmethod described below. Once this list of possible filenames is built it is treated exactly as in "load_files()" above, as which it takes the same parameters. Please read the "load_files()" documentation before using this method. finder( ) The "finder()" classmethod returns the Module::Pluggable::Object object which is used to load the plugins. See the documentation for that module for more information. plugins( ) The "plugins()" classmethod returns the names of configuration loading plugins as found by Module::Pluggable::Object. extensions( ) The "extensions()" classmethod returns the possible file extensions which can be loaded by "load_stems()" and "load_files()". This may be useful if you set the "use_ext" parameter to those methods. DIAGNOSTICS "No files specified!" or "No stems specified!" The "load_files()" and "load_stems()" methods will issue this warning if called with an empty list of files/stems to load. "_load requires a arrayref of file paths" This fatal error will be thrown by the internal "_load" method. It should not occur but is specified here for completeness. If your code dies with this error, please email a failing test case to the authors below. CONFIGURATION AND ENVIRONMENT Config::Any requires no configuration files or environment variables. DEPENDENCIES Module::Pluggable::Object And at least one of the following: Config::General Config::Tiny JSON YAML JSON::Syck YAML::Syck XML::Simple INCOMPATIBILITIES None reported. BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to "bug-config-any@rt.cpan.org", or through the web interface at . AUTHOR Joel Bernstein CONTRIBUTORS This module was based on the original Catalyst::Plugin::ConfigLoader module by Brian Cassidy "". With ideas and support from Matt S Trout "". Further enhancements suggested by Evan Kaufman "". LICENCE AND COPYRIGHT Copyright (c) 2006, Portugal Telecom "http://www.sapo.pt/". All rights reserved. Portions copyright 2007, Joel Bernstein "". This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SEE ALSO Catalyst::Plugin::ConfigLoader -- now a wrapper around this module. Config-Any-0.32/t/000755 000765 000024 00000000000 13077221024 014112 5ustar00gknopstaff000000 000000 Config-Any-0.32/xt/000755 000765 000024 00000000000 13077221024 014302 5ustar00gknopstaff000000 000000 Config-Any-0.32/xt/author/000755 000765 000024 00000000000 13077221024 015604 5ustar00gknopstaff000000 000000 Config-Any-0.32/xt/author/pod-coverage.t000644 000765 000024 00000000137 13072431370 020347 0ustar00gknopstaff000000 000000 use strict; use warnings; use Test::More; use Test::Pod::Coverage 1.04; all_pod_coverage_ok; Config-Any-0.32/xt/author/pod.t000644 000765 000024 00000000122 13072431367 016556 0ustar00gknopstaff000000 000000 use strict; use warnings; use Test::More; use Test::Pod 1.14; all_pod_files_ok; Config-Any-0.32/t/00-report-prereqs.t000644 000765 000024 00000001325 13077220720 017511 0ustar00gknopstaff000000 000000 use strict; use warnings; if (!eval { require ExtUtils::MakeMaker }) { print "1..0 # SKIP ExtUtils::MakeMaker not available\n"; exit 0; } print "1..1\n"; print "ok 1\n"; print STDERR "#\n# Optional Prereq Versions:\n"; for my $module (qw( Config::General Config::Tiny Cpanel::JSON::XS JSON::MaybeXS JSON::DWIW JSON::XS JSON::Syck JSON::PP JSON XML::Simple XML::NamespaceSupport YAML::XS YAML::Syck YAML )) { my $file = "$module.pm"; $file =~ s{::}{/}g; my ($full_file) = grep -e, map "$_/$file", @INC; my $v; if (defined $full_file) { $v = MM->parse_version($full_file); } else { $v = 'missing'; } printf STDERR "# %-25s %s\n", $module, $v; } print STDERR "#\n"; Config-Any-0.32/t/10-branches.t000644 000765 000024 00000003276 13072211334 016310 0ustar00gknopstaff000000 000000 use strict; use warnings; no warnings 'once'; # use Test::Without::Module qw(YAML YAML::Syck Config::General XML::Simple JSON JSON::Syck Config::Tiny ); use Test::More tests => 9; use Config::Any; use Config::Any::YAML; { my @warnings; local $SIG{ __WARN__ } = sub { push @warnings, @_ }; Config::Any->load_files(); like( shift @warnings, qr/^No files specified!/, "load_files expects args" ); Config::Any->load_files( {} ); like( shift @warnings, qr/^No files specified!/, "load_files expects files" ); Config::Any->load_stems(); like( shift @warnings, qr/^No stems specified!/, "load_stems expects args" ); Config::Any->load_stems( {} ); like( shift @warnings, qr/^No stems specified!/, "load_stems expects stems" ); } my @files = glob( "t/supported/conf.*" ); { require Config::Any::General; local $SIG{ __WARN__ } = sub { } if Config::Any::General->is_supported; ok( Config::Any->load_files( { files => \@files, use_ext => 0 } ), "use_ext 0 works" ); } my $filter = sub { return }; ok( Config::Any->load_files( { files => \@files, use_ext => 1 } ), "use_ext 1 works" ); ok( Config::Any->load_files( { files => \@files, use_ext => 1, filter => \&$filter } ), "filter works" ); eval { Config::Any->load_files( { files => \@files, use_ext => 1, filter => sub { die "reject" } } ); }; like $@, qr/reject/, "filter breaks"; my @stems = qw(t/supported/conf); ok( Config::Any->load_stems( { stems => \@stems, use_ext => 1 } ), "load_stems with stems works" ); Config-Any-0.32/t/20-parse.t000644 000765 000024 00000003504 13077215470 015642 0ustar00gknopstaff000000 000000 package MockApp; use strict; use warnings; no warnings 'once'; use Test::More tests => 6*9; use Scalar::Util qw(blessed reftype); use Config::Any; use Config::Any::General; use Config::Any::INI; use Config::Any::JSON; use Config::Any::Perl; use Config::Any::XML; use Config::Any::YAML; our %ext_map = ( conf => 'Config::Any::General', ini => 'Config::Any::INI', json => 'Config::Any::JSON', pl => 'Config::Any::Perl', xml => 'Config::Any::XML', yml => 'Config::Any::YAML' ); sub load_parser_for { my $f = shift; return unless $f; my ( $ext ) = $f =~ m{ \. ( [^\.]+ ) \z }xms; my $mod = $ext_map{ $ext }; return !$mod->is_supported ? ( 1, $mod ) : ( 0, $mod ); } for my $f ( map { "t/conf/conf.$_" } keys %ext_map ) { my ( $skip, $mod ) = load_parser_for( $f ); SKIP: { skip "File loading backend for $mod not found", 9 if $skip && !$ENV{RELEASE_TESTING}; ok( my $c_arr = Config::Any->load_files( { files => [ $f ], use_ext => 1 } ), "load_files with use_ext works [$f]" ); ok( my $c = $c_arr->[ 0 ], "load_files returns an arrayref" ); ok( ref $c, "load_files arrayref contains a ref" ); my $ref = blessed $c ? reftype $c : ref $c; is( substr( $ref, 0, 4 ), "HASH", "hashref" ); my ( $name, $cfg ) = each %$c; is( $name, $f, "filename matches" ); my $cfgref = blessed $cfg ? reftype $cfg : ref $cfg; is( substr( $cfgref, 0, 4 ), "HASH", "hashref cfg" ); is( $cfg->{ name }, 'TestApp', "appname parses" ); is( $cfg->{ Component }{ "Controller::Foo" }->{ foo }, 'bar', "component->cntrlr->foo = bar" ); is( $cfg->{ Model }{ "Model::Baz" }->{ qux }, 'xyzzy', "model->model::baz->qux = xyzzy" ); } } Config-Any-0.32/t/50-general.t000644 000765 000024 00000002255 13077215470 016152 0ustar00gknopstaff000000 000000 use strict; use warnings; use Test::More; use Config::Any; use Config::Any::General; if ( !Config::Any::General->is_supported && !$ENV{RELEASE_TESTING}) { plan skip_all => 'Config::General format not supported'; } else { plan tests => 9; } { my $config = Config::Any::General->load( 't/conf/conf.conf' ); ok( $config ); is( $config->{ name }, 'TestApp' ); ok( exists $config->{ Component } ); } { my $config = Config::Any::General->load( 't/conf/conf.conf', { -LowerCaseNames => 1 } ); ok( exists $config->{ component } ); } { my $config = Config::Any::General->load( 't/conf/single_element_arrayref.conf' ); is_deeply $config->{ foo }, [ 'bar' ], 'single element arrayref'; } # test invalid config { my $file = 't/invalid/conf.conf'; my $config = eval { Config::Any::General->load( $file ) }; is $config, undef, 'config load failed'; isnt $@, '', 'error thrown'; } # parse error generated on invalid config { my $file = 't/invalid/conf.conf'; my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) }; is $config, undef, 'config load failed'; isnt $@, '', 'error thrown'; } Config-Any-0.32/t/51-ini.t000644 000765 000024 00000003631 13072432420 015303 0ustar00gknopstaff000000 000000 use strict; use warnings; use Test::More; use Config::Any; use Config::Any::INI; if ( !Config::Any::INI->is_supported && !$ENV{RELEASE_TESTING} ) { plan skip_all => 'INI format not supported'; } else { plan tests => 15; } { my $config = Config::Any::INI->load( 't/conf/conf.ini' ); ok( $config, 'config loaded' ); is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" ); is( $config->{ Component }->{ 'Controller::Foo' }->{ foo }, 'bar', "nested hashref hack lookup succeeded" ); } { my $config = Config::Any::INI->load( 't/conf/conf2.ini' ); ok( $config, 'config loaded' ); is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" ); is( $config->{ 'Controller::Foo' }->{ foo }, 'bar', "nested hashref hack lookup succeeded" ); } { local $Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY = 0; my $config = Config::Any::INI->load( 't/conf/conf.ini' ); ok( $config, 'config loaded (no-map-space mode)' ); is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" ); is( $config->{ 'Component Controller::Foo' }->{ foo }, 'bar', "unnested key lookup succeeded" ); } { my $config = Config::Any::INI->load( 't/conf/subsections.ini' ); my %expected = ( section1 => { a => 1, subsection1 => { b => 2 }, subsection2 => { c => 3 } } ); ok( $config, 'config loaded' ); is_deeply( $config, \%expected, 'subsections parsed properly' ); } # test invalid config { my $file = 't/invalid/conf.ini'; my $config = eval { Config::Any::INI->load( $file ) }; is $config, undef, 'config load failed'; isnt $@, '', 'error thrown'; } # parse error generated on invalid config { my $file = 't/invalid/conf.ini'; my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) }; is $config, undef, 'config load failed'; isnt $@, '', 'error thrown'; } Config-Any-0.32/t/52-json.t000644 000765 000024 00000001462 13077215470 015507 0ustar00gknopstaff000000 000000 use strict; use warnings; use Test::More; use Config::Any; use Config::Any::JSON; if ( !Config::Any::JSON->is_supported && !$ENV{RELEASE_TESTING} ) { plan skip_all => 'JSON format not supported'; } else { plan tests => 6; } { my $config = Config::Any::JSON->load( 't/conf/conf.json' ); ok( $config ); is( $config->{ name }, 'TestApp' ); } # test invalid config { my $file = 't/invalid/conf.json'; my $config = eval { Config::Any::JSON->load( $file ) }; is $config, undef, 'config load failed'; isnt $@, '', 'error thrown'; } # parse error generated on invalid config { my $file = 't/invalid/conf.json'; my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) }; is $config, undef, 'config load failed'; isnt $@, '', 'error thrown'; } Config-Any-0.32/t/53-perl.t000644 000765 000024 00000002536 13077211415 015477 0ustar00gknopstaff000000 000000 use strict; use warnings; use Test::More tests => 12; use Config::Any; use Config::Any::Perl; { my $file = 't/conf/conf.pl'; my $config = Config::Any::Perl->load( $file ); ok( $config ); is( $config->{ name }, 'TestApp' ); my $config_load2 = Config::Any::Perl->load( $file ); is_deeply( $config_load2, $config, 'multiple loads of the same file' ); } # test invalid config { my $file = 't/invalid/conf.pl'; my $config; my $loaded = eval { $config = Config::Any::Perl->load( $file ); 1; }; ok !$loaded, 'config load failed'; is $config, undef, 'config load failed'; like $@, qr/syntax error/, 'error thrown'; } # parse error generated on invalid config { my $file = 't/invalid/conf.pl'; my $config; my $loaded = eval { $config = Config::Any::Perl->load( $file ); Config::Any->load_files( { files => [$file], use_ext => 1} ); 1; }; ok !$loaded, 'config load failed'; is $config, undef, 'config load failed'; like $@, qr/syntax error/, 'error thrown'; } # test missing config { my $file = 't/invalid/missing.pl'; my $config; my $loaded = eval { $config = Config::Any::Perl->load( $file ); 1; }; ok !$loaded, 'config load failed'; is $config, undef, 'config load failed'; isnt $@, '', 'error thrown'; } Config-Any-0.32/t/54-xml.t000644 000765 000024 00000003376 13072432026 015337 0ustar00gknopstaff000000 000000 use strict; use warnings; use Test::More; use Config::Any; use Config::Any::XML; if ( !Config::Any::XML->is_supported && !$ENV{RELEASE_TESTING} ) { plan skip_all => 'XML format not supported'; } else { plan tests => 7; } { my $config = Config::Any::XML->load( 't/conf/conf.xml' ); is_deeply $config, { 'Component' => { 'Controller::Foo' => { 'foo' => 'bar' }, }, 'name' => 'TestApp', 'Model' => { 'Model::Baz' => { 'qux' => 'xyzzy', }, }, }, 'config loaded'; } # test invalid config SKIP: { my $broken_libxml = eval { require XML::LibXML; XML::LibXML->VERSION lt '1.59'; }; skip 'XML::LibXML < 1.58 has issues', 2 if $broken_libxml; local $SIG{ __WARN__ } = sub { }; # squash warnings from XML::Simple my $file = 't/invalid/conf.xml'; my $config = eval { Config::Any::XML->load( $file ) }; is $config, undef, 'config load failed'; isnt $@, '', 'error thrown'; } # test conf file with array ref { my $file = 't/conf/conf_arrayref.xml'; my $config = eval { Config::Any::XML->load( $file ) }; is_deeply $config, { 'indicator' => 'submit', 'elements' => [ { 'label' => 'Label1', 'type' => 'Text', }, { 'label' => 'Label2', 'type' => 'Text', }, ], }, 'config loaded'; is $@, '', 'no error thrown'; } # parse error generated on invalid config { my $file = 't/invalid/conf.xml'; my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) }; is $config, undef, 'config load failed'; isnt $@, '', 'error thrown'; } Config-Any-0.32/t/55-yaml.t000644 000765 000024 00000002344 13077220721 015476 0ustar00gknopstaff000000 000000 use strict; use warnings; no warnings 'once'; use Test::More; use Config::Any; use Config::Any::YAML; use Data::Dumper; sub _dump { local $Data::Dumper::Terse = 1; local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Indent = 1; my $out = Data::Dumper::Dumper(@_); $out =~ s/\s*\z//; $out eq 'undef' ? undef : $out; } if ( !Config::Any::YAML->is_supported && !$ENV{RELEASE_TESTING} ) { plan skip_all => 'YAML format not supported'; } else { plan tests => 6; } { my $config = Config::Any::YAML->load( 't/conf/conf.yml' ); ok( $config ); is( $config->{ name }, 'TestApp' ); } # test invalid config { local $TODO = 'YAML::Syck parses invalid files' if $INC{'YAML/Syck.pm'}; my $file = 't/invalid/conf.yml'; my $config = eval { Config::Any::YAML->load( $file ) }; is _dump($config), undef, 'config load failed'; isnt $@, '', 'error thrown'; } # parse error generated on invalid config { local $TODO = 'YAML::Syck parses invalid files' if $INC{'YAML/Syck.pm'}; my $file = 't/invalid/conf.yml'; my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) }; is _dump($config), undef, 'config load failed'; isnt $@, '', 'error thrown'; } Config-Any-0.32/t/61-features.t000644 000765 000024 00000004517 13053073424 016353 0ustar00gknopstaff000000 000000 package MockApp; use strict; use warnings; $|++; use Test::More tests => 14; use Scalar::Util qw(blessed reftype); use Config::Any; use Config::Any::INI; our $cfg_file = 't/conf/conf.foo'; eval { Config::Any::INI->load( $cfg_file ); }; SKIP: { skip "File loading backend for INI not found", 14 if $@; my $struct; # used to make sure parsing works for arrays and hashes # force_plugins { my $result = Config::Any->load_files( { files => [ $cfg_file ], force_plugins => [ qw(Config::Any::INI) ] } ); ok( $result, 'load file with parser forced' ); ok( my $first = $result->[ 0 ], 'load_files returns an arrayref' ); ok( ref $first, 'load_files arrayref contains a ref' ); my $ref = blessed $first ? reftype $first : ref $first; is( substr( $ref, 0, 4 ), 'HASH', 'hashref' ); $struct = $first; my ( $name, $cfg ) = %$first; is( $name, $cfg_file, 'filenames match' ); my $cfgref = blessed $cfg ? reftype $cfg : ref $cfg; is( substr( $cfgref, 0, 4 ), 'HASH', 'hashref cfg' ); is( $cfg->{ name }, 'TestApp', 'appname parses' ); is( $cfg->{ Component }{ "Controller::Foo" }->{ foo }, 'bar', 'component->cntrlr->foo = bar' ); is( $cfg->{ Model }{ "Model::Baz" }->{ qux }, 'xyzzy', 'model->model::baz->qux = xyzzy' ); } # flatten_to_hash { my $result = Config::Any->load_files( { files => [ $cfg_file ], force_plugins => [ qw(Config::Any::INI) ], flatten_to_hash => 1 } ); ok( $result, 'load file with parser forced, flatten to hash' ); ok( ref $result, 'load_files hashref contains a ref' ); my $ref = blessed $result ? reftype $result : ref $result; is( substr( $ref, 0, 4 ), 'HASH', 'hashref' ); is_deeply( $result, $struct, 'load_files return an hashref (flatten_to_hash)' ); } # use_ext { ok( my $result = Config::Any->load_files( { files => [ $cfg_file ], force_plugins => [ qw(Config::Any::INI) ], use_ext => 1 } ), "load file with parser forced" ); } } Config-Any-0.32/t/62-multi.t000644 000765 000024 00000001406 13053073424 015662 0ustar00gknopstaff000000 000000 use strict; use warnings; no warnings 'once'; use Test::More tests => 3; use Config::Any; use Config::Any::YAML; my $file = 't/multi/conf.yml'; my @expect = ( { name => 'TestApp', Model => { 'Model::Baz' => { qux => 'xyzzy' } } }, { name2 => 'TestApp2', Model2 => { 'Model::Baz2' => { qux2 => 'xyzzy2' } } }, ); my @results = eval { Config::Any::YAML->load( $file ); }; SKIP: { skip "Can't load multi-stream YAML files", 3 if $@; is( @results, 2, '2 documents' ); is_deeply( \@results, \@expect, 'structures ok' ); my $return = Config::Any->load_files( { use_ext => 1, files => [ $file ] } ); is_deeply( $return, [ { $file => \@expect } ], 'config-any structures ok' ); } Config-Any-0.32/t/63-unsupported.t000644 000765 000024 00000000654 13053073424 017125 0ustar00gknopstaff000000 000000 use strict; use warnings; use Test::More tests => 3; use lib 't/lib'; use Config::Any; { my $result = eval { Config::Any->load_files( { files => [ 't/conf/conf.unsupported' ], use_ext => 1 } ); }; ok( !defined $result, 'empty result' ); ok( $@, 'error thrown' ); like( $@, qr/required support modules are not available/, 'error message' ); } Config-Any-0.32/t/64-extfail.t000644 000765 000024 00000000637 13053073424 016173 0ustar00gknopstaff000000 000000 use strict; use warnings; use Test::More tests => 3; use Config::Any; { my $result = eval { Config::Any->load_files( { files => [ 't/conf/conf.extfail' ], use_ext => 1 } ); }; ok( !defined $result, 'empty result' ); ok( $@, 'error thrown' ); like( $@, qr/There are no loaders available for \.extfail files/, 'error message' ); } Config-Any-0.32/t/65-force_plugins.t000644 000765 000024 00000000457 13053073424 017377 0ustar00gknopstaff000000 000000 use strict; use warnings; use Test::More tests => 2; use Config::Any; { my $result = eval { Config::Any->load_files( { files => [ 't/conf/conf.pl' ], force_plugins => [ 'Config::Any::Perl' ] } ); }; ok( $result, 'config loaded' ); ok( !$@, 'no error thrown' ); } Config-Any-0.32/t/conf/000755 000765 000024 00000000000 13077221024 015037 5ustar00gknopstaff000000 000000 Config-Any-0.32/t/invalid/000755 000765 000024 00000000000 13077221024 015540 5ustar00gknopstaff000000 000000 Config-Any-0.32/t/lib/000755 000765 000024 00000000000 13077221024 014660 5ustar00gknopstaff000000 000000 Config-Any-0.32/t/multi/000755 000765 000024 00000000000 13077221024 015244 5ustar00gknopstaff000000 000000 Config-Any-0.32/t/perl-taint.t000644 000765 000024 00000000115 13063551125 016356 0ustar00gknopstaff000000 000000 #!perl -T use strict; use warnings; do './t/53-perl.t' or die ($@ || $!); Config-Any-0.32/t/supported/000755 000765 000024 00000000000 13077221024 016137 5ustar00gknopstaff000000 000000 Config-Any-0.32/t/supported/conf.pl000644 000765 000024 00000000222 13053073424 017420 0ustar00gknopstaff000000 000000 { name => 'TestApp', Component => { 'Controller::Foo' => { foo => 'bar' } }, Model => { 'Model::Baz' => { qux => 'xyzzy' } } } Config-Any-0.32/t/multi/conf.yml000644 000765 000024 00000000177 13053073424 016724 0ustar00gknopstaff000000 000000 --- name: TestApp Model: Model::Baz: qux: xyzzy --- name2: TestApp2 Model2: Model::Baz2: qux2: xyzzy2 Config-Any-0.32/t/lib/Config/000755 000765 000024 00000000000 13077221024 016065 5ustar00gknopstaff000000 000000 Config-Any-0.32/t/lib/Config/Any/000755 000765 000024 00000000000 13077221024 016614 5ustar00gknopstaff000000 000000 Config-Any-0.32/t/lib/Config/Any/Unsupported.pm000644 000765 000024 00000000324 13053073424 021504 0ustar00gknopstaff000000 000000 package Config::Any::Unsupported; use strict; use warnings; use base 'Config::Any::Base'; sub extensions { return qw( unsupported ); } sub load { } sub requires_all_of { 'My::Module::DoesNotExist' } 1; Config-Any-0.32/t/invalid/conf.conf000644 000765 000024 00000000155 13053073424 017340 0ustar00gknopstaff000000 000000 name = TestApp qux xyzzy Config-Any-0.32/t/invalid/conf.ini000644 000765 000024 00000000117 13072436146 017175 0ustar00gknopstaff000000 000000 name=TestApp [Component Controller::Foo foo=bar [Model Model::Baz] qux=xyzzy Config-Any-0.32/t/invalid/conf.json000644 000765 000024 00000000306 13053073424 017362 0ustar00gknopstaff000000 000000 { "name": "TestApp", "Component": { "Controller::Foo": { "foo": "bar" } }, "Model": { "Model::Baz": { "qux": "xyzzy" } } Config-Any-0.32/t/invalid/conf.pl000644 000765 000024 00000000221 13053073424 017020 0ustar00gknopstaff000000 000000 { name => 'TestApp' Component => { 'Controller::Foo' => { foo => 'bar' } }, Model => { 'Model::Baz' => { qux => 'xyzzy' } } } Config-Any-0.32/t/invalid/conf.xml000644 000765 000024 00000000276 13053073424 017217 0ustar00gknopstaff000000 000000 TestApp bar xyzzy Config-Any-0.32/t/invalid/conf.yml000644 000765 000024 00000000154 13072437363 017222 0ustar00gknopstaff000000 000000 --- name: TestApp Component: Controller::Foo foo: bar Model: Model::Baz: qux: xyzzy Config-Any-0.32/t/conf/conf.conf000644 000765 000024 00000000156 13053073424 016640 0ustar00gknopstaff000000 000000 name = TestApp foo bar qux xyzzy Config-Any-0.32/t/conf/conf.extfail000644 000765 000024 00000000044 13053073424 017343 0ustar00gknopstaff000000 000000 Placeholder file for t/64-extfail.t Config-Any-0.32/t/conf/conf.foo000644 000765 000024 00000000120 13072436163 016471 0ustar00gknopstaff000000 000000 name=TestApp [Component Controller::Foo] foo=bar [Model Model::Baz] qux=xyzzy Config-Any-0.32/t/conf/conf.ini000644 000765 000024 00000000120 13072436157 016470 0ustar00gknopstaff000000 000000 name=TestApp [Component Controller::Foo] foo=bar [Model Model::Baz] qux=xyzzy Config-Any-0.32/t/conf/conf.json000644 000765 000024 00000000307 13053073424 016662 0ustar00gknopstaff000000 000000 { "name": "TestApp", "Component": { "Controller::Foo": { "foo": "bar" } }, "Model": { "Model::Baz": { "qux": "xyzzy" } } } Config-Any-0.32/t/conf/conf.pl000644 000765 000024 00000000222 13053073424 016320 0ustar00gknopstaff000000 000000 { name => 'TestApp', Component => { 'Controller::Foo' => { foo => 'bar' } }, Model => { 'Model::Baz' => { qux => 'xyzzy' } } } Config-Any-0.32/t/conf/conf.unsupported000644 000765 000024 00000000000 13053073424 020267 0ustar00gknopstaff000000 000000 Config-Any-0.32/t/conf/conf.xml000644 000765 000024 00000000277 13053073424 016517 0ustar00gknopstaff000000 000000 TestApp bar xyzzy Config-Any-0.32/t/conf/conf.yml000644 000765 000024 00000000155 13053073424 016513 0ustar00gknopstaff000000 000000 --- name: TestApp Component: Controller::Foo: foo: bar Model: Model::Baz: qux: xyzzy Config-Any-0.32/t/conf/conf2.ini000644 000765 000024 00000000100 13072436153 016544 0ustar00gknopstaff000000 000000 name=TestApp [Controller::Foo] foo=bar [Model::Baz] qux=xyzzy Config-Any-0.32/t/conf/conf_arrayref.xml000644 000765 000024 00000000323 13053073424 020402 0ustar00gknopstaff000000 000000
submit
Config-Any-0.32/t/conf/single_element_arrayref.conf000644 000765 000024 00000000014 13053073424 022571 0ustar00gknopstaff000000 000000 foo [ bar ] Config-Any-0.32/t/conf/subsections.ini000644 000765 000024 00000000113 13053073424 020077 0ustar00gknopstaff000000 000000 [section1] a = 1 [section1 subsection1] b = 2 [section1 subsection2] c = 3 Config-Any-0.32/maint/Makefile.PL.include000644 000765 000024 00000000507 13053073424 020360 0ustar00gknopstaff000000 000000 BEGIN { -e 'Distar' or system("git clone git://git.shadowcat.co.uk/p5sagit/Distar.git") } use lib 'Distar/lib'; use Distar; author 'Joel Bernstein '; manifest_include 't/conf' => qr/.*/; manifest_include 't/invalid' => qr/.*/; manifest_include 't/multi' => qr/.*/; manifest_include 't/supported' => qr/.*/; Config-Any-0.32/lib/Config/000755 000765 000024 00000000000 13077221024 015622 5ustar00gknopstaff000000 000000 Config-Any-0.32/lib/Config/Any/000755 000765 000024 00000000000 13077221024 016351 5ustar00gknopstaff000000 000000 Config-Any-0.32/lib/Config/Any.pm000644 000765 000024 00000030254 13077220721 016716 0ustar00gknopstaff000000 000000 package Config::Any; use strict; use warnings; use Carp; use Module::Pluggable::Object (); our $VERSION = '0.32'; =head1 NAME Config::Any - Load configuration from different file formats, transparently =head1 SYNOPSIS use Config::Any; my $cfg = Config::Any->load_stems({stems => \@filepath_stems, ... }); # or my $cfg = Config::Any->load_files({files => \@filepaths, ... }); for (@$cfg) { my ($filename, $config) = %$_; $class->config($config); warn "loaded config from file: $filename"; } =head1 DESCRIPTION L provides a facility for Perl applications and libraries to load configuration data from multiple different file formats. It supports XML, YAML, JSON, Apache-style configuration, Windows INI files, and even Perl code. The rationale for this module is as follows: Perl programs are deployed on many different platforms and integrated with many different systems. Systems administrators and end users may prefer different configuration formats than the developers. The flexibility inherent in a multiple format configuration loader allows different users to make different choices, without generating extra work for the developers. As a developer you only need to learn a single interface to be able to use the power of different configuration formats. =head1 INTERFACE =head2 load_files( \%args ) Config::Any->load_files( { files => \@files } ); Config::Any->load_files( { files => \@files, filter => \&filter } ); Config::Any->load_files( { files => \@files, use_ext => 1 } ); Config::Any->load_files( { files => \@files, flatten_to_hash => 1 } ); C attempts to load configuration from the list of files passed in the C parameter, if the file exists. If the C parameter is set, it is used as a callback to modify the configuration data before it is returned. It will be passed a single hash-reference parameter which it should modify in-place. If the C parameter is defined, the loader will attempt to parse the file extension from each filename and will skip the file unless it matches a standard extension for the loading plugins. Only plugins whose standard extensions match the file extension will be used. For efficiency reasons, its use is encouraged, but be aware that you will lose flexibility -- for example, a file called C containing YAML data will not be offered to the YAML plugin, whereas C or C would be. When the C parameter is defined, the loader will return a hash keyed on the file names, as opposed to the usual list of single-key hashes. C also supports a 'force_plugins' parameter, whose value should be an arrayref of plugin names like C. Its intended use is to allow the use of a non-standard file extension while forcing it to be offered to a particular parser. It is not compatible with 'use_ext'. You can supply a C hashref to pass special options to a particular parser object. Example: Config::Any->load_files( { files => \@files, driver_args => { General => { -LowerCaseNames => 1 } } ) =cut sub load_files { my ( $class, $args ) = @_; unless ( $args && exists $args->{ files } ) { warn "No files specified!"; return; } return $class->_load( $args ); } =head2 load_stems( \%args ) Config::Any->load_stems( { stems => \@stems } ); Config::Any->load_stems( { stems => \@stems, filter => \&filter } ); Config::Any->load_stems( { stems => \@stems, use_ext => 1 } ); Config::Any->load_stems( { stems => \@stems, flatten_to_hash => 1 } ); C attempts to load configuration from a list of files which it generates by combining the filename stems list passed in the C parameter with the potential filename extensions from each loader, which you can check with the C classmethod described below. Once this list of possible filenames is built it is treated exactly as in C above, as which it takes the same parameters. Please read the C documentation before using this method. =cut sub load_stems { my ( $class, $args ) = @_; unless ( $args && exists $args->{ stems } ) { warn "No stems specified!"; return; } my $stems = delete $args->{ stems }; my @files; for my $s ( @$stems ) { for my $ext ( $class->extensions ) { push @files, "$s.$ext"; } } $args->{ files } = \@files; return $class->_load( $args ); } sub _load { my ( $class, $args ) = @_; croak "_load requires a arrayref of file paths" unless $args->{ files }; my $force = defined $args->{ force_plugins }; if ( !$force and !defined $args->{ use_ext } ) { warn "use_ext argument was not explicitly set, as of 0.09, this is true by default"; $args->{ use_ext } = 1; } # figure out what plugins we're using my @plugins = $force ? map { eval "require $_;"; $_; } @{ $args->{ force_plugins } } : $class->plugins; # map extensions if we have to my ( %extension_lut, $extension_re ); my $use_ext_lut = !$force && $args->{ use_ext }; if ( $use_ext_lut ) { for my $plugin ( @plugins ) { for ( $plugin->extensions ) { $extension_lut{ $_ } ||= []; push @{ $extension_lut{ $_ } }, $plugin; } } $extension_re = join( '|', keys %extension_lut ); } # map args to plugins my $base_class = __PACKAGE__; my %loader_args; for my $plugin ( @plugins ) { $plugin =~ m{^$base_class\::(.+)}; $loader_args{ $plugin } = $args->{ driver_args }->{ $1 } || {}; } my @results; for my $filename ( @{ $args->{ files } } ) { # don't even bother if it's not there next unless -f $filename; my @try_plugins = @plugins; if ( $use_ext_lut ) { $filename =~ m{\.($extension_re)\z}; if ( !$1 ) { $filename =~ m{\.([^.]+)\z}; croak "There are no loaders available for .${1} files"; } @try_plugins = @{ $extension_lut{ $1 } }; } # not using use_ext means we try all plugins anyway, so we'll # ignore it for the "unsupported" error my $supported = $use_ext_lut ? 0 : 1; for my $loader ( @try_plugins ) { next unless $loader->is_supported; $supported = 1; my @configs; my $err = do { local $@; @configs = eval { $loader->load( $filename, $loader_args{ $loader } ); }; $@; }; # fatal error if we used extension matching croak "Error parsing $filename: $err" if $err and $use_ext_lut; next if $err or !@configs; # post-process config with a filter callback if ( $args->{ filter } ) { $args->{ filter }->( $_ ) for @configs; } push @results, { $filename => @configs == 1 ? $configs[ 0 ] : \@configs }; last; } if ( !$supported ) { croak "Cannot load $filename: required support modules are not available.\nPlease install " . join( " OR ", map { _support_error( $_ ) } @try_plugins ); } } if ( defined $args->{ flatten_to_hash } ) { my %flattened = map { %$_ } @results; return \%flattened; } return \@results; } sub _support_error { my $module = shift; if ( $module->can( 'requires_all_of' ) ) { return join( ' and ', map { ref $_ ? join( ' ', @$_ ) : $_ } $module->requires_all_of ); } if ( $module->can( 'requires_any_of' ) ) { return 'one of ' . join( ' or ', map { ref $_ ? join( ' ', @$_ ) : $_ } $module->requires_any_of ); } } =head2 finder( ) The C classmethod returns the L object which is used to load the plugins. See the documentation for that module for more information. =cut sub finder { my $class = shift; my $finder = Module::Pluggable::Object->new( search_path => [ __PACKAGE__ ], except => [ __PACKAGE__ . '::Base' ], require => 1 ); return $finder; } =head2 plugins( ) The C classmethod returns the names of configuration loading plugins as found by L. =cut sub plugins { my $class = shift; # filter out things that don't look like our plugins return grep { $_->isa( 'Config::Any::Base' ) } $class->finder->plugins; } =head2 extensions( ) The C classmethod returns the possible file extensions which can be loaded by C and C. This may be useful if you set the C parameter to those methods. =cut sub extensions { my $class = shift; my @ext = map { $_->extensions } $class->plugins; return wantarray ? @ext : \@ext; } =head1 DIAGNOSTICS =over =item C or C The C and C methods will issue this warning if called with an empty list of files/stems to load. =item C<_load requires a arrayref of file paths> This fatal error will be thrown by the internal C<_load> method. It should not occur but is specified here for completeness. If your code dies with this error, please email a failing test case to the authors below. =back =head1 CONFIGURATION AND ENVIRONMENT Config::Any requires no configuration files or environment variables. =head1 DEPENDENCIES L And at least one of the following: L L L L L L L =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to C, or through the web interface at L. =head1 AUTHOR Joel Bernstein =head1 CONTRIBUTORS This module was based on the original L module by Brian Cassidy C<< >>. With ideas and support from Matt S Trout C<< >>. Further enhancements suggested by Evan Kaufman C<< >>. =head1 LICENCE AND COPYRIGHT Copyright (c) 2006, Portugal Telecom C<< http://www.sapo.pt/ >>. All rights reserved. Portions copyright 2007, Joel Bernstein C<< >>. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. =head1 SEE ALSO L -- now a wrapper around this module. =cut "Drink more beer"; Config-Any-0.32/lib/Config/Any/Base.pm000644 000765 000024 00000003424 13072440530 017564 0ustar00gknopstaff000000 000000 package Config::Any::Base; use strict; use warnings; =head1 NAME Config::Any::Base - Base class for loaders =head1 DESCRIPTION This is a base class for all loaders. It currently handles the specification of dependencies in order to ensure the subclass can load the config file format. =head1 METHODS =head2 is_supported( ) Allows us to determine if the file format can be loaded. The can be done via one of two subclass methods: =over 4 =item * C - returns an array of items that must all be present in order to work =item * C - returns an array of items in which at least one must be present =back You can specify a module version by passing an array reference in the return. sub requires_all_of { [ 'My::Module', '1.1' ], 'My::OtherModule' } Lack of specifying these subs will assume you require no extra modules to function. =cut sub is_supported { my ( $class ) = shift; local $@; if ( $class->can( 'requires_all_of' ) ) { return eval { _require($_) for $class->requires_all_of; 1; } || 0; } if ( $class->can( 'requires_any_of' ) ) { eval { _require( $_ ); 1 } and return 1 for $class->requires_any_of; return 0; } # requires nothing! return 1; } sub _require { my ( $input ) = shift; my ( $module, $version ) = ( ref $input ? @$input : $input ); (my $file = "$module.pm") =~ s{::}{/}g; require $file; $module->VERSION if $version; } =head1 AUTHOR Brian Cassidy =head1 COPYRIGHT AND LICENSE Copyright 2008-2009 by Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO =over 4 =item * L =back =cut 1; Config-Any-0.32/lib/Config/Any/General.pm000644 000765 000024 00000003064 13072441040 020264 0ustar00gknopstaff000000 000000 package Config::Any::General; use strict; use warnings; use base 'Config::Any::Base'; =head1 NAME Config::Any::General - Load Config::General files =head1 DESCRIPTION Loads Config::General files. Example: name = TestApp foo bar bar [ arrayref-value ] qux xyzzy =head1 METHODS =head2 extensions( ) return an array of valid extensions (C, C). =cut sub extensions { return qw( cnf conf ); } =head2 load( $file ) Attempts to load C<$file> via Config::General. =cut sub load { my $class = shift; my $file = shift; my $args = shift || {}; $args->{ -ConfigFile } = $file; require Config::General; Config::General->VERSION( '2.47' ); $args->{ -ForceArray } = 1 unless exists $args->{ -ForceArray }; my $configfile = Config::General->new( %$args ); my $config = { $configfile->getall }; return $config; } =head2 requires_all_of( ) Specifies that this module requires L in order to work. =cut sub requires_all_of { [ 'Config::General' => '2.47' ] } =head1 AUTHOR Brian Cassidy =head1 CONTRIBUTORS Joel Bernstein =head1 COPYRIGHT AND LICENSE Copyright 2006-2016 by Brian Cassidy Portions Copyright 2006 Portugal Telecom This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO =over 4 =item * L =item * L =item * L =back =cut 1; Config-Any-0.32/lib/Config/Any/INI.pm000644 000765 000024 00000004230 13072441016 017325 0ustar00gknopstaff000000 000000 package Config::Any::INI; use strict; use warnings; use base 'Config::Any::Base'; our $MAP_SECTION_SPACE_TO_NESTED_KEY = 1; =head1 NAME Config::Any::INI - Load INI config files =head1 DESCRIPTION Loads INI files. Example: name=TestApp [Controller::Foo] foo=bar [Model::Baz] qux=xyzzy =head1 METHODS =head2 extensions( ) return an array of valid extensions (C). =cut sub extensions { return qw( ini ); } =head2 load( $file ) Attempts to load C<$file> as an INI file. =cut sub load { my $class = shift; my $file = shift; require Config::Tiny; my $config = Config::Tiny->read( $file ); die $Config::Tiny::errstr if not defined $config; my $out = delete $config->{ _ } || {}; for my $k ( keys %$config ) { my @keys = split /\s+/, $k; my $ref = $config->{ $k }; if ( $MAP_SECTION_SPACE_TO_NESTED_KEY && @keys > 1 ) { my ( $a, $b ) = @keys[ 0, 1 ]; $out->{ $a }->{ $b } = $ref; } else { $out->{ $k } = { %{ $out->{ $k } || {} }, %$ref }; } } return $out; } =head2 requires_all_of( ) Specifies that this module requires L in order to work. =cut sub requires_all_of { 'Config::Tiny' } =head1 PACKAGE VARIABLES =over 4 =item $MAP_SECTION_SPACE_TO_NESTED_KEY (boolean) This variable controls whether spaces in INI section headings will be expanded into nested hash keys. e.g. it controls whether [Full Power] maps to $config->{'Full Power'} or $config->{'Full'}->{'Power'} By default it is set to 1 (i.e. true). Set it to 0 to preserve literal spaces in section headings: use Config::Any; use Config::Any::INI; $Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY = 0; =back =head1 AUTHORS Brian Cassidy Joel Bernstein =head1 COPYRIGHT AND LICENSE Copyright 2006-2016 by Brian Cassidy, portions copyright 2006, 2007 by Joel Bernstein This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO =over 4 =item * L =item * L =item * L =back =cut 1; Config-Any-0.32/lib/Config/Any/JSON.pm000644 000765 000024 00000005176 13077211671 017500 0ustar00gknopstaff000000 000000 package Config::Any::JSON; use strict; use warnings; use base 'Config::Any::Base'; =head1 NAME Config::Any::JSON - Load JSON config files =head1 DESCRIPTION Loads JSON files. Example: { "name": "TestApp", "Controller::Foo": { "foo": "bar" }, "Model::Baz": { "qux": "xyzzy" } } =head1 METHODS =head2 extensions( ) return an array of valid extensions (C, C). =cut sub extensions { return qw( json jsn ); } =head2 load( $file ) Attempts to load C<$file> as a JSON file. =cut sub load { my $class = shift; my $file = shift; open( my $fh, '<', $file ) or die $!; binmode $fh; my $content = do { local $/; <$fh> }; close $fh; if ( eval { require Cpanel::JSON::XS } ) { my $decoder = Cpanel::JSON::XS->new->utf8->relaxed; return $decoder->decode( $content ); } elsif ( eval { require JSON::MaybeXS } ) { my $decoder = JSON::MaybeXS::JSON()->new->utf8->relaxed; return $decoder->decode( $content ); } elsif ( eval { require JSON::DWIW } ) { my $decoder = JSON::DWIW->new; my ( $data, $error ) = $decoder->from_json( $content ); die $error if $error; return $data; } elsif ( eval { require JSON::XS } ) { my $decoder = JSON::XS->new->utf8->relaxed; return $decoder->decode( $content ); } elsif ( eval { require JSON::Syck } ) { require Encode; return JSON::Syck::Load( Encode::decode('UTF-8', $content ) ); } elsif ( eval { require JSON::PP; JSON::PP->VERSION( 2 ); } ) { my $decoder = JSON::PP->new->utf8->relaxed; return $decoder->decode( $content ); } require JSON; if ( eval { JSON->VERSION( 2 ) } ) { return JSON::decode_json( $content ); } else { return JSON::jsonToObj( $content ); } } =head2 requires_any_of( ) Specifies that this modules requires one of, L, L, L, L, L, L or L in order to work. =cut sub requires_any_of { qw( Cpanel::JSON::XS JSON::MaybeXS JSON::DWIW JSON::XS JSON::Syck JSON::PP JSON ) } =head1 AUTHOR Brian Cassidy =head1 COPYRIGHT AND LICENSE Copyright 2006-2016 by Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO =over 4 =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =back =cut 1; Config-Any-0.32/lib/Config/Any/Perl.pm000644 000765 000024 00000002705 13072440667 017630 0ustar00gknopstaff000000 000000 package Config::Any::Perl; use strict; use warnings; use base 'Config::Any::Base'; use File::Spec; use Cwd (); =head1 NAME Config::Any::Perl - Load Perl config files =head1 DESCRIPTION Loads Perl files. Example: { name => 'TestApp', 'Controller::Foo' => { foo => 'bar' }, 'Model::Baz' => { qux => 'xyzzy' } } =head1 METHODS =head2 extensions( ) return an array of valid extensions (C, C). =cut sub extensions { return qw( pl perl ); } =head2 load( $file ) Attempts to load C<$file> as a Perl file. =cut sub load { my $class = shift; my $file = shift; my( $exception, $content ); { local $@; # previously this would load based on . being in @INC, and wouldn't # trigger taint errors even if '.' probably should have been considered # tainted. untaint for backwards compatibility. my ($cwd) = Cwd::cwd() =~ /\A(.*)\z/s; $content = do File::Spec->rel2abs($file, $cwd); $exception = $@ || $! if !defined $content; } die $exception if $exception; return $content; } =head1 AUTHOR Brian Cassidy =head1 COPYRIGHT AND LICENSE Copyright 2006-2016 by Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO =over 4 =item * L =item * L =back =cut 1; Config-Any-0.32/lib/Config/Any/XML.pm000644 000765 000024 00000004333 13072440711 017353 0ustar00gknopstaff000000 000000 package Config::Any::XML; use strict; use warnings; use base 'Config::Any::Base'; =head1 NAME Config::Any::XML - Load XML config files =head1 DESCRIPTION Loads XML files. Example: TestApp bar xyzzy =head1 METHODS =head2 extensions( ) return an array of valid extensions (C). =cut sub extensions { return qw( xml ); } =head2 load( $file ) Attempts to load C<$file> as an XML file. =cut sub load { my $class = shift; my $file = shift; my $args = shift || {}; require XML::Simple; my $config = XML::Simple::XMLin( $file, ForceArray => [ qw( component model view controller ) ], %$args ); return $class->_coerce( $config ); } sub _coerce { # coerce the XML-parsed config into the correct format my $class = shift; my $config = shift; my $out; for my $k ( keys %$config ) { my $ref = $config->{ $k }; my $name = ref $ref eq 'HASH' ? delete $ref->{ name } : undef; if ( defined $name ) { $out->{ $k }->{ $name } = $ref; } else { $out->{ $k } = $ref; } } $out; } =head2 requires_all_of( ) Specifies that this module requires L and L in order to work. =cut sub requires_all_of { 'XML::Simple', 'XML::NamespaceSupport' } =head1 CAVEATS =head2 Strict Mode If, by some chance, L has already been loaded with the strict flag turned on, then you will likely get errors as warnings will become fatal exceptions and certain arguments to XMLin() will no longer be optional. See L for more information. =head1 AUTHORS Brian Cassidy Joel Bernstein =head1 COPYRIGHT AND LICENSE Copyright 2006-2016 by Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO =over 4 =item * L =item * L =item * L =back =cut 1; Config-Any-0.32/lib/Config/Any/YAML.pm000644 000765 000024 00000003063 13072440775 017466 0ustar00gknopstaff000000 000000 package Config::Any::YAML; use strict; use warnings; use base 'Config::Any::Base'; use Carp (); =head1 NAME Config::Any::YAML - Load YAML config files =head1 DESCRIPTION Loads YAML files. Example: --- name: TestApp Controller::Foo: foo: bar Model::Baz: qux: xyzzy =head1 METHODS =head2 extensions( ) return an array of valid extensions (C, C). =cut sub extensions { return qw( yml yaml ); } =head2 load( $file ) Attempts to load C<$file> as a YAML file. =cut sub load { my $class = shift; my $file = shift; if (eval { require YAML::XS; 1 }) { return YAML::XS::LoadFile( $file ); } elsif ($] > 5.008008 && eval { require YAML::Syck; YAML::Syck->VERSION(0.70) } ) { open( my $fh, $file ) or die $!; my $content = do { local $/; <$fh> }; close $fh; return YAML::Syck::Load( $content ); } require YAML; return YAML::LoadFile( $file ); } =head2 requires_any_of( ) Specifies that this modules requires one of L, L (0.70) or L in order to work. =cut sub requires_any_of { 'YAML::XS', ( $] > 5.008008 ? [ 'YAML::Syck', '0.70' ] : ()), 'YAML'; } =head1 AUTHOR Brian Cassidy =head1 COPYRIGHT AND LICENSE Copyright 2006-2016 by Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO =over 4 =item * L =item * L =item * L =item * L =item * L =back =cut 1;