Config-Tiny-2.20000755001750001750 012244240043 12335 5ustar00ronron000000000000Config-Tiny-2.20/Changelog.ini000444001750001750 1475012244240043 15111 0ustar00ronron000000000000[Module] Name=Config-Tiny: Changelog.Creator=Module::Metadata::Changes V 2.05 Changelog.Parser=Config::IniFiles V 2.82 [V 2.20] Date=2013-11-24T10:52:00 Comments=- Relax pre-req version requirements [V 2.19] Date=2013-09-15T09:16:00 Comments= < $VERSION in Makefile.PL to VERSION_FROM => 'lib/Config/Tiny.pm'. Reported by Jean-Louis Morel. See RT#88670. EOT [V 2.18] Date=2013-09-14T10:03:00 Comments= < newdir('temp.XXXX', CLEANUP => 1, EXLOCK => 0, TMPDIR => 1); - Rename t/*.t files. I use '.' rather than '_' in file names because the latter is a shift char. - Add MANIFEST.SKIP, Changelog.ini, Build.PL, META.json. - Add an FAQ to the docs. - Clean up the docs. EOT [V 2.14] Date=2011-03-24T12:00:00 Comments= <write() it was erroneous - Removed dependency on Fcntl - Added the read_string() method - Other minor tweaks to shrink the code EOT [V 0.3] Date=2002-12-09T00:44:21 Comments= < $VERSION in Makefile.PL to VERSION_FROM => 'lib/Config/Tiny.pm'. Reported by Jean-Louis Morel. See RT#88670. 2.18 Sat Sep 14 10:03:00 2013 - Remove obsolete and wrong version # from Makefile.PL. Reported by Jean-Louis Morel. See RT#88658. - Implement Kevin Ryde's suggestion to test if read() will return undef. If so, set an error message and (still) return undef. 2.17 Fri Sep 13 12:41:00 2013 - Remove the file tests -efr during calls to read(). The open() tests for any error. Also, the -f test was reporting /dev/null as a directory, not a file. Thanx to Kevin Ryde for pushing me to implement this. See RT#36974. - Clean up some error messages slightly. 2.16 Fri Sep 6 11:54:00 2013 - Replace Path::Tiny with File::Spec, because the former's list of dependencies is soooo long :-(. Changed files: t/02.main.t, t/04.utf8.t, Build.PL and Makefile.PL. See: RT#88435 (for Tree::DAG_Node) for an explanation. 2.15 Sun Aug 4 14:59:00 2013 - Clean up the shambolic dates in this file. - Add a note under Caveats about setting options more that once. Only the first case is respected. Thanx to Kimmel K. See RT#69795. - Add a $encoding parameter to read_file() and write_file(). See docs for details. Add t/04.utf8.t and t/04.utf8.txt. Thanx to Mark Lawrence and Wolfgang Husmann. See RT#71029 and RT#85571. - For BSD-based systems, when writing a file during tests, use: my($temp_dir) = File::Temp -> newdir('temp.XXXX', CLEANUP => 1, EXLOCK => 0, TMPDIR => 1); - Rename t/*.t files. I use '.' rather than '_' in file names because the latter is a shift char. - Add MANIFEST.SKIP, Changelog.ini, Build.PL, META.json. - Add an FAQ to the docs. - Clean up the docs. 2.14 Thu Mar 24 12:00:00 2011 - Resolved #63080: module can write multiline values but not read them - Removed -w from tests to allow tests with tainting on 2.13 Fri Sep 3 12:00:00 2010 - Resolved #60703: Display glitch in Config::Tiny 2.12 POD - Resolved #40585: member 'set;' doesn't exist - Resolved #30479: does not warn or die when writing data it cannot later. 2.12 Thu Nov 1 12:00:00 2007 - Converting build script from Module::Install to tinier EU:MM 2.10 Sat Sep 20 12:00:00 2006 - This release contains only build-time changes - Did a little housekeeping on Makefile.PL and the unit tests - Upgrading to Module::Install 0.64 2.09 Sat Jul 15 12:00:00 2006 - This release contains only build-time changes - Added a dependency on ExtUtils::MakeMaker 6.11 Module::Install may have an issue with older EU:MM installs 2.08 Sat 15 Jul 12:00:00 2006 - This release contains only build-time changes - Upgraded to Module::Install 0.63 2.07 Wed May 10 12:00:00 2006 - This release contains only build-time changes - AutoInstall is only needed for options, so remove auto_install 2.06 Sun Apr 23 12:00:00 2006 - No functional changes. - Moved test.conf to the root dir, removing last use of File::Spec - It also means we don't need FindBin, so removed that too - Upgrading to Module::Install 0.62 2.05 Thu Feb 23 12:00:00 2006 - No functional changes. - Moved over from the old CVS repository to the new SVN one - Updated tests for the new release system - Upgrading to a newer Module::Install 2.04 Sat Dec 31 12:00:00 2005 - No functional changes. - Upgrading to a newer Module::Install to address Cygwin problem 2.03 Fri Dec 30 12:00:00 2005 - No functional changes. - POD Change: CPAN #15143 Clear things up about $! after unsuccessful read()? (flatworm) - Upgraded Makefile.PL to use Module::Install 2.02 Sun Jun 19 12:00:00 2005 - Add trimming of whitespace from the section names so that we can use section tags like [ section ] and have it Do What You Mean. - Cleaned up the POD a little more. 2.01 Thu Mar 24 12:00:00 2005 - Lars Thegler noted in CSS::Tiny that 3-argument open is not supported by 5.005. Added a small fix to change it to 2-argument open. 2.00 Fri Jul 16 12:00:00 2004 - Final tweaks to round out complete 5.004 and Win32 compatibility 1.9 Wed Jul 7 12:00:00 2004 - Applied some small optimisations from Japheth Cleaver 1.8 Wed Jun 30 12:00:00 2004 - Fixed a bug whereby trying to load an empty file returned an error, when it should be valid (if an empty object) 1.7 Tue Jun 22 12:00:00 2004 - Added a little more flexibility in the 'read' and 'read_string' methods to handle being called in unexpected, but recoverable, ways. 1.6 Mon Mar 1 12:00:00 2004 - Bug fix: Sections without keys didn't appear at all in the parsed struct 1.5 Wed Jan 7 12:00:00 2004 - Updating documentation to provide a correct location to send bug reports 1.4 Wed Dec 24 12:00:00 2003 - Caught a warning when trying to parse an undefined string. Returns undef in that case. - Merry Christmas and a productive New Year to you all! 1.3 Fri Nov 7 12:00:00 2003 - Slightly altered a regex so that trailing whitespace in properties is dropped. 1.2 Wed Aug 12 15:51:12 2003 - Applied a variety of small changed designed to reduce the number of opcodes generated, without changing the functionality. This should save a few K in load overhead. 1.1 Wed Apr 23 22:56:21 2003 - When reporting a bad line, put single quotes around the lines contents in the error message. - Small updates to the pod documentation 1.0 Sat Dec 21 11:53:51 2002 - Removed file locking, since we read/write virtually atomically now - Removed mode support from ->write() it was erroneous - Removed dependency on Fcntl - Added the read_string() method - Other minor tweaks to shrink the code 0.3 Mon Dec 09 00:44:21 2002 - Upgraded tests to Test::More, to deep test the structs - Added Fcntl to the required modules 0.2 Tue Nov 26 21:51:34 2002 - Don't import Fcntl symbols 0.1 Wed Nov 13 16:50:23 2002 - original version Config-Tiny-2.20/Makefile.PL000444001750001750 274712244240043 14456 0ustar00ronron000000000000use strict; use warnings; BEGIN { require 5.008001; } use ExtUtils::MakeMaker; WriteMakefile1( META_MERGE => { resources => { repository => 'http://svn.ali.as/cpan/trunk/Config-Tiny', }, }, BUILD_REQUIRES => { # Skip on Windows to avoid breaking ActivePerl PPMs # 0.47 means 5.6.2 or newer, which everyone on Win32 has. ($^O eq 'MSWin32' ? () : ('Test::More' => '0.47')), }, NAME => 'Config::Tiny', ABSTRACT => 'Read/Write .ini style files with as little code as possible', VERSION_FROM => 'lib/Config/Tiny.pm', PREREQ_PM => { 'File::Spec' => 3.30, 'File::Temp' => 0.22, 'perl' => '5.8.1', # For the utf stuff. 'strict' => 0, 'UNIVERSAL' => 0, 'utf8' => 0, }, AUTHOR => 'Adam Kennedy ', LICENSE => 'perl', ); # Written by Alexandr Ciornii, version 0.20. Added by eumm-upgrade. sub WriteMakefile1 { my %params = @_; my $eumm_version = $ExtUtils::MakeMaker::VERSION; $eumm_version = eval $eumm_version; die "License not specified" if not exists $params{LICENSE}; if ($params{BUILD_REQUIRES} and $eumm_version < 6.5503) { #EUMM 6.5502 has problems with BUILD_REQUIRES $params{PREREQ_PM}={ %{$params{PREREQ_PM} || {}} , %{$params{BUILD_REQUIRES}} }; delete $params{BUILD_REQUIRES}; } delete $params{MIN_PERL_VERSION} if $eumm_version < 6.48; delete $params{META_MERGE} if $eumm_version < 6.46; delete $params{LICENSE} if $eumm_version < 6.31; delete $params{AUTHOR} if $] < 5.005; WriteMakefile(%params); } Config-Tiny-2.20/README000444001750001750 1114112244240043 13370 0ustar00ronron000000000000NAME Config::Tiny - Read/Write .ini style files with as little code as possible SYNOPSIS # In your configuration file rootproperty=blah [section] one=twp three= four Foo =Bar empty= # In your program use Config::Tiny; # Create a config my $Config = Config::Tiny->new; # Open the config $Config = Config::Tiny->read( 'file.conf' ); # Reading properties my $rootproperty = $Config->{_}->{rootproperty}; my $one = $Config->{section}->{one}; my $Foo = $Config->{section}->{Foo}; # Changing data $Config->{newsection} = { this => 'that' }; # Add a section $Config->{section}->{Foo} = 'Not Bar!'; # Change a value delete $Config->{_}; # Delete a value or section # Save a config $Config->write( 'file.conf' ); DESCRIPTION "Config::Tiny" is a perl class to read and write .ini style configuration files with as little code as possible, reducing load time and memory overhead. Most of the time it is accepted that Perl applications use a lot of memory and modules. The "::Tiny" family of modules is specifically intended to provide an ultralight alternative to the standard modules. This module is primarily for reading human written files, and anything we write shouldn't need to have documentation/comments. If you need something with more power move up to Config::Simple, Config::General or one of the many other "Config::" modules. To rephrase, Config::Tiny does not preserve your comments, whitespace, or the order of your config file. CONFIGURATION FILE SYNTAX Files are the same format as for windows .ini files. For example: [section] var1=value1 var2=value2 If a property is outside of a section at the beginning of a file, it will be assigned to the "root section", available at "$Config->{_}". Lines starting with '#' or ';' are considered comments and ignored, as are blank lines. When writing back to the config file, all comments, custom whitespace, and the ordering of your config file elements is discarded. If you need to keep the human elements of a config when writing back, upgrade to something better, this module is not for you. METHODS new The constructor "new" creates and returns an empty "Config::Tiny" object. read $filename The "read" constructor reads a config file, and returns a new "Config::Tiny" object containing the properties in the file. Returns the object on success, or "undef" on error. When "read" fails, "Config::Tiny" sets an error message internally you can recover via "Config::Tiny->errstr". Although in some cases a failed "read" will also set the operating system error variable $!, not all errors do and you should not rely on using the $! variable. read_string $string; The "read_string" method takes as argument the contents of a config file as a string and returns the "Config::Tiny" object for it. write $filename The "write" method generates the file content for the properties, and writes it to disk to the filename specified. Returns true on success or "undef" on error. write_string Generates the file content for the object and returns it as a string. errstr When an error occurs, you can retrieve the error message either from the $Config::Tiny::errstr variable, or using the "errstr()" method. CAVEATS Unsupported Section Headers Some edge cases in section headers are not support, and additionally may not be detected when writing the config file. Specifically, section headers with leading whitespace, trailing whitespace, or newlines anywhere in the section header, will not be written correctly to the file and may cause file corruption. SUPPORT Bugs should be reported via the CPAN bug tracker at For other issues, or commercial enhancement or support, contact the author. AUTHOR Adam Kennedy ACKNOWLEGEMENTS Thanks to Sherzod Ruzmetov for Config::Simple, which inspired this module by being not quite "simple" enough for me :) SEE ALSO Config::Simple, Config::General, ali.as COPYRIGHT Copyright 2002 - 2011 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. Config-Tiny-2.20/META.yml000444001750001750 122312244240043 13741 0ustar00ronron000000000000--- abstract: 'Read/Write .ini style files with as little code as possible' author: - 'Adam Kennedy ' build_requires: File::Spec: 3.3 File::Temp: 0.22 Test::More: 0.47 configure_requires: Module::Build: 0.34 dynamic_config: 1 generated_by: 'Module::Build version 0.4005, CPAN::Meta::Converter version 2.131560' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Config-Tiny provides: Config::Tiny: file: lib/Config/Tiny.pm version: 2.20 requires: UNIVERSAL: 0 perl: v5.8.1 strict: 0 utf8: 0 resources: license: http://dev.perl.org/licenses/ version: 2.20 Config-Tiny-2.20/MANIFEST000444001750001750 35412244240043 13605 0ustar00ronron000000000000Build.PL Changelog.ini Changes lib/Config/Tiny.pm LICENSE Makefile.PL MANIFEST This list of files META.json META.yml README t/01.compile.t t/02.main.t t/03.read.string.t t/04.utf8.t t/04.utf8.txt test.conf xt/meta.t xt/pmv.t xt/pod.t Config-Tiny-2.20/Build.PL000444001750001750 120112244240043 13760 0ustar00ronron000000000000use strict; use warnings; use Module::Build; Module::Build -> new ( module_name => 'Config::Tiny', license => 'perl', dist_abstract => 'Read/Write .ini style files with as little code as possible', dist_author => 'Adam Kennedy ', build_requires => { 'File::Spec' => 3.30, 'File::Temp' => 0.22, 'Test::More' => 0.47, # 'Test::Pod' => 1.45, # Make it optional. See xt/pod.t }, configure_requires => { 'Module::Build' => 0.3400, }, requires => { 'perl' => '5.8.1', # For the utf stuff. 'strict' => 0, 'UNIVERSAL' => 0, 'utf8' => 0, }, ) -> create_build_script(); Config-Tiny-2.20/META.json000444001750001750 223312244240043 14113 0ustar00ronron000000000000{ "abstract" : "Read/Write .ini style files with as little code as possible", "author" : [ "Adam Kennedy " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4005, CPAN::Meta::Converter version 2.131560", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Config-Tiny", "prereqs" : { "build" : { "requires" : { "File::Spec" : "3.3", "File::Temp" : "0.22", "Test::More" : "0.47" } }, "configure" : { "requires" : { "Module::Build" : "0.34" } }, "runtime" : { "requires" : { "UNIVERSAL" : "0", "perl" : "v5.8.1", "strict" : "0", "utf8" : "0" } } }, "provides" : { "Config::Tiny" : { "file" : "lib/Config/Tiny.pm", "version" : "2.20" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ] }, "version" : "2.20" } Config-Tiny-2.20/test.conf000555001750001750 17612244240043 14307 0ustar00ronron000000000000root=something [section] one=two Foo=Bar this=Your Mother! blank= [Section Two] something else=blah remove = whitespace Config-Tiny-2.20/xt000755001750001750 012244240043 12770 5ustar00ronron000000000000Config-Tiny-2.20/xt/meta.t000444001750001750 107312244240043 14241 0ustar00ronron000000000000#!/usr/bin/perl # Test that our META.yml file matches the current specification. use strict; BEGIN { $| = 1; $^W = 1; } my $MODULE = 'Test::CPAN::Meta 0.17'; # Don't run tests for installs use Test::More; unless ( $ENV{AUTOMATED_TESTING} or $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } # Load the testing module eval "use $MODULE"; if ( $@ ) { $ENV{RELEASE_TESTING} ? die( "Failed to load required release-testing module $MODULE" ) : plan( skip_all => "$MODULE not available for testing" ); } meta_yaml_ok(); Config-Tiny-2.20/xt/pmv.t000444001750001750 125212244240043 14114 0ustar00ronron000000000000#!/usr/bin/perl # Test that our declared minimum Perl version matches our syntax use strict; BEGIN { $| = 1; $^W = 1; } my @MODULES = ( 'Perl::MinimumVersion 1.27', 'Test::MinimumVersion 0.101080', ); # Don't run tests for installs use Test::More; unless ( $ENV{AUTOMATED_TESTING} or $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } # Load the testing modules foreach my $MODULE ( @MODULES ) { eval "use $MODULE"; if ( $@ ) { $ENV{RELEASE_TESTING} ? die( "Failed to load required release-testing module $MODULE" ) : plan( skip_all => "$MODULE not available for testing" ); } } all_minimum_version_from_metayml_ok(); Config-Tiny-2.20/xt/pod.t000444001750001750 116712244240043 14101 0ustar00ronron000000000000#!/usr/bin/perl # Test that the syntax of our POD documentation is valid use strict; BEGIN { $| = 1; $^W = 1; } my @MODULES = ( 'Pod::Simple 3.14', 'Test::Pod 1.44', ); # Don't run tests for installs use Test::More; unless ( $ENV{AUTOMATED_TESTING} or $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } # Load the testing modules foreach my $MODULE ( @MODULES ) { eval "use $MODULE"; if ( $@ ) { $ENV{RELEASE_TESTING} ? die( "Failed to load required release-testing module $MODULE" ) : plan( skip_all => "$MODULE not available for testing" ); } } all_pod_files_ok(); Config-Tiny-2.20/t000755001750001750 012244240043 12600 5ustar00ronron000000000000Config-Tiny-2.20/t/03.read.string.t000444001750001750 52412244240043 15544 0ustar00ronron000000000000#!/usr/bin/perl use Config::Tiny; use Test::More tests => 2; # ------------------------ my($string) = <<'EOS'; param1=One param2=Two EOS my($config) = Config::Tiny -> read_string($string); isa_ok($config, 'Config::Tiny', 'read_string() returns an object'); ok($$config{_}{param1} eq 'One', 'Access to hashref returns correct value'); Config-Tiny-2.20/t/02.main.t000444001750001750 1115512244240043 14311 0ustar00ronron000000000000#!/usr/bin/perl # Main testing script for Config::Tiny use strict; BEGIN { $| = 1; $^W = 1; } use Config::Tiny (); use File::Spec; use File::Temp; use Test::More tests => 33; use UNIVERSAL (); our $VERSION = '2.20'; # -------------------- # Check their perl version is( $Config::Tiny::VERSION, $VERSION, 'Loaded correct version of Config::Tiny' ); # Test trivial creation my $Trivial = Config::Tiny->new; ok( $Trivial, 'new() returns true' ); ok( ref $Trivial, 'new() returns a reference' ); # Legitimate use of UNIVERSAL::isa ok( UNIVERSAL::isa( $Trivial, 'HASH' ), 'new() returns a hash reference' ); isa_ok( $Trivial, 'Config::Tiny' ); ok( scalar keys %$Trivial == 0, 'new() returns an empty object' ); # Try to read in a config my $Config = Config::Tiny->read( 'test.conf' ); ok( $Config, 'read() returns true' ); ok( ref $Config, 'read() returns a reference' ); # Legitimate use of UNIVERSAL::isa ok( UNIVERSAL::isa( $Config, 'HASH' ), 'read() returns a hash reference' ); isa_ok( $Config, 'Config::Tiny' ); # Check the structure of the config my $expected = { '_' => { root => 'something', }, section => { one => 'two', Foo => 'Bar', this => 'Your Mother!', blank => '', }, 'Section Two' => { 'something else' => 'blah', 'remove' => 'whitespace', }, }; bless $expected, 'Config::Tiny'; is_deeply( $Config, $expected, 'Config structure matches expected' ); # Add some stuff to the trivial config and check write_string() for it $Trivial->{_} = { root1 => 'root2', }; $Trivial->{section} = { foo => 'bar', this => 'that', blank => '', }; $Trivial->{section2} = { 'this little piggy' => 'went to market' }; my $string = <read_string( $string ); ok( $Read, 'read_string() returns true' ); is_deeply( $Read, $Trivial, 'read_string() returns expected value' ); my $generated = $Trivial->write_string(); ok( length $generated, 'write_string() returns something' ); ok( $generated eq $string, 'write_string() returns the correct file contents' ); # The EXLOCK option is for BSD-based systems. my($temp_dir) = File::Temp -> newdir('temp.XXXX', CLEANUP => 1, EXLOCK => 0, TMPDIR => 1); my($temp_file) = File::Spec -> catfile($temp_dir, 'write.test.conf'); # Try to write a file my $rv = $Trivial->write($temp_file); ok( $rv, 'write() returned true' ); ok( -e $temp_file, 'write() actually created a file' ); # Try to read the config back in $Read = Config::Tiny->read( $temp_file ); ok( $Read, 'read() of what we wrote returns true' ); ok( ref $Read, 'read() of what we wrote returns a reference' ); # Legitimate use of UNIVERSAL::isa ok( UNIVERSAL::isa( $Read, 'HASH' ), 'read() of what we wrote returns a hash reference' ); isa_ok( $Read, 'Config::Tiny' ); # Check the structure of what we read back in is_deeply( $Read, $Trivial, 'What we read matches what we wrote out' ); ##################################################################### # Bugs that happened we don't want to happen again SCOPE: { # Reading in an empty file, or a defined but zero length string, should yield # a valid, but empty, object. my $Empty = Config::Tiny->read_string(''); isa_ok( $Empty, 'Config::Tiny' ); is( scalar(keys %$Empty), 0, 'Config::Tiny object from empty string, is empty' ); } SCOPE: { # A Section header like [ section ] doesn't end up at ->{' section '}. # Trim off whitespace from the section header. my $string = <<'END_CONFIG'; # The need to trim off whitespace makes a lot more sense # when you are trying to maximise readability. [ /path/to/file.txt ] this=that [ section2] this=that [section3 ] this=that END_CONFIG my $Trim = Config::Tiny->read_string($string); isa_ok( $Trim, 'Config::Tiny' ); ok( exists $Trim->{'/path/to/file.txt'}, 'First section created' ); is( $Trim->{'/path/to/file.txt'}->{this}, 'that', 'First section created properly' ); ok( exists $Trim->{section2}, 'Second section created' ); is( $Trim->{section2}->{this}, 'that', 'Second section created properly' ); ok( exists $Trim->{section3}, 'Third section created' ); is( $Trim->{section3}->{this}, 'that', 'Third section created properly' ); } ###################################################################### # Refuse to write config files with newlines in them SCOPE: { my $newline = Config::Tiny->new; $newline->{_}->{string} = "foo\nbar"; local $@; my $output = undef; eval { $output = $newline->write_string; }; is( $output, undef, 'write_string() returns undef on newlines' ); is( Config::Tiny->errstr, "Illegal newlines in property '_.string'", 'errstr() returns expected error', ); } Config-Tiny-2.20/t/01.compile.t000444001750001750 22412244240043 14747 0ustar00ronron000000000000#!/usr/bin/perl # Compile testing for Config::Tiny use strict; BEGIN { $| = 1; $^W = 1; } use Test::More tests => 1; use_ok('Config::Tiny'); Config-Tiny-2.20/t/04.utf8.txt000444001750001750 14112244240043 14562 0ustar00ronron000000000000[utf8_data] Name = Δ Lady Class = Reichwaldstraße Type = Πηληϊάδεω Ἀχιλῆος Config-Tiny-2.20/t/04.utf8.t000444001750001750 237512244240043 14241 0ustar00ronron000000000000#!/usr/bin/perl use Config::Tiny; use File::Spec; use File::Temp; use Test::More tests => 7; use utf8; # ------------------------ my($config) = Config::Tiny -> read('t/04.utf8.txt', 'utf8'); ok($$config{utf8_data}{Name} eq 'Δ Lady', 'Hashref after read() returns correct value'); ok($$config{utf8_data}{Class} eq 'Reichwaldstraße', 'Hashref after read() returns correct value'); ok($$config{utf8_data}{Type} eq 'Πηληϊάδεω Ἀχιλῆος', 'Hashref after read() returns correct value'); # The EXLOCK option is for BSD-based systems. my($temp_dir) = File::Temp -> newdir('temp.XXXX', CLEANUP => 1, EXLOCK => 0, TMPDIR => 1); my($temp_file) = File::Spec -> catfile($temp_dir, 'write.utf8.conf'); my($string) =< read_string($string); ok($conf1, 'read_string() returns true'); is_deeply($conf1, {init => {weird_text => 'Reichwaldstraße'} }, 'read_string() returns expected value'); $conf1 -> write($temp_file, 'utf8'); my($conf2) = Config::Tiny -> read($temp_file, 'encoding(utf8)'); is_deeply($conf1, $conf1, 'write() followed by read() works'); is_deeply($conf2, {init => {weird_text => 'Reichwaldstraße'} }, 'write() + read() returns expected value'); Config-Tiny-2.20/lib000755001750001750 012244240043 13103 5ustar00ronron000000000000Config-Tiny-2.20/lib/Config000755001750001750 012244240043 14310 5ustar00ronron000000000000Config-Tiny-2.20/lib/Config/Tiny.pm000444001750001750 2372012244240043 15752 0ustar00ronron000000000000package Config::Tiny; # If you thought Config::Simple was small... use strict; our $VERSION = '2.20'; # Also change version # in t/02.main.t. BEGIN { require 5.008001; $Config::Tiny::errstr = ''; } # Create an empty object sub new { bless {}, shift } # Create an object from a file sub read { my $class = ref $_[0] ? ref shift : shift; my $file = shift or return $class->_error('No file name provided'); # Slurp in the file. my $encoding = shift; $encoding = $encoding ? "<:$encoding" : '<'; local $/ = undef; open( CFG, $encoding, $file ) or return $class->_error( "Failed to open file '$file' for reading: $!" ); my $contents = ; close( CFG ); return $class -> _error("Reading from '$file' returned undef") if (! defined $contents); return $class->read_string( $contents ); } # Create an object from a string sub read_string { my $class = ref $_[0] ? ref shift : shift; my $self = bless {}, $class; return undef unless defined $_[0]; # Parse the file my $ns = '_'; my $counter = 0; foreach ( split /(?:\015{1,2}\012|\015|\012)/, shift ) { $counter++; # Skip comments and empty lines next if /^\s*(?:\#|\;|$)/; # Remove inline comments s/\s\;\s.+$//g; # Handle section headers if ( /^\s*\[\s*(.+?)\s*\]\s*$/ ) { # Create the sub-hash if it doesn't exist. # Without this sections without keys will not # appear at all in the completed struct. $self->{$ns = $1} ||= {}; next; } # Handle properties if ( /^\s*([^=]+?)\s*=\s*(.*?)\s*$/ ) { $self->{$ns}->{$1} = $2; next; } return $self->_error( "Syntax error at line $counter: '$_'" ); } $self; } # Save an object to a file sub write { my $self = shift; my $file = shift or return $self->_error('No file name provided'); my $encoding = shift; $encoding = $encoding ? ">:$encoding" : '>'; # Write it to the file my $string = $self->write_string; return undef unless defined $string; open( CFG, $encoding, $file ) or return $self->_error( "Failed to open file '$file' for writing: $!" ); print CFG $string; close CFG; return 1; } # Save an object to a string sub write_string { my $self = shift; my $contents = ''; foreach my $section ( sort { (($b eq '_') <=> ($a eq '_')) || ($a cmp $b) } keys %$self ) { # Check for several known-bad situations with the section # 1. Leading whitespace # 2. Trailing whitespace # 3. Newlines in section name return $self->_error( "Illegal whitespace in section name '$section'" ) if $section =~ /(?:^\s|\n|\s$)/s; my $block = $self->{$section}; $contents .= "\n" if length $contents; $contents .= "[$section]\n" unless $section eq '_'; foreach my $property ( sort keys %$block ) { return $self->_error( "Illegal newlines in property '$section.$property'" ) if $block->{$property} =~ /(?:\012|\015)/s; $contents .= "$property=$block->{$property}\n"; } } $contents; } # Error handling sub errstr { $Config::Tiny::errstr } sub _error { $Config::Tiny::errstr = $_[1]; undef } 1; __END__ =pod =head1 NAME Config::Tiny - Read/Write .ini style files with as little code as possible =head1 SYNOPSIS # In your configuration file rootproperty=blah [section] one=twp three= four Foo =Bar empty= # In your program use Config::Tiny; # Create a config my $Config = Config::Tiny->new; # Open the config $Config = Config::Tiny->read( 'file.conf' ); $Config = Config::Tiny->read( 'file.conf', 'utf8' ); # Neither ':' nor '<:' prefix! $Config = Config::Tiny->read( 'file.conf', 'encoding(iso-8859-1)'); # Reading properties my $rootproperty = $Config->{_}->{rootproperty}; my $one = $Config->{section}->{one}; my $Foo = $Config->{section}->{Foo}; # Changing data $Config->{newsection} = { this => 'that' }; # Add a section $Config->{section}->{Foo} = 'Not Bar!'; # Change a value delete $Config->{_}; # Delete a value or section # Save a config $Config->write( 'file.conf' ); $Config->write( 'file.conf', 'utf8' ); # Neither ':' nor '>:' prefix! # Shortcuts my($rootproperty) = $$Config{_}{rootproperty}; my($config) = Config::Tiny -> read_string('alpha=bet'); my($value) = $$config{_}{alpha}; # $value is 'bet'. my($config) = Config::Tiny -> read_string("[init]\nalpha=bet"); my($value) = $$config{init}{alpha}; # $value is 'bet'. =head1 DESCRIPTION C is a Perl class to read and write .ini style configuration files with as little code as possible, reducing load time and memory overhead. Most of the time it is accepted that Perl applications use a lot of memory and modules. The C<*::Tiny> family of modules is specifically intended to provide an ultralight alternative to the standard modules. This module is primarily for reading human written files, and anything we write shouldn't need to have documentation/comments. If you need something with more power move up to L, L or one of the many other C modules. Lastly, L does B preserve your comments, whitespace, or the order of your config file. See L (and possibly others) for the preservation of the order of the entries in the file. =head1 CONFIGURATION FILE SYNTAX Files are the same format as for MS Windows C<*.ini> files. For example: [section] var1=value1 var2=value2 If a property is outside of a section at the beginning of a file, it will be assigned to the C<"root section">, available at C<$Config-E{_}>. Lines starting with C<'#'> or C<';'> are considered comments and ignored, as are blank lines. When writing back to the config file, all comments, custom whitespace, and the ordering of your config file elements is discarded. If you need to keep the human elements of a config when writing back, upgrade to something better, this module is not for you. =head1 METHODS =head2 errstr() Returns a string representing the most recent error, or the empty string. You can also retrieve the error message from the C<$Config::Tiny::errstr> variable. =head2 new() The constructor C creates and returns an empty C object. =head2 read($filename, [$encoding]) Here, the [] indicate an optional parameter. The C constructor reads a config file, $filename, and returns a new C object containing the properties in the file. $encoding may be used to indicate the encoding of the file, e.g. 'utf8' or 'encoding(iso-8859-1)'. Do not add a prefix to $encoding, such as '<' or '<:'. Returns the object on success, or C on error. When C fails, C sets an error message internally you can recover via Cerrstr>. Although in B cases a failed C will also set the operating system error variable C<$!>, not all errors do and you should not rely on using the C<$!> variable. See t/04.utf8.t and t/04.utf8.txt. =head2 read_string($string) The C method takes as argument the contents of a config file as a string and returns the C object for it. =head2 write($filename, [$encoding]) Here, the [] indicate an optional parameter. The C method generates the file content for the properties, and writes it to disk to the filename specified. $encoding may be used to indicate the encoding of the file, e.g. 'utf8' or 'encoding(iso-8859-1)'. Do not add a prefix to $encoding, such as '>' or '>:'. Returns true on success or C on error. See t/04.utf8.t and t/04.utf8.txt. =head2 write_string() Generates the file content for the object and returns it as a string. =head1 FAQ =head2 Why can't I put comments at the ends of lines? Because a line like: key=value # A comment Sets key to 'value # A comment' :-(. This conforms to the syntax discussed in L. =head2 Why can't I omit the '=' signs? E.g.: [Things] my = list = of = things = Instead of: [Things] my list of things Because the use of '=' signs is a type of mandatory documentation. It indicates that that section contains 4 items, and not 1 odd item split over 4 lines. =head2 Why do I have to assign the result of a method call to a variable? This question comes from RT#85386. Yes, the syntax may seem odd, but you don't have to call both new() and read_string(). Try: perl -MData::Dumper -MConfig::Tiny -E 'my $c=Config::Tiny->read_string("one=s"); say Dumper $c' Or: my($config) = Config::Tiny -> read_string('alpha=bet'); my($value) = $$config{_}{alpha}; # $value is 'bet'. Or even, a bit ridiculously: my($value) = ${Config::Tiny -> read_string('alpha=bet')}{_}{alpha}; # $value is 'bet'. =head1 CAVEATS =head2 Unsupported Section Headers Some edge cases in section headers are not supported, and additionally may not be detected when writing the config file. Specifically, section headers with leading whitespace, trailing whitespace, or newlines anywhere in the section header, will not be written correctly to the file and may cause file corruption. =head2 Setting an option more than once C will only recognize the first time an option is set in a config file. Any further attempts to set the same option later in the config file are ignored. =head1 SUPPORT Bugs should be reported via the CPAN bug tracker at L For other issues, or commercial enhancement or support, contact the author. =head1 AUTHOR Adam Kennedy Eadamk@cpan.orgE Maintanence from V 2.15: Ron Savage L. =head1 ACKNOWLEGEMENTS Thanks to Sherzod Ruzmetov Esherzodr@cpan.orgE for L, which inspired this module by being not quite "simple" enough for me :). =head1 SEE ALSO See, amongst many: L and L. See L (and possibly others) for the preservation of the order of the entries in the file. =head1 COPYRIGHT Copyright 2002 - 2011 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. =cut