From: Brian Cassidy Date: Wed, 22 Aug 2007 03:21:48 +0000 (+0000) Subject: distro work X-Git-Tag: v0.08~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=commitdiff_plain;h=f0e3c2214342d0d8a8839009b8b9c7e6bfbc7ab2 distro work --- diff --git a/Build.PL b/Build.PL deleted file mode 100644 index d1d1cd9..0000000 --- a/Build.PL +++ /dev/null @@ -1,19 +0,0 @@ -use strict; -use warnings; -use Module::Build; - -my $builder = Module::Build->new( - module_name => 'Config::Any', - license => 'perl', - dist_author => 'Joel Bernstein ', - dist_version_from => 'lib/Config/Any.pm', - requires => { - 'Test::More' => 0, - 'version' => 0, - 'Module::Pluggable' => '3.01' - }, - add_to_cleanup => [ 'Config-Any-*' ], - create_makefile_pl => 'traditional', -); - -$builder->create_build_script(); diff --git a/Changes b/Changes index 5f9c313..17e7c67 100644 --- a/Changes +++ b/Changes @@ -1,9 +1,15 @@ Revision history for Config-Any -0.01 - 0.03 dev releases +0.07 Mon Feb 26 2007 + promote 0.06_01 to non-dev. -0.04 Mon Aug 7 15:15:15 2006 - Initial CPAN-worthy release with proper test suite +0.06_01 Sun Feb 25 19:23:00 2007 + 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 Thu Feb 22 21:05:00 2007 + removed reference to Test::Exception, bumped version number 0.05 Wed Feb 21 22:00:00 2007 added support for: @@ -14,11 +20,8 @@ Revision history for Config-Any to nested hashrefs both as requested by Evan Kaufman -0.06 Thu Feb 22 21:05:00 2007 - removed reference to Test::Exception, bumped version number +0.04 Mon Aug 7 15:15:15 2006 + Initial CPAN-worthy release with proper test suite -0.06_01 Sun Feb 25 19:23:00 2007 - 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.01 - 0.03 dev releases diff --git a/MANIFEST b/MANIFEST deleted file mode 100644 index 0eac562..0000000 --- a/MANIFEST +++ /dev/null @@ -1,33 +0,0 @@ -Build.PL -Changes -lib/Config/Any.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 -Makefile.PL -MANIFEST This list of files -README -t/01-use.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/conf/conf.conf -t/conf/conf.foo -t/conf/conf.ini -t/conf/conf.json -t/conf/conf.pl -t/conf/conf.xml -t/conf/conf.yml -t/conf/conf2.ini -t/pod-coverage.t -t/pod.t -META.yml diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..f21a21f --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,29 @@ +# Avoid version control files. +\bRCS\b +\bCVS\b +,v$ +\B\.svn\b + +# Avoid Makemaker generated and utility files. +\bMakefile$ +\bblib +\bMakeMaker-\d +\bpm_to_blib$ +\bblibdirs$ +^MANIFEST\.SKIP$ + +# Avoid Module::Build generated and utility files. +\bBuild$ +\b_build + +# Avoid temp and backup files. +~$ +\.tmp$ +\.old$ +\.bak$ +\#$ +\b\.# +\.DS_Store$ + +# No tarballs! +\.gz$ diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..bdff64a --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,12 @@ +use inc::Module::Install 0.65; + +name 'Config-Any'; +all_from 'lib/Config/Any.pm'; + +requires 'Module::Pluggable' => '3.01'; +requires 'version'; + +requires 'Test::More'; + +auto_install; +WriteAll; diff --git a/README b/README index 3d80d7e..cef9105 100644 --- a/README +++ b/README @@ -1,26 +1,163 @@ -Config-Any version 0.0.4 +NAME + Config::Any - Load configuration from different file formats, + transparently -This module generalises loading class configuration data from a number of different -file formats. +VERSION + This document describes Config::Any version 0.0.7 -INSTALLATION +SYNOPSIS + use Config::Any; -To install this module, run the following commands: - perl Build.PL - ./Build - ./Build test - ./Build install + my $cfg = Config::Any->load_stems({stems => \@filepath_stems, ... }); + # or + my $cfg = Config::Any->load_files({files => \@filepaths, ... }); + for (@$cfg) { + my ($filename, $config) = each %$_; + $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( ) + Config::Any->load_files({files => \@files]}); + Config::Any->load_files({files => \@files, filter => \&filter}); + Config::Any->load_files({files => \@files, use_ext => 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. + + "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'. + + load_stems( ) + Config::Any->load_stems({stems => \@stems]}); + Config::Any->load_stems({stems => \@stems, filter => \&filter}); + Config::Any->load_stems({stems => \@stems, use_ext => 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 + + 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 "". -Module::Pluggable >= 3.01 + This module is free software; you can redistribute it and/or modify it + under the same terms as Perl itself. See perlartistic. -COPYRIGHT AND LICENCE +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. -The development of this module was sponsored by SAPO, a division of Portugal Telecom. + 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. -Copyright (C) 2006, Portugal Telecom +SEE ALSO + Catalyst::Plugin::ConfigLoader -- now a wrapper around this module. -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. diff --git a/lib/Config/Any.pm b/lib/Config/Any.pm index 98ed929..d2f77e5 100644 --- a/lib/Config/Any.pm +++ b/lib/Config/Any.pm @@ -6,7 +6,7 @@ use Carp; use Module::Pluggable::Object (); use English qw(-no_match_vars); -our $VERSION = '0.06_01'; +our $VERSION = '0.07'; =head1 NAME @@ -14,21 +14,21 @@ Config::Any - Load configuration from different file formats, transparently =head1 VERSION -This document describes Config::Any version 0.0.5 +This document describes Config::Any version 0.0.7 =head1 SYNOPSIS use Config::Any; - my $cfg = Config::Any->load_stems({stems => \@filepath_stems, ... }); - # or - my $cfg = Config::Any->load_files({files => \@filepaths, ... }); + my $cfg = Config::Any->load_stems({stems => \@filepath_stems, ... }); + # or + my $cfg = Config::Any->load_files({files => \@filepaths, ... }); - for (@$cfg) { - my ($filename, $config) = each %$_; - $class->config($config); - warn "loaded config from file: $filename"; - } + for (@$cfg) { + my ($filename, $config) = each %$_; + $class->config($config); + warn "loaded config from file: $filename"; + } =head1 DESCRIPTION @@ -150,7 +150,7 @@ sub _load { @{$args}{qw(files filter use_ext force_plugins)}; croak "_load requires a arrayref of file paths" unless defined $files_ref; - my %files = _maphash @$files_ref; + my %files = _maphash @$files_ref; my %force_plugins = _maphash @$force_plugins_ref; my $enforcing = keys %force_plugins ? 1 : 0; @@ -160,7 +160,7 @@ sub _load { # perform a separate file loop for each loader for my $loader ( $class->plugins ) { next if $enforcing && not defined $force_plugins{$loader}; - last unless keys %files; + last unless keys %files; my %ext = _maphash $loader->extensions; FILE: @@ -168,25 +168,25 @@ sub _load { # use file extension to decide whether this loader should try this file # use_ext => 1 hits this block if (defined $use_ext && !$enforcing) { - my $matched_ext = 0; + my $matched_ext = 0; EXT: for my $e (keys %ext) { next EXT unless $filename =~ m{ \. $e \z }xms; next FILE unless exists $ext{$e}; - $matched_ext = 1; + $matched_ext = 1; } - next FILE unless $matched_ext; + next FILE unless $matched_ext; } my $config; - eval { - $config = $loader->load( $filename ); - }; + eval { + $config = $loader->load( $filename ); + }; - next if $EVAL_ERROR; # if it croaked or warned, we can't use it + next if $EVAL_ERROR; # if it croaked or warned, we can't use it next if !$config; - delete $files{$filename}; + delete $files{$filename}; # post-process config with a filter callback, if we got one $filter_cb->( $config ) if defined $filter_cb; @@ -238,7 +238,7 @@ parameter to those methods. sub extensions { my $class = shift; my @ext = map { $_->extensions } $class->plugins; - return wantarray ? @ext : [@ext]; + return wantarray ? @ext : [@ext]; } =head1 DIAGNOSTICS @@ -289,7 +289,7 @@ L. =head1 AUTHOR -Joel Bernstein C<< >> +Joel Bernstein Erataxis@cpan.orgE =head1 CONTRIBUTORS diff --git a/lib/Config/Any/General.pm b/lib/Config/Any/General.pm index b453ca4..76b04a9 100644 --- a/lib/Config/Any/General.pm +++ b/lib/Config/Any/General.pm @@ -1,108 +1,108 @@ -package Config::Any::General; - -use strict; -use warnings; - -=head1 NAME - -Config::Any::General - Load Config::General files - -=head1 DESCRIPTION - -Loads Config::General files. Example: - - name = TestApp - - foo bar - - - 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; - - # work around bug (?) in Config::General -# return if $class->_test_perl($file); - - require Config::General; - my $configfile = Config::General->new( $file ); - my $config = { $configfile->getall }; - - return $config; -} - -# this is a bit of a hack but necessary, because Config::General is *far* too lax -# about what it will load -- specifically, it seems to be quite happy to load a Perl -# config file (ie, a file which is valid Perl and creates a hashref) as if it were -# an Apache-style configuration file, presumably due to laziness on the part of the -# developer. - -sub _test_perl { - my ($class, $file) = @_; - my $is_perl_src; - eval { $is_perl_src = do "$file"; }; - delete $INC{$file}; # so we don't screw stuff later on - return defined $is_perl_src; -} - -=head1 AUTHOR - -=over 4 - -=item * Brian Cassidy Ebricas@cpan.orgE - -=back - -=head1 CONTRIBUTORS - -=over 4 - -=item * Joel Bernstein C<< >> - -=back - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006 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; - +package Config::Any::General; + +use strict; +use warnings; + +=head1 NAME + +Config::Any::General - Load Config::General files + +=head1 DESCRIPTION + +Loads Config::General files. Example: + + name = TestApp + + foo bar + + + 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; + + # work around bug (?) in Config::General +# return if $class->_test_perl($file); + + require Config::General; + my $configfile = Config::General->new( $file ); + my $config = { $configfile->getall }; + + return $config; +} + +# this is a bit of a hack but necessary, because Config::General is *far* too lax +# about what it will load -- specifically, it seems to be quite happy to load a Perl +# config file (ie, a file which is valid Perl and creates a hashref) as if it were +# an Apache-style configuration file, presumably due to laziness on the part of the +# developer. + +sub _test_perl { + my ($class, $file) = @_; + my $is_perl_src; + eval { $is_perl_src = do "$file"; }; + delete $INC{$file}; # so we don't screw stuff later on + return defined $is_perl_src; +} + +=head1 AUTHOR + +=over 4 + +=item * Brian Cassidy Ebricas@cpan.orgE + +=back + +=head1 CONTRIBUTORS + +=over 4 + +=item * Joel Bernstein C<< >> + +=back + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 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; + diff --git a/lib/Config/Any/INI.pm b/lib/Config/Any/INI.pm index 3b92c5b..a8ec52f 100644 --- a/lib/Config/Any/INI.pm +++ b/lib/Config/Any/INI.pm @@ -1,117 +1,117 @@ -package Config::Any::INI; - -use strict; -use warnings; - -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 ); - - my $main = delete $config->{ _ }; - my $out; - $out->{$_} = $main->{$_} for keys %$main; - - for my $k (keys %$config) { - my @keys = split /\s+/, $k if $MAP_SECTION_SPACE_TO_NESTED_KEY; - my $ref = $config->{$k}; - - if (@keys > 1) { - my ($a, $b) = @keys[0,1]; - $out->{$a}->{$b} = $ref; - } else { - $out->{$k} = $ref; - } - } - return $out; -} - -=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 AUTHOR - -=over 4 - -=item * Brian Cassidy Ebricas@cpan.orgE - -=item * Joel Bernstein Erataxis@cpan.orgE - -=back - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006 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; +package Config::Any::INI; + +use strict; +use warnings; + +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 ); + + my $main = delete $config->{ _ }; + my $out; + $out->{$_} = $main->{$_} for keys %$main; + + for my $k (keys %$config) { + my @keys = split /\s+/, $k if $MAP_SECTION_SPACE_TO_NESTED_KEY; + my $ref = $config->{$k}; + + if (@keys > 1) { + my ($a, $b) = @keys[0,1]; + $out->{$a}->{$b} = $ref; + } else { + $out->{$k} = $ref; + } + } + return $out; +} + +=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 AUTHOR + +=over 4 + +=item * Brian Cassidy Ebricas@cpan.orgE + +=item * Joel Bernstein Erataxis@cpan.orgE + +=back + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 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; diff --git a/lib/Config/Any/JSON.pm b/lib/Config/Any/JSON.pm index faa041d..954e305 100644 --- a/lib/Config/Any/JSON.pm +++ b/lib/Config/Any/JSON.pm @@ -1,92 +1,92 @@ -package Config::Any::JSON; - -use strict; -use warnings; - -=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 $!; - my $content = do { local $/; <$fh> }; - close $fh; - - eval { require JSON::Syck; }; - if( $@ ) { - require JSON; - JSON->import; - return jsonToObj( $content ); - } - else { - return JSON::Syck::Load( $content ); - } -} - -=head1 AUTHOR - -=over 4 - -=item * Brian Cassidy Ebricas@cpan.orgE - -=back - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006 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 - -=back - -=cut - -1; \ No newline at end of file +package Config::Any::JSON; + +use strict; +use warnings; + +=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 $!; + my $content = do { local $/; <$fh> }; + close $fh; + + eval { require JSON::Syck; }; + if( $@ ) { + require JSON; + JSON->import; + return jsonToObj( $content ); + } + else { + return JSON::Syck::Load( $content ); + } +} + +=head1 AUTHOR + +=over 4 + +=item * Brian Cassidy Ebricas@cpan.orgE + +=back + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 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 + +=back + +=cut + +1; diff --git a/lib/Config/Any/Perl.pm b/lib/Config/Any/Perl.pm index ae7bd7b..6c20ced 100644 --- a/lib/Config/Any/Perl.pm +++ b/lib/Config/Any/Perl.pm @@ -1,75 +1,75 @@ -package Config::Any::Perl; - -use strict; -use warnings; - -=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; - return eval { require $file }; -} - -=head1 AUTHOR - -=over 4 - -=item * Brian Cassidy Ebricas@cpan.orgE - -=back - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006 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; +package Config::Any::Perl; + +use strict; +use warnings; + +=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; + return eval { require $file }; +} + +=head1 AUTHOR + +=over 4 + +=item * Brian Cassidy Ebricas@cpan.orgE + +=back + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 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; diff --git a/lib/Config/Any/XML.pm b/lib/Config/Any/XML.pm index 42a8380..4660338 100644 --- a/lib/Config/Any/XML.pm +++ b/lib/Config/Any/XML.pm @@ -1,104 +1,104 @@ -package Config::Any::XML; - -use strict; -use warnings; - -=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; - - require XML::Simple; - XML::Simple->import; - my $config = XMLin( - $file, - ForceArray => [ qw( component model view controller ) ], - ); - - 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 ? delete $ref->{name} : undef; - if (defined $name) { - $out->{$k}->{$name} = $ref; - } else { - $out->{$k} = $ref; - } - } - $out; -} - -=head1 AUTHOR - -=over 4 - -=item * Brian Cassidy Ebricas@cpan.orgE - -=item * Joel Bernstein Erataxis@cpan.orgE - -=back - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006 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; +package Config::Any::XML; + +use strict; +use warnings; + +=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; + + require XML::Simple; + XML::Simple->import; + my $config = XMLin( + $file, + ForceArray => [ qw( component model view controller ) ], + ); + + 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 ? delete $ref->{name} : undef; + if (defined $name) { + $out->{$k}->{$name} = $ref; + } else { + $out->{$k} = $ref; + } + } + $out; +} + +=head1 AUTHOR + +=over 4 + +=item * Brian Cassidy Ebricas@cpan.orgE + +=item * Joel Bernstein Erataxis@cpan.orgE + +=back + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 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; diff --git a/lib/Config/Any/YAML.pm b/lib/Config/Any/YAML.pm index 564fc52..f5d680d 100644 --- a/lib/Config/Any/YAML.pm +++ b/lib/Config/Any/YAML.pm @@ -1,88 +1,88 @@ -package Config::Any::YAML; - -use strict; -use warnings; - -=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; - - eval { require YAML::Syck; }; - if( $@ ) { - require YAML; - return YAML::LoadFile( $file ); - } - else { - open( my $fh, $file ) or die $!; - my $content = do { local $/; <$fh> }; - close $fh; - return YAML::Syck::Load( $content ); - } -} - -=head1 AUTHOR - -=over 4 - -=item * Brian Cassidy Ebricas@cpan.orgE - -=back - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006 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 - -=back - -=cut - -1; \ No newline at end of file +package Config::Any::YAML; + +use strict; +use warnings; + +=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; + + eval { require YAML::Syck; }; + if( $@ ) { + require YAML; + return YAML::LoadFile( $file ); + } + else { + open( my $fh, $file ) or die $!; + my $content = do { local $/; <$fh> }; + close $fh; + return YAML::Syck::Load( $content ); + } +} + +=head1 AUTHOR + +=over 4 + +=item * Brian Cassidy Ebricas@cpan.orgE + +=back + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 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 + +=back + +=cut + +1; diff --git a/t/01-use.t b/t/01-use.t index b14426a..5e46259 100644 --- a/t/01-use.t +++ b/t/01-use.t @@ -1,10 +1,10 @@ -use Test::More tests => 6; - -BEGIN { - use_ok( 'Config::Any' ); - use_ok( 'Config::Any::INI' ); - use_ok( 'Config::Any::JSON' ); - use_ok( 'Config::Any::Perl' ); - use_ok( 'Config::Any::XML' ); - use_ok( 'Config::Any::YAML' ); -} +use Test::More tests => 6; + +BEGIN { + use_ok( 'Config::Any' ); + use_ok( 'Config::Any::INI' ); + use_ok( 'Config::Any::JSON' ); + use_ok( 'Config::Any::Perl' ); + use_ok( 'Config::Any::XML' ); + use_ok( 'Config::Any::YAML' ); +} diff --git a/t/10-branches.t b/t/10-branches.t index 8e8d1b3..e74294b 100644 --- a/t/10-branches.t +++ b/t/10-branches.t @@ -1,26 +1,26 @@ -use Test::More tests => 9; -use Config::Any; - -ok ( ! Config::Any->load_files(), "load_files expects args" ); -ok ( ! Config::Any->load_stems(), "load_stems expects args" ); - -{ - my @warnings; - local $SIG{__WARN__} = sub { push @warnings, @_ }; - 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 stems"); -} - -my @files = glob("t/conf/conf.*"); -my $filter = sub { return }; -ok(Config::Any->load_files({files=>\@files, use_ext=>0}), "use_ext 0 works"); -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}}) }; -ok($@, "filter breaks"); - -my @stems = qw(t/conf/conf); -ok(Config::Any->load_stems({stems=>\@stems, use_ext=>1}), "load_stems with stems works"); +use Test::More tests => 9; +use Config::Any; + +ok ( ! Config::Any->load_files(), "load_files expects args" ); +ok ( ! Config::Any->load_stems(), "load_stems expects args" ); + +{ + my @warnings; + local $SIG{__WARN__} = sub { push @warnings, @_ }; + 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 stems"); +} + +my @files = glob("t/conf/conf.*"); +my $filter = sub { return }; +ok(Config::Any->load_files({files=>\@files, use_ext=>0}), "use_ext 0 works"); +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}}) }; +ok($@, "filter breaks"); + +my @stems = qw(t/conf/conf); +ok(Config::Any->load_stems({stems=>\@stems, use_ext=>1}), "load_stems with stems works"); diff --git a/t/20-parse.t b/t/20-parse.t index 420b581..b75eab7 100644 --- a/t/20-parse.t +++ b/t/20-parse.t @@ -1,63 +1,63 @@ -package MockApp; -use strict; -use warnings; - -$|++; -use Test::More tests => 54; -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}; - my $mod_load_result; - eval { $mod_load_result = $mod->load( $f ); delete $INC{$f} if $ext eq 'pl' }; - return $@ ? (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; - - 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" ); - } -} - +package MockApp; +use strict; +use warnings; + +$|++; +use Test::More tests => 54; +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}; + my $mod_load_result; + eval { $mod_load_result = $mod->load( $f ); delete $INC{$f} if $ext eq 'pl' }; + return $@ ? (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; + + 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" ); + } +} + diff --git a/t/50-general.t b/t/50-general.t index cf334cb..9d4a884 100644 --- a/t/50-general.t +++ b/t/50-general.t @@ -1,11 +1,11 @@ -use Test::More tests => 2; - -use Config::Any::General; - -my $config = eval { Config::Any::General->load( 't/conf/conf.conf' ) }; - -SKIP: { - skip "Couldn't Load Config::General plugin", 2 if $@; - ok( $config ); - is( $config->{ name }, 'TestApp' ); -} +use Test::More tests => 2; + +use Config::Any::General; + +my $config = eval { Config::Any::General->load( 't/conf/conf.conf' ) }; + +SKIP: { + skip "Couldn't Load Config::General plugin", 2 if $@; + ok( $config ); + is( $config->{ name }, 'TestApp' ); +} diff --git a/t/52-json.t b/t/52-json.t index f4e45c3..dcf084f 100644 --- a/t/52-json.t +++ b/t/52-json.t @@ -1,11 +1,11 @@ -use Test::More tests => 2; - -use Config::Any::JSON; - -my $config = eval { Config::Any::JSON->load( 't/conf/conf.json' ) }; - -SKIP: { - skip "Couldn't Load JSON plugin", 2 if $@; - ok( $config ); - is( $config->{ name }, 'TestApp' ); -} +use Test::More tests => 2; + +use Config::Any::JSON; + +my $config = eval { Config::Any::JSON->load( 't/conf/conf.json' ) }; + +SKIP: { + skip "Couldn't Load JSON plugin", 2 if $@; + ok( $config ); + is( $config->{ name }, 'TestApp' ); +} diff --git a/t/53-perl.t b/t/53-perl.t index 427f611..4914075 100644 --- a/t/53-perl.t +++ b/t/53-perl.t @@ -1,11 +1,11 @@ -use Test::More tests => 2; - -use Config::Any::Perl; - -my $config = eval { Config::Any::Perl->load( 't/conf/conf.pl' ) }; - -SKIP: { - skip "Couldn't Load Perl plugin", 2 if $@; - ok( $config ); - is( $config->{ name }, 'TestApp' ); -} +use Test::More tests => 2; + +use Config::Any::Perl; + +my $config = eval { Config::Any::Perl->load( 't/conf/conf.pl' ) }; + +SKIP: { + skip "Couldn't Load Perl plugin", 2 if $@; + ok( $config ); + is( $config->{ name }, 'TestApp' ); +} diff --git a/t/54-xml.t b/t/54-xml.t index c8f94e9..4ddba3c 100644 --- a/t/54-xml.t +++ b/t/54-xml.t @@ -1,11 +1,11 @@ -use Test::More tests => 2; - -use Config::Any::XML; - -my $config = eval { Config::Any::XML->load( 't/conf/conf.xml' ) }; - -SKIP: { - skip "Couldn't Load XML plugin", 2 if $@; - ok( $config ); - is( $config->{ name }, 'TestApp' ); -} +use Test::More tests => 2; + +use Config::Any::XML; + +my $config = eval { Config::Any::XML->load( 't/conf/conf.xml' ) }; + +SKIP: { + skip "Couldn't Load XML plugin", 2 if $@; + ok( $config ); + is( $config->{ name }, 'TestApp' ); +} diff --git a/t/55-yaml.t b/t/55-yaml.t index 74ff1b1..049b79f 100644 --- a/t/55-yaml.t +++ b/t/55-yaml.t @@ -1,11 +1,11 @@ -use Test::More tests => 2; - -use Config::Any::YAML; - -my $config = eval { Config::Any::YAML->load( 't/conf/conf.yml' ) }; - -SKIP: { - skip "Couldn't Load YAML plugin", 2 if $@; - ok( $config ); - is( $config->{ name }, 'TestApp' ); -} +use Test::More tests => 2; + +use Config::Any::YAML; + +my $config = eval { Config::Any::YAML->load( 't/conf/conf.yml' ) }; + +SKIP: { + skip "Couldn't Load YAML plugin", 2 if $@; + ok( $config ); + is( $config->{ name }, 'TestApp' ); +} diff --git a/t/61-features.t b/t/61-features.t index 8436cc6..c3512aa 100644 --- a/t/61-features.t +++ b/t/61-features.t @@ -1,51 +1,51 @@ -package MockApp; -use strict; -use warnings; - -$|++; - -use Test::More tests => 10; -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", 10 if $@; - - ok( my $c_arr = Config::Any->load_files({ - files => [ $cfg_file ], - force_plugins => [qw(Config::Any::INI)] - }), "load file with parser forced" ); - - 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, $cfg_file, "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" ); - - - ok( my $c_arr_2 = Config::Any->load_files({ - files => [ $cfg_file ], - force_plugins => [qw(Config::Any::INI)], - use_ext => 1 - }), "load file with parser forced" ); -} - - - +package MockApp; +use strict; +use warnings; + +$|++; + +use Test::More tests => 10; +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", 10 if $@; + + ok( my $c_arr = Config::Any->load_files({ + files => [ $cfg_file ], + force_plugins => [qw(Config::Any::INI)] + }), "load file with parser forced" ); + + 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, $cfg_file, "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" ); + + + ok( my $c_arr_2 = Config::Any->load_files({ + files => [ $cfg_file ], + force_plugins => [qw(Config::Any::INI)], + use_ext => 1 + }), "load file with parser forced" ); +} + + + diff --git a/t/conf/conf.pl b/t/conf/conf.pl index f78c973..3e243b1 100644 --- a/t/conf/conf.pl +++ b/t/conf/conf.pl @@ -1,13 +1,13 @@ -{ - name => 'TestApp', - Component => { - 'Controller::Foo' => { - foo => 'bar' - } - }, - Model => { - 'Model::Baz' => { - qux => 'xyzzy' - } - } -} +{ + name => 'TestApp', + Component => { + 'Controller::Foo' => { + foo => 'bar' + } + }, + Model => { + 'Model::Baz' => { + qux => 'xyzzy' + } + } +} diff --git a/t/conf/conf.xml b/t/conf/conf.xml index 3754b15..069002f 100644 --- a/t/conf/conf.xml +++ b/t/conf/conf.xml @@ -1,9 +1,9 @@ - - TestApp - - bar - - - xyzzy - - + + TestApp + + bar + + + xyzzy + + diff --git a/t/conf/conf.yml b/t/conf/conf.yml index 29f4b73..169991e 100644 --- a/t/conf/conf.yml +++ b/t/conf/conf.yml @@ -1,8 +1,8 @@ ---- -name: TestApp -Component: - Controller::Foo: - foo: bar -Model: - Model::Baz: - qux: xyzzy +--- +name: TestApp +Component: + Controller::Foo: + foo: bar +Model: + Model::Baz: + qux: xyzzy