Config-Onion-1.006000755001750001750 012654061546 14271 5ustar00dsherohdsheroh000000000000Changes100644001750001750 127112654061546 15646 0ustar00dsherohdsheroh000000000000Config-Onion-1.0061.006 2016-02-02 - Workaround for Config::Any bug(?) in use_ext (Docs state that it will ignore files with unrecognized extensions; actual behavior is to die) 1.005 2016-01-17 - Allow passing parameters to Config::Any 1.004 2014-05-09 - Changed prefix_key from a global setting to a per-instance property 1.003 2014-05-09 - Fixed Perl 5.8 compatibility - Fixed POD syntax error 1.002 2014-05-08 - Added "prefix structure" capability 1.001 2013-04-02 - Added missing test-depends on YAML 1.000 2013-04-29 - Added Override layer - Removed Perl 5.10 dependency from Config::Onion::Simple 0.003 2013-03-23 - Added Config::Onion::Simple 0.002 2012-12-03 - Initial release LICENSE100644001750001750 4371612654061546 15412 0ustar00dsherohdsheroh000000000000Config-Onion-1.006This software is copyright (c) 2012 by Lund University Library. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. 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) 2012 by Lund University Library. 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) 2012 by Lund University Library. 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End INSTALL100644001750001750 167112654061546 15410 0ustar00dsherohdsheroh000000000000Config-Onion-1.006This is the Perl distribution Config-Onion. Installing Config-Onion is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm Config::Onion If you are installing into a system-wide directory, you may need to pass the "-S" flag to cpanm, which uses sudo to install the module: % cpanm -S Config::Onion ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan Config::Onion ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Makefile.PL % make && make test Then install it: % make install If you are installing into a system-wide directory, you may need to run: % sudo make install ## Documentation Config-Onion documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc Config::Onion META.yml100644001750001750 135112654061546 15623 0ustar00dsherohdsheroh000000000000Config-Onion-1.006--- abstract: 'Layered configuration, because configs are like ogres' author: - 'Dave Sherohman ' build_requires: FindBin: '0' Test::Exception: '0' Test::More: '0' YAML: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.043, CPAN::Meta::Converter version 2.142690' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Config-Onion requires: Config::Any: '0' Exporter: '0' Hash::Merge::Simple: '0' Moo: '0' base: '0' strict: '0' warnings: '0' resources: bugtracker: https://github.com/dsheroh/Config-Onion/issues repository: https://github.com/dsheroh/Config-Onion.git version: '1.006' MANIFEST100644001750001750 63012654061546 15462 0ustar00dsherohdsheroh000000000000Config-Onion-1.006# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.043. Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README.mkdn lib/Config/Onion.pm lib/Config/Onion/Simple.pm t/00-load.t t/01-defaults.t t/02-load.t t/03-mixed.t t/04-simple.t t/conf/basic.yml t/conf/basic2.zzz t/conf/prefix.yml t/conf/withlocal.local.yml t/conf/withlocal.yml t/release-eol.t t/release-no-tabs.t META.json100644001750001750 305612654061546 15777 0ustar00dsherohdsheroh000000000000Config-Onion-1.006{ "abstract" : "Layered configuration, because configs are like ogres", "author" : [ "Dave Sherohman " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.043, CPAN::Meta::Converter version 2.142690", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Config-Onion", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Test::EOL" : "0", "Test::More" : "0.88", "Test::NoTabs" : "0" } }, "runtime" : { "requires" : { "Config::Any" : "0", "Exporter" : "0", "Hash::Merge::Simple" : "0", "Moo" : "0", "base" : "0", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "FindBin" : "0", "Test::Exception" : "0", "Test::More" : "0", "YAML" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "dsheroh@cpan.org", "web" : "https://github.com/dsheroh/Config-Onion/issues" }, "repository" : { "type" : "git", "url" : "https://github.com/dsheroh/Config-Onion.git", "web" : "https://github.com/dsheroh/Config-Onion" } }, "version" : "1.006" } README.mkdn100644001750001750 1401012654061546 16176 0ustar00dsherohdsheroh000000000000Config-Onion-1.006# NAME Config::Onion - Layered configuration, because configs are like ogres # VERSION version 1.006 # SYNOPSIS my $cfg = Config::Onion->new; my $cfg = Config::Onion->set_default(db => {name => 'foo', password => 'bar'}); my $cfg = Config::Onion->load('/etc/myapp', './myapp'); my $cfg = Config::Onion->load('/etc/myapp', './myapp', {use_ext => 1, filter => \&filter}); my $cfg = Config::Onion->load_glob('./plugins/*'); my $cfg = Config::Onion->load_glob('./plugins/*', {force_plugins => ['Config::Any::YAML']}); $cfg->set_default(font => 'Comic Sans'); $cfg->load('config'); $cfg->load_glob('conf.d/myapp*'); $cfg->set_override(font => 'Arial'); my $dbname = $cfg->get->{db}{name}; my $plain_hashref_conf = $cfg->get; my $dbpassword = $plain_hashref_conf->{db}{password}; # DESCRIPTION All too often, configuration is not a universal or one-time thing, yet most configuration-handling treats it as such. Perhaps you can only load one config file. If you can load more than one, you often have to load all of them at the same time or each is stored completely independently, preventing one from being able to override another. Config::Onion changes that. Config::Onion stores all configuration settings in four layers: Defaults, Main, Local, and Override. Each layer can be added to as many times as you like. Within each layer, settings which are given multiple times will take the last specified value, while those which are not repeated will remain untouched. $cfg->set_default(name => 'Arthur Dent', location => 'Earth'); $cfg->set_default(location => 'Magrathea'); # In the Default layer, 'name' is still 'Arthur Dent', but 'location' has # been changed to 'Magrathea'. Regardless of the order in which they are set, values in Main will always override values in the Default layer, the Local layer always overrides both Default and Main, and the Override layer overrides all the others. The design intent for each layer is: - Default Hardcoded default values to be used when no further configuration is present - Main Values loaded from standard configuration files shipped with the application - Local Values loaded from local configuration files which are kept separate to prevent them from being overwritten by application upgrades, etc. - Override Settings provided at run-time which take precendence over all configuration files, such as settings provided via command line switches # METHODS ## new Returns a new, empty configuration object. ## load(@file\_stems) =head2 load(@file\\\_stems, {...}) Loads files matching the given stems using `Config::Any->load_stems` into the Main layer. Also concatenates ".local" to each stem and loads matching files into the Local layer. e.g., `$cfg->load('myapp')` would load `myapp.yml` into Main and `myapp.local.js` into Local. All filename extensions supported by `Config::Any` are recognized along with their corresponding formats. An optional hash ref final argument can be provided to override the default option `use_ext => 1` passed to `Config::Any`. All options supported by `Config::Any` are supported except flatten\_to\_hash. See `Config::Any->load_files` documentation for available options. ## load\_glob(@globs) =head2 load\_glob(@globs, {...}) Uses the Perl `glob` function to expand each parameter into a list of filenames and loads each file using `Config::Any`. Files whose names contain the string ".local." are loaded into the Local layer. All other files are loaded into the Main layer. An optional hash ref final argument can be provided to override the default option `use_ext => 1` passed to `Config::Any`. All options supported by `Config::Any` are supported except flatten\_to\_hash. See `Config::Any->load_files` documentation for available options. ## set\_default(\[\\%settings,...,\] %settings) ## set\_override(\[\\%settings,...,\] %settings) Imports `%settings` into the Default or Override layer. Accepts settings both as a plain hash and as hash references, but, if the two are mixed, all hash references must appear at the beginning of the parameter list, before any non-hashref settings. # PROPERTIES ## cfg ## get Returns the complete configuration as a hash reference. ## default ## main ## local ## override These properties each return a single layer of the configuration. This is not likely to be useful other than for debugging. For most other purposes, you probably want to use `get` instead. ## prefix\_key If set, enables the Prefix Structures functionality described below when using the `load` or `load_glob` methods. The value of `prefix_key` specifies the name of the key under which the prefix structure may be found. Default value is `undef`. # Prefix Structures If you find that your configuration structure is becoming unwieldy due to deeply-nested structures, you can define a file-specific "prefix structure" and all other settings within that file will be loaded as children of the prefix structure. For example, if your main program uses $cfg = Config::Onion->new(prefix_key => '_prefix'); $cfg->load("myapp/config"); and `myapp/config.yml` contains _prefix: foo: bar: baz: 1 then `$cfg` will contain the configuration foo: bar: baz: 1 Note that the top-level `prefix_key` is removed. There are some limitations on the prefix structure, in order to keep it sane and deterministic. First, the prefix structure may only contain hashes. Second, each hash must contain exactly one key. Finally, the value associated with the final key must be left undefined. # BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests at [https://github.com/dsheroh/Config-Onion/issues](https://github.com/dsheroh/Config-Onion/issues) # AUTHOR Dave Sherohman <dsheroh@cpan.org> # COPYRIGHT AND LICENSE This software is copyright (c) 2012 by Lund University Library. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. t000755001750001750 012654061546 14455 5ustar00dsherohdsheroh000000000000Config-Onion-1.00602-load.t100644001750001750 475012654061546 16146 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/tuse strict; use warnings; use Test::Exception; use Test::More; use Config::Onion; use FindBin; my $conf_dir = $FindBin::Bin . '/conf'; # construct bare, then load conf file { my $cfg = Config::Onion->new; isa_ok($cfg, 'Config::Onion', 'construct bare config'); $cfg->load("$conf_dir/basic"); is($cfg->get->{foo}, 'bar', 'retrieve value from single conf file'); } # construct by loading conf file { my $cfg = Config::Onion->load("$conf_dir/basic"); isa_ok($cfg, 'Config::Onion', 'construct by loading config file'); is($cfg->get->{xyzzy}, 'plugh', 'get value after constucting via load'); } # override main conf file with local conf { my $cfg = Config::Onion->load("$conf_dir/withlocal"); is($cfg->get->{main}, 1, 'local config does not clear main values'); is($cfg->get->{local}, 1, 'local config does override main values'); } # load list of conf files { my $cfg = Config::Onion->load("$conf_dir/basic", "$conf_dir/withlocal"); is_deeply([ $cfg->get->{xyzzy}, $cfg->get->{main}, $cfg->get->{local} ], [ 'plugh', 1, 1 ], 'multiple config files loaded correctly'); } # load files by glob match { my $cfg = Config::Onion->load_glob("$conf_dir/*"); ok(defined $cfg->get->{joker}, 'load multiple configs'); is($cfg->get->{joker}, 'wild', 'globbed load gives precedence to later files'); is($cfg->get->{local}, 1, 'globbed load gives precedence to local files'); } # GH5: handle load_glob correctly when nothing matches { my $cfg; lives_ok { $cfg = Config::Onion->load_glob("$conf_dir/DoesNotExist"); } q(glob with no matches doesn't die); is_deeply($cfg->get, {}, 'glob with no matches loads nothing'); } # prefix structures { my $cfg = Config::Onion->load("$conf_dir/prefix"); is($cfg->get->{deep_key}, 1, 'prefix structure disabled by default'); ok(exists $cfg->get->{_prefix}, 'prefix key present by default'); $cfg = Config::Onion->new(prefix_key => '_prefix'); $cfg->load("$conf_dir/prefix"); is($cfg->get->{some}{levels}{down}{deep_key}, 1, 'key found in prefix structure'); is($cfg->get->{some}{levels}{down}{deep}{subkey}, 2, 'subkey found in prefix structure'); ok(!defined $cfg->get->{_prefix}, 'prefix key replaced by prefix structure'); ok(!defined $cfg->get->{deep}, 'non-prefix keys cleared from config'); } # pass parameter to Config::Any, overrides use_ext { my $cfg = Config::Onion->load_glob("$conf_dir/basic*", {force_plugins => ['Config::Any::YAML']}); is($cfg->get->{joker}, 'one', 'use_ext was not used'); } done_testing; 00-load.t100644001750001750 16412654061546 16117 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/tuse strict; use warnings; use Test::More; use_ok 'Config::Onion'; use_ok 'Config::Onion::Simple'; done_testing; Makefile.PL100644001750001750 254312654061546 16330 0ustar00dsherohdsheroh000000000000Config-Onion-1.006# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.043. use strict; use warnings; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Layered configuration, because configs are like ogres", "AUTHOR" => "Dave Sherohman ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Config-Onion", "LICENSE" => "perl", "NAME" => "Config::Onion", "PREREQ_PM" => { "Config::Any" => 0, "Exporter" => 0, "Hash::Merge::Simple" => 0, "Moo" => 0, "base" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "FindBin" => 0, "Test::Exception" => 0, "Test::More" => 0, "YAML" => 0 }, "VERSION" => "1.006", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Config::Any" => 0, "Exporter" => 0, "FindBin" => 0, "Hash::Merge::Simple" => 0, "Moo" => 0, "Test::Exception" => 0, "Test::More" => 0, "YAML" => 0, "base" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); 03-mixed.t100644001750001750 115112654061546 16326 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/tuse strict; use warnings; use Test::More; use Config::Onion; use FindBin; my $test_dir = $FindBin::Bin; # construct with set_default, then load conf files over the defaults and # apply an override { my $cfg = Config::Onion->set_default(foo => 'default'); $cfg->load("$test_dir/conf/basic"); is($cfg->get->{foo}, 'bar', 'main config file overwrites defaults'); $cfg->load("$test_dir/conf/withlocal"); is($cfg->get->{local}, 1, 'local config file overwrites defaults and main'); $cfg->set_override(foo => 'baz'); is($cfg->get->{foo}, 'baz', 'override overwrites everything else'); } done_testing; 04-simple.t100644001750001750 33212654061546 16472 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/tuse strict; use warnings; use Test::More; use Config::Onion::Simple ':all'; isa_ok(cfg_obj, 'Config::Onion', 'cfg_obj returns a Config::Onion instance'); is_deeply(cfg, {}, 'cfg returns a hashref'); done_testing; 01-defaults.t100644001750001750 262612654061546 17035 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/tuse strict; use warnings; use Test::Exception; use Test::More; use Config::Onion; # GH5: don't die if config is empty { lives_ok { Config::Onion->new->get } q(empty config isn't fatal); } # construct bare, then add/retrieve default values { my $cfg = Config::Onion->new; isa_ok($cfg, 'Config::Onion', 'construct bare config'); $cfg->set_default(foo => 1); is($cfg->get->{foo}, 1, 'retrieve single value'); is_deeply($cfg->get, { foo => 1 }, 'retrieve full config'); } # construct by setting default values { my $cfg = Config::Onion->set_default(bar => 2); isa_ok($cfg, 'Config::Onion', 'construct with set_default'); is($cfg->get->{bar}, 2, 'retrieve value after set_default construction'); } # override existing defaults with new defaults { my $cfg = Config::Onion->set_default(foo => 3); $cfg->set_default(bar => 'baz'); is($cfg->get->{foo}, 3, 'merge defaults preserves old values'); is($cfg->get->{bar}, 'baz', 'merge defaults sets new values'); $cfg->set_default(foo => 'new'); is($cfg->get->{foo}, 'new', 'merge defaults overwrites old values'); } # accept defaults as either hash or hashref(s) { my $cfg = Config::Onion->set_default({ a => 1 }); is($cfg->get->{a}, 1, 'set defaults with hashref'); $cfg->set_default({ b => 2 }, { c => 3 }, d => 4); is_deeply( $cfg->get, { a => 1, b => 2, c => 3, d => 4 }, 'set defaults with mixed hashrefs and hash' ); } done_testing; release-eol.t100644001750001750 133312654061546 17177 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/t BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::EOLTests 0.18 use Test::More 0.88; use Test::EOL; my @files = ( 'lib/Config/Onion.pm', 'lib/Config/Onion/Simple.pm', 't/00-load.t', 't/01-defaults.t', 't/02-load.t', 't/03-mixed.t', 't/04-simple.t', 't/conf/basic.yml', 't/conf/basic2.zzz', 't/conf/prefix.yml', 't/conf/withlocal.local.yml', 't/conf/withlocal.yml', 't/release-eol.t', 't/release-no-tabs.t' ); eol_unix_ok($_, { trailing_whitespace => 1 }) foreach @files; done_testing; conf000755001750001750 012654061546 15402 5ustar00dsherohdsheroh000000000000Config-Onion-1.006/tbasic.yml100644001750001750 4412654061546 17304 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/t/conf foo: bar joker: none xyzzy: plugh prefix.yml100644001750001750 11212654061546 17534 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/t/conf _prefix: some: levels: down: deep_key: 1 deep: subkey: 2 basic2.zzz100644001750001750 4212654061546 17420 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/t/conf foo: baz joker: one xyzzy: plug Config000755001750001750 012654061546 16165 5ustar00dsherohdsheroh000000000000Config-Onion-1.006/libOnion.pm100644001750001750 2436612654061546 20000 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/lib/Configpackage Config::Onion; use strict; use warnings; our $VERSION = 1.006; use Config::Any; use Hash::Merge::Simple 'merge'; use Moo; has cfg => ( is => 'lazy', clearer => '_reset_cfg' ); has prefix_key => ( is => 'rw' ); sub get { goto &cfg } has [qw( default main local override )] => ( is => 'rwp', default => sub { {} } ); sub set_default { my $self = shift; $self = $self->new unless ref $self; my $default = $self->default; $default = merge $default, shift while ref $_[0] eq 'HASH'; $default = merge $default, { @_ } if @_; $self->_set_default($default); $self->_reset_cfg; return $self; } sub set_override { my $self = shift; $self = $self->new unless ref $self; my $override = $self->override; $override = merge $override, shift while ref $_[0] eq 'HASH'; $override = merge $override, { @_ } if @_; $self->_set_override($override); $self->_reset_cfg; return $self; } sub load { my $self = shift; $self = $self->new unless ref $self; my $ca_opts = $self->_ca_opts; # user passed in a hash ref as the last argument. if (ref $_[$#_] eq "HASH") { # allow user to override the default use_ext => 1 delete $ca_opts->{use_ext} unless exists $_[$#_]{use_ext}; # merge in any other options passed in $ca_opts = merge $ca_opts, pop @_; # ensure that flatten_to_hash feature that Config::Any supports is turned off delete $ca_opts->{flatten_to_hash} if exists $ca_opts->{flatten_to_hash}; } my $main = Config::Any->load_stems({ stems => \@_ , %$ca_opts }); my $local = Config::Any->load_stems({ stems => [ map { "$_.local" } @_ ], %$ca_opts }); $self->_add_loaded($main, $local); return $self; } sub load_glob { my $self = shift; $self = $self->new unless ref $self; my $ca_opts = $self->_ca_opts; # user passed in a hash ref as the last argument. if (ref $_[$#_] eq "HASH") { # allow user to override the default use_ext => 1 delete $ca_opts->{use_ext} unless exists $_[$#_]{use_ext}; # merge in any other options passed in $ca_opts = merge $ca_opts, pop @_; # ensure that flatten_to_hash feature that Config::Any supports is turned off delete $ca_opts->{flatten_to_hash} if exists $ca_opts->{flatten_to_hash}; } # if use_ext is on, we need to query Config::Any to see what extensions are allowed my $ext_re = ''; if ($ca_opts->{use_ext}) { my @exts = Config::Any->extensions(); $ext_re = '\.' . (shift @exts) . '$'; $ext_re .= "|\\.$_\$" foreach @exts; } my (@main_files, @local_files); for my $globspec (@_) { for (glob $globspec) { next if $ca_opts->{use_ext} && !/$ext_re/; if (/\.local\./) { push @local_files, $_ } else { push @main_files, $_ } } } my $main = Config::Any->load_files({ files => \@main_files, %$ca_opts }); my $local = Config::Any->load_files({ files => \@local_files, %$ca_opts }); $self->_add_loaded($main, $local); return $self; } sub _add_loaded { my $self = shift; my ($main, $local) = @_; my @main; @main = map { values %$_ } @$main if @$main; my @local; @local = map { values %$_ } @$local if @$local; if ($self->prefix_key) { for my $cfg (@main, @local) { $self->_replace_prefix_key($cfg) if exists $cfg->{$self->prefix_key}; } } $self->_set_main( merge $self->main, @main); $self->_set_local(merge $self->local, @local); $self->_reset_cfg; } sub _build_cfg { my $self = shift; merge $self->default, $self->main, $self->local, $self->override; } sub _ca_opts { { use_ext => 1 } } sub _replace_prefix_key { my $self = shift; my $cfg = shift; my $top_key; my $root = $cfg->{$self->prefix_key}; while (1) { die "Config::Onion prefix key structure may not branch" if keys %$root > 1; $top_key ||= (keys %$root)[0]; my $child = (values %$root)[0]; unless ($child) { my $key = (keys %$root)[0]; $root = $root->{$key} = {}; last; } $root = $child; } my $new = $cfg->{$self->prefix_key}{$top_key}; delete $cfg->{$self->prefix_key}; for (keys %$cfg) { $root->{$_} = $cfg->{$_}; delete $cfg->{$_}; } $cfg->{$top_key} = $new; } 1; =pod =encoding UTF-8 =head1 NAME Config::Onion - Layered configuration, because configs are like ogres =head1 VERSION version 1.006 =head1 SYNOPSIS my $cfg = Config::Onion->new; my $cfg = Config::Onion->set_default(db => {name => 'foo', password => 'bar'}); my $cfg = Config::Onion->load('/etc/myapp', './myapp'); my $cfg = Config::Onion->load('/etc/myapp', './myapp', {use_ext => 1, filter => \&filter}); my $cfg = Config::Onion->load_glob('./plugins/*'); my $cfg = Config::Onion->load_glob('./plugins/*', {force_plugins => ['Config::Any::YAML']}); $cfg->set_default(font => 'Comic Sans'); $cfg->load('config'); $cfg->load_glob('conf.d/myapp*'); $cfg->set_override(font => 'Arial'); my $dbname = $cfg->get->{db}{name}; my $plain_hashref_conf = $cfg->get; my $dbpassword = $plain_hashref_conf->{db}{password}; =head1 DESCRIPTION All too often, configuration is not a universal or one-time thing, yet most configuration-handling treats it as such. Perhaps you can only load one config file. If you can load more than one, you often have to load all of them at the same time or each is stored completely independently, preventing one from being able to override another. Config::Onion changes that. Config::Onion stores all configuration settings in four layers: Defaults, Main, Local, and Override. Each layer can be added to as many times as you like. Within each layer, settings which are given multiple times will take the last specified value, while those which are not repeated will remain untouched. $cfg->set_default(name => 'Arthur Dent', location => 'Earth'); $cfg->set_default(location => 'Magrathea'); # In the Default layer, 'name' is still 'Arthur Dent', but 'location' has # been changed to 'Magrathea'. Regardless of the order in which they are set, values in Main will always override values in the Default layer, the Local layer always overrides both Default and Main, and the Override layer overrides all the others. The design intent for each layer is: =over 4 =item * Default Hardcoded default values to be used when no further configuration is present =item * Main Values loaded from standard configuration files shipped with the application =item * Local Values loaded from local configuration files which are kept separate to prevent them from being overwritten by application upgrades, etc. =item * Override Settings provided at run-time which take precendence over all configuration files, such as settings provided via command line switches =back =head1 METHODS =head2 new Returns a new, empty configuration object. =head2 load(@file_stems) =head2 load(@file\_stems, {...}) Loads files matching the given stems using C<< Config::Any->load_stems >> into the Main layer. Also concatenates ".local" to each stem and loads matching files into the Local layer. e.g., C<< $cfg->load('myapp') >> would load C into Main and C into Local. All filename extensions supported by C are recognized along with their corresponding formats. An optional hash ref final argument can be provided to override the default option C<< use_ext => 1 >> passed to C. All options supported by C are supported except flatten_to_hash. See C<< Config::Any->load_files >> documentation for available options. =head2 load_glob(@globs) =head2 load_glob(@globs, {...}) Uses the Perl C function to expand each parameter into a list of filenames and loads each file using C. Files whose names contain the string ".local." are loaded into the Local layer. All other files are loaded into the Main layer. An optional hash ref final argument can be provided to override the default option C<< use_ext => 1 >> passed to C. All options supported by C are supported except flatten_to_hash. See C<< Config::Any->load_files >> documentation for available options. =head2 set_default([\%settings,...,] %settings) =head2 set_override([\%settings,...,] %settings) Imports C<%settings> into the Default or Override layer. Accepts settings both as a plain hash and as hash references, but, if the two are mixed, all hash references must appear at the beginning of the parameter list, before any non-hashref settings. =head1 PROPERTIES =head2 cfg =head2 get Returns the complete configuration as a hash reference. =head2 default =head2 main =head2 local =head2 override These properties each return a single layer of the configuration. This is not likely to be useful other than for debugging. For most other purposes, you probably want to use C instead. =head2 prefix_key If set, enables the Prefix Structures functionality described below when using the C or C methods. The value of C specifies the name of the key under which the prefix structure may be found. Default value is C. =head1 Prefix Structures If you find that your configuration structure is becoming unwieldy due to deeply-nested structures, you can define a file-specific "prefix structure" and all other settings within that file will be loaded as children of the prefix structure. For example, if your main program uses $cfg = Config::Onion->new(prefix_key => '_prefix'); $cfg->load("myapp/config"); and C contains _prefix: foo: bar: baz: 1 then C<$cfg> will contain the configuration foo: bar: baz: 1 Note that the top-level C is removed. There are some limitations on the prefix structure, in order to keep it sane and deterministic. First, the prefix structure may only contain hashes. Second, each hash must contain exactly one key. Finally, the value associated with the final key must be left undefined. =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests at L =head1 AUTHOR Dave Sherohman =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2012 by Lund University Library. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut __END__ # ABSTRACT: Layered configuration, because configs are like ogres release-no-tabs.t100644001750001750 130112654061546 17756 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/t BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::NoTabsTests 0.15 use Test::More 0.88; use Test::NoTabs; my @files = ( 'lib/Config/Onion.pm', 'lib/Config/Onion/Simple.pm', 't/00-load.t', 't/01-defaults.t', 't/02-load.t', 't/03-mixed.t', 't/04-simple.t', 't/conf/basic.yml', 't/conf/basic2.zzz', 't/conf/prefix.yml', 't/conf/withlocal.local.yml', 't/conf/withlocal.yml', 't/release-eol.t', 't/release-no-tabs.t' ); notabs_ok($_) foreach @files; done_testing; withlocal.yml100644001750001750 3712654061546 20213 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/t/conf main: 1 local: 0 joker: wild withlocal.local.yml100644001750001750 1312654061546 21276 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/t/conf local: 1 Onion000755001750001750 012654061546 17247 5ustar00dsherohdsheroh000000000000Config-Onion-1.006/lib/ConfigSimple.pm100644001750001750 352112654061546 21177 0ustar00dsherohdsheroh000000000000Config-Onion-1.006/lib/Config/Onionpackage Config::Onion::Simple; use strict; use warnings; our $VERSION = 1.004; use Config::Onion; use base 'Exporter'; BEGIN { our @EXPORT = (); our @EXPORT_OK = qw( cfg cfg_obj ); our %EXPORT_TAGS = ( all => [ @EXPORT, @EXPORT_OK ], ); } my $cfg_obj; sub cfg { cfg_obj()->get } sub cfg_obj { $cfg_obj ||= Config::Onion->new } 1; =pod =encoding UTF-8 =head1 NAME Config::Onion::Simple - Simple interface to a Config::Onion singleton =head1 VERSION version 1.006 =head1 SYNOPSIS use Config::Onion::Simple qw( cfg cfg_obj ); cfg_obj->load('myapp'); my $setting = cfg->{setting}; =head1 DESCRIPTION It is often useful for a single master configuration to be shared across multiple modules in an application. Config::Onion::Simple provides an interface to do this without requiring any of those modules to know about each other. =head1 EXPORTABLE FUNCTIONS Config::Onion::Simple exports nothing by default. The following functions are exported only on request. =head2 cfg Returns a reference to the complete configuration hash managed by the Config::Onion singleton. This hash should be treated as read-only, as any changes will be lost if the configuration is altered using the underlying Config::Onion instance's methods. Calling C is equivalent to calling C<< cfg_obj->get >>. =head2 cfg_obj Returns a reference to the Config::Onion singleton. Use this object's methods to make any changes to the configuration. =head1 SEE ALSO L =head1 AUTHOR Dave Sherohman =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2012 by Lund University Library. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut __END__ # ABSTRACT: Simple interface to a Config::Onion singleton