Config-Any-0.33/000755 000000 000000 00000000000 14424476167 013507 5ustar00rootwheel000000 000000 Config-Any-0.33/README000644 000000 000000 00000017615 14424476167 014401 0ustar00rootwheel000000 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 for each file type to be supported: * For ".cnf", ".conf" files: Config::General * For ".ini" files: Config::Tiny * For ".json", ".jsn" files: Cpanel::JSON::XS, JSON::MaybeXS, JSON::DWIW, JSON::XS, JSON::Syck, JSON::PP, JSON * For ".pl", ".perl" files: no additional requirements * For ".xml" files: XML::Simple * For ".yml", ".yaml" files: YAML::XS, YAML::Syck, YAML Additionally, other file types are supported by third-party plugins in the "Config::Any::" namespace, installed separately. BUGS AND LIMITATIONS 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.33/Changes000644 000000 000000 00000013250 14424475755 015005 0ustar00rootwheel000000 000000 Revision history for Config-Any 0.33 - 2023-05-03 - update docs describe which modules are needed for which formats - update Config::General requirement for conf files to a non-broken version (2.48) - don't try to upgrade old Config::General versions - fix is_supported method verifying the version of required modules - documentation cleanups 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.33/MANIFEST000644 000000 000000 00000002371 14424476167 014643 0ustar00rootwheel000000 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) LICENSE LICENSE file (added by Distar) Config-Any-0.33/LICENSE000644 000000 000000 00000043424 14424476167 014523 0ustar00rootwheel000000 000000 Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2023 by Joel Bernstein . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. 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 PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2023 by Joel Bernstein . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Config-Any-0.33/t/000755 000000 000000 00000000000 14424476165 013750 5ustar00rootwheel000000 000000 Config-Any-0.33/xt/000755 000000 000000 00000000000 14424476165 014140 5ustar00rootwheel000000 000000 Config-Any-0.33/META.yml000644 000000 000000 00000001365 14424476165 014763 0ustar00rootwheel000000 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.66, CPAN::Meta::Converter version 2.150010' 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: https://github.com/p5sagit/Config-Any.git version: '0.33' x_authority: cpan:RATAXIS x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Config-Any-0.33/META.json000644 000000 000000 00000003673 14424476166 015140 0ustar00rootwheel000000 000000 { "abstract" : "Load configuration from different file formats, transparently", "author" : [ "Joel Bernstein " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.66, CPAN::Meta::Converter version 2.150010", "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.48", "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.48", "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" : "https://github.com/p5sagit/Config-Any.git", "web" : "https://github.com/p5sagit/Config-Any" } }, "version" : "0.33", "x_authority" : "cpan:RATAXIS", "x_serialization_backend" : "JSON::PP version 4.16" } Config-Any-0.33/lib/000755 000000 000000 00000000000 14424476165 014253 5ustar00rootwheel000000 000000 Config-Any-0.33/maint/000755 000000 000000 00000000000 14424476165 014615 5ustar00rootwheel000000 000000 Config-Any-0.33/Makefile.PL000644 000000 000000 00000006111 14424476065 015455 0ustar00rootwheel000000 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.48', 'Config::Tiny' => 0, 'Cpanel::JSON::XS' => 0, 'XML::Simple' => 0, 'XML::NamespaceSupport' => 0, 'YAML::XS' => 0, }, }, develop => { requires => { 'Config::General' => '2.48', '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 => 'https://github.com/p5sagit/Config-Any.git', web => 'https://github.com/p5sagit/Config-Any', 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 = (); ## 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'; $MM_ARGS{PL_FILES} ||= {}; $MM_ARGS{NORECURS} = 1 if not exists $MM_ARGS{NORECURS}; 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.33/maint/Makefile.PL.include000644 000000 000000 00000000501 14424475735 020207 0ustar00rootwheel000000 000000 BEGIN { -e 'Distar' or system qw(git clone https://github.com/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.33/lib/Config/000755 000000 000000 00000000000 14424476165 015460 5ustar00rootwheel000000 000000 Config-Any-0.33/lib/Config/Any.pm000644 000000 000000 00000031034 14424475746 016552 0ustar00rootwheel000000 000000 package Config::Any; use strict; use warnings; use Carp; use Module::Pluggable::Object (); our $VERSION = '0.33'; =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 for each file type to be supported: =over 4 =item * For C<.cnf>, C<.conf> files: L =item * For C<.ini> files: L =item * For C<.json>, C<.jsn> files: L, L, L, L, L, L, L =item * For C<.pl>, C<.perl> files: no additional requirements =item * For C<.xml> files: L =item * For C<.yml>, C<.yaml> files: L, L, L =back Additionally, other file types are supported by third-party plugins in the C namespace, installed separately. =head1 BUGS AND LIMITATIONS 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.33/lib/Config/Any/000755 000000 000000 00000000000 14424476165 016207 5ustar00rootwheel000000 000000 Config-Any-0.33/lib/Config/Any/YAML.pm000644 000000 000000 00000003063 13353154350 017276 0ustar00rootwheel000000 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; Config-Any-0.33/lib/Config/Any/Perl.pm000644 000000 000000 00000002705 13353154350 017440 0ustar00rootwheel000000 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.33/lib/Config/Any/INI.pm000644 000000 000000 00000004230 13353154350 017150 0ustar00rootwheel000000 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.33/lib/Config/Any/JSON.pm000644 000000 000000 00000005176 13353154350 017314 0ustar00rootwheel000000 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.33/lib/Config/Any/General.pm000644 000000 000000 00000003064 13645566712 020127 0ustar00rootwheel000000 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.48' ); $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.48' ] } =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.33/lib/Config/Any/Base.pm000644 000000 000000 00000003436 14424475735 017427 0ustar00rootwheel000000 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($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.33/lib/Config/Any/XML.pm000644 000000 000000 00000004333 13353154350 017175 0ustar00rootwheel000000 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.33/xt/author/000755 000000 000000 00000000000 14424476165 015442 5ustar00rootwheel000000 000000 Config-Any-0.33/xt/author/pod.t000644 000000 000000 00000000122 13353154350 016371 0ustar00rootwheel000000 000000 use strict; use warnings; use Test::More; use Test::Pod 1.14; all_pod_files_ok; Config-Any-0.33/xt/author/pod-coverage.t000644 000000 000000 00000000137 13353154350 020170 0ustar00rootwheel000000 000000 use strict; use warnings; use Test::More; use Test::Pod::Coverage 1.04; all_pod_coverage_ok; Config-Any-0.33/t/10-branches.t000644 000000 000000 00000003276 13353154350 016135 0ustar00rootwheel000000 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.33/t/51-ini.t000644 000000 000000 00000003631 13353154350 015127 0ustar00rootwheel000000 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.33/t/54-xml.t000644 000000 000000 00000003376 13353154350 015161 0ustar00rootwheel000000 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.33/t/multi/000755 000000 000000 00000000000 14424476165 015102 5ustar00rootwheel000000 000000 Config-Any-0.33/t/53-perl.t000644 000000 000000 00000002536 13353154350 015317 0ustar00rootwheel000000 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.33/t/invalid/000755 000000 000000 00000000000 14424476165 015376 5ustar00rootwheel000000 000000 Config-Any-0.33/t/55-yaml.t000644 000000 000000 00000002344 13353154350 015316 0ustar00rootwheel000000 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.33/t/50-general.t000644 000000 000000 00000002255 13353154350 015765 0ustar00rootwheel000000 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.33/t/65-force_plugins.t000644 000000 000000 00000000457 13353154350 017217 0ustar00rootwheel000000 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.33/t/63-unsupported.t000644 000000 000000 00000000654 13353154350 016745 0ustar00rootwheel000000 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.33/t/52-json.t000644 000000 000000 00000001462 13353154350 015322 0ustar00rootwheel000000 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.33/t/supported/000755 000000 000000 00000000000 14424476165 015775 5ustar00rootwheel000000 000000 Config-Any-0.33/t/64-extfail.t000644 000000 000000 00000000637 13353154350 016013 0ustar00rootwheel000000 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.33/t/61-features.t000644 000000 000000 00000004517 13353154350 016173 0ustar00rootwheel000000 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.33/t/00-report-prereqs.t000644 000000 000000 00000001325 13353154350 017332 0ustar00rootwheel000000 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.33/t/lib/000755 000000 000000 00000000000 14424476165 014516 5ustar00rootwheel000000 000000 Config-Any-0.33/t/perl-taint.t000644 000000 000000 00000000115 13353154350 016176 0ustar00rootwheel000000 000000 #!perl -T use strict; use warnings; do './t/53-perl.t' or die ($@ || $!); Config-Any-0.33/t/conf/000755 000000 000000 00000000000 14424476165 014675 5ustar00rootwheel000000 000000 Config-Any-0.33/t/62-multi.t000644 000000 000000 00000001406 13353154350 015502 0ustar00rootwheel000000 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.33/t/20-parse.t000644 000000 000000 00000003504 13353154350 015455 0ustar00rootwheel000000 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.33/t/conf/conf.json000644 000000 000000 00000000307 13353154350 016502 0ustar00rootwheel000000 000000 { "name": "TestApp", "Component": { "Controller::Foo": { "foo": "bar" } }, "Model": { "Model::Baz": { "qux": "xyzzy" } } } Config-Any-0.33/t/conf/conf.xml000644 000000 000000 00000000277 13353154350 016337 0ustar00rootwheel000000 000000 TestApp bar xyzzy Config-Any-0.33/t/conf/conf.pl000644 000000 000000 00000000222 13353154350 016140 0ustar00rootwheel000000 000000 { name => 'TestApp', Component => { 'Controller::Foo' => { foo => 'bar' } }, Model => { 'Model::Baz' => { qux => 'xyzzy' } } } Config-Any-0.33/t/conf/conf.conf000644 000000 000000 00000000156 13353154350 016460 0ustar00rootwheel000000 000000 name = TestApp foo bar qux xyzzy Config-Any-0.33/t/conf/conf_arrayref.xml000644 000000 000000 00000000323 13353154350 020222 0ustar00rootwheel000000 000000
submit
Config-Any-0.33/t/conf/single_element_arrayref.conf000644 000000 000000 00000000014 13353154350 022411 0ustar00rootwheel000000 000000 foo [ bar ] Config-Any-0.33/t/conf/subsections.ini000644 000000 000000 00000000113 13353154350 017717 0ustar00rootwheel000000 000000 [section1] a = 1 [section1 subsection1] b = 2 [section1 subsection2] c = 3 Config-Any-0.33/t/conf/conf.yml000644 000000 000000 00000000155 13353154350 016333 0ustar00rootwheel000000 000000 --- name: TestApp Component: Controller::Foo: foo: bar Model: Model::Baz: qux: xyzzy Config-Any-0.33/t/conf/conf.unsupported000644 000000 000000 00000000000 13353154350 020107 0ustar00rootwheel000000 000000 Config-Any-0.33/t/conf/conf.foo000644 000000 000000 00000000120 13353154350 016305 0ustar00rootwheel000000 000000 name=TestApp [Component Controller::Foo] foo=bar [Model Model::Baz] qux=xyzzy Config-Any-0.33/t/conf/conf.ini000644 000000 000000 00000000120 13353154350 016301 0ustar00rootwheel000000 000000 name=TestApp [Component Controller::Foo] foo=bar [Model Model::Baz] qux=xyzzy Config-Any-0.33/t/conf/conf.extfail000644 000000 000000 00000000044 13353154350 017163 0ustar00rootwheel000000 000000 Placeholder file for t/64-extfail.t Config-Any-0.33/t/conf/conf2.ini000644 000000 000000 00000000100 13353154350 016361 0ustar00rootwheel000000 000000 name=TestApp [Controller::Foo] foo=bar [Model::Baz] qux=xyzzy Config-Any-0.33/t/lib/Config/000755 000000 000000 00000000000 14424476165 015723 5ustar00rootwheel000000 000000 Config-Any-0.33/t/lib/Config/Any/000755 000000 000000 00000000000 14424476165 016452 5ustar00rootwheel000000 000000 Config-Any-0.33/t/lib/Config/Any/Unsupported.pm000644 000000 000000 00000000324 13353154350 021324 0ustar00rootwheel000000 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.33/t/supported/conf.pl000644 000000 000000 00000000222 13353154350 017240 0ustar00rootwheel000000 000000 { name => 'TestApp', Component => { 'Controller::Foo' => { foo => 'bar' } }, Model => { 'Model::Baz' => { qux => 'xyzzy' } } } Config-Any-0.33/t/invalid/conf.json000644 000000 000000 00000000306 13353154350 017202 0ustar00rootwheel000000 000000 { "name": "TestApp", "Component": { "Controller::Foo": { "foo": "bar" } }, "Model": { "Model::Baz": { "qux": "xyzzy" } } Config-Any-0.33/t/invalid/conf.xml000644 000000 000000 00000000276 13353154350 017037 0ustar00rootwheel000000 000000 TestApp bar xyzzy Config-Any-0.33/t/invalid/conf.pl000644 000000 000000 00000000221 13353154350 016640 0ustar00rootwheel000000 000000 { name => 'TestApp' Component => { 'Controller::Foo' => { foo => 'bar' } }, Model => { 'Model::Baz' => { qux => 'xyzzy' } } } Config-Any-0.33/t/invalid/conf.conf000644 000000 000000 00000000155 13353154350 017160 0ustar00rootwheel000000 000000 name = TestApp qux xyzzy Config-Any-0.33/t/invalid/conf.yml000644 000000 000000 00000000154 13353154350 017033 0ustar00rootwheel000000 000000 --- name: TestApp Component: Controller::Foo foo: bar Model: Model::Baz: qux: xyzzy Config-Any-0.33/t/invalid/conf.ini000644 000000 000000 00000000117 13353154350 017010 0ustar00rootwheel000000 000000 name=TestApp [Component Controller::Foo foo=bar [Model Model::Baz] qux=xyzzy Config-Any-0.33/t/multi/conf.yml000644 000000 000000 00000000177 13353154350 016544 0ustar00rootwheel000000 000000 --- name: TestApp Model: Model::Baz: qux: xyzzy --- name2: TestApp2 Model2: Model::Baz2: qux2: xyzzy2