Config-Std-0.901/0000755000175000017500000000000012213730443011631 5ustar wdrwdrConfig-Std-0.901/Build.PL0000644000175000017500000000135211551174261013132 0ustar wdrwdruse strict; use warnings; use Module::Build '0.19'; my $builder = Module::Build->new( module_name => 'Config::Std', license => 'perl', create_license => 'perl', dist_author => [ 'Damian Conway ', 'Bill Ricker ', 'Tom Metro '], dist_version_from => 'lib/Config/Std.pm', requires => { 'Test::More' => 0, 'Class::Std' => 0, 'version' => 0, 'perl' => '5.7.3', }, recommends => { 'Test::Pod' => 0, 'Test::Distribution' => 0, }, add_to_cleanup => [ 'Config-Std-*' ], create_makefile_pl => 'traditional', # Module::Build::Compat ); $builder->create_build_script(); Config-Std-0.901/README0000644000175000017500000000166312213724743012525 0ustar wdrwdrConfig::Std version 0.901 This module implements yet another damn configuration-file system. The configuration language is deliberately simple and limited, and the module works hard to preserve as much information (section order, comments, etc.) as possible when a configuration file is updated. See Chapter 19 of "Perl Best Practices" (O'Reilly, 2005) for the rationale for this approach. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install Alternatively, to install with Module::Build, you can use the following commands: perl Build.PL ./Build ./Build test ./Build install DEPENDENCIES None. COPYRIGHT AND LICENCE Copyright (C) 2005, Damian Conway; Copyright (C) 2011,2013 William Ricker + Tom Metro, maintainers for Boston.PM This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Config-Std-0.901/MANIFEST0000644000175000017500000000053012213730444012761 0ustar wdrwdrBuild.PL Changes MANIFEST META.yml # Will be created by "make dist" Makefile.PL README lib/Config/Std.pm t/00.load.t t/00write.t t/01read.t t/02rewrite.t t/pod-coverage.t t/pod.t t/01read_renamed.t t/02rewrite_eq.t t/03autoviv.t t/comments.t t/undef.t LICENSE META.json Module JSON meta-data (added by MakeMaker) Config-Std-0.901/Changes0000644000175000017500000000371212213725274013135 0ustar wdrwdrRevision history for Config-Std 0.901 Tue Sep 10, 2013 - Copyright, added co-maintainers * RT 85956 - 5.18 Hash ordering randomization hit the tests. Thanks to Gregor on Debian for report and Zefram for patch. 0.900 Tue Apr 12 20:41:04 2011 - Change of Maintainers. - Reordered Changes to latest first. - Module::Build::Compat creating Makefile.PL traditional - LICENSE file created (in Build.PL) - 21184: require v5.7.3 (Thanks Leo) - Doc patches per RT queue - 18642: Dynamic loading of Config::Std breaks the interface, doc workaround. (thanks Schwern & Uri) - 16488: Philosophy is 'as simple as possible'. (thanks Steven) - 21604: read from string_ref (thanks Todd) 0.007 Wed Nov 18 13:21:08 2009 - Fixed major bug in gap algorithm for new keys (thanks Jojo!) 0.0.5 Tue Sep 22 15:17:49 2009 - Made spacing between key/values more intelligent - Added def_sep option to control that intelligence (thanks David) - Added support for standard INI-style comments: ; like this (thanks William and FSD) - Fixed bug in section heading parsing (thanks Kirk) 0.0.4 Mon Feb 20 08:03:45 2006 - Removed spurious dependency on Smart::Comments 0.0.3 Fri Feb 17 15:50:09 2006 - Fixed bug in writing back from a hash-ref - Fixed spelling bug in append_comments (thanks Torsten!) - Added {def_sep => '='} option (thanks Nick) - Clarified use of comments with config vars - Removed unused "" sections from read_config hash (thanks carcassonne) - Added logic to decide whether new sections have spaces after them - Changed write_config() behaviour for undefined hash entries: they now throw an exception (thanks David) - Added mechanism to allow read_config() and write_config() to be renamed when exported (thanks David) 0.0.2 Wed May 25 22:30:51 2005 - First public release 0.0.1 Wed Feb 16 04:04:39 2005 - Initial release. Config-Std-0.901/META.json0000664000175000017500000000157312213730443013262 0ustar wdrwdr{ "abstract" : "unknown", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.120921", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Config-Std", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Class::Std" : "0", "Test::More" : "0", "version" : "0" } } }, "release_status" : "stable", "version" : "0.901" } Config-Std-0.901/Makefile.PL0000644000175000017500000000100011551217523013575 0ustar wdrwdr# Note: this file was auto-generated by Module::Build::Compat version 0.3603 require 5.007003; use ExtUtils::MakeMaker; WriteMakefile ( 'PL_FILES' => {}, 'INSTALLDIRS' => 'site', 'NAME' => 'Config::Std', 'EXE_FILES' => [], 'VERSION_FROM' => 'lib/Config/Std.pm', 'PREREQ_PM' => { 'Test::More' => 0, 'version' => 0, 'Class::Std' => 0 } ) ; Config-Std-0.901/LICENSE0000644000175000017500000004410511551217523012645 0ustar wdrwdrThis software is copyright (c) 2011 by Damian Conway & Bill Ricker & Tom Metro . 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) 2011 by Damian Conway & Bill Ricker & Tom Metro . 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. 59 Temple Place, Suite 330, Boston, MA 02111-1307, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 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) 2011 by Damian Conway & Bill Ricker & Tom Metro . 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 Config-Std-0.901/t/0000755000175000017500000000000012213730443012074 5ustar wdrwdrConfig-Std-0.901/t/pod-coverage.t0000644000175000017500000000025410407102716014634 0ustar wdrwdr#!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); Config-Std-0.901/t/pod.t0000644000175000017500000000021411461275777013062 0ustar wdrwdr#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); Config-Std-0.901/t/comments.t0000644000175000017500000000116511064100771014107 0ustar wdrwdruse Config::Std; use Test::More 'no_plan'; my $data = q{ # A comment foo: bar # Not a trailing comment. This is data for the 'foo' config var ; Another comment baz: qux ; Not a trailing comment. This is data for the 'qux' config var }; # Read in the config file from Example 19-3... read_config \$data => my %config; write_config %config, \$results; is $results, $data => "Comments preserved on simple round-trip"; $config{""}{foo} = 'baz'; $config{""}{baz} = 'foo'; $data =~ s/bar.*/baz/; $data =~ s/qux.*/foo/; write_config %config, \$results; is $results, $data => "Comments preserved on mutating round-trip"; Config-Std-0.901/t/00write.t0000644000175000017500000000252212213723655013563 0ustar wdrwdruse Config::Std; use Test::More 'no_plan'; # May fail with v5.8.1 only, # if so define PERL_HASH_SEED=0 to suppress Hash Randomisation my $output_file = 'test.cfg'; my %data = ( # Default section... '' => { 'def1' => 'def val 1', 'def 2' => 'def val 2', 'def 3 ml' => "def val 3\nacross several\n lines", 'def 3' => 'def val 3', 'def 4' => 'def val 4', }, # Named section... 'Named' => { 'hi there' => q{What's your name???}, 'list' => [qw(a list of values), 'all different'], }, # Complex named section... 'Complex named!!!' => { 123456789 => 'zero', '%^$%$#%' => 'curses', }, ); ok eval{ write_config %data => $output_file } => 'Write succeeded'; ok open(my $fh, '<', $output_file) => 'File created'; ok my $config = do{ local $/; <$fh> } => 'File read'; ok my $orig_config = do{ local $/; } => 'DATA loaded'; is $orig_config, $config => 'Content correct'; __DATA__ def 2: def val 2 def 3: def val 3 def 3 ml: def val 3 : across several : lines def 4: def val 4 def1: def val 1 [Complex named!!!] %^$%$#%: curses 123456789: zero [Named] hi there: What's your name??? list: a list: list list: of list: values list: all different Config-Std-0.901/t/02rewrite_eq.t0000644000175000017500000000125210333206301014561 0ustar wdrwdruse Config::Std {def_sep => '='}; use Test::More 'no_plan'; my $input_file = 'test.cfg'; my %config; ok eval{ read_config $input_file => %config } => 'Read succeeded'; diag( $@ ) if $@; $config{'Extra Eq'}{'key 1'} = 'extra key 1'; push @{$config{Named}{list}}, 'an extra line'; ok eval{ write_config %config } => 'Write succeeded'; ok open(my $fh, '<', $input_file) => 'File opened'; ok my @config = <$fh> => 'File read'; ok my @extra = => 'DATA loaded'; is_deeply [@config[-4..-1]], [@extra[-4..-1]] => 'Extra content correct'; __DATA__ [Extra Eq] key 1 = extra key 1 Config-Std-0.901/t/02rewrite.t0000644000175000017500000000236611064100766014115 0ustar wdrwdruse Config::Std; use Test::More 'no_plan'; my $input_file = 'test.cfg'; my %data = ( # Default section... '' => { 'def1' => 'def val 1', 'def 2' => 'def val 2', 'def 3 ml' => "def val 3\nacross several\n lines", 'def 3' => 'def val 3', 'def 4' => 'def val 4', }, # Named section... 'Named' => { 'hi there' => q{What's your name???}, 'list' => [qw(a list of values), 'all different'], }, # Complex named section... 'Complex named!!!' => { 123456789 => 'zero', '%^$%$#%' => 'curses', }, ); my %config; ok eval{ read_config $input_file => %config } => 'Read succeeded'; diag( $@ ) if $@; is_deeply \%data, \%config => 'Data correct'; $config{Extra}{'key 1'} = 'extra key 1'; push @{$config{Named}{list}}, 'an extra line'; ok eval{ write_config %config } => 'Write succeeded'; ok open(my $fh, '<', $input_file) => 'File opened'; ok my @config = <$fh> => 'File read'; ok my @extra = => 'DATA loaded'; is_deeply [@extra[-4..-1]], [@config[-4..-1]] => 'Extra content correct'; __DATA__ [Extra] key 1: extra key 1 Config-Std-0.901/t/03autoviv.t0000644000175000017500000000126210376156263014134 0ustar wdrwdruse Test::More 'no_plan'; use Config::Std; my $orig_contents = <', $tmp_file or die; print {$fh} $orig_contents; close $fh; read_config $tmp_file, my %config; $config{section2}{mutating}++; write_config %config; open $fh, '<', $tmp_file; my $contents = do {local $/; <$fh>}; close $fh; ok $contents =~ m/mutating: 1/ => 'Mutation via hash'; read_config $tmp_file, my $config_ref; $config_ref->{section2}{mutating}++; write_config $config_ref; open $fh, '<', $tmp_file; $contents = do {local $/; <$fh>}; close $fh; ok $contents =~ m/mutating: 2/ => 'Mutation via hash-ref'; unlink $tmp_file; Config-Std-0.901/t/01read.t0000644000175000017500000000142611064100764013340 0ustar wdrwdruse Config::Std; use Test::More 'no_plan'; my $input_file = 'test.cfg'; my %data = ( # Default section... '' => { 'def1' => 'def val 1', 'def 2' => 'def val 2', 'def 3 ml' => "def val 3\nacross several\n lines", 'def 3' => 'def val 3', 'def 4' => 'def val 4', }, # Named section... 'Named' => { 'hi there' => q{What's your name???}, 'list' => [qw(a list of values), 'all different'], }, # Complex named section... 'Complex named!!!' => { 123456789 => 'zero', '%^$%$#%' => 'curses', }, ); my %config; ok eval{ read_config $input_file => %config } => 'Read succeeded'; diag( $@ ) if $@; is_deeply \%data, \%config => 'Data correct'; Config-Std-0.901/t/00.load.t0000644000175000017500000000016510204543127013417 0ustar wdrwdruse Test::More tests => 1; BEGIN { use_ok( 'Config::Std' ); } diag( "Testing Config::Std $Config::Std::VERSION" ); Config-Std-0.901/t/01read_renamed.t0000644000175000017500000000146511064100765015037 0ustar wdrwdruse Config::Std { read_config => 'get_config' }; use Test::More 'no_plan'; my $input_file = 'test.cfg'; my %data = ( # Default section... '' => { 'def1' => 'def val 1', 'def 2' => 'def val 2', 'def 3 ml' => "def val 3\nacross several\n lines", 'def 3' => 'def val 3', 'def 4' => 'def val 4', }, # Named section... 'Named' => { 'hi there' => q{What's your name???}, 'list' => [qw(a list of values), 'all different'], }, # Complex named section... 'Complex named!!!' => { 123456789 => 'zero', '%^$%$#%' => 'curses', }, ); my %config; ok eval{ get_config $input_file => %config } => 'Read succeeded'; diag( $@ ) if $@; is_deeply \%data, \%config => 'Data correct'; Config-Std-0.901/t/undef.t0000644000175000017500000000070010375252770013370 0ustar wdrwdruse Config::Std; use Test::More 'no_plan'; my %data = ( 'FOO' => { 'foo1' => 'defined', 'foo2' => undef, }, ); local $SIG{__WARN__} = sub { ok 0 => "Bad warning: @_"; }; my $output; ok !eval{ write_config %data => \$output } => 'Write failed as expected'; like $@, qr/\ACan't save undefined value for key {'FOO'}{'foo2'}/ => 'Failed with expected exception'; Config-Std-0.901/META.yml0000664000175000017500000000072512213730443013110 0ustar wdrwdr--- abstract: unknown author: - unknown build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.120921' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Config-Std no_index: directory: - t - inc requires: Class::Std: 0 Test::More: 0 version: 0 version: 0.901 Config-Std-0.901/lib/0000755000175000017500000000000012213730443012377 5ustar wdrwdrConfig-Std-0.901/lib/Config/0000755000175000017500000000000012213730443013604 5ustar wdrwdrConfig-Std-0.901/lib/Config/Std.pm0000644000175000017500000010143412213726135014702 0ustar wdrwdrpackage Config::Std; our $VERSION = '0.901'; require v5.7.3; # RT#21184 my %global_def_sep; my %global_inter_gap; sub import { my ($package, $opt_ref) = @_; my $caller = caller(); $global_def_sep{$caller} = $opt_ref->{def_sep}; $global_inter_gap{$caller} = $opt_ref->{def_gap}; for my $sub_name (qw( read_config write_config )) { $opt_ref->{$sub_name} ||= $sub_name; } *{$caller.'::'.$opt_ref->{read_config}} = \&Config::Std::Hash::read_config; *{$caller.'::'.$opt_ref->{write_config}} = \&Config::Std::Hash::write_config; } package Config::Std::Gap; use Class::Std; { sub serialize { return "\n" } sub update {} sub extend {} sub copy_to {} } package Config::Std::Comment; use Class::Std; { my %text_of : ATTR( :init_arg ); sub serialize { my ($self) = @_; return $text_of{ident $self}; } sub append_comment { my ($self, $new_text) = @_; $text_of{ident $self} .= $new_text; } sub update {} sub extend {} sub copy_to {} } package Config::Std::Keyval; use Class::Std; { my %key_of : ATTR( :init_arg :get ); my %vals_of : ATTR; my %deleted_of : ATTR; sub BUILD { my ($self, $ident, $arg_ref) = @_; $vals_of{$ident} = [ { %{$arg_ref} } ]; } my %SEPARATOR = ( ':' => ': ', '=' => ' = ' ); use Carp; sub serialize { my ($self, $def_sep, $block_name) = @_; my $ident = ident $self; return "" if $deleted_of{$ident}; my ($key, $vals) = ($key_of{$ident}, $vals_of{$ident}); my $keyspace = q{ } x length($key); my $serialization = q{}; for $n (0..$#{$vals}) { my ($val,$sep,$comm) = @{$vals->[$n]}{qw(val sep comm)}; my $val_type = ref $val; croak qq{Can't save \L$val_type\E ref as value for key {'$block_name'}{'$key'} (only scalars or array refs)} if $val_type && $val_type ne 'ARRAY'; $sep = $SEPARATOR{$sep || $def_sep}; my @vals = $val_type eq 'ARRAY' ? @{$val} : $val; s/ (?!\Z) \n /\n$keyspace$sep/gxms for @vals; $serialization .= $comm || q{}; $serialization .= join q{}, map {"$key$sep$_\n"} @vals; } return $serialization; } sub update { my ($self, $hash_ref, $updated_ref) = @_; my $ident = ident $self; my $key = $key_of{$ident}; if (!exists $hash_ref->{$key}) { $deleted_of{$ident} = 1; } else { my $val = $hash_ref->{$key}; @newvals = ref $val eq 'ARRAY' ? @{$val} : $val; for my $n (0..$#newvals) { $vals_of{$ident}[$n]{val} = $newvals[$n]; } splice @{$vals_of{$ident}}, scalar @newvals; } $updated_ref->{$key} = 1; return 1; } sub copy_to { my ($self, $hash_ref) = @_; my $ident = ident $self; my @vals = map $_->{val}, @{$vals_of{$ident}}; $hash_ref->{$key_of{$ident}} = @vals > 1 ? \@vals : $vals[0]; } sub multivalue { my ($self, $sep, $val, $comm) = @_; push @{$vals_of{ident $self}}, {val=>$val, sep=>$sep, comm=>$comm}; } } package Config::Std::Block; use Class::Std; { my %name_of : ATTR( :init_arg :get default => '' ); my %sep_count_of : ATTR; my %precomm_of : ATTR( :init_arg default => '' ); my %parcomm_of : ATTR( :init_arg default => '' ); my %components_of : ATTR; my %deleted_of : ATTR; my %seen : ATTR; my %is_first : ATTR( :init_arg default => '' ); sub BUILD { my ($self, $ident) = @_; @{$sep_count_of{$ident}}{':','='} = (0,0); $components_of{$ident} = []; $seen{$ident} = {}; } sub copy_to { my ($self, $hash_ref) = @_; my $ident = ident $self; my $keyvals = $hash_ref->{$name_of{$ident}} ||= {}; for my $comp ( @{$components_of{$ident}} ) { $comp->copy_to($keyvals); } $hash_ref->{$name_of{$ident}} = $keyvals; } sub serialize { my ($self, $first, $caller, $post_gap, $inter_gap) = @_; my $ident = ident $self; return q{} if $deleted_of{$ident}; my $is_anon = $first && length($name_of{$ident}) == 0; my $serialization = q{}; if (!$is_anon) { $serialization = ($precomm_of{$ident} || q{}) . "[$name_of{$ident}]" . (defined $parcomm_of{$ident}?$parcomm_of{$ident}:q{}) . "\n"; } my $gds = $global_def_sep{$caller}; my $def_sep = defined $gds ? $gds : $sep_count_of{$ident}{':'} >= $sep_count_of{$ident}{'='} ? ':' : '=' ; $self->ensure_gap() if $inter_gap && !$is_anon; for my $comp ( @{$components_of{$ident}} ) { $serialization .= $comp->serialize($def_sep, $name_of{$ident}); } return $serialization; } sub update { my ($self, $hash_ref, $updated_ref) = @_; my $ident = ident $self; if (!defined $hash_ref) { $deleted_of{$ident} = 1; return; } for my $comp ( @{$components_of{$ident}} ) { $comp->update($hash_ref, $updated_ref) or next; } } sub extend { my ($self, $hash_ref, $updated_ref, $post_gap, $inter_gap) = @_; # Only the first occurrence of a block has new keys added... return unless $is_first{ident $self}; my $first = 1; # RT 85956 for my $key ( sort grep {!$updated_ref->{$_}} keys %{$hash_ref}) { my $value = $hash_ref->{$key}; my $separate = ref $value || $value =~ m/\n./xms; $self->ensure_gap() if ($first ? $post_gap : $inter_gap) || $separate; $self->add_keyval($key, undef, $hash_ref->{$key}); $self->add_gap() if $separate; $first = 0; } } sub ensure_gap { my ($self) = @_; my $comp_ref = $components_of{ident $self}; return if @{$comp_ref} && $comp_ref->[-1]->isa('Config::Std::Gap'); push @{$comp_ref}, Config::Std::Gap->new(); } sub add_gap { my ($self) = @_; push @{$components_of{ident $self}}, Config::Std::Gap->new(); } sub add_comment { my ($self, $text) = @_; my $comp_ref = $components_of{ident $self}; if ($comp_ref && @{$comp_ref} && $comp_ref->[-1]->isa('Config::Std::Comment') ) { $comp_ref->[-1]->append_comment($text); } else { push @{$comp_ref}, Config::Std::Comment->new({text=>$text}); } } sub add_keyval { my ($self, $key, $sep, $val, $comm) = @_; my $ident = ident $self; $sep_count_of{$ident}{$sep}++ if $sep; my $seen = $seen{$ident}; if ($seen->{$key}) { $seen->{$key}->multivalue($sep, $val, $comm); return; } my $keyval = Config::Std::Keyval->new({key=>$key, sep=>$sep, val=>$val, comm=>$comm}); push @{$components_of{$ident}}, $keyval; $seen->{$key} = $keyval; } } package Config::Std::Hash; use Class::Std; { use Carp; use Fcntl ':flock'; # import LOCK_* constants my %post_section_gap_for :ATTR; my %array_rep_for :ATTR; my %filename_for :ATTR; sub write_config (\[%$];$) { my ($hash_ref, $filename) = @_; $hash_ref = ${$hash_ref} if ref $hash_ref eq 'REF'; $filename = $filename_for{$hash_ref} if @_<2; croak "Missing filename for call to write_config()" unless $filename; my $caller = caller; my $inter_gap = exists $global_inter_gap{$caller} ? $global_inter_gap{$caller} : 1; my $post_gap = $post_section_gap_for{$hash_ref} || (defined $global_inter_gap{$caller} ? $global_inter_gap{$caller} : 1 ); # Update existing keyvals in each block... my %updated; for my $block ( @{$array_rep_for{$hash_ref}} ) { my $block_name = $block->get_name(); $block->update($hash_ref->{$block_name}, $updated{$block_name}||={}); } # Add new keyvals to the first section of block... for my $block ( @{$array_rep_for{$hash_ref}} ) { my $block_name = $block->get_name(); $block->extend($hash_ref->{$block_name}, $updated{$block_name}, $post_gap, inter_gap ); } # Add new blocks at the end... for my $block_name ( sort grep {!$updated{$_}} keys %{$hash_ref} ) { my $block = Config::Std::Block->new({name=>$block_name}); my $subhash = $hash_ref->{$block_name}; my $first = 1; # RT 85956 for my $key ( sort keys %{$subhash} ) { if (!defined $subhash->{$key}) { croak "Can't save undefined value for key {'$block_name'}{'$key'} (only scalars or array refs)"; } my $value = $subhash->{$key}; my $separate = ref $value || $value =~ m/\n./xms; $block->ensure_gap() if ($first ? $post_gap : $inter_gap) || $separate; $block->add_keyval($key, undef, $value); $block->add_gap() if $separate; $first = 0; } $block->ensure_gap(); push @{$array_rep_for{$hash_ref}}, $block; } open my $fh, '>', $filename or croak "Can't open config file '$filename' for writing (\L$!\E)"; flock($fh,LOCK_EX|LOCK_NB) || croak "Can't write to locked config file '$filename'" if ! ref $filename; my $first = 1; for my $block ( @{$array_rep_for{$hash_ref}} ) { print {$fh} $block->serialize($first, scalar caller, $post_gap); $first = 0; } flock($fh,LOCK_UN) if ! ref $filename; return 1; } sub read_config ($\[%$]) { my ($filename, $var_ref, $opt_ref) = @_; my $var_type = ref($var_ref) || q{}; my $hash_ref; if ($var_type eq 'SCALAR' && !defined ${$var_ref} ) { ${$var_ref} = $hash_ref = {}; } elsif ($var_type eq 'HASH') { $hash_ref = $var_ref; } else { croak q{Scalar second argument to 'read_config' must be empty}; } bless $hash_ref, 'Config::Std::Hash'; my $blocks = $array_rep_for{$hash_ref} = _load_config_for($filename, $hash_ref); for my $block ( @{$blocks} ) { $block->copy_to($hash_ref); } $filename_for{$hash_ref} = $filename; # Remove initial empty section if no data... if (!keys %{ $hash_ref->{q{}} }) { delete $hash_ref->{q{}}; } return 1; } sub _load_config_for { my ($filename, $hash_ref) = @_; open my $fh, '<', $filename or croak "Can't open config file '$filename' (\L$!\E)"; flock($fh,LOCK_SH|LOCK_NB) || croak "Can't read from locked config file '$filename'" if !ref $filename; my $text = do{local $/; <$fh>}; flock($fh,LOCK_UN) if !ref $filename; my @config_file = Config::Std::Block->new({ name=>q{}, first=>1 }); my $comment = q{}; my %seen; # Start tracking whether section markers have gaps after them... $post_section_gap_for{$hash_ref} = 0; for ($text) { pos = 0; while (pos() < length() ) { # Gap... if (m/\G (?: [^\S\n]* (?:\n|\z)+)/gcxms) { ### Found gap $config_file[-1]->add_comment($comment) if $comment; $config_file[-1]->add_gap(); $comment = q{}; } # Comment... elsif (m/\G (\s* [#;] [^\n]* (?:\n|\z) )/gcxms) { ### Found comment: $1 $comment .= $1; } # Block... elsif (m/\G ([^\S\n]*) [[] ( [^]\n]* ) []] ( ([^\S\n]*) [#;] [^\n]* )? [^\S\n]* (?:\n|\z)/gcxms) { my ($pre, $name, $parcomm, $ws) = ($1, $2, $3, $4); ### Found block: $name if ($parcomm) { $pre = 2 + length($pre) + length($name) + length($ws); if (m/\G ( (?: \n? [ ]{$pre,} [#] [^\n]* )+ )/gcxms) { $parcomm .= "\n$1"; } } push @config_file, Config::Std::Block->new({ name => $name, precomm => $comment, parcomm => $parcomm, first => !$seen{$name}++, }); $comment = q{}; # Check for trailing gap... $post_section_gap_for{$hash_ref} += m/\G (?= [^\S\n]* (?:\n|\z) )/xms ? +1 : -1; } # Key/value... elsif (m/\G [^\S\n]* ([^=:\n]+?) [^\S\n]* ([:=] [^\S\n]*) ([^\n]*) (?:\n|\z)/gcxms) { my ($key, $sep, $val) = ($1, $2, $3); my $pure_sep = $sep; $pure_sep =~ s/\s*//g; # Continuation lines... my $continued = 0; while (m/\G [^\S\n]* \Q$sep\E ([^\n]*) (?:\n|\z) /gcxms || m/\G [^\S\n]* \Q$pure_sep\E ([^\n]*) (?:\n|\z) /gcxms ) { $val .= "\n$1"; $continued = 1; } $val =~ s/\A \s*|\s* \z//gxms if !$continued; ### Found kv: $key, $val $config_file[-1]->add_keyval($key, $pure_sep, $val, $comment); $comment = q{}; } # Mystery... else { my ($problem) = m/\G ([^\n]{10,40}|.{10}) /gcxms; die "Error in config file '$filename' near:\n\n\t$problem\n"; } } } return \@config_file; } } 1; # Magic true value required at end of module __END__ =head1 NAME Config::Std - Load and save configuration files in a standard format =head1 VERSION This document describes Config::Std version 0.901 =head1 SYNOPSIS use Config::Std; # Load named config file into specified hash... read_config 'demo2.cfg' => my %config; # Extract the value of a key/value pair from a specified section... $config_value = $config{Section_label}{key}; # Change (or create) the value of a key/value pair... $config{Other_section_label}{other_key} = $new_val; # Update the config file from which this hash was loaded... write_config %config; # Write the config information to another file as well... write_config %config, $other_file_name; =head1 DESCRIPTION This module implements yet another damn configuration-file system. The configuration language is deliberately simple and limited, and the module works hard to preserve as much information (section order, comments, etc.) as possible when a configuration file is updated. The whole point of Config::Std is to encourage use of one standard layout and syntax in config files. Damian says "I could have gotten away with it, I would have only allowed one separator. But it proved impossible to choose between C<:> and C<=> (half the people I asked wanted one, half wanted the other)." Providing round-trip file re-write is the spoonful of sugar to help the medicine go down. The supported syntax is within the general INI file family See Chapter 19 of "Perl Best Practices" (O'Reilly, 2005) for more detail on the rationale for this approach. =head2 Configuration language The configuration language is a slight extension of the Windows INI format. =head3 Comments A comment starts with a C<#> character (Perl-style) or a C<;> character (INI-style), and runs to the end of the same line: # This is a comment ; Ywis, eke hight thilke Comments can be placed almost anywhere in a configuration file, except inside a section label, or in the key or value of a configuration variable: # Valid comment [ # Not a comment, just a weird section label ] ; Valid comment key: value ; Not a comment, just part of the value NOTE BENE -- that last is a BAD EXAMPLE of what is NOT supported. This module supports full-line comments only, not on same line with semantic content. =head3 Sections A configuration file consists of one or more I, each of which is introduced by a label in square brackets: [SECTION1] # Almost anything is a valid section label [SECTION 2] # Internal whitespace is allowed (except newlines) [%^$%^&!!!] # The label doesn't have to be alphanumeric [ETC. ETC. AS MANY AS YOU WANT] The only restriction on section labels is that they must be by themselves on a single line (except for any surrounding whitespace or trailing comments), and they cannot contain the character C<]>. Every line after a given section label until the next section label (or the end of the config file) belongs to the given section label. If no section label is currently in effect, the current section has an empty label. In other words, there is an implicit: [] # Label is the empty string at the start of each config file. =head3 Configuration variables Each non-empty line within a section must consist of the specification of a I. Each such variable consists of a key and a string value. For example: name: George age: 47 his weight! : 185 The key consists of every character (including internal whitespace) from the start of the line until the key/value separator. So, the previous example declares three keys: C<'name'>, C<'age'>, and C<'his weight!'>. Note that whitespace before and after the key is removed. This makes it easier to format keys cleanly: name : George age : 47 his weight! : 185 The key/value separator can be either a colon (as above) or an equals sign, like so: name= George age= 47 his weight! = 185 Both types of separators can be used in the same file, but neither can be used as part of a key. Newlines are not allowed in keys either. When writing out a config file, Config::Std tries to preserve whichever separator was used in the original data (if that data was read in). New data (created by code not parsed by C) is written back with a colon as its default separator, unless you specify the only other separator value C<'='> when the module is loaded: use Config::Std { def_sep => '=' }; Note that this does not change read-in parsing, does not change punctuation for values that were parsed, and will not allow values other than C<'='> or C<':'>. Everything from the first non-whitespace character after the separator, up to the end of the line, is treated as the value for the config variable. So all of the above examples define the same three values: C<'George'>, C<'47'>, and C<'185'>. In other words, any whitespace immediately surrounding the separator character is part of the separator, not part of the key or value. Note that you can't put a comment on the same line as a configuration variable. The C<# etc.> is simply considered part of the value: [Delimiters] block delims: { } string delims: " " comment delims: # \n You can comment a config var on the preceding or succeeding line: [Delimiters] # Use braces to delimit blocks... block delims: { } # Use double quotes to delimit strings string delims: " " # Use octothorpe/newline to delimit comments comment delims: # \n =head3 Multi-line configuration values A single value can be continued over two or more lines. If the line immediately after a configuration variable starts with the separator character used in the variable's definition, then the value of the variable continues on that line. For example: address: 742 Evergreen Terrace : Springfield : USA The newlines then form part of the value, so the value specified in the previous example is: C> Note that the second and subsequent lines of a continued value are considered to start where the whitespace after the I separator finished, not where the whitespace after their own separator finishes. For example, if the previous example had been: address: 742 Evergreen Terrace : Springfield : USA then the value would be: "742 Evergreen Terrace\n Springfield\n USA" If a continuation line has less leading whitespace that the first line: address: 742 Evergreen Terrace : Springfield : USA it's treated as having no leading whitespace: "742 Evergreen Terrace\nSpringfield\nUSA" =head3 Multi-part configuration values If the particular key appears more than once in the same section, it is considered to be part of the same configuration variable. The value of that configuration value is then a list, containing all the individual values for each instance of the key. For example, given the definition: cast: Homer cast: Marge cast: Lisa cast: Bart cast: Maggie the corresponding value of the C<'cast'> configuration variable is: C> Individual values in a multi-part list can also be multi-line (see above). For example, given: extras: Moe : (the bartender) extras: Smithers : (the dogsbody) the value for the C<'extras'> config variable is: C> =head2 Internal representation Each section label in a configuration file becomes a top-level hash key whe the configuration file is read in. The corresponding value is a nested hash reference. Each configuration variable's key becomes a key in that nested hash reference. Each configuration variable's value becomes the corresponding value in that nested hash reference. Single-line and multi-line values become strings. Multi-part values become references to arrays of strings. For example, the following configuration file: # A simple key (just an identifier)... simple : simple value # A more complex key (with whitespace)... more complex key : more complex value # A new section... [MULTI-WHATEVERS] # A value spread over several lines... multi-line : this is line 1 : this is line 2 : this is line 3 # Several values for the same key... multi-value: this is value 1 multi-value: this is value 2 multi-value: this is value 3 would be read into a hash whose internal structure looked like this: { # Default section... '' => { 'simple' => 'simple value', 'more complex key' => 'more complex value', }, # Named section... 'MULTI-WHATEVERS' => { 'multi-line' => "this is line 1\nthis is line 2\nthis is line 3", 'multi-value' => [ 'this is value 1', 'this is value 2', 'this is value 3' ], } } =head1 INTERFACE The following subroutines are exported automatically whenever the module is loaded... =over =item C<< read_config($filename => %config_hash) >> =item C<< read_config($filename => $config_hash_ref) >> =item C<< read_config($string_ref => %config_hash_or_ref) >> The C subroutine takes two arguments: the filename of a configuration file, and a variable into which the contents of that configuration file are to be loaded. If the variable is a hash, then the configuration sections and their key/value pairs are loaded into nested subhashes of the hash. If the variable is a scalar with an undefined value, a reference to an anonymous hash is first assigned to that scalar, and that hash is then filled as described above. The subroutine returns true on success, and throws an exception on failure. If you pass a reference to the string as the first argument to C it uses that string as the source of the config info. For example: use Config::Std; # here we load the config text to a scalar my $cfg = q{ [Section 1] attr1 = at attr2 = bat [Section 2] attr3 = cat }; # here we parse the config from that scalar by passing a reference to it. read_config( \$cfg, my %config ); use Data::Dumper 'Dumper'; warn Dumper [ \%config ]; =item C<< write_config(%config_hash => $filename) >> =item C<< write_config($config_hash_ref => $filename) >> =item C =item C The C subroutine takes two arguments: the hash or hash reference containing the configuration data to be written out to disk, and an optional filename specifying which file it is to be written to. The data hash must conform to the two-level structure described earlier: with top-level keys naming sections and their values being references to second-level hashes that store the keys and values of the configuartion variables. If the structure of the hash differs from this, an exception is thrown. If a filename is also specified, the subroutine opens that file and writes to it. It no filename is specified, the subroutine uses the name of the file from which the hash was originally loaded using C. It no filename is specified and the hash I originally loaded using C, an exception is thrown. The subroutine returns true on success and throws and exception on failure. =back If necessary (typically to avoid conflicts with other modules), you can have the module export its two subroutines with different names by loading it with the appropriate options: use Config::Std { read_config => 'get_ini', write_config => 'update_ini' }; # and later... get_ini($filename => %config_hash); # and later still... update_ini(%config_hash); You can also control how much spacing the module puts between single- line values when they are first written to a file, by using the C option: # No empty line between single-line config values... use Config::Std { def_gap => 0 }; # An empty line between all single-line config values... use Config::Std { def_gap => 1 }; Regardless of the value passed for C, new multi-line values are always written with an empty line above and below them. Likewise, values that were previously read in from a file are always written back with whatever spacing they originally had. =head1 DIAGNOSTICS =over =item Can't open config file '%s' (%s) You tried to read in a configuration file, but the file you specified didn't exist. Perhaps the filepath you specified was wrong. Or maybe your application didn't have permission to access the file you specified. =item Can't read from locked config file '$filename' You tried to read in a configuration file, but the file you specified was being written by someone else (they had a file lock active on it). Either try again later, or work out who else is using the file. =item Scalar second argument to 'read_config' must be empty You passed a scalar variable as the destination into C was supposed to load a configuration file, but that variable already had a defined value, so C couldn't autovivify a new hash for you. Did you mean to pass the subroutine a hash instead of a scalar? =item Can't save %s value for key '%s' (only scalars or array refs) You called C and passed it a hash containing a configuration variable whose value wasn't a single string, or a list of strings. The configuration file format supported by this module only supports those two data types as values. If you really need to store other kinds of data in a configuration file, you should consider using C or C instead. =item Missing filename in call to write_config() You tried to calll C with only a configuration hash, but that hash wasn't originally loaded using C, so C has no idea where to write it to. Either make sure the hash you're trying to save was originally loaded using C, or else provide an explicit filename as the second argument to C. =item Can't open config file '%s' for writing (%s) You tried to update or create a configuration file, but the file you specified could not be opened for writing (for the reason given in the parentheses). This is often caused by incorrect filepaths or lack of write permissions on a directory. =item Can't write to locked config file '%s' You tried to update or create a configuration file, but the file you specified was being written at the time by someone else (they had a file lock active on it). Either try again later, or work out who else is using the file. =back =head1 CONFIGURATION AND ENVIRONMENT Config::Std requires no configuration files or environment variables. (To do so would be disturbingly recursive.) =head1 DEPENDENCIES This module requires the Class::Std module (available from the CPAN) =head1 INCOMPATIBILITIES Those variants of INI file dialect supporting partial-line comment are incompatible. (This is the price of keeping comments when re-writing.) =head1 BUGS AND LIMITATIONS =over =item Loading on demand If you attempt to load C and C at runtime with C, you can not rely upon the prototype to convert a regular hash to a reference. To work around this, you must explicitly pass a reference to the config hash. require Config::Std; Config::Std->import; my %config; read_config($file, \%config); write_config(\%config, $file); =item Windows line endings on Unix/Linux (RT#21547/23550) If the config file being read contains carriage returns and line feeds at the end of each line rather than just line feeds (i.e. the standard Windows file format, when read on a machine expecting POSIX file format), Config::Std emits an error with embedded newline. Workaround is match file line-endings to locale. This will be fixed in 1.000. =item leading comment vanishes (RT#24597,) A comment before the first section is not always retained on write-back, if the '' default section is empty. =item 00write.t test 5 fails on perl5.8.1 (RT#17425) Due to an incompatible change in v5.8.1 partially reversed in v5.8.2, hash key randomisation can cause test to fail in that one version of Perl. Workaround is export environment variable PERL_HASH_SEED=0. =back Please report any bugs or feature requests to C, or through the web interface at L. =head1 AUTHOR Damian Conway C<< >> Maintainers Bill Ricker C<< >> Tom Metro C<< >> =head1 LICENCE AND COPYRIGHT Copyright (c) 2005, Damian Conway C<< >>. Copyright (c) 2011, D.Conway, W.Ricker C<< >> All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.