ConfigReader-Simple-1.298/0000755000076500000240000000000014777037122014304 5ustar brianstaffConfigReader-Simple-1.298/LICENSE0000644000076500000240000002174314777037120015316 0ustar brianstaffThe ConfigReader::Simple module is licensed under the same terms as perl itself, under the Artistic License 2.0. Artistic License 2.0 Copyright (c) 2000-2006, The Perl Foundation. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble ******** This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. Definitions *********** "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. "You" and "your" means any person who would like to copy, distribute, or modify the Package. "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. "Source" form means the source code, documentation source, and configuration files for the Package. "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. Permission for Use and Modification Without Distribution ******************************************************** (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. Permissions for Redistribution of the Standard Version ****************************************************** (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. Distribution of Modified Versions of the Package as Source ********************************************************** (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under (i) the Original License or (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. Distribution of Compiled Forms of the Standard Version or Modified ****************************************************************** Versions without the Source *************************** (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. Aggregating or Linking the Package ********************************** (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. Items That are Not Considered Part of a Modified Version ******************************************************** (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. General Provisions ****************** (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ConfigReader-Simple-1.298/Changes0000644000076500000240000000705114777037120015600 0ustar brianstaffRevision history for Perl module ConfigReader::Simple 1.298 2025-04-13T22:44:32Z * require a newer version.pm for v5.10.1 tests 1.297 2025-01-04T16:09:56Z * refresh distro and move to BRIANDFOY 1.296 2024-01-23T14:28:43Z * refresh distro, update email address, update repo URL 1.295 2022-01-09T00:15:28Z * No code changes. Fix a link in the README.pod. 1.294 2021-01-15T07:52:01Z * freshen distro, remove Travis CI, add Github Actions * fix problem with blank line ending processing (Github #2, Axel Beckert) 1.293 2018-04-26T16:17:17Z * Clarify that it's Artistic License 2.0 1.291 2016-11-23T21:08:11Z * Remove the prereq test, but oddly, update all the prereqs. If it shows up in a use statement, it shows up in the prereqs. 1.29 - 2014-08-16 * Check for reference arguments without using UNIVERSAL::isa 1.28 - 2009-06-09 * Various distro fixes, correct license, and new Makemaker hotness. No need to upgrade. 1.27 - 2008-08-20 * Fixed bug in _validate_keys that looked at a directives value instead of checking for the directive name. This affected directives with perly false values when you gave a list of required keys to new(). 1.26 - 2007-11-09 * cleanups for the move from CVS to SVN, and for the latest kwalitee * no need to upgrade 1.25 - 2007-03-16 * Fixing up distro and verifying that all bugs in RT are fixed * A call to new() without args now doesn't try to open the null file 1.24 - 2007-01-09 * updated copyright and license info * no code changes, so no need to upgrade 1.23 - 2006-04-10 * Changed configuration directive parsing to accept [^\s=]+ instead of just \w+ * If you want to name your configuration directives with characters outside of \w, you should upgrade to this version * If your teammates are using config directives with characters outside of \w, they're going to make you upgrade. :) 1.21 - 2005-08-24 * Fixed string parsing bug which messed up on continuation lines * cloning an object now makes a deep copy, fixing another bug * Removed all module dependencies except Test::More 1.18 - 2004-02-10 * Adam Trickett added support for continuation lines * I added docs for config file formats 1.17 - 2003-11-30 * some fix ups for the POD docs * fixed a problem in t/pod.t so the test finds the files * if you already have this installed, you don't need this update 1.15 - 2002-10-22 * new_multiple can keep going if it cannot read a file * added $Die, $Warn, $ERROR, %Error variables for settings * things that should croak do 1.14 - 2002-09-29 * cleaned up Makefile.PL * added prereq test 1.12 - 2002-07-13 * added add_config_file() to pull in more configuration directives after you have already created the object. 1.11 - 2002-04-28 * added new_multiple() to parse multiple files into the same object. 0.91 - 1997-11-03 * you don't need to call parse() since new() does it for you * you can use the NAME=VALUE format in config files thanks to Alan W. Jurgensen * the module is now maintained by brian d foy, briandfoy@pobox.com 0.9 - 2000-08-11 * Bumped up the version number because it's nearly mature * Now you can declare all, some or no keys and it will only die if a declared key is not found in the config file. (Kim Ryan ) 0.5 - 1999-02-10 * Changed module name to ConfigReader::Simple to match up with other modules in CPAN better. * Quote delimiters now have to be matched, ie not 'foo" etc. * Doesn't get confused by trailing whitespace * Copes with quote-delimited strings as long as they're all on the same line. ConfigReader-Simple-1.298/MANIFEST0000644000076500000240000000126514777037122015441 0ustar brianstaffChanges eg/config.desc eg/config_creator.pl eg/example.pl examples/README INSTALL.SKIP lib/ConfigReader/Simple.pm LICENSE Makefile.PL MANIFEST This list of files MANIFEST.SKIP README.pod SECURITY.md t/_save.t t/add_config_file.t t/clone.config t/clone.t t/eof.config t/example.config t/exists.t t/get.t t/global.config t/load.t t/new_multiple.t t/new_string.t t/parse.t t/parse_line.t t/parse_string.t t/pod.t t/pod_coverage.t t/remove.t t/save.t t/set.t t/test_manifest t/unparseable.config t/validate_keys.t xt/changes.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) ConfigReader-Simple-1.298/t/0000755000076500000240000000000014777037121014546 5ustar brianstaffConfigReader-Simple-1.298/t/pod.t0000644000076500000240000000020114777037120015505 0ustar brianstaffuse Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); ConfigReader-Simple-1.298/t/example.config0000644000076500000240000000017014777037120017365 0ustar brianstaff# A Comment Test1 Test 1 value Test2 Test 2 value Test3=foo Test4=bar Zero 0 Undef Test10 foo \ bar \ baz #Faketest ConfigReader-Simple-1.298/t/parse_string.t0000644000076500000240000000144114777037120017432 0ustar brianstaff#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $class = 'ConfigReader::Simple'; my $method = 'parse_string'; use_ok( $class ); can_ok( $class, $method ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # { my $string = <<"HERE"; cat Buster dog \\ Tuffy bird Poppy # comment = hello kitty \\ Mimi HERE my $config = $class->new(); $config->parse_string( \$string ); is( $config->get( "cat" ), "Buster" ); is( $config->get( "kitty" ), "Mimi" ); is( $config->get( "dog" ), "Tuffy" ); is( $config->get( "bird" ), "Poppy" ); is( $config->get( "comment" ), undef ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ConfigReader-Simple-1.298/t/eof.config0000644000076500000240000000014314777037120016503 0ustar brianstaff# This file should end with a continuation line that is not # actually continued Cat Buster Kitty \ConfigReader-Simple-1.298/t/save.t0000644000076500000240000000453714777037120015701 0ustar brianstaffuse Test::More tests => 22; use Test::Warn; use File::Spec::Functions qw(catfile); my $class = 'ConfigReader::Simple'; use_ok( $class ); can_ok( $class, qw( save ) ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my @Directives = qw( Test1 Test2 Test3 Test4 ); my @Files = map { catfile( "t" , "$_.config" ) } qw(save_test1 save_test2); unlink @Files; my $config = $class->new( catfile( qw( t example.config) ), \@Directives ); isa_ok( $config, $class ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # test with no values { my $result; warning_like { $result = $config->save() } qr/No arguments to method/, 'No arguments emits warning'; ok( ! defined $result, 'No arguments return undef' ); is( $@, '', 'There is nothing in $@ for a warning' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # test with one value { ok( ! -e $Files[0], 'File does not exist' ); my $result = $config->save( $Files[0] ); ok( $result, 'Single argument returns true value' ); ok( -e $Files[0], 'File exists' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # test with two values foreach my $value ( undef, 'foo', {}, 0 ) { my $result = eval { $config->save( $Files[0] => $value ) }; ok( ! defined $result, 'Bad arguments return undef' ); like( $@, qr/Argument is not an array reference/, 'Error string says the right thing' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # test with three values { my $result = eval { $config->save( $Files[0] => [], $Files[1] ) }; ok( ! defined $result, 'Three arguments return undef' ); like( $@, qr/Odd number of arguments/ ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # test with four values { my $result = eval { $config->save( $Files[0] => [ qw( Test1 Test2 ) ], $Files[1] => [ qw( Zero Test3 ) ] ) }; ok( $result, 'Four arguments return true' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # test when _save fails { no warnings 'redefine'; no warnings 'once'; no strict 'refs'; local *{ "${class}::_save" } = sub { $ConfigReader::Simple::ERROR = 'Oops'; 0 }; ok( ! $class->_save, "_save mock fails as it should" ); warning_like { $config->save( $Files[0] => [ qw( Test1 Test2 ) ] ) } qr/Oops/; } unlink @Files; ConfigReader-Simple-1.298/t/load.t0000644000076500000240000000017514777037120015654 0ustar brianstaffuse Test::More tests => 1; print "Bail out! ConfigReader::Simple did not compile" unless use_ok( 'ConfigReader::Simple' ); ConfigReader-Simple-1.298/t/clone.t0000644000076500000240000000410414777037120016031 0ustar brianstaffuse Test::More tests => 17; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $class = 'ConfigReader::Simple'; use_ok( $class ); can_ok( $class, qw(clone new_from_prototype) ); my @Directives = qw( Test1 Test2 Test3 Test4 ); my $config = $class->new( "t/example.config", \@Directives ); isa_ok( $config, $class ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # can we clone the object? # this should be a deep copy my $clone = $config->clone; isa_ok( $clone, $class ); my $proto = $config->new_from_prototype; isa_ok( $proto, $class ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # can we change the clone without affecting the original? { my $Test1_value = 'Kundry'; $clone->set( 'Test1', $Test1_value ); is( $clone->Test1, $Test1_value, 'Cloned object has right value after change' ); isnt( $config->Test1, $Test1_value, 'Original object has right value after clone change' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # can we change the original without affecting the clone? { my $Test2_value = 'Second Squire'; $config->set( 'Test2', $Test2_value ); is( $config->Test2, $Test2_value, 'Original object has right value after change' ); isnt( $clone->Test2, $Test2_value, 'Clone object has right value after original change' ); my @files = $config->files; my @clone_files = $clone->files; is( scalar @files, 1, "Original object has 1 associated file" ); is( scalar @clone_files, 1, "Clone object has 1 associated file" ); is( $files[-1], "t/example.config", "Original object returns right file" ); is( $clone_files[-1], "t/example.config", "Clone object returns right file" ); $config->add_config_file( 't/clone.config' ); @files = $config->files; @clone_files = $clone->files; is( scalar @files, 2, "Original object has 1 associated file" ); is( scalar @clone_files, 1, "Clone object has 1 associated file" ); is( $files[-1], "t/clone.config", "Original object returns right file" ); is( $clone_files[-1], "t/example.config", "Clone object returns right file" ); } ConfigReader-Simple-1.298/t/remove.t0000644000076500000240000000112014777037120016221 0ustar brianstaffuse Test::More tests => 5; use ConfigReader::Simple; my @Directives = qw( Test1 Test2 Test3 Test4 ); my $config = ConfigReader::Simple->new( "t/example.config", \@Directives ); isa_ok( $config, 'ConfigReader::Simple' ); # remove things that do exist is( $config->get( 'Test3' ), 'foo', 'Test3 has the right value' ); ok( $config->remove( 'Test3' ), 'Test3 is removed' ); my $value = not $config->exists( 'Test3' ); ok( $value, 'Test3 no longer exists' ); # remove things that do not exist $value = not $config->remove( 'Tenor' ); ok( $value, 'Tenor does not exist, but was removed' ); ConfigReader-Simple-1.298/t/parse.t0000644000076500000240000000540414777037120016047 0ustar brianstaff#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; use Test::Output; use File::Spec::Functions qw(catfile); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $class = 'ConfigReader::Simple'; my $method = 'parse'; use_ok( $class ); can_ok( $class, $method ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with a missing file, Warn off, Die off # should return nothing, but with no warning { my $missing = 'a/b/c'; ok( ! -e $missing, "Missing file is actually missing" ); local $ConfigReader::Simple::Warn = 0; local $ConfigReader::Simple::Die = 0; my $mock = bless {}, $class; isa_ok( $mock, $class ); can_ok( $mock, $method ); ok( ! $mock->parse( $missing ), 'parse fails with missing file, $Warn and $Die off' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with a missing file, Warn off, Die on # should return nothing, but with no warning { my $missing = 'a/b/c'; ok( ! -e $missing, "Missing file is actually missing" ); local $ConfigReader::Simple::Warn = 0; local $ConfigReader::Simple::Die = 1; my $mock = bless {}, $class; isa_ok( $mock, $class ); can_ok( $mock, $method ); ok( ! $mock->parse( $missing ), 'parse fails with missing file, $Warn and $Die off' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with a missing file, Warn on, Die off # should return nothing, but with a warning { my $missing = 'a/b/c'; ok( ! -e $missing, "Missing file is actually missing" ); local $ConfigReader::Simple::Warn = 1; local $ConfigReader::Simple::Die = 0; local $SIG{__WARN__} = sub { print STDERR @_ }; my $mock = bless {}, $class; isa_ok( $mock, $class ); can_ok( $mock, $method ); stderr_like { $mock->parse( $missing ) } qr/Could not open/, "parse fails with missing file"; } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with a missing file, Warn on, Die on # should return nothing, but with a warning { my $missing = 'a/b/c'; ok( ! -e $missing, "Missing file is actually missing" ); local $ConfigReader::Simple::Warn = 1; local $ConfigReader::Simple::Die = 1; local $SIG{__WARN__} = sub { print STDERR @_ }; my $mock = bless {}, $class; isa_ok( $mock, $class ); can_ok( $mock, $method ); stderr_like { $mock->parse( $missing ) } qr/Could not open/, "parse fails with missing file"; } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with a file that ends on a continuation line that is uncontinued # should still work { my $file = catfile( qw(t eof.config) ); ok( -e $file, "File exists" ); my $mock = bless {}, $class; isa_ok( $mock, $class ); can_ok( $mock, $method ); ok( $mock->parse( $file ), 'parsing file is just fine' ); } ConfigReader-Simple-1.298/t/clone.config0000644000076500000240000000017014777037120017032 0ustar brianstaff# A Comment Test1 Test 1 value Test2 Test 2 value Test3=foo Test4=bar Zero 0 Undef Test10 foo \ bar \ baz #Faketest ConfigReader-Simple-1.298/t/exists.t0000644000076500000240000000217714777037120016260 0ustar brianstaffuse Test::More tests => 20; use File::Spec::Functions qw(catfile); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $class = 'ConfigReader::Simple'; my $method = 'exists'; use_ok( $class ); can_ok( $class, $method ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my @Directives = qw( Test1 Test2 Test3 Test4 ); my $config = $class->new( catfile( qw(t example.config) ), \@Directives ); isa_ok( $config, $class ); can_ok( $config, $method ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # these directives should be okay { foreach my $directive ( @Directives ) { ok( $config->$method( $directive ), "Directive [$directive] exists" ); } } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # these directives should not be okay { my @Directives = qw( Test5 exists blah get ); foreach my $directive ( @Directives ) { ok( ! $config->$method( $directive ), "$method fails for $directive"); ok( ! $config->get( $directive ), "get( $directive ) fails" ); ok( ! $config->$directive, "->$method fails" ); } } ConfigReader-Simple-1.298/t/_save.t0000644000076500000240000000274514777037120016037 0ustar brianstaff#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; use Data::Dumper; use File::Spec; my $null_file = File::Spec->devnull; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $class = 'ConfigReader::Simple'; my $method = '_save'; use_ok( $class ); can_ok( $class, $method ); my $config = $class->new_string( Strings => [ \ 'Cat Buster' ] ); isa_ok( $config, $class ); is( $config->get( 'Cat' ), 'Buster' ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test _save without a list of directives. It should fail { my $rc = $config->_save( $null_file ); ok( ! $rc, "return value is false without list of directives" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test _save with list of directives, but not as an array ref { my $rc = $config->_save( $null_file, 'Cat' ); ok( ! $rc, "return value is false without list of directives" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test _save with a file name I can't open. Should fail { my $filename = "/a/b/c/d/e/f/1/2/3/4/5/buster"; my $rc = $config->_save( $filename, [ qw( Cat ) ] ); ok( ! $rc, "return value is false without list of directives" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test _save with a file name I can open. Should work { my $rc = $config->_save( $null_file, [ qw(Cat) ] ); ok( $rc, "return value is true without list of directives" ); }ConfigReader-Simple-1.298/t/new_multiple.t0000644000076500000240000000264114777037120017441 0ustar brianstaff#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $class = 'ConfigReader::Simple'; my $method = 'new_multiple'; use_ok( $class ); can_ok( $class, $method ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test with no arguments { my $rc = eval{ $class->$method() }; my $at = $@; ok( length $at, "eval fails with no arguments" ); like( $at, qr/must be an array reference/, "reports that it must be an array ref" ); like( $at, qr/Files/, "reports that Files is the problem" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test with Files argument which is not an array ref { my $rc = eval{ $class->$method( Files => 'a b c' ) }; my $at = $@; ok( length $at, "eval fails with no arguments" ); like( $at, qr/must be an array reference/, "reports that it must be an array ref" ); like( $at, qr/Files/, "reports that Files is the problem" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test with Files arguments which is an array ref, Keys that isn't { my $rc = eval{ $class->$method( Files => [], Keys => 'a b c' ) }; my $at = $@; ok( length $at, "eval fails with no arguments" ); like( $at, qr/must be an array reference/, "reports that it must be an array ref" ); like( $at, qr/Keys/, "reports that Keys is the problem" ); }ConfigReader-Simple-1.298/t/add_config_file.t0000644000076500000240000000176214777037120020014 0ustar brianstaff#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; use File::Spec::Functions qw(catfile); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $class = 'ConfigReader::Simple'; my $method = 'add_config_file'; use_ok( $class ); can_ok( $class, $method ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test with a file that does not exist { my $filename = 'a/b/c'; ok( ! -e $filename, "Missing file is actually missing" ); my $mock = bless {}, $class; is( $mock->$method( $filename ), undef, "$method with missing file fails" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test with a file that isn't parseable { no warnings 'redefine'; no strict 'refs'; local *{ "${class}::parse" } = sub { 0 }; my $filename = catfile( qw(t example.config) ); ok( -e $filename, "$filename exists" ); my $mock = bless {}, $class; is( $mock->$method( $filename ), undef, "$method with empty file fails" ); }ConfigReader-Simple-1.298/t/global.config0000644000076500000240000000003214777037120017167 0ustar brianstaffTest3 Global Scope Global ConfigReader-Simple-1.298/t/parse_line.t0000644000076500000240000000156514777037120017062 0ustar brianstaff#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $class = 'ConfigReader::Simple'; my $method = 'parse_line'; use_ok( $class ); ok( defined &ConfigReader::Simple::parse_line, "$method is defined" ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with a line that should work { my( $directive, $value ) = &ConfigReader::Simple::parse_line( "Cat = Buster" ); is( $directive, 'Cat' ); is( $value, 'Buster' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with a line that should fails { my $rc = eval { &ConfigReader::Simple::parse_line( "" ) }; my $at = $@; ok( length $at, "eval of parse_line failed with empty string" ); like( $at, qr/Can't parse/, "Reports that it can't parse the string" ); }ConfigReader-Simple-1.298/t/test_manifest0000644000076500000240000000026314777037120017336 0ustar brianstaffload.t pod.t pod_coverage.t validate_keys.t parse.t parse_line.t parse_string.t new_multiple.t add_config_file.t exists.t get.t set.t remove.t clone.t _save.t save.t new_string.t ConfigReader-Simple-1.298/t/pod_coverage.t0000644000076500000240000000040614777037120017367 0ustar brianstaffuse Test::More; eval "use Test::Pod::Coverage"; if( $@ ) { plan skip_all => "Test::Pod::Coverage required for testing POD"; } else { plan tests => 1; pod_coverage_ok( "ConfigReader::Simple", { trustme => [ qr/^[A-Z_]+$/, qr/parse_line/ ] } ); } ConfigReader-Simple-1.298/t/validate_keys.t0000644000076500000240000000242214777037120017556 0ustar brianstaff#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $class = 'ConfigReader::Simple'; my $method = '_validate_keys'; use_ok( $class ); can_ok( $class, $method ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test that it works if validkeys is not set { my $config = bless {}, $class; # a mock, nothing set ok( $config->$method(), "$method returns true without validkeys set" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test that it works if validkeys is set, but not an array reference { my $config = bless { validkeys => 4 }, $class; # a mock, nothing set eval { $config->$method() }; my $at = $@; ok( length $at, 'eval fails when validkeys is not an aray ref' ); like( $at, qr/not an array reference/, "Passing non array ref fails" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test that it works if validkeys is set, but missing in config { my $config = bless { validkeys => [ qw(Buster) ] }, $class; # a mock, nothing set eval { $config->$method() }; my $at = $@; ok( length $at, 'eval fails when Buster directive is missing' ); like( $at, qr/do not occur/, "Missing key fails" ); }ConfigReader-Simple-1.298/t/new_string.t0000644000076500000240000000411714777037120017114 0ustar brianstaff#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $class = 'ConfigReader::Simple'; my $method = 'new_string'; use_ok( $class ); can_ok( $class, $method ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test that it works with both Strings and Keys # Has all valid keys { my $key = 'Cat'; my $cat = 'Buster'; my $config = $class->$method( Strings => [ \ "$key = $cat" ], Keys => [ $key ], ); isa_ok( $config, $class ); is( $config->get( $key ), $cat ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test that it works with only Strings { my $key = 'Cat'; my $cat = 'Mimi'; my $config = $class->$method( Strings => [ \ "$key = $cat" ], ); isa_ok( $config, $class ); is( $config->get( $key ), $cat ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test that it croaks with no arguments { eval { $class->$method() }; my $at = $@; ok( defined $at, "$method fails with no arguments" ); like( $at, qr/must be an array reference/ ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test that it croaks with Strings containing a non-scalar ref { eval { $class->$method( Strings => [ 'Foo = Bar' ] ) }; my $at = $@; ok( defined $at, "$method fails when string contains a non-reference" ); like( $at, qr/not a scalar reference/ ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test that it croaks when Strings value is not an array ref { eval { $class->$method( Strings => '', Keys => [] ) }; my $at = $@; ok( defined $at, "$method fails when Keys value is the empty string" ); like( $at, qr/must be an array reference/ ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Test that it croaks when Keys value is not an array ref { eval { $class->$method( Strings => [ ], Keys => '' ) }; my $at = $@; ok( defined $at, "$method fails when Keys value is the empty string" ); like( $at, qr/must be an array reference/ ); } ConfigReader-Simple-1.298/t/get.t0000644000076500000240000001051014777037120015506 0ustar brianstaff#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; use File::Spec::Functions qw(catfile); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $class = 'ConfigReader::Simple'; my $method = 'get'; use_ok( $class ); can_ok( $class, $method ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my @Directives = qw( Test1 Test2 Test3 Test4 ); my $config = $class->new( "t/example.config", \@Directives ); isa_ok( $config, $class ); # get things that do exist is( $config->get( 'Test3' ), 'foo', 'Test3 has right value' ); is( $config->Test3, 'foo' ); is( $config->get( 'Test2' ), 'Test 2 value', 'Test2 has right value' ); is( $config->Test2, 'Test 2 value' ); # get things that do exist, but look like false values to perl is( $config->get( 'Zero' ), '0', 'Zero has right value as string' ); is( $config->get( 'Zero' ), 0,, 'Zero has right value as number' ); is( $config->get( 'Undef' ), '', 'Undef has right value (empty)' ); # get long lines is( $config->get( 'Test10' ), 'foo bar baz', 'Continuation line has right value'); is( $config->Test10, 'foo bar baz') ; # get things that do not exist # using get my $value = not defined $config->get( 'Test' ); ok( $value, 'Test has no value with get()' ); $value = not defined $config->Test; ok( $value, 'Test has no value with AUTOLOAD' ); $value = not defined $config->get( 'Test5' ); ok( $value, 'Test5 has no value with get()' ); $value = not defined $config->Test5; ok( $value, 'Test5 has no value with AUTOLOAD' ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Now try it with multiple files $config = $class->new_multiple( Files => [ qw( t/global.config t/example.config ) ] ); isa_ok( $config, $class ); # get things that do exist is( $config->get( 'Test3' ), 'foo', 'Test3 has right value with AUTOLOAD' ); is( $config->get( 'Scope' ), 'Global', 'Scope has right value with AUTOLOAD' ); is( $config->get( 'Test2' ), 'Test 2 value', 'Test2 has right value with AUTOLOAD' ); is( $config->get( 'Test10'), 'foo bar baz', 'Test10 has right value with AUTOLOAD' ); # try it one at a time { my $config = $class->new( "t/example.config" ); is( $config->get( 'Test3' ), 'foo', 'Test3 has right value with get(), before global' ); is( $config->get( 'Test2' ), 'Test 2 value', 'Test2 has right value with get(), before global' ); is( $config->get( 'Test10' ), 'foo bar baz', 'Test10 has right value with get), before global' ); my $global = catfile( qw( t global.config ) ); ok( -e $global, "$global exists" ); ok( $config->add_config_file( $global), "Added $global" ); is( $config->get( 'Scope' ), 'Global', "Scope has right value after adding $global" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Now try it with multiple files with one missing $config = $class->new_multiple( Files => [ qw( t/missing.config t/global.config ) ] ); isa_ok( $config, $class ); # get things that do exist is( $config->get( 'Scope' ), 'Global', 'Scope has right value with AUTOLOAD, missing file' ); # config should be undef $config = eval { no strict 'refs'; ${ "${class}::Die" } = 1; $class->new_multiple( Files => [ qw( t/missing.config t/example.config ) ] ); }; like( $@, qr|\QCould not open configuration file [t/missing.config]| ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Now try it with a string { my $string = <<'STRING'; TestA Lear TestB MacBeth TestC Richard STRING $config = $class->new_string( Strings => [ \$string ] ); isa_ok( $config, $class ); is( $config->get( 'TestA' ), 'Lear', 'TestA has right value (from string)' ); is( $config->get( 'TestB' ), 'MacBeth', 'TestB has right value (from string)' ); is( $config->get( 'TestC' ), 'Richard', 'TestC has right value (from string)' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Now try it with a string with a continuation line { my $string = <<'STRING'; TestA King \ Lear TestB MacBeth TestC Richard STRING $config = $class->new_string( Strings => [ \$string ] ); isa_ok( $config, $class ); is( $config->get( 'TestA' ), 'King Lear', 'TestA has right value (from string)' ); is( $config->get( 'TestB' ), 'MacBeth', 'TestB has right value (from string)' ); is( $config->get( 'TestC' ), 'Richard', 'TestC has right value (from string)' ); } ConfigReader-Simple-1.298/t/unparseable.config0000644000076500000240000000000014777037120020223 0ustar brianstaffConfigReader-Simple-1.298/t/set.t0000644000076500000240000000534214777037120015531 0ustar brianstaffuse Test::More tests => 19; use Test::Output; my $class = 'ConfigReader::Simple'; use_ok( $class ); my @Directives = qw( Test1 Test2 Test3 Test4 ); my $config = $class->new( "t/example.config", \@Directives ); isa_ok( $config, $class ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # set things that do exist foreach my $pair ( [ qw(Test1 Foo)] , [ qw(Pagagena Papageno) ], [ qw(Tamino Pamina) ] ) { my $key = $pair->[0]; my $value = $pair->[1]; $config->set( $key, $value ); is( $config->get( $key ), $value, "$key has the right value with get" ); is( $config->$key, $value, "$key has the right value with autoload" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Setting things to references should fail: With $Die set { no warnings 'once'; local $ConfigReader::Simple::Die = 1; my $config = $class->new; isa_ok( $config, $class ); my $rc = eval { $class->set( 'Cat', \ 'Buster' ) }; my $at = $@; ok( length $at, '$@ is set while trying to set with a scalar reference' ); like( $at, qr/must be a simple scalar/ ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Setting things to references should fail: With $Die not set, $Warn set { no warnings 'once'; local $ConfigReader::Simple::Die = undef; local $ConfigReader::Simple::Warn = 1; local $SIG{__WARN__} = sub { print STDERR @_ }; my $config = $class->new; isa_ok( $config, $class ); stderr_like { $class->set( 'Cat', \ 'Buster' ) } qr/must be a simple scalar/, 'set complains when $Warn is set and given a reference'; } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Setting things to references should fail: With $Die not set, $Warn not set { no warnings 'once'; local $ConfigReader::Simple::Die = undef; local $ConfigReader::Simple::Warn = undef; local $SIG{__WARN__} = sub { print STDERR @_ }; my $config = $class->new; isa_ok( $config, $class ); stderr_like { $class->set( 'Cat', \ 'Buster' ) } qr/^$/, 'set silent when $Warn, $Die are unset and given a reference'; } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # unset things that do exist { my $directive = 'Test2'; ok( $config->unset( $directive ), "Unset thing that exists [$directive]" ); my $not_defined = not defined $config->$directive; ok( $not_defined, "Unset thing [$directive] still has value" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # unset things that do not exist { my $directive = 'Tenor'; my $value = not $config->unset( $directive ); ok( $value, 'Unset thing that does not exist [$directive]' ); $value = not $config->exists( $directive ); ok( $value, 'Unset thing that did not exist [$directive] exists' ); } ConfigReader-Simple-1.298/xt/0000755000076500000240000000000014777037121014736 5ustar brianstaffConfigReader-Simple-1.298/xt/changes.t0000644000076500000240000000020314777037120016525 0ustar brianstaffuse Test::More; eval 'use Test::CPAN::Changes'; plan skip_all => 'Test::CPAN::Changes required for this test' if $@; changes_ok(); ConfigReader-Simple-1.298/README.pod0000644000076500000240000001163214777037120015746 0ustar brianstaff=pod =encoding utf8 =for HTML =for HTML =for HTML =for HTML =for HTML Coverage Status =for HTML =for HTML =head1 The ConfigReader::Simple module This is the I for the L Perl module. You're probably looking at this because you don't know where else to find what you're looking for. Read this once and you might never have to read one again for any Perl module. =head2 Documentation To read about L, look at the embedded documentation in the module itself. Inside the distribution, you can format it with L: % perldoc lib/ConfigReader/Simple.pm If you have already installed the module, you can specify the module name instead of the file location: % perldoc ConfigReader::Simple You can read the documentation and inspect the meta data at L. The standard module documentation has example uses in the SYNOPSIS section, but you can also look in the I directory (if it's there), or look at the test files in I. =head2 Installation You can install this module with a CPAN client, which will resolve and install the dependencies: % cpan ConfigReader::Simple % cpanm ConfigReader::Simple You can also install directly from the distribution directory, which will also install the dependencies: % cpan . % cpanm . You could install just this module manually: % perl Makefile.PL % make % make test % make install You probably don't want to do that unless you're fiddling with the module and only want to run the tests without installing anything. =head2 Source location The meta data, such as the source repository and bug tracker, is in I or the I files it creates. You can find that on those CPAN web interfaces, but you can also look at files directly in the source repository: L If you find a problem, file a ticket in the L. There are also backup repositories hosted on other services. These reflect the state of the main repo and exist only for redundancy: =over 4 =item * L =item * L =item * L =back =head2 GitHub Attestations This distribution now uses L, which allow you to verify that the archive file you have was made from the official repo. You need a GitHub account and the L. # download the distro file from GitHub, MetaCPAN, or a CPAN mirror $ gh auth login ...follow instructions... $ gh attestation verify ConfigReader-Simple-1.23.tar.gz --owner briandfoy =head2 Getting help Although I'm happy to hear from module users in private email, that's the best way for me to forget to do something. Besides the issue trackers, you can find help at L or L, both of which have many competent Perlers who can answer your question, almost in real time. They might not know the particulars of this module, but they can help you diagnose your problem. You might like to read L. =head2 Copyright and License You should have received a I file, but the license is also noted in the module files. About the only thing you can't do is pretend that you wrote code that you didn't. =head2 Good luck! Enjoy, brian d foy, briandfoy@pobox.com =cut ConfigReader-Simple-1.298/MANIFEST.SKIP0000644000076500000240000000215514777037120016203 0ustar brianstaff #!start included /usr/local/perls/perl-5.20.0/lib/5.20.0/ExtUtils/MANIFEST.SKIP # Avoid version control files. \bRCS\b \bCVS\b \bSCCS\b ,v$ \B\.svn\b \B\.git\b \B\.gitignore\b \b_darcs\b \B\.cvsignore$ # Avoid VMS specific MakeMaker generated files \bDescrip.MMS$ \bDESCRIP.MMS$ \bdescrip.mms$ # Avoid Makemaker generated and utility files. \bMANIFEST\.bak \bMakefile$ \bblib/ \bMakeMaker-\d \bpm_to_blib\.ts$ \bpm_to_blib$ \bblibdirs\.ts$ # 6.18 through 6.25 generated this # Avoid Module::Build generated and utility files. \bBuild$ \b_build/ \bBuild.bat$ \bBuild.COM$ \bBUILD.COM$ \bbuild.com$ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# \.bak$ \.tmp$ \.# \.rej$ # Avoid OS-specific files/dirs # Mac OSX metadata \B\.DS_Store # Mac OSX SMB mount metadata files \B\._ # Avoid Devel::Cover and Devel::CoverX::Covered files. \bcover_db\b \bcovered\b # Avoid MYMETA files ^MYMETA\. #!end included /usr/local/perls/perl-5.20.0/lib/5.20.0/ExtUtils/MANIFEST.SKIP \.?appveyor.yml \.releaserc \.lwpcookies ConfigReader-Simple-* \.svncover_db \bMANIFEST\s\d \bChanges\s\d \.icloud$ \A\.github\b \.gitattributes\b ConfigReader-Simple-1.298/examples/0000755000076500000240000000000014777037121016121 5ustar brianstaffConfigReader-Simple-1.298/examples/README0000644000076500000240000000010514777037120016774 0ustar brianstaffSee the tests in the t/ directory for examples until I add some more.ConfigReader-Simple-1.298/META.yml0000664000076500000240000000200314777037121015551 0ustar brianstaff--- abstract: 'A simple line-oriented configuration file parser' author: - 'brian d foy ' build_requires: Test::More: '1' Test::Output: '0' Test::Warn: '0' version: '0.86' configure_requires: ExtUtils::MakeMaker: '6.64' File::Spec::Functions: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010' keywords: - config license: artistic_2 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: ConfigReader-Simple no_index: directory: - t - inc requires: Carp: '0' Data::Dumper: '0' File::Spec: '0' File::Spec::Functions: '0' perl: '5.008' strict: '0' subs: '0' vars: '0' warnings: '0' resources: bugtracker: https://github.com/briandfoy/ConfigReader-Simple/issues homepage: https://github.com/briandfoy/ConfigReader-Simple repository: https://github.com/briandfoy/ConfigReader-Simple version: '1.298' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' ConfigReader-Simple-1.298/lib/0000755000076500000240000000000014777037121015051 5ustar brianstaffConfigReader-Simple-1.298/lib/ConfigReader/0000755000076500000240000000000014777037121017401 5ustar brianstaffConfigReader-Simple-1.298/lib/ConfigReader/Simple.pm0000644000076500000240000004165214777037120021177 0ustar brianstaffpackage ConfigReader::Simple; use strict; use warnings; no warnings; use subs qw(_init_errors); use vars qw($VERSION $AUTOLOAD %ERROR $ERROR $Warn $Die); use Carp qw(croak carp); $ERROR = ''; $VERSION = '1.298'; $Warn = 0; $Die = ''; our $DEBUG = 0; my $Error = ''; sub SUCCESS() { 1 }; sub FAILURE() { 0 }; =encoding utf8 =head1 NAME ConfigReader::Simple - A simple line-oriented configuration file parser =head1 SYNOPSIS use ConfigReader::Simple; # parse one file $config = ConfigReader::Simple->new("configrc", [qw(Foo Bar Baz Quux)]); # parse multiple files, in order $config = ConfigReader::Simple->new_multiple( Files => [ "global", "configrc" ], Keys => [qw(Foo Bar Baz Quux)] ); my @directives = $config->directives; $config->get( "Foo" ); if( $config->exists( "Bar" ) ) { print "Bar was in the config file\n"; } # copy an object to play with it separately my $clone = $config->clone; # only affects clone $clone->set( "Foo", "Buster" ); # save the config to a single file $clone->save( "configrc" ) # save the config to a single file, but only with # certain directives $clone->save( "configrc" => [qw(Foo Bar)] ) # save to multiple configuration files $clone->save( "configrc" => [qw(Foo Bar)], "global" => [qw(Baz Quux)], ); =head1 DESCRIPTION C reads and parses simple configuration files. It is designed to be smaller and simpler than the C module and is more suited to simple configuration files. =head2 The configuration file format The configuration file uses a line-oriented format, meaning that the directives do not have containers. The values can be split across lines with a continuation character, but for the most part everything ends up on the same line. The first group of non-whitespace characters is the "directive", or the name of the configuration item. The linear whitespace after that separates the directive from the "value", which is the rest of the line, including any other whitespace. In this example, the directive is "Camel" and the value is "Dromedary". Camel Dromedary Optionally, you can use a equal sign to separate the directive from the value. Camel=Dromedary The equal sign can also have whitespace on either or both sides. Camel = Dromedary Camel= Dromedary In the next example, the directive is "Llama" and the value is "Live from Peru" Llama Live from Peru This is the same, to C, as the following which has more whitespace between the directive and the value. Llama Live from Peru You can also enclose the value in single or double quotes. Llama "Live from Peru" Llama 'Live from Peru' Llama='Live from Peru' In some cases you may want to split the logical line across two lines, perhaps to see it better in a terminal window. For that, use a \ followed only by whitespace. To split the last entry across two lines, we use the \ at the end of the line. These three entries are the same: Llama Live from Peru Llama Live from \ Peru Llama Live \ from \ Peru If a line is only whitespace, or the first non-whitespace character is a #, the Perl comment character, C ignores the line unless it is the continuation of the previous line. =head2 Methods =over 4 =item new ( FILENAME, DIRECTIVES ) Creates a C object. C tells the instance where to look for the configuration file. If FILENAME cannot be found, an error message for the file is added to the %ERROR hash with the FILENAME as a key, and a combined error message appears in $ERROR. C is an optional argument and is a reference to an array. Each member of the array should contain one valid directive. A directive is the name of a key that must occur in the configuration file. If it is not found, the method croaks. The directive list may contain all the keys in the configuration file, a sub set of keys or no keys at all. The C method is really a wrapper around C. =cut sub new { my $class = shift; my $filename = shift; my $keyref = shift; $keyref = [] unless defined $keyref; my $self = $class->new_multiple( Files => [ defined $filename ? $filename : () ], Keys => $keyref ); return $self; } =item new_multiple( Files => ARRAY_REF, Keys => ARRAY_REF ) Create a configuration object from several files listed in the anonymous array value for the C key. The module reads the files in the same order that they appear in the array. Later values override earlier ones. This allows you to specify global configurations which you may override with more specific ones: ConfigReader::Simple->new_multiple( Files => [ qw( /etc/config /usr/local/etc/config /home/usr/config ) ], ); This function croaks if the values are not array references. If this method cannot read a file, an error message for that file is added to the C<%ERROR> hash with the filename as a key, and a combined error message appears in C<$ERROR>. Processing the list of filenames continues if a file cannot be found, which may produced undesired results. You can disable this feature by setting the C<$ConfigReader::Simple::Die> variable to a true value. =cut sub new_multiple { _init_errors(); my $class = shift; my %args = @_; my $self = {}; $args{'Keys'} = [] unless defined $args{'Keys'}; croak( __PACKAGE__ . ': Files argument must be an array reference') unless ref $args{'Files'} eq ref []; croak( __PACKAGE__ . ': Keys argument must be an array reference') unless ref $args{'Keys'} eq ref []; $self->{"filenames"} = $args{'Files'}; $self->{"validkeys"} = $args{'Keys'}; bless $self, $class; foreach my $file ( @{ $self->{"filenames"} } ) { my $result = $self->parse( $file ); croak $Error if( not $result and $Die ); $ERROR{$file} = $Error unless $result; } $ERROR = join "\n", map { $ERROR{$_} } keys %ERROR; return $self; } =item new_string( Strings => ARRAY_REF, Keys => ARRAY_REF ) Create a configuration object from several strings listed in the anonymous array value for the C key. The module reads the strings in the same order that they appear in the array. Later values override earlier ones. This allows you to specify global configurations which you may override with more specific ones: ConfigReader::Simple->new_strings( Strings => [ \$global, \$local ], ); This function croaks if the values are not array references. =cut sub new_string { _init_errors; my $class = shift; my %args = @_; my $self = {}; $args{'Keys'} = [] unless defined $args{'Keys'}; croak( __PACKAGE__ . ': Strings argument must be an array reference') unless ref $args{'Strings'} eq ref []; croak( __PACKAGE__ . ': Keys argument must be an array reference') unless ref $args{'Keys'} eq ref []; bless $self, $class; $self->{"strings"} = $args{'Strings'}; $self->{"validkeys"} = $args{'Keys'}; foreach my $string_ref ( @{ $self->{"strings"} } ) { croak( __PACKAGE__ . ': Element of Strings is not a scalar reference' ) unless ref $string_ref eq ref \ ''; $self->parse_string( $string_ref ); } return $self; } =item add_config_file( FILENAME ) Parse another configuration file and add its directives to the current configuration object. Any directives already defined will be replaced with the new values found in FILENAME. =cut sub add_config_file { _init_errors; my( $self, $filename ) = @_; return unless $self->parse( $filename ); push @{ $self->{"filenames"} }, $filename; return 1; } =item files Return the list of configuration files associated with this object. The order of the return values is the order of parsing, so the first value is the first file parsed (and subsequent files may mask it). =cut sub files { @{ $_[0]->{"filenames"} } } =item new_from_prototype( Create a clone object. This is the same thing as calling clone(). =cut sub new_from_prototype { _init_errors; my $self = shift; my $clone = $self->clone; return $clone; } sub AUTOLOAD { my $self = shift; my $method = $AUTOLOAD; $method =~ s/.*:://; $self->get( $method ); } sub DESTROY { return 1; } =item parse( FILENAME ) This does the actual work. This is automatically called from C, although you can reparse the configuration file by calling C again. =cut sub parse { my( $self, $file ) = @_; $Error = ''; unless( open CONFIG, $file ) { $Error = "Could not open configuration file [$file]: $!"; carp $Error if $Warn; return; } $self->{"file_fields"}{$file} = []; while( ) { if ( s/\\ \s* $//x ) { $_ .= ; redo unless eof CONFIG; } chomp; next if /^\s*(#|$)/; my ($key, $value) = &parse_line($_); #carp "Key: '$key' Value: '$value'\n" if $DEBUG; $self->{"config_data"}{$key} = $value; push @{ $self->{"file_fields"}{$file} }, $key; } close(CONFIG); $self->_validate_keys; return 1; } =item parse_string( SCALAR_REF ) Parses the string inside the reference SCALAR_REF just as if it found it in a file. =cut sub parse_string { my $self = shift; my $string = shift; my @lines = split /\r?\n/, $$string; chomp( @lines ); # carp "A: Found " . @lines . " lines" if $DEBUG; while( defined( my $line = shift @lines )) { # carp "1: Line is $line" if $DEBUG; CONT: { if ( $line =~ s/\\ \s* $//x ) { # carp "a: reading continuation line $lines[0]" if $DEBUG; $line .= shift @lines; # carp "b: Line is $line" if $DEBUG; redo CONT unless @lines == 0; } } # carp "2: Line is $line" if $DEBUG; chomp $line; next if $line =~ /^\s*(#|$)/; # carp "3: Line is $line" if $DEBUG; my ($key, $value) = &parse_line( $line ); # carp "Key: '$key' Value: '$value'" if $DEBUG; $self->{"config_data"}{$key} = $value; } $self->_validate_keys; return 1; } =item get( DIRECTIVE ) Returns the parsed value for that directive. For directives which did not have a value in the configuration file, C returns the empty string. =cut sub get { $_[0]->{"config_data"}{$_[1]} } =item set( DIRECTIVE, VALUE ) Sets the value for DIRECTIVE to VALUE. The DIRECTIVE need not already exist. This overwrites previous values. The VALUE must be a simple scalar. It cannot be a reference. If the VALUE is a reference, the function prints a warning and returns false. =cut sub set { my $self = shift; my( $key, $value ) = @_; if( ref $value ) { $ERROR = "Second argument to set must be a simple scalar"; if( $Warn ) { carp $ERROR; return; } elsif( $Die ) { croak $ERROR; } return; } $self->{"config_data"}{$key} = $value; } =item unset( DIRECTIVE ) Remove the value from DIRECTIVE, which will still exist. It's value is undef. If the DIRECTIVE does not exist, it will not be created. Returns FALSE if the DIRECTIVE does not already exist, and TRUE otherwise. =cut sub unset { my $self = shift; my $key = shift; return unless $self->exists( $key ); $self->{"config_data"}{$key} = undef; return 1; } =item remove( DIRECTIVE ) Remove the DIRECTIVE. Returns TRUE is DIRECTIVE existed and FALSE otherwise. =cut sub remove { my $self = shift; my $key = shift; return unless $self->exists( $key ); delete $self->{"config_data"}{$key}; return 1; } =item directives() Returns a list of all of the directive names found in the configuration file. The keys are sorted ASCII-betically. =cut sub directives { my $self = shift; my @keys = sort keys %{ $self->{"config_data"} }; return @keys; } =item exists( DIRECTIVE ) Return TRUE if the specified directive exists, and FALSE otherwise. =cut sub exists { my $self = shift; my $name = shift; return CORE::exists $self->{"config_data"}{ $name }; } =item clone Return a copy of the object. The new object is distinct from the original so you can make changes to the new object without affecting the old one. =cut # this is only the first stab at this -- from 35,000 # feet in coach class # # I expect that the hash will be very simple. Some keys # might have a reference value, but that reference value # will be "flat", so it won't have references in it. sub clone { my $self = shift; my $clone = bless {}, ref $self; $clone->{"filenames"} = [ @{ $self->{"filenames"} } ]; $clone->{"validkeys"} = [ @{ $self->{"validkeys"} } ]; foreach my $file ( keys %{ $self->{"file_fields"} } ) { $clone->{"file_fields"}{ $file } = [ @{ $self->{"file_fields"}{ $file } } ]; } foreach my $key ( $self->directives ) { $clone->set( $key, $self->get( $key ) ); } return $clone; } =item save( FILENAME [ => ARRAY_REF [, FILENAME => ARRAY_REF ] ] ); The save method works in three ways, depending on the argument list. With a single argument, the save function attempts to save all of the field-value pairs of the object to the file named by the argument. $clone->save( "configrc" ); With two arguments, the method expects the second argument to be an array reference which lists the directives to save in the file. $clone->save( "configrc" => [qw(Foo Bar)] ); With more than two arguments, the method expects filename-list pairs. The method will save in each file the values in their respective array references. $clone->save( "configrc" => [qw(Foo Bar)], "global" => [qw(Baz Quux)], ); In the last two cases, the method checks that the value for each pair is an array reference before it affects any files. It croaks if any value is not an array reference. Once the method starts writing files, it tries to write all of the specified files. Even if it has a problem with one of them, it continues onto the next one. The method does not necessarily write the files in the order they appear in the argument list, and it does not check if you specified the same file twice. =cut sub save { my $self = shift; my @args = @_; if( @args == 0 ) { # no args! carp "No arguments to method!"; return; } if( @args == 1 ) { # this is a single file push @args, [ $self->directives ]; } unless( @args % 2 == 0 ) { croak "Odd number of arguments" }; my %hash = @args; foreach my $value ( values %hash ) { croak "Argument is not an array reference" unless ref $value eq ref []; } foreach my $file ( keys %hash ) { carp $ERROR unless $self->_save( $file, $hash{$file} ); } 1; } sub _save { my( $self, $file, $directives ) = @_; unless( ref $directives eq ref [] ) { $ERROR = 'Argument is not an array reference'; return; } my $fh; unless( open $fh, ">", $file ) { $ERROR = $!; return; } foreach my $directive ( @$directives ) { print $fh ( join( "\t", $directive, $self->get( $directive ) ), "\n" ); } return SUCCESS; } =begin private =item parse_line( STRING ) Internal method. Don't call this directly. Takes a line of text and turns it into the directive and value. =end private =cut sub parse_line { return ( $1, $3 ) if $_[0] =~ / ^\s* ( [^\s=]+ ) \s* [=]? \s* (['"]?) (.*?) \2 \s* $/x; croak "Config: Can't parse line: $_[0]\n"; } sub _init_errors { %ERROR = (); $Error = undef; $ERROR = undef; } =begin private =item _validate_keys If any keys were declared when the object was constructed, check that those keys actually occur in the configuration file. This function croaks if a declared key does not exist. =end private =cut sub _validate_keys { my $self = shift; return SUCCESS unless exists $self->{"validkeys"}; croak "validkeys was not an array reference!" unless ref $self->{"validkeys"} eq ref []; my @keys = eval { @{ $self->{"validkeys"} } }; my @missing = grep { ! exists $self->{"config_data"}{$_} }@keys; croak "Config: required keys [@missing] do not occur in config" if @missing; return SUCCESS; } =back =head2 Package variables =over 4 =item $Die - DEPRECATED If set to a true value, all errors are fatal. =item $ERROR The last error message. =item %ERROR The error messages from unreadable files. The key is the filename and the value is the error message. =item $Warn - DEPRECATED If set to a true value, methods may output warnings. =back =head1 LIMITATIONS/BUGS Directives are case-sensitive. If a directive is repeated, the first instance will silently be ignored. =head1 CREDITS Bek Oberin C<< >> wote the original module Kim Ryan C<< >> adapted the module to make declaring keys optional. Thanks Kim. Alan W. Jurgensen C<< >> added a change to allow the NAME=VALUE format in the configuration file. Andy Lester, C<< >>, for maintaining the module while brian was on active duty. Adam Trickett, C<< >>, added multi-line support. You might want to see his C module. Greg White has been a very patient user and tester. =head1 SOURCE AVAILABILITY The source is in Github: http://github.com/briandfoy/configreader-simple/ =head1 AUTHORS brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright © 2002-2025, brian d foy . All rights reserved. This program is free software; you can redistribute it and/or modify it under the Artistic License 2.0. =cut 1; ConfigReader-Simple-1.298/Makefile.PL0000644000076500000240000000573414777037120016265 0ustar brianstaffpackage ConfigReader::Simple; use strict; use warnings; =encoding utf8 =head1 The build file for ConfigReader::Simple This build file is a modulino; it works as both a build script and a module. To build the distribution, run this file normally: % perl Makefile.PL But, it's more interesting than that. You can load it with C and call C to get the data structure it passes to C: my $package = require '/path/to/Makefile.PL'; my $arguments = $package->arguments; Note that C-ing a file makes an entry in C<%INC> for exactly that name. If you try to C another file with the same name, even from a different path, C thinks it has already loaded the file. As such, I recommend you always require the full path to the file. The return value of the C is a package name (in this case, the name of the main module. Use that to call the C method. Even if this distribution needs a higher version of Perl, this bit only needs v5.8. You can play with the data structure with a primitive Perl. =cut use File::Spec::Functions qw(catfile); my $module = __PACKAGE__; ( my $dist = $module ) =~ s/::/-/g; my $github = 'https://github.com/briandfoy/ConfigReader-Simple'; my $main_file = catfile( 'lib', split /::/, "$module.pm" ); my %WriteMakefile = ( 'MIN_PERL_VERSION' => '5.008', 'NAME' => $module, 'VERSION_FROM' => $main_file, 'ABSTRACT_FROM' => $main_file, 'LICENSE' => 'artistic_2', 'AUTHOR' => 'brian d foy ', 'CONFIGURE_REQUIRES' => { 'ExtUtils::MakeMaker' => '6.64', 'File::Spec::Functions' => '0', }, 'BUILD_REQUIRES' => { }, 'TEST_REQUIRES' => { 'Test::More' => '1', 'Test::Warn' => '0', 'Test::Output' => '0', 'version' => '0.86', }, 'PREREQ_PM' => { 'Carp' => '0', 'Data::Dumper' => '0', 'File::Spec' => '0', 'File::Spec::Functions' => '0', 'strict' => '0', 'subs' => '0', 'vars' => '0', 'warnings' => '0', }, 'META_MERGE' => { 'meta-spec' => { version => 2 }, keywords => ['config'], resources => { repository => { type => 'git', url => $github, web => $github, }, bugtracker => { web => "$github/issues", }, homepage => $github, }, }, clean => { FILES => "$dist-*" }, ); sub arguments { \%WriteMakefile } do_it() unless caller; sub do_it { require File::Spec; my $MM ='ExtUtils::MakeMaker'; my $MM_version = eval{ "$MM " . $WriteMakefile{'CONFIGURE_REQUIRES'}{'ExtUtils::MakeMaker'} } || "$MM 6.64"; eval "use $MM_version; 1" or die "Could not load $MM_version: $@"; eval "use Test::Manifest 1.21" if -e File::Spec->catfile( qw(t test_manifest) ); my $arguments = arguments(); my $minimum_perl = $arguments->{MIN_PERL_VERSION} || '5.008'; eval "require $minimum_perl;" or die $@; WriteMakefile( %$arguments ); } no warnings; __PACKAGE__; ConfigReader-Simple-1.298/eg/0000755000076500000240000000000014777037121014676 5ustar brianstaffConfigReader-Simple-1.298/eg/config_creator.pl0000644000076500000240000000202514777037120020215 0ustar brianstaff#!/usr/bin/perl =head1 NAME config_creator.pl - read a configuration description and prompt for value =head1 SYNOPSIS config_creator.pl description_file =head1 DESCRIPTION The config_creator.pl program reads a configuration description file and then prompts the user for values, creating a configuration file in the process. =head1 SOURCE AVAILABILITY The source is in Github: http://github.com/briandfoy/configreader-simple/ =head1 AUTHORS brian d foy, Ebriandfoy@pobox.comE =head1 COPYRIGHT Copyright © 2002-2024, brian d foy . All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut my $config = ''; while( <> ) { next if m/\s*#/; chomp; my( $directive, $description ) = split m/\s+/, $_, 2; my $answer = prompt( $description ); $config .= "$directive $answer\n"; } print $config; sub prompt maps { my $message = shift; print "$message> "; my $answer = ; chomp $answer; return $answer; } ConfigReader-Simple-1.298/eg/example.pl0000755000076500000240000000067214777037120016675 0ustar brianstaff#!/usr/bin/perl -w # # Testing ConfigReader::Simple # # Last updated by gossamer on Tue Sep 1 22:43:42 EST 1998 # use ConfigReader::Simple; my $config = ConfigReader::Simple->new("./example.config", [qw(Test1 Test2)]); $config->parse(); $config->_validate_keys(); # die if there are keys in example.config # that aren't declared. print "The value for directive Test1 is: " . $config->get("Test1") . "\n"; ConfigReader-Simple-1.298/eg/config.desc0000644000076500000240000000014314777037120017000 0ustar brianstaffCamel What is the name of the camel? Llama Where is the home of the llama? Sum What is two and two?ConfigReader-Simple-1.298/INSTALL.SKIP0000644000076500000240000000015614777037120016102 0ustar brianstaffREADME\.pod README.* # things that might be in local directories after fooling # around with them \.DS_Store ConfigReader-Simple-1.298/SECURITY.md0000644000076500000240000000231514777037120016074 0ustar brianstaff# Security Policy for ConfigReader::Simple ## Reporting security issues **Do not report security problems on public forums or in repository issues.** Privately report vulnerabilities to the maintainers listed at the end of this document. Include as many details as possible to reproduce the issue, including code samples or test cases. Check that your report does not expose any of your sensitive data, such as passwords, tokens, or other secrets. You do not need to have a solution or fix. Depending on the issue, CPANSec may be notified. Depending on the issue, CPANSec may be notified. You can also privately report issues to the CPAN Security Group (CPANSec) . This is especially important if you think a vulnerability is being actively exploited. CPANSec may report the issue to the relevant authorities. See [Report a Security Issue](https://security.metacpan.org/docs/report.html). ## Response to reports The maintainers aim to respond to all reports within one day, but this may be affected by life and other things that happen to people who maintain open source code. A new release will be provided as soon as possible. ## Maintainers * brian d foy, ConfigReader-Simple-1.298/META.json0000664000076500000240000000344314777037122015733 0ustar brianstaff{ "abstract" : "A simple line-oriented configuration file parser", "author" : [ "brian d foy " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010", "keywords" : [ "config" ], "license" : [ "artistic_2" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "ConfigReader-Simple", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : {} }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.64", "File::Spec::Functions" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Data::Dumper" : "0", "File::Spec" : "0", "File::Spec::Functions" : "0", "perl" : "5.008", "strict" : "0", "subs" : "0", "vars" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Test::More" : "1", "Test::Output" : "0", "Test::Warn" : "0", "version" : "0.86" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/briandfoy/ConfigReader-Simple/issues" }, "homepage" : "https://github.com/briandfoy/ConfigReader-Simple", "repository" : { "type" : "git", "url" : "https://github.com/briandfoy/ConfigReader-Simple", "web" : "https://github.com/briandfoy/ConfigReader-Simple" } }, "version" : "1.298", "x_serialization_backend" : "JSON::PP version 4.16" }