Config-JSON-1.5202000755000765000024 012447114176 12467 5ustar00jtstaff000000000000README100644000765000024 57412447114176 13416 0ustar00jtstaff000000000000Config-JSON-1.5202 This archive contains the distribution Config-JSON, version 1.5202: A JSON based config file system. This software is copyright (c) 2014 by Plain Black Corporation. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v5.019. Changes100644000765000024 631412447114176 14047 0ustar00jtstaff000000000000Config-JSON-1.5202Revision history for Config-JSON 1.5202 2014-12-25 - Fix: Moo does not import Carp it would seem - Joel Berger 1.5201 2014-12-25 - Forgot to update the prereqs to move to Moo. 1.5200 2014-12-25 - Switched from Any::Moose to Moo at the behest of Joel Berger. 1.5100 2010-12-09 - Swtiched to Any::Moose so that it runs faster if used in a command line app. - Now requires Any::Moose. - No longer requires Moose. - Added test for possible interaction problem with Data::GUID reported by David Delikat. 1.5000 2009-12-19 - Converted Config::JSON to use Moose. - Removed requirements for version and Class::InsideOut. - Swiched to Dist::Zilla to build this package. - Removed authors.t since I never use them anyway. 1.4.0 Fixed resetting permissions of file on write Fixed another bug that could lead to erasing the config file. Add addToArrayAfter and addToArrayBefore methods to more easily insert items into lists. Added support for slashes in keys via escaping. 1.3.1 Mon Dec 8 14:00:00 2008 fix: #41525 Cleaning up temporary directory Throws a better error message when trying to access an element of an array using a multi-level directive. Writes config file directives in alphabetical order for easier human reading. Better handling of UTF-8 data in the config file. Better version numbers on prereqs. 1.3.0 Tue Oct 28 23:00:00 2008 Rewrote includes to be much cleaner. Fixed a bug where a full disk could cause Config::JSON to destroy the config file. 1.2.1 Sat Oct 18 16:58:19 EDT 2008 Fixed version number. 1.2.0 Fri Oct 17 10:14:02 EDT 2008 Patch from Christopher Nehren to enable configuration file includes as in Apache. 1.1.4 Fri Jan 23 16:20:00 2008 Patch from Doug Bell that uses better slurping action, and fixes a problem with killing config files on set() errors. Switched to using blib instead of relative lib path for tests. 1.1.3 Fri Jan 23 15:00:00 2008 fix: Copyright was mistakenly assigned to me rather than Plain Black in the Readme 1.1.2 Thu Jan 23 23:00:00 2008 fix: #27078: predictable filename in /tmp fix: #29122: Dependency declaration on Test::Deep missing fix: #32633: Config::JSON 1.1.1 doesn't work with JSON 2.x (thanks to Ernesto Hernández-Novich for patch) 1.1.1 Fri Aug 17 11:00:00 2007 Removed requirements for author related tests. Should make it easier to install for the average user. 1.1.0 Wed Aug 08 20:00:00 2007 Added direct access multi-level directive support. Now is an Inside Out object per Perl Best Practices. API CHANGE: getFilename() does what you expect now, and getFilePath() returns the path and filename of the config. Fixed qv/qw version number problem. 1.0.3 Thu Mar 05 09:29:00 2007 Sorting out more CPAN issues. No code changes. (Sorry, this is the first module I've released to CPAN, and there seems to be more that happens after upload than I know how to test from the command line.) 1.0.2 Thu Mar 01 11:33:00 2007 Sorting out more CPAN issues. No code changes. 1.0.1 Tue Feb 27 20:10:00 2007 Sorting out CPAN issues. No code changes. 1.0.0 Mon Feb 26 15:06:38 2007 Initial public release. Has been used in production environments for more than a year. LICENSE100644000765000024 4371412447114176 13606 0ustar00jtstaff000000000000Config-JSON-1.5202This software is copyright (c) 2014 by Plain Black Corporation. 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) 2014 by Plain Black Corporation. 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, Suite 500, Boston, MA 02110-1335 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) 2014 by Plain Black Corporation. 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 dist.ini100644000765000024 37612447114176 14202 0ustar00jtstaff000000000000Config-JSON-1.5202name = Config-JSON version = 1.5202 author = JT Smith license = Perl_5 copyright_holder = Plain Black Corporation [@Classic] [Prereqs] List::Util = 1.19 Test::More = 0.7 Test::Deep = 0.095 File::Temp = 0.18 Moo = 0 JSON = 2.16 META.yml100644000765000024 100712447114176 14017 0ustar00jtstaff000000000000Config-JSON-1.5202--- abstract: 'A JSON based config file system.' author: - 'JT Smith ' build_requires: {} configure_requires: ExtUtils::MakeMaker: '6.30' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.019, 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-JSON requires: File::Temp: '0.18' JSON: '2.16' List::Util: '1.19' Moo: '0' Test::Deep: '0.095' Test::More: '0.7' version: '1.5202' MANIFEST100644000765000024 44012447114176 13657 0ustar00jtstaff000000000000Config-JSON-1.5202# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.019. Changes Config-JSON.kpf LICENSE MANIFEST META.yml Makefile.PL README dist.ini lib/Config/JSON.pm t/00.load.t t/Config.t t/Duplicate.t t/Include.t t/Wildcard.t t/release-pod-coverage.t t/release-pod-syntax.t t000755000765000024 012447114176 12653 5ustar00jtstaff000000000000Config-JSON-1.5202Config.t100644000765000024 1230212447114176 14423 0ustar00jtstaff000000000000Config-JSON-1.5202/tuse Test::More tests => 36; use lib '../lib'; use Test::Deep; use Config::JSON; use File::Temp qw/ tempfile /; my ($fh, $filename) = tempfile(); close($fh); my $config = Config::JSON->create($filename); ok (defined $config, "create new config"); # set up test data if (open(my $file, ">", $filename)) { my $testData = <new($filename); isa_ok($config, "Config::JSON" ); # getFilePath and getFilename is( $config->getFilePath, $filename, "getFilePath()" ); my $justTheName = $filename; $justTheName =~ s{.*/(\w+)$}{$1}xmsg; is( $config->getFilename, $justTheName, "getFilename()" ); # get ok( $config->get("dsn") ne "", "get()" ); is( ref $config->get("stats"), "HASH", "get() hash" ); is( ref $config->get("colors"), "ARRAY", "get() array" ); is( $config->get("this/that/scalar"), "foo", "get() multilevel"); is( ref $config->get("this/that/hash"), "HASH", "get() hash multilevel" ); is( ref $config->get("this/that/array"), "ARRAY", "get() array multilevel" ); eval{$config->get("this/that/array/non-existant-element")}; ok($@, "Throw an error when trying to access an element of an array."); # set $config->set('privateArray', ['a', 'b', 'c']); cmp_bag($config->get('privateArray'), ['a', 'b', 'c'], 'set()'); $config->set('cars/ford', "mustang"); is($config->get('cars/ford'), "mustang", 'set() multilevel non-exisistant'); $config->set('cars/ford', [qw( mustang pinto maverick )]); cmp_bag($config->get('cars/ford'),[qw( mustang pinto maverick )], 'set() multilevel'); $config->addToHash('hash','cdn\\/','CDNRoot'); my $hash = $config->get('hash'); is $hash->{'cdn/'}, 'CDNRoot', 'allow for escaped slashes in keys'; my $reconfig = Config::JSON->new($filename); cmp_bag($config->get('cars/ford'),$reconfig->get('cars/ford'), 'set() multilevel after re-reading config file'); $config->set('Data::GUID', '9EDE9D96-D416-11DF-A7FC-B391564030AF'); is($config->get('Data::GUID'), '9EDE9D96-D416-11DF-A7FC-B391564030AF', 'report that Data::GUID does not work with CJ'); # delete $config->delete("dsn"); ok(!(defined $config->get("dsn")), "delete()"); $config->delete("stats/vitality"); ok(!(defined $config->get("stats/vitality")), "delete() multilevel"); ok(defined $config->get("stats"), "delete() multilevel - doesn't delete parent"); $config->delete('this/that/hash'); ok(defined $config->get('this/that/scalar'), "delete() multilevel - doesn't delete siblings"); # addToArray $config->addToArray("colors","TEST"); ok((grep /TEST/, @{$config->get("colors")}), "addToArray()"); $config->addToArray("cars/ford", "fairlane"); ok((grep /fairlane/, @{$config->get("cars/ford")}), "addToArray() multilevel"); # deleteFromArray $config->deleteFromArray("colors","TEST"); ok(!(grep /TEST/, @{$config->get("colors")}), "deleteFromArray()"); $config->deleteFromArray("cars/ford", "fairlane"); ok(!(grep /fairlane/, @{$config->get("cars/ford")}), "deleteFromArray() multilevel"); # addToArrayBefore $config->addToArrayBefore("colors","green",'orange'); is_deeply($config->get('colors'), [qw(red orange green blue)], "addToArrayBefore works"); $config->addToArrayBefore("colors","green",'orange'); is_deeply($config->get('colors'), [qw(red orange green blue)], "addToArrayBefore doesn't insert duplicate entries"); $config->addToArrayBefore('colors', 'purple', 'black'); is_deeply($config->get('colors'), [qw(black red orange green blue)], "addToArrayBefore with item that doesn't exist adds to beginning of array"); $config->set('colors', [qw(red green blue)]); # addToArrayAfter $config->addToArrayAfter('colors', 'green', 'orange'); is_deeply($config->get('colors'), [qw(red green orange blue)], "addToArrayAfter works"); $config->addToArrayAfter('colors', 'green', 'orange'); is_deeply($config->get('colors'), [qw(red green orange blue)], "addToArrayAfter doesn't insert duplicate entries"); $config->addToArrayAfter('colors', 'purple', 'black'); is_deeply($config->get('colors'), [qw(red green orange blue black)], "addToArrayAfter with item that doesn't exist adds to end of array"); $config->set('colors', [qw(red green blue)]); # addToHash $config->addToHash("stats","TEST","VALUE"); is($config->get("stats/TEST"), "VALUE", "addToHash()"); $config->addToHash("this/that/hash", "three", 3); is($config->get("this/that/hash/three"), 3, "addToHash() multilevel"); # deleteFromHash $config->deleteFromHash("stats","TEST"); $hash = $config->get("stats"); ok(!(exists $hash->{TEST}), "deleteFromHash()"); $config->deleteFromHash("this/that/hash", "three"); $hash = $config->get("this/that/hash"); ok(!(exists $hash->{three}), "deleteFromHash() multilevel"); 00.load.t100644000765000024 11312447114176 14310 0ustar00jtstaff000000000000Config-JSON-1.5202/tuse Test::More tests => 1; use lib '../lib'; use_ok( 'Config::JSON' ); Include.t100644000765000024 2410512447114176 14605 0ustar00jtstaff000000000000Config-JSON-1.5202/tuse strict; use warnings; use Test::More tests => 55; use lib '../lib'; use Test::Deep; use Config::JSON; use File::Temp qw/ tempfile /; use JSON; my ($mainHandle, $mainConfigFile) = tempfile(); my ($firstIncludeHandle, $firstIncludeFile) = tempfile(); my ($secondIncludeHandle, $secondIncludeFile) = tempfile(); close($mainHandle); close($firstIncludeHandle); close($secondIncludeHandle); my $mainConfig = Config::JSON->create($mainConfigFile); my $firstConfig = Config::JSON->create($firstIncludeFile); my $secondConfig = Config::JSON->create($secondIncludeFile); # set up main config file with include section if (open(my $file, ">", $mainConfigFile)) { my $testData = <', $firstIncludeFile ) { my $testData = <', $secondIncludeFile ) { my $testData = <new($mainConfigFile); isa_ok($mainConfig, "Config::JSON" ); # getFilePath and getFilename is( $mainConfig->getFilePath, $mainConfigFile, "getFilePath()" ); my $justTheName = $mainConfigFile; $justTheName =~ s{.*/(\w+)$}{$1}xmsg; is( $mainConfig->getFilename, $justTheName, "getFileName()" ); # getFilePaths and getFilenames #cmp_deeply( $mainConfig->getFilePaths, ($mainConfigFile, $firstIncludeFile, $secondIncludeFile), "getFilePaths()" ); #my @justTheNames = map { s{.*/(\w+)$}{$1}xmsg, $_ } ($mainConfigFile, $firstIncludeFile, $secondIncludeFile); #cmp_deeply( $mainConfig->getFileNames, @justTheNames, "getFileNames()" ); # get # first, make sure stuff in the main file works is( $mainConfig->get('dsn'), 'DBI:mysql:test', 'get() scalar' ); cmp_deeply( $mainConfig->get('colors'), ['red', 'green', 'blue'], 'get() arrayref' ); cmp_deeply( $mainConfig->get('stats'), {health => 32, vitality => 11}, 'get() hashref' ); # now make sure stuff in the included files work is( $mainConfig->get('firstFileName'), $firstIncludeFile, 'get() first include scalar' ); is( $mainConfig->get('secondFileName'), $secondIncludeFile, 'get() second include scalar' ); cmp_deeply( $mainConfig->get('metasyntacticVariables'), ['foo', 'bar', 'baz'], 'get() first include arrayref' ); cmp_deeply( $mainConfig->get('programmingLanguages'), ['perl', 'python', 'intercal'], 'get() second include arrayref' ); cmp_deeply( $mainConfig->get('myFavoriteColors'), {mostFavorite => 'black', leastFavorite => 'white'}, 'get() first include hashref' ); cmp_deeply( $mainConfig->get('OSVendors'), {'OS X' => 'Apple', 'Windows' => 'Microsoft'}, 'get() first include hashref' ); # set # testing set is different for includes because we have to make sure that the # key goes to the right file. thus we need to check the files after writing to # ensure that the correct key was written to the correct file. $mainConfig->set('dsn', 'DBI:mysql:test2'); is( getKey($mainConfigFile, 'dsn'), 'DBI:mysql:test2', 'set() works for existing scalar in main file'); is( getKey($firstIncludeFile, 'dsn'), undef, 'set() does not write to the wrong file for an existing scalar'); is( getKey($secondIncludeFile, 'dsn'), undef, 'set() does not write to the wrong file for an existing scalar'); $mainConfig->set('foobar', 'the foobar value'); is( getKey($mainConfigFile, 'foobar'), 'the foobar value', 'set() works for new value in main file'); is( getKey($firstIncludeFile, 'foobar'), undef, 'set() does not write to the wrong file for a new scalar'); is( getKey($secondIncludeFile, 'foobar'), undef, 'set() does not write to the wrong file for a new scalar'); $mainConfig->set('colors', ['blue', 'green', 'red']); cmp_deeply( getKey($mainConfigFile, 'colors'), ['blue', 'green', 'red'], 'set() works for existing array in main file' ); is( getKey($firstIncludeFile, 'colors'), undef, 'set() does not write to the wrong file for an existing array'); is( getKey($secondIncludeFile, 'colors'), undef, 'set() does not write to the wrong file for an existing array'); $mainConfig->set('numbers', ['one', 'two', 'three']); cmp_deeply( getKey($mainConfigFile, 'numbers'), ['one', 'two', 'three'], 'set() works for existing array in main file' ); is( getKey($firstIncludeFile, 'numbers'), undef, 'set() does not write to the wrong file for a new array'); is( getKey($secondIncludeFile, 'numbers'), undef, 'set() does not write to the wrong file for a new array'); $mainConfig->set('stats', { height => 65, weight => 'none of your business' }); cmp_deeply( getKey($mainConfigFile, 'stats'), { height => 65, weight => 'none of your business'}, 'set() works for existing hash in main file' ); is( getKey($firstIncludeFile, 'stats'), undef, 'set() does not write to the wrong file for an existing hash'); is( getKey($secondIncludeFile, 'stats'), undef, 'set() does not write to the wrong file for an existing hash'); $mainConfig->set('developerNames', { 'JT' => 'Smith', 'Chris' => 'Nehren' } ); cmp_deeply( getKey($mainConfigFile, 'developerNames'), { 'JT' => 'Smith', 'Chris' => 'Nehren' }, 'set() works for a new hash in main file' ); is( getKey($firstIncludeFile, 'developerNames'), undef, 'set() does not write to the wrong file for a new hash'); is( getKey($secondIncludeFile, 'developerNames'), undef, 'set() does not write to the wrong file for a new hash'); $mainConfig->set('firstFileName', "$firstIncludeFile first"); is( getKey($firstIncludeFile, 'firstFileName'), "$firstIncludeFile first", 'set() writes a scalar to the correct include file'); is( getKey($mainConfigFile, 'firstFileName'), undef, 'set() does not write to the wrong file for a scalar in an include file'); is( getKey($secondIncludeFile, 'firstFileName'), undef, 'set() does not write to the wrong file for a scalar in an include file'); $mainConfig->set('metasyntacticVariables', ['baz', 'bar', 'foo']); cmp_deeply( getKey($firstIncludeFile, 'metasyntacticVariables'), ['baz', 'bar', 'foo'], 'set() works for an existing array in an include file' ); is( getKey($mainConfigFile, 'metasyntacticVariables'), undef, 'set() does not write to the wrong file for an existing array in an include file'); is( getKey($secondIncludeFile, 'metasyntacticVariables'), undef, 'set() does not write to the wrong file for an existing array in an include file'); $mainConfig->set('myFavoriteColors', { 'black' => 'mostFavorite', 'white' => 'leastFavorite' } ); cmp_deeply( getKey($firstIncludeFile, 'myFavoriteColors'), { 'black' => 'mostFavorite', 'white' => 'leastFavorite' }, 'set() works for an existing hash in an include file' ); is( getKey($mainConfigFile, 'myFavoriteColors'), undef, 'set() does not write to the wrong file for an existing hash in an include file'); is( getKey($secondIncludeFile, 'myFavoriteColors'), undef, 'set() does not write to the wrong file for an existing hash in an include file'); # delete $mainConfig->delete("dsn"); ok(!(defined getKey($mainConfigFile, "dsn")), "delete() writes changes for scalar in main file"); ok(!(defined $mainConfig->get("dsn")), "delete() works for scalar in main file"); $mainConfig->delete("stats/vitality"); ok(!(defined getKey($mainConfigFile, "stats/vitality")), "delete() multilevel works for main file"); ok(!(defined $mainConfig->get("stats/vitality")), "delete() multilevel works for main file"); ok(defined getKey($mainConfigFile, "stats"), "delete() multilevel - doesn't delete parent in main file"); ok(defined $mainConfig->get("stats"), "delete() multilevel - doesn't delete parent in main file"); $mainConfig->delete('firstFileName'); ok(!(defined getKey($firstIncludeFile, "firstFileName")), "delete() works for scalar in first include file"); ok(!(defined $mainConfig->get("dsn")), "delete() works for scalar in main file"); $mainConfig->delete('metasyntacticVariables'); ok(!(defined getKey($firstIncludeFile, "metasyntacticVariables")), "delete() works for multilevel in first include file"); ok(!(defined $mainConfig->get("metasyntacticVariables")), "delete() works for multilevel in main file"); $mainConfig->delete('cars/ford'); ok(!(defined getKey($firstIncludeFile, "cars/ford")), "delete() works for multilevel in first include file"); ok(!(defined $mainConfig->get("cars/ford")), "delete() works for multilevel in main file"); ok(defined getKey($firstIncludeFile, 'cars'), "delete() on multilevel doesn't delete parent in include file"); #---------------------------------------------------- # get a value from a config file that has includes. Can't use Config::JSON # because the main file includes the other files, which means the value we're # looking for will be found regardless. that's what we're testing, so we have # to use raw JSON. sub getKey { my $configFile = shift; my $key = shift; open my $fh, '<', $configFile or die "open($configFile): $!"; my $raw = do { local $/; <$fh>; }; close $fh; my $data = JSON->new->relaxed(1)->decode($raw); return $data->{$key}; } Makefile.PL100644000765000024 225112447114176 14522 0ustar00jtstaff000000000000Config-JSON-1.5202 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.019. use strict; use warnings; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "A JSON based config file system.", "AUTHOR" => "JT Smith ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "Config-JSON", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "Config::JSON", "PREREQ_PM" => { "File::Temp" => "0.18", "JSON" => "2.16", "List::Util" => "1.19", "Moo" => 0, "Test::Deep" => "0.095", "Test::More" => "0.7" }, "VERSION" => "1.5202", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "File::Temp" => "0.18", "JSON" => "2.16", "List::Util" => "1.19", "Moo" => 0, "Test::Deep" => "0.095", "Test::More" => "0.7" ); 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); Wildcard.t100644000765000024 661312447114176 14737 0ustar00jtstaff000000000000Config-JSON-1.5202/tuse strict; use warnings; use Test::More tests => 12; use lib '../lib'; use Test::Deep; use Config::JSON; use File::Temp qw/ tempfile /; use JSON; my ($mainHandle, $mainConfigFile) = tempfile(); my ($firstIncludeHandle, $firstIncludeFile) = tempfile('XXXXX', SUFFIX => '.include.conf', UNLINK => 1); my ($secondIncludeHandle, $secondIncludeFile) = tempfile('XXXXX', SUFFIX => '.include.conf', UNLINK => 1); close($mainHandle); close($firstIncludeHandle); close($secondIncludeHandle); my $mainConfig = Config::JSON->create($mainConfigFile); my $firstConfig = Config::JSON->create($firstIncludeFile); my $secondConfig = Config::JSON->create($secondIncludeFile); # set up main config file with include section if (open(my $file, ">", $mainConfigFile)) { my $testData = <', $firstIncludeFile ) { my $testData = <', $secondIncludeFile ) { my $testData = <new($mainConfigFile); # get # first, make sure stuff in the main file works is( $mainConfig->get('dsn'), 'DBI:mysql:test', 'get() scalar' ); cmp_deeply( $mainConfig->get('colors'), ['red', 'green', 'blue'], 'get() arrayref' ); cmp_deeply( $mainConfig->get('stats'), {health => 32, vitality => 11}, 'get() hashref' ); # now make sure stuff in the included files work is( $mainConfig->get('firstFileName'), $firstIncludeFile, 'get() first include scalar' ); is( $mainConfig->get('secondFileName'), $secondIncludeFile, 'get() second include scalar' ); cmp_deeply( $mainConfig->get('metasyntacticVariables'), ['foo', 'bar', 'baz'], 'get() first include arrayref' ); cmp_deeply( $mainConfig->get('programmingLanguages'), ['perl', 'python', 'intercal'], 'get() second include arrayref' ); cmp_deeply( $mainConfig->get('myFavoriteColors'), {mostFavorite => 'black', leastFavorite => 'white'}, 'get() first include hashref' ); cmp_deeply( $mainConfig->get('OSVendors'), {'OS X' => 'Apple', 'Windows' => 'Microsoft'}, 'get() first include hashref' ); Duplicate.t100644000765000024 1250312447114176 15133 0ustar00jtstaff000000000000Config-JSON-1.5202/tuse strict; use warnings; use Test::More tests => 22; use lib '../lib'; use Test::Deep; use Config::JSON; use File::Temp qw/ tempfile /; use JSON; my ($mainHandle, $mainConfigFile) = tempfile(); my ($firstIncludeHandle, $firstIncludeFile) = tempfile(); my ($secondIncludeHandle, $secondIncludeFile) = tempfile(); close($mainHandle); close($firstIncludeHandle); close($secondIncludeHandle); # set up main config file with include section if (open(my $file, ">", $mainConfigFile)) { my $testData = <', $firstIncludeFile ) { my $testData = <', $secondIncludeFile ) { my $testData = <new($mainConfigFile); $mainConfig->delete("dsn"); ok(!(defined getKey($mainConfigFile, "dsn")), "delete() writes changes for scalar in main file"); ok(!(defined getKey($firstIncludeFile, "dsn")), "delete() writes changes for scalar in first include file"); ok(!(defined getKey($secondIncludeFile, "dsn")), "delete() writes changes for scalar in second include file"); ok(!(defined $mainConfig->get("dsn")), "delete() works for scalar in main file"); $mainConfig->delete("stats/vitality"); ok(!(defined getKey($mainConfigFile, "stats/vitality")), "delete() multilevel works for main file"); ok(!(defined getKey($firstIncludeFile, "stats/vitality")), "delete() multilevel works for first include file"); ok(!(defined getKey($secondIncludeFile, "stats/vitality")), "delete() multilevel works for second include file"); ok(!(defined $mainConfig->get("stats/vitality")), "delete() multilevel works for main file"); ok(defined getKey($mainConfigFile, "stats"), "delete() multilevel - doesn't delete parent in main file"); ok(defined getKey($firstIncludeFile, "stats"), "delete() multilevel - doesn't delete parent in first include file"); ok(defined getKey($secondIncludeFile, "stats"), "delete() multilevel - doesn't delete parent in second include file"); ok(defined $mainConfig->get("stats"), "delete() multilevel - doesn't delete parent in main file"); $mainConfig->delete('this/that/hash'); ok(!(defined getKey($firstIncludeFile, "this/that/hash")), "delete() works for multilevel in first include file"); ok(!(defined getKey($secondIncludeFile, "this/that/hash")), "delete() works for multilevel in second include file"); ok(!(defined getKey($mainConfigFile, "this/that/hash")), "delete() works for multilevel in main file"); ok(!(defined $mainConfig->get("this/that/hash")), "delete() works for multilevel in main file"); ok(defined getKey($firstIncludeFile, 'this/that'), "delete() on multilevel doesn't delete parent in first include file"); ok(defined getKey($secondIncludeFile, 'this/that'), "delete() on multilevel doesn't delete parent in second include file"); ok(defined getKey($mainConfigFile, 'this/that'), "delete() on multilevel doesn't delete parent in main file"); #---------------------------------------------------- # get a value from a config file that has includes. Can't use Config::JSON # because the main file includes the other files, which means the value we're # looking for will be found regardless. that's what we're testing, so we have # to use raw JSON. sub getKey { my $configFile = shift; my $key = shift; my @parts = split '/', $key; my $lastPart = pop @parts; open my $fh, '<', $configFile or die "open($configFile): $!"; my $raw = do { local $/; <$fh>; }; close $fh; my $data = JSON->new->relaxed(1)->decode($raw); my $directive = $data; for my $part (@parts) { $directive = $directive->{$part}; } return $directive->{$lastPart}; } Config-JSON.kpf100644000765000024 46012447114176 15206 0ustar00jtstaff000000000000Config-JSON-1.5202 1 Config000755000765000024 012447114176 14363 5ustar00jtstaff000000000000Config-JSON-1.5202/libJSON.pm100644000765000024 4041712447114176 15660 0ustar00jtstaff000000000000Config-JSON-1.5202/lib/Configpackage Config::JSON; $Config::JSON::VERSION = '1.5202'; use strict; use Moo; use Carp; use File::Spec; use JSON 2.0; use List::Util; use constant FILE_HEADER => "# config-file-type: JSON 1\n"; #------------------------------------------------------------------- has config => ( is => 'rw', default => sub {{}}, ); #------------------------------------------------------------------- sub getFilePath { my $self = shift; return $self->pathToFile; } #------------------------------------------------------------------- has pathToFile => ( is => 'ro', required => 1, trigger => sub { my ($self, $pathToFile, $old) = @_; if (open(my $FILE, "<", $pathToFile)) { # slurp local $/ = undef; my $json = <$FILE>; close($FILE); my $conf = eval { JSON->new->relaxed->utf8->decode($json); }; confess "Couldn't parse JSON in config file '$pathToFile'\n" unless ref $conf; $self->config($conf); # process includes my @includes = map { glob $_ } @{ $self->get('includes') || [] }; my @loadedIncludes; foreach my $include (@includes) { push @loadedIncludes, __PACKAGE__->new(pathToFile=>$include, isInclude=>1); } $self->includes(\@loadedIncludes); } else { confess "Cannot read config file: ".$pathToFile; } }, ); #------------------------------------------------------------------- has isInclude => ( is => 'ro', default => sub {0}, ); #------------------------------------------------------------------- has includes => ( is => 'rw', default => sub {[]}, ); #------------------------------------------------------------------- sub getIncludes { my $self = shift; return $self->includes; } #------------------------------------------------------------------- around BUILDARGS => sub { my $orig = shift; my $class = shift; if ( @_ == 1 && ! ref $_[0] ) { return $class->$orig(pathToFile => $_[0]); } else { return $class->$orig(@_); } }; #------------------------------------------------------------------- sub addToArray { my ($self, $property, $value) = @_; my $array = $self->get($property); unless (defined List::Util::first { $value eq $_ } @{$array}) { # check if it already exists # add it push(@{$array}, $value); $self->set($property, $array); } } #------------------------------------------------------------------- sub addToArrayAfter { my ($self, $property, $afterValue, $value) = @_; my $array = $self->get($property); unless (defined List::Util::first { $value eq $_ } @{ $array }) { # check if it already exists my $idx = 0; for (; $idx < $#{ $array }; $idx++) { if ($array->[$idx] eq $afterValue) { last; } } splice @{ $array }, $idx + 1, 0, $value; $self->set($property, $array); } } #------------------------------------------------------------------- sub addToArrayBefore { my ($self, $property, $beforeValue, $value) = @_; my $array = $self->get($property); unless (defined List::Util::first { $value eq $_ } @{ $array }) { # check if it already exists my $idx = $#{ $array }; for (; $idx > 0; $idx--) { if ($array->[$idx] eq $beforeValue) { last; } } splice @{ $array }, $idx , 0, $value; $self->set($property, $array); } } #------------------------------------------------------------------- sub addToHash { my ($self, $property, $key, $value) = @_; $self->set($property."/".$key, $value); } #------------------------------------------------------------------- sub create { my ($class, $filename) = @_; if (open(my $FILE,">",$filename)) { print $FILE FILE_HEADER."\n{ }\n"; close($FILE); } else { warn "Can't write to config file ".$filename; } return $class->new(pathToFile=>$filename); } #------------------------------------------------------------------- sub delete { my ($self, $param) = @_; # inform the includes foreach my $include (@{$self->includes}) { $include->delete($param); } # find the directive my $directive = $self->config; my @parts = $self->splitKeyParts($param); my $lastPart = pop @parts; foreach my $part (@parts) { $directive = $directive->{$part}; } # only delete it if it exists if (exists $directive->{$lastPart}) { delete $directive->{$lastPart}; $self->write; } } #------------------------------------------------------------------- sub deleteFromArray { my ($self, $property, $value) = @_; my $array = $self->get($property); for (my $i = 0; $i < scalar(@{$array}); $i++) { if ($array->[$i] eq $value) { splice(@{$array}, $i, 1); last; } } $self->set($property, $array); } #------------------------------------------------------------------- sub deleteFromHash { my ($self, $property, $key) = @_; $self->delete($property."/".$key); } #------------------------------------------------------------------- sub get { my ($self, $property) = @_; # they want a specific property if (defined $property) { # look in this config my $value = $self->config; foreach my $part ($self->splitKeyParts($property)) { $value = eval{$value->{$part}}; if ($@) { confess "Can't access $property. $@"; } } return $value if (defined $value); # look through includes foreach my $include (@{$self->includes}) { my $value = $include->get($property); return $value if (defined $value); } # didn't find it return undef; } # they want the whole properties list my %whole = (); foreach my $include (@{$self->includes}) { %whole = (%whole, %{$include->get}); } %whole = (%whole, %{$self->config}); return \%whole; } #------------------------------------------------------------------- sub getFilename { my $self = shift; my @path = split "/", $self->pathToFile; return pop @path; } #------------------------------------------------------------------- sub set { my ($self, $property, $value) = @_; # see if the directive exists in this config my $directive = $self->config; my @parts = $self->splitKeyParts($property); my $numParts = scalar @parts; for (my $i=0; $i < $numParts; $i++) { my $part = $parts[$i]; if (exists $directive->{$part}) { # exists so we continue if ($i == $numParts - 1) { # we're on the last part $directive->{$part} = $value; $self->write; return 1; } else { $directive = $directive->{$part}; } } else { # doesn't exist so we quit last; } } # see if any of the includes have this directive foreach my $include (@{$self->includes}) { my $found = $include->set($property, $value); return 1 if ($found); } # let's create the directive new in this config if it's not an include unless ($self->isInclude) { $directive = $self->config; my $lastPart = pop @parts; foreach my $part (@parts) { unless (exists $directive->{$part}) { $directive->{$part} = {}; } $directive = $directive->{$part}; } $directive->{$lastPart} = $value; $self->write; return 1; } # didn't find a place to write it return 0; } #------------------------------------------------------------------- sub splitKeyParts { my ($self, $key) = @_; my @parts = split /(?pathToFile; # convert data to json my $json = JSON->new->pretty->utf8->canonical->encode($self->config); my $to_write = FILE_HEADER . "\n" . $json; my $needed_bytes = length $to_write; # open as read/write open my $fh, '+<:raw', $realfile or confess "Unable to open $realfile for write: $!"; my $current_bytes = (stat $fh)[7]; # shrink file if needed if ($needed_bytes < $current_bytes) { truncate $fh, $needed_bytes; } # make sure we can expand the file to the needed size before we overwrite it elsif ($needed_bytes > $current_bytes) { my $padding = q{ } x ($needed_bytes - $current_bytes); sysseek $fh, 0, 2; if (! syswrite $fh, $padding) { sysseek $fh, 0, 0; truncate $fh, $current_bytes; close $fh; confess "Unable to expand $realfile: $!"; } sysseek $fh, 0, 0; seek $fh, 0, 0; } print {$fh} $to_write; close $fh; return 1; } =head1 NAME Config::JSON - A JSON based config file system. =head1 VERSION version 1.5202 =head1 SYNOPSIS use Config::JSON; my $config = Config::JSON->create($pathToFile); my $config = Config::JSON->new($pathToFile); my $config = Config::JSON->new(pathToFile=>$pathToFile); my $element = $config->get($directive); $config->set($directive,$value); $config->delete($directive); $config->deleteFromHash($directive, $key); $config->deleteFromArray($directive, $value); $config->addToHash($directive, $key, $value); $config->addToArray($directive, $value); my $path = $config->pathToFile; my $filename = $config->getFilename; =head2 Example Config File # config-file-type: JSON 1 { "dsn" : "DBI:mysql:test", "user" : "tester", "password" : "xxxxxx", # some colors to choose from "colors" : [ "red", "green", "blue" ], # some statistics "stats" : { "health" : 32, "vitality" : 11 }, # including another file "includes" : ["macros.conf"] } =head1 DESCRIPTION This package parses the config files written in JSON. It also does some non-JSON stuff, like allowing for comments in the files. If you want to see it in action, it is used as the config file system in WebGUI L. =head2 Why? Why build yet another config file system? Well there are a number of reasons: We used to use other config file parsers, but we kept running into limitations. We already use JSON in our app, so using JSON to store config files means using less memory because we already have the JSON parser in memory. In addition, with JSON we can have any number of hierarchcal data structures represented in the config file, whereas most config files will give you only one level of hierarchy, if any at all. JSON parses faster than XML and YAML. JSON is easier to read and edit than XML. Many other config file systems allow you to read a config file, but they don't provide any mechanism or utilities to write back to it. JSON is taint safe. JSON is easily parsed by languages other than Perl when we need to do that. =head2 Multi-level Directives You may of course access a directive called "foo", but since the config is basically a hash you can traverse multiple elements of the hash when specifying a directive name by simply delimiting each level with a slash, like "foo/bar". For example you may: my $vitality = $config->get("stats/vitality"); $config->set("stats/vitality", 15); You may do this wherever you specify a directive name. =head2 Comments You can put comments in the config file as long as # is the first non-space character on the line. However, if you use this API to write to the config file, your comments will be eliminated. =head2 Includes There is a special directive called "includes", which is an array of include files that may be brought in to the config. Even the files you include can have an "includes" directive, so you can do hierarchical includes. Any directive in the main file will take precedence over the directives in the includes. Likewise the files listed first in the "includes" directive will have precedence over the files that come after it. When writing to the files, the same precedence is followed. If you're setting a new directive that doesn't currently exist, it will only be written to the main file. If a directive is deleted, it will be deleted from all files, including the includes. =head1 INTERFACE =head2 addToArray ( directive, value ) Adds a value to an array directive in the config file. =head3 directive The name of the array. =head3 value The value to add. =head2 addToArrayBefore ( directive, insertBefore, value ) Inserts a value into an array immediately before another item. If that item can't be found, inserts at the beginning on the array. =head3 directive The name of the array. =head3 insertBefore The value to search for and base the positioning on. =head3 value The value to insert. =head2 addToArrayAfter ( directive, insertAfter, value ) Inserts a value into an array immediately after another item. If that item can't be found, inserts at the end on the array. =head3 directive The name of the array. =head3 insertAfter The value to search for and base the positioning on. =head3 value The value to insert. =head2 addToHash ( directive, key, value ) Adds a value to a hash directive in the config file. B This is really the same as $config->set("directive/key", $value); =head3 directive The name of the hash. =head3 key The key to add. =head3 value The value to add. =head2 create ( pathToFile ) Constructor. Creates a new empty config file. =head3 pathToFile The path and filename of the file to create. =head2 delete ( directive ) Deletes a key from the config file. =head3 directive The name of the directive to delete. =head2 deleteFromArray ( directive, value ) Deletes a value from an array directive in the config file. =head3 directive The name of the array. =head3 value The value to delete. =head2 deleteFromHash ( directive, key ) Delete a key from a hash directive in the config file. B This is really just the same as doing $config->delete("directive/key"); =head3 directive The name of the hash. =head3 key The key to delete. =head2 get ( directive ) Returns the value of a particular directive from the config file. =head3 directive The name of the directive to return. =head2 getFilename ( ) Returns the filename for this config. =head2 pathToFile ( ) Returns the filename and path for this config. May also be called as C for backward campatibility sake. =head2 includes ( ) Returns an array reference of Config::JSON objects that are files included by this config. May also be called as C for backward compatibility sake. =head2 new ( pathToFile ) Constructor. Builds an object around a config file. =head3 pathToFile A string representing a path such as "/etc/my-cool-config.conf". =head2 set ( directive, value ) Creates a new or updates an existing directive in the config file. =head3 directive A directive name. =head3 value The value to set the paraemter to. Can be a scalar, hash reference, or array reference. =head2 splitKeyParts ( key ) Returns an array of key parts. =head3 key A key string. Could be 'foo' (simple key), 'foo/bar' (a multilevel key referring to the bar key as a child of foo), or 'foo\/bar' (a simple key that contains a slash in the key). Don't forget to double escape in your perl code if you have a slash in your key parts like this: $config->get('foo\\/bar'); =cut =head2 write ( ) Writes the file to the filesystem. Normally you'd never need to call this as it's called automatically by the other methods when a change occurs. =head1 DIAGNOSTICS =over =item C<< Couldn't parse JSON in config file >> This means that the config file does not appear to be formatted properly as a JSON file. Common mistakes are missing commas or trailing commas on the end of a list. =item C<< Cannot read config file >> We couldn't read the config file. This usually means that the path specified in the constructor is incorrect. =item C<< Can't write to config file >> We couldn't write to the config file. This usually means that the file system is full, or the that the file is write protected. =back =head1 PREREQS L L L L L =head1 SUPPORT =over =item Repository L =item Bug Reports L =back =head1 AUTHOR JT Smith =head1 LEGAL Config::JSON is Copyright 2009 Plain Black Corporation (L) and is licensed under the same terms as Perl itself. =cut 1; release-pod-syntax.t100644000765000024 45612447114176 16711 0ustar00jtstaff000000000000Config-JSON-1.5202/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok(); release-pod-coverage.t100644000765000024 57212447114176 17155 0ustar00jtstaff000000000000Config-JSON-1.5202/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' });