Config-IniHash-3.01.01000777000000000000 011213225104 14724 5ustar00unknownunknown000000000000Build.PL000444000000000000 104111207567753 16314 0ustar00unknownunknown000000000000Config-IniHash-3.01.01use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'Config::IniHash', license => 'perl', dist_author => 'Jenda Krynicky ', dist_version_from => 'lib/Config/IniHash.pm', build_requires => { 'Hash::Case' => '0', # or a minimum workable version 'Hash::WithDefaults' => '0.04', }, add_to_cleanup => [ 'Config-IniHash-*' ], create_makefile_pl => 'traditional', ); $builder->create_build_script(); Changes000444000000000000 315711213225072 16303 0ustar00unknownunknown000000000000Config-IniHash-3.01.01Revision history for Perl extension Config::IniHash. 2.0 Tue Jul 23 19:15:34 2002 - first public version 2.2 Thu Dec 5 2002 - some fixes and tuneups 2.3 Sun Jan 5 2003 - Makefile.PL and use statement fixes 2.4 Wed Jan 29 2003 - added sectionorder option - section names are now subject to tolower/toupper as well - minor fixes 2.6 - some -w related fixes - fixed %varname% handling - WriteIni uses the section order 2.7 Fri Nov 05 2004 - fixed WriteINI's handling of multiline values 2.8 Sun Feb 20 2005 - you may specify what hash to take the %varname%s from - you may specify what do comments look like 2.8.2 Thu Jan 25 2007 - added IO::Scalar to prerequisities to silence test errors in some environments - added the key name to the generated heredoc marks 3.00.02 Sun Jan 11 2009 - fixed the interoperation of case and sectionorder - added ability to tie the hashes to custom classes - added lots of tests 3.00.03 Sun Jan 18 2009 - fixed the test to work on Unixes (the TEMP variable was not defined and %ENV is case sensitive under Unix) 3.00.04 Mon Jan 19 2009 - erm. hopefully the test script finaly works under unix 3.00.05 Mon Jan 26 2009 - erm. hopefully the test script finaly works under unix - it now doesn't attempt to create files in the temp directory 3.01.00 Thu May 28 2009 - added the layer=> option to allow you to specify the IO layers used to open the file - add :utf8 layer automaticaly for files starting with BOM - add :crlf layer for files containing CRLF if needed 3.01.01 Mon Jun 8 2009 - fix a bug with repeated sectionsMakefile.PL000444000000000000 74711213225103 16737 0ustar00unknownunknown000000000000Config-IniHash-3.01.01# Note: this file was auto-generated by Module::Build::Compat version 0.03 use ExtUtils::MakeMaker; WriteMakefile ( 'PL_FILES' => {}, 'INSTALLDIRS' => 'site', 'NAME' => 'Config::IniHash', 'EXE_FILES' => [], 'VERSION_FROM' => 'lib/Config/IniHash.pm', 'PREREQ_PM' => { 'Hash::Case' => '0', 'Hash::WithDefaults' => '0.04' } ) ; MANIFEST000444000000000000 25411207557054 16127 0ustar00unknownunknown000000000000Config-IniHash-3.01.01Changes lib/Config/IniHash.pm Build.PL MANIFEST README test.pl test.ini META.yml Module meta-data (added by MakeMaker) Makefile.PL META.yml000444000000000000 106511213225104 16251 0ustar00unknownunknown000000000000Config-IniHash-3.01.01--- name: Config-IniHash version: 3.01.01 author: - 'Jenda Krynicky ' abstract: Perl extension for reading and writing INI files license: perl resources: license: http://dev.perl.org/licenses/ build_requires: Hash::Case: 0 Hash::WithDefaults: 0.04 provides: Config::IniHash: file: lib/Config/IniHash.pm version: 3.01.01 Hash::Case::LowerX: file: lib/Config/IniHash.pm generated_by: Module::Build version 0.2808 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 README000444000000000000 104011207556450 15667 0ustar00unknownunknown000000000000Config-IniHash-3.01.01Config/IniHash version 3.01.00 =========================== This module reads and writes INI files. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: Hash::Case Hash::WithDefaults COPYRIGHT AND LICENCE Copyright (C) 2002-2009 Jenda Krynicky This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. test.ini000444000000000000 46611204353617 16457 0ustar00unknownunknown000000000000Config-IniHash-3.01.01[:default] int=5 foo=dz_difolt [one] int=1 real=4.7547 string=blah blah string2=blah=flah [Two] temp=%TEMP% foo=jedna foo=dva [Three] aaaa=asd Bbbb=asd CCCC=asd [Four] foo=1 foo=2 foo=3 bar=U Trech Sudu [Five] #com1=hi ;com2=ho 'com3=hu //com4=hy [Six] long=<<*END* blah blah blah blah *END* short=Hello test.pl000444000000000000 5450111207562567 16363 0ustar00unknownunknown000000000000Config-IniHash-3.01.01# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### use Test::More tests => 208; #use diagnostics; use strict; use File::Spec; BEGIN { use_ok( 'Config::IniHash' ); } use Config::IniHash qw(ReadINI WriteINI AddDefaults); my %orig_data = ( sec1 => { foo => 5, BAR => 'Hello World!' }, seC2 => { What => 'sgfdfg=wtert', other => 'fsdgfg;dfhfdghfg', }, ); if (!exists $ENV{TEMP} or !-d $ENV{TEMP}) { $ENV{TEMP} = File::Spec->tmpdir; } my $script_file = $0; if (! File::Spec->file_name_is_absolute($script_file)) { $script_file = File::Spec->rel2abs($script_file); } { (my $filename = $script_file) =~ s/\.pl$/-write.ini/; ok( WriteINI( $filename, \%orig_data), "WriteINI => $filename"); END { unlink $filename } { my $read_data = ReadINI( $filename, {case => 'sensitive'}); ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename'"); is_deeply( \%orig_data, $read_data, "Read data match the original"); } { my $read_data = ReadINI( $filename); ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename'"); my $read_data2 = ReadINI( $filename, {case => 'lower'}); ok( (defined($read_data2) and ref($read_data2)), "ReadINI '$filename', {case => 'lower'}"); is_deeply( $read_data, $read_data2, "case => 'lower' is the default"); } } (my $filename = $script_file) =~ s/\.pl$/.ini/; { my $read_data = ReadINI( $filename); ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename' (different data)"); is( $read_data->{Two}{temp}, $ENV{TEMP}, "System variables are interpolated by default"); } { my $read_data = ReadINI( $filename, {systemvars => 0}); ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {systemvars => 0}"); is( $read_data->{Two}{temp}, '%TEMP%', "System variables are not interpolated if not wanted"); } { my $read_data = ReadINI( $filename, {systemvars => 1}); ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {systemvars => 1}"); is( $read_data->{Two}{temp}, $ENV{TEMP}, "System variables are interpolated if asked to"); } { my $read_data = ReadINI( $filename, {systemvars => {TEMP => 'subverted'}}); ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {systemvars => {...}}"); is( $read_data->{Two}{TEMP}, 'subverted', "System variables are interpolated using a custom hash"); } { my $read_data = ReadINI( $filename, {allowmultiple => 0}); ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {allowmultiple => 0}"); is( $read_data->{Four}{foo}, 3, "Multiple values overwrite each other"); } { my $read_data = ReadINI( $filename, {allowmultiple => 1}); ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {allowmultiple => 1}"); is_deeply( $read_data->{Four}{foo}, [1,2,3], "Multiple values produce an array"); is_deeply( $read_data->{Four}{bar}, 'U Trech Sudu', "But single values still produce a scalar"); } { my $read_data = ReadINI( $filename, {allowmultiple => {Four => 'foo,bar'}}); ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {allowmultiple => {Four => 'foo,bar'}}"); is_deeply( $read_data->{Four}{foo}, [1,2,3], "Specified multiple values produce an array"); is_deeply( $read_data->{Four}{bar}, ['U Trech Sudu'], "Single values as well if specified"); is_deeply( $read_data->{Two}{foo}, 'dva', "Multiple values that are not specified produce scalars"); my $read_data2 = ReadINI( $filename, {allowmultiple => {Four => [qw(foo bar)]}}); ok( (defined($read_data2) and ref($read_data2)), "ReadINI '$filename', {allowmultiple => {Four => [qw(foo bar)]}}"); is_deeply( $read_data, $read_data2, "Comma separated lists and arrayrefs both work"); } { my $read_data = ReadINI( $filename, {allowmultiple => {'*' => 'foo,bar'}}); ok( (defined($read_data) and ref($read_data)), "ReadINI '$filename', {allowmultiple => {'*' => 'foo,bar'}}"); is_deeply( $read_data->{Four}{foo}, [1,2,3], "Specified multiple values produce an array"); is_deeply( $read_data->{Two}{foo}, ['jedna','dva'], "Specified multiple values produce an array in all sections"); } { my $read_data = ReadINI( $filename, {}); is( $read_data->{Five}{'#com1'}, undef, "# is a comment char by default"); is( $read_data->{Five}{';com2'}, undef, "; is a comment char by default"); is( $read_data->{Five}{'\'com3'}, 'hu', "' is NOT a comment char by default"); is( $read_data->{Five}{'//com4'}, 'hy', "// is NOT a comment char by default"); } { my $read_data = ReadINI( $filename, {comment => ";'"}); is( $read_data->{Five}{'#com1'}, 'hi', "# is NOT a specified comment char"); is( $read_data->{Five}{';com2'}, undef, "; is a specified comment char"); is( $read_data->{Five}{'\'com3'}, undef, "' is a specified comment char"); is( $read_data->{Five}{'//com4'}, 'hy', "// is NOT a specified comment char"); } { my $read_data = ReadINI( $filename, {comment => qr{^\s*//}}); is( $read_data->{Five}{'#com1'}, 'hi', "# is NOT a specified comment char"); is( $read_data->{Five}{';com2'}, 'ho', "; is NOT a specified comment char"); is( $read_data->{Five}{'\'com3'}, 'hu', "' is NOT a specified comment char"); is( $read_data->{Five}{'//com4'}, undef, "// is the specified comment char"); } { my $read_data = ReadINI( $filename); is( $read_data->{Six}{long}, "<<*END*", "heredocs are not allowed by default"); is( $read_data->{Six}{short}, "Hello", "short value is read fine"); } { my $read_data = ReadINI( $filename, {heredoc => 1}); is( $read_data->{Six}{long}, "blah\nblah blah\nblah", "heredoc works if allowed"); is( $read_data->{Six}{short}, "Hello", "short value is read fine"); } { use File::Copy qw(copy); (my $filename2 = $filename) =~ s/\.ini/-2.ini/; copy $filename => $filename2; END {unlink $filename2}; open my $FH, '>>', $filename2 or die "Unable to append to $filename2: $^E\n"; print $FH <<'*EnD*'; long2=<<"*END*" blah blah blah %TEMP% blah %NONSE_NS% *END* long3=<<'*END*' blah blah blah %TEMP% blah %NONSE_NS% *END* long4=<<*END* the temp directory is %TEMP% nonsense is %NONSE_NS% *END* *EnD* close $FH; { my $read_data = eval {ReadINI( $filename2, {heredoc => 0})}; ok(ref($read_data), "Extended heredocs are ignored if heredoc => 0") } { my $read_data = eval {ReadINI( $filename2, {heredoc => 1})}; ok(! defined ($read_data), "Extended heredocs cause errors if heredoc => 1"); ok(scalar($@ =~ /^\QHeredoc value for [Six]long2 not closed at end of file!\E/), "With the right error message (\$\@=$@)"); } { my $read_data = eval {ReadINI( $filename2, {heredoc => 'Perl'})}; ok(ref($read_data), "Extended heredocs are allowed if heredoc => 'Perl'"); is( $read_data->{Six}{long}, "blah\nblah blah\nblah", "heredoc works if allowed"); is( $read_data->{Six}{short}, "Hello", "short value is read fine"); is( $read_data->{Six}{long2}, "blah\nblah blah $ENV{TEMP}\nblah ", "heredoc works if allowed, <<\"*END*\" interpolates"); is( $read_data->{Six}{long3}, "blah\nblah blah %TEMP%\nblah %NONSE_NS%", "heredoc works if allowed, <<'*END*' doesn't interpolate"); is( $read_data->{Six}{long4}, "the temp directory is $ENV{TEMP}\nnonsense is %NONSE_NS%", "heredoc works if allowed, <<*END* does interpolate by default"); } { my $read_data = eval {ReadINI( $filename2, {heredoc => 'Perl', systemvars => 0})}; ok(ref($read_data), "Extended heredocs are allowed if heredoc => 'Perl', systemvars => 0: \$\@=$@"); is( $read_data->{Six}{long2}, "blah\nblah blah $ENV{TEMP}\nblah ", "heredoc works if allowed, <<\"*END*\" interpolates"); is( $read_data->{Six}{long3}, "blah\nblah blah %TEMP%\nblah %NONSE_NS%", "heredoc works if allowed, <<'*END*' doesn't interpolate"); is( $read_data->{Six}{long4}, "the temp directory is %TEMP%\nnonsense is %NONSE_NS%", "heredoc works if allowed, <<*END* doesn't interpolate by if systemvars => 0"); } } { my $read_data = ReadINI( $filename, ); ok( ! defined $read_data->{'__SECTIONS__'}, "the sections order is not remembered by default"); } { my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'sensitive'}); ok( defined $read_data->{'__SECTIONS__'}, "the sections order is remembered if sectionorder => 1"); is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one Two Three Four Five Six)], "the sections order is remembered correctly"); my $missing=0; foreach (@{$read_data->{'__SECTIONS__'}}) { $missing++ unless exists ($read_data->{$_}); } is ($missing, 0, "All sections in __SECTIONS__ are accessible"); } { my @sections; my $read_data = ReadINI( $filename, {sectionorder => \@sections, case => 'sensitive'}); ok( ! defined $read_data->{'__SECTIONS__'}, "\$config->{'__SECTIONS__'} is not defined sectionorder => \\\@array"); is_deeply(\@sections, [qw(:default one Two Three Four Five Six)], "the sections order is remembered correctly"); my $missing=0; foreach (@sections) { $missing++ unless exists ($read_data->{$_}); } is ($missing, 0, "All sections in \@sections are accessible"); } { my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'sensitive'}); is($read_data->{Three}{aaaa}, 'asd', "case sensitive"); is($read_data->{three}{aaaa}, undef, "case sensitive"); is($read_data->{THREE}{aaaa}, undef, "case sensitive"); is($read_data->{Three}{aaaa}, 'asd', "case sensitive"); is($read_data->{Three}{Bbbb}, 'asd', "case sensitive"); is($read_data->{Three}{CCCC}, 'asd', "case sensitive"); is($read_data->{Three}{aaaa}, 'asd', "case sensitive"); is($read_data->{Three}{bbbb}, undef, "case sensitive"); is($read_data->{Three}{cccc}, undef, "case sensitive"); is($read_data->{Three}{AAAA}, undef, "case sensitive"); is($read_data->{Three}{BBBB}, undef, "case sensitive"); is($read_data->{Three}{CCCC}, 'asd', "case sensitive"); is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one Two Three Four Five Six)], "the sections order is remembered with correct case"); my $missing=0; foreach (@{$read_data->{'__SECTIONS__'}}) { $missing++ unless exists ($read_data->{$_}); } is ($missing, 0, "All sections in __SECTIONS__ are accessible"); } { my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'tolower'}); is($read_data->{Three}{aaaa}, undef, "tolower"); is($read_data->{three}{aaaa}, 'asd', "tolower"); is($read_data->{THREE}{aaaa}, undef, "tolower"); is($read_data->{three}{aaaa}, 'asd', "tolower"); is($read_data->{three}{Bbbb}, undef, "tolower"); is($read_data->{three}{CCCC}, undef, "tolower"); is($read_data->{three}{aaaa}, 'asd', "tolower"); is($read_data->{three}{bbbb}, 'asd', "tolower"); is($read_data->{three}{cccc}, 'asd', "tolower"); is($read_data->{three}{AAAA}, undef, "tolower"); is($read_data->{three}{BBBB}, undef, "tolower"); is($read_data->{three}{CCCC}, undef, "tolower"); is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one two three four five six)], "the sections order is remembered with correct case"); my $missing=0; foreach (@{$read_data->{'__SECTIONS__'}}) { $missing++ unless exists ($read_data->{$_}); } is ($missing, 0, "All sections in __SECTIONS__ are accessible"); } { my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'toupper'}); is($read_data->{Three}{AAAA}, undef, "toupper"); is($read_data->{three}{AAAA}, undef, "toupper"); is($read_data->{THREE}{AAAA}, 'asd', "toupper"); is($read_data->{THREE}{aaaa}, undef, "toupper"); is($read_data->{THREE}{Bbbb}, undef, "toupper"); is($read_data->{THREE}{CCCC}, 'asd', "toupper"); is($read_data->{THREE}{aaaa}, undef, "toupper"); is($read_data->{THREE}{bbbb}, undef, "toupper"); is($read_data->{THREE}{cccc}, undef, "toupper"); is($read_data->{THREE}{AAAA}, 'asd', "toupper"); is($read_data->{THREE}{BBBB}, 'asd', "toupper"); is($read_data->{THREE}{CCCC}, 'asd', "toupper"); is_deeply($read_data->{'__SECTIONS__'}, [qw(:DEFAULT ONE TWO THREE FOUR FIVE SIX)], "the sections order is remembered with correct case"); my $missing=0; foreach (@{$read_data->{'__SECTIONS__'}}) { $missing++ unless exists ($read_data->{$_}); } is ($missing, 0, "All sections in __SECTIONS__ are accessible"); } { my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'preserve'}); is($read_data->{Three}{AAAA}, 'asd', "preserve"); is($read_data->{three}{AAAA}, 'asd', "preserve"); is($read_data->{THREE}{AAAA}, 'asd', "preserve"); is($read_data->{THREE}{aaaa}, 'asd', "preserve"); is($read_data->{THREE}{Bbbb}, 'asd', "preserve"); is($read_data->{THREE}{CCCC}, 'asd', "preserve"); is($read_data->{THREE}{aaaa}, 'asd', "preserve"); is($read_data->{THREE}{bbbb}, 'asd', "preserve"); is($read_data->{THREE}{cccc}, 'asd', "preserve"); is($read_data->{THREE}{AAAA}, 'asd', "preserve"); is($read_data->{THREE}{BBBB}, 'asd', "preserve"); is($read_data->{THREE}{CCCC}, 'asd', "preserve"); is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one Two Three Four Five Six)], "the sections order is remembered with correct case"); my $missing=0; foreach (@{$read_data->{'__SECTIONS__'}}) { $missing++ unless exists ($read_data->{$_}); } is ($missing, 0, "All sections in __SECTIONS__ are accessible"); } { my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'lower'}); is($read_data->{Three}{AAAA}, 'asd', "lower"); is($read_data->{three}{AAAA}, 'asd', "lower"); is($read_data->{THREE}{AAAA}, 'asd', "lower"); is($read_data->{THREE}{aaaa}, 'asd', "lower"); is($read_data->{THREE}{Bbbb}, 'asd', "lower"); is($read_data->{THREE}{CCCC}, 'asd', "lower"); is($read_data->{THREE}{aaaa}, 'asd', "lower"); is($read_data->{THREE}{bbbb}, 'asd', "lower"); is($read_data->{THREE}{cccc}, 'asd', "lower"); is($read_data->{THREE}{AAAA}, 'asd', "lower"); is($read_data->{THREE}{BBBB}, 'asd', "lower"); is($read_data->{THREE}{CCCC}, 'asd', "lower"); my %keys; @keys{keys %$read_data} = (); is_deeply(\%keys, {map {$_ => undef} qw(:default one two three four five six __SECTIONS__)}, "the sections are remembered with correct case"); is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one two three four five six)], "the sections order is remembered with correct case"); my $missing=0; foreach (@{$read_data->{'__SECTIONS__'}}) { $missing++ unless exists ($read_data->{$_}); } is ($missing, 0, "All sections in __SECTIONS__ are accessible"); } { my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'upper'}); is($read_data->{Three}{AAAA}, 'asd', "upper"); is($read_data->{three}{AAAA}, 'asd', "upper"); is($read_data->{THREE}{AAAA}, 'asd', "upper"); is($read_data->{THREE}{aaaa}, 'asd', "upper"); is($read_data->{THREE}{Bbbb}, 'asd', "upper"); is($read_data->{THREE}{CCCC}, 'asd', "upper"); is($read_data->{THREE}{aaaa}, 'asd', "upper"); is($read_data->{THREE}{bbbb}, 'asd', "upper"); is($read_data->{THREE}{cccc}, 'asd', "upper"); is($read_data->{THREE}{AAAA}, 'asd', "upper"); is($read_data->{THREE}{BBBB}, 'asd', "upper"); is($read_data->{THREE}{CCCC}, 'asd', "upper"); my %keys; @keys{keys %$read_data} = (); is_deeply(\%keys, {map {$_ => undef} qw(:DEFAULT ONE TWO THREE FOUR FIVE SIX __SECTIONS__)}, "the sections are remembered with correct case"); is_deeply($read_data->{'__SECTIONS__'}, [qw(:DEFAULT ONE TWO THREE FOUR FIVE SIX)], "the sections order is remembered with correct case"); is_deeply($read_data->{'__SECTIONS__'}, [qw(:DEFAULT ONE TWO THREE FOUR FIVE SIX)], "the sections order is remembered with correct case"); my $missing=0; foreach (@{$read_data->{'__SECTIONS__'}}) { $missing++ unless exists ($read_data->{$_}); } is ($missing, 0, "All sections in __SECTIONS__ are accessible"); } # defaults { my $read_data = ReadINI( $filename, {case => 'preserve', withdefaults => 1}); ok(ref($read_data), "withdefaults => 1, case => preserve"); AddDefaults($read_data, 'one', ':default'); is($read_data->{one}{int}, 1, "found the own value"); is($read_data->{one}{foo}, 'dz_difolt', "found a default value"); is($read_data->{one}{bar}, undef, "found a missing value"); } { my $read_data = ReadINI( $filename, {case => 'preserve', withdefaults => 1}); ok(ref($read_data), "withdefaults => 1, case => preserve with custom defaults"); AddDefaults($read_data, 'one', {int => 99, foo => 'custom'}); is($read_data->{one}{int}, 1, "found the own value"); is($read_data->{one}{foo}, 'custom', "found a default value"); is($read_data->{one}{bar}, undef, "found a missing value"); } { my $read_data = ReadINI( $filename, {case => 'toupper', withdefaults => 1}); ok(ref($read_data), "withdefaults => 1, case => toupper"); AddDefaults($read_data, 'ONE', ':DEFAULT'); is($read_data->{ONE}{INT}, 1, "found the own value"); is($read_data->{ONE}{FOO}, 'dz_difolt', "found a default value"); is($read_data->{ONE}{BAR}, undef, "found a missing value"); } { my $read_data = ReadINI( $filename, {case => 'preserve', sectionorder => 1}); (my $filename2 = $filename) =~ s/\.ini$/-3.ini/; ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => preserve, sectionorder => 1"); END {unlink $filename2}; my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 1}); is_deeply( $read_data2, $read_data, "Still have the same data") } { my $read_data = ReadINI( $filename, {case => 'tolower', sectionorder => 1}); (my $filename2 = $filename) =~ s/\.ini$/-3.ini/; ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => tolower, sectionorder => 1"); my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 1}); is_deeply( $read_data2, $read_data, "Still have the same data") } { my $read_data = ReadINI( $filename, {case => 'toupper', sectionorder => 1}); (my $filename2 = $filename) =~ s/\.ini$/-3.ini/; ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => toupper, sectionorder => 1"); my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 1}); is_deeply( $read_data2, $read_data, "Still have the same data") } { my $read_data = ReadINI( $filename, {case => 'lower', sectionorder => 1}); (my $filename2 = $filename) =~ s/\.ini$/-3.ini/; ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => lower, sectionorder => 1"); my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 1}); is_deeply( $read_data2, $read_data, "Still have the same data") } { my $read_data = ReadINI( $filename, {case => 'upper', sectionorder => 1}); (my $filename2 = $filename) =~ s/\.ini$/-3.ini/; ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => upper, sectionorder => 1"); my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 1}); is_deeply( $read_data2, $read_data, "Still have the same data") } { my $read_data = ReadINI( $filename, {case => 'preserve', sectionorder => 1}); (my $filename2 = $filename) =~ s/\.ini$/-3.ini/; ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => preserve, sectionorder => 1"); my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 1}); is_deeply( $read_data2, $read_data, "Still have the same data") } { my $read_data = ReadINI( $filename, {case => 'preserve', sectionorder => 0}); (my $filename2 = $filename) =~ s/\.ini$/-3.ini/; ok(WriteINI( $filename2, $read_data), "Wrote the ini file with case => preserve, sectionorder => 0"); my $read_data2 = ReadINI( $filename2, {case => 'preserve', sectionorder => 0}); is_deeply( $read_data2, $read_data, "Still have the same data") } { my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'lower', class => 'Hash::Case::Lower'}); is($read_data->{Three}{AAAA}, 'asd', "Hash::Case::Lower"); is($read_data->{three}{AAAA}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{AAAA}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{aaaa}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{Bbbb}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{CCCC}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{aaaa}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{bbbb}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{cccc}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{AAAA}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{BBBB}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{CCCC}, 'asd', "Hash::Case::Lower"); my %keys; @keys{keys %$read_data} = (); is_deeply(\%keys, {map {$_ => undef} qw(:default one two three four five six __sections__)}, "the sections are remembered with correct case"); is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one two three four five six)], "the sections order is remembered with correct case"); my $missing=0; foreach (@{$read_data->{'__SECTIONS__'}}) { $missing++ unless exists ($read_data->{$_}); } is ($missing, 0, "All sections in __SECTIONS__ are accessible"); } { my $read_data = ReadINI( $filename, {sectionorder => 1, case => 'preserve', class => 'Hash::Case::Lower'}); is($read_data->{Three}{AAAA}, 'asd', "Hash::Case::Lower"); is($read_data->{three}{AAAA}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{AAAA}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{aaaa}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{Bbbb}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{CCCC}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{aaaa}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{bbbb}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{cccc}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{AAAA}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{BBBB}, 'asd', "Hash::Case::Lower"); is($read_data->{THREE}{CCCC}, 'asd', "Hash::Case::Lower"); my %keys; @keys{keys %$read_data} = (); is_deeply(\%keys, {map {$_ => undef} qw(:default one two three four five six __sections__)}, "the sections are remembered with correct case"); is_deeply($read_data->{'__SECTIONS__'}, [qw(:default one Two Three Four Five Six)], "the sections order is remembered with correct case"); my $missing=0; foreach (@{$read_data->{'__SECTIONS__'}}) { $missing++ unless exists ($read_data->{$_}); } is ($missing, 0, "All sections in __SECTIONS__ are accessible"); } lib000777000000000000 011213225104 15413 5ustar00unknownunknown000000000000Config-IniHash-3.01.01Config000777000000000000 011213225104 16620 5ustar00unknownunknown000000000000Config-IniHash-3.01.01/libIniHash.pm000444000000000000 4717111213224621 20667 0ustar00unknownunknown000000000000Config-IniHash-3.01.01/lib/Configpackage Config::IniHash; use 5.8.0; use Carp; use strict; use warnings;no warnings 'uninitialized'; use Symbol; use Encode qw(is_utf8); use Exporter; use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION); @ISA = qw(Exporter); @EXPORT = qw(&ReadINI &WriteINI &PrintINI); @EXPORT_OK = qw(&ReadINI &WriteINI &PrintINI &AddDefaults &ReadSection); $VERSION = '3.01.01'; if (0) { # for PerlApp/PerlSvc/PerlCtrl/Perl2Exe require 'Hash/WithDefaults.pm'; require 'Hash/Case/Lower.pm'; require 'Hash/Case/Upper.pm'; require 'Hash/Case/Preserve.pm'; } #use vars qw(heredoc systemvars withdefaults forValue); $Config::IniHash::case = 'lower'; # upper, preserve, toupper, tolower $Config::IniHash::heredoc = 0; $Config::IniHash::systemvars = 1; $Config::IniHash::withdefaults = 0; $Config::IniHash::sectionorder = 0; $Config::IniHash::allowmultiple = 0; $Config::IniHash::comment = qr/^\s*[#;]/; $Config::IniHash::layer = ''; *Config::IniHash::allow_multiple = \$Config::IniHash::allowmultiple; sub BREAK () {1} sub prepareOpt { my $opt = shift(); $opt->{case} = $Config::IniHash::case unless exists $opt->{case}; $opt->{case} = $opt->{insensitive} if exists $opt->{insensitive}; # for backwards compatibility $opt->{heredoc} = $Config::IniHash::heredoc unless exists $opt->{heredoc}; $opt->{systemvars} = $Config::IniHash::systemvars unless exists $opt->{systemvars}; $opt->{withdefaults} = $Config::IniHash::withdefaults unless exists $opt->{withdefaults}; $opt->{forValue} = $Config::IniHash::forValue unless exists $opt->{forValue}; $opt->{sectionorder} = $Config::IniHash::sectionorder unless exists $opt->{sectionorder}; $opt->{allowmultiple} = $opt->{allow_multiple} unless exists $opt->{allowmultiple}; $opt->{allowmultiple} = $Config::IniHash::allowmultiple unless exists $opt->{allowmultiple}; $opt->{comment} = $Config::IniHash::comment unless exists $opt->{comment}; $opt->{layer} = $Config::IniHash::layer unless exists $opt->{layer}; $opt->{layer} = ':' . $opt->{layer} if $opt->{layer} and $opt->{layer} !~ /^:/; if ($opt->{class}) { delete $opt->{withdefaults}; } else { for ($opt->{case}) { $_ = lc $_; $_ = 'no' unless $_; local $Carp::CarpLevel = 1; /^lower/ and do { if ($opt->{sectionorder} and !ref($opt->{sectionorder})) { $opt->{class} = 'Hash::Case::LowerX'; } else { $opt->{class} = 'Hash::Case::Lower'; } undef $opt->{forName}; BREAK} or /^upper/ and do { $opt->{class} = 'Hash::Case::Upper'; undef $opt->{forName}; BREAK} or /^preserve/ and do { $opt->{class} = 'Hash::Case::Preserve'; undef $opt->{forName}; BREAK} or /^toupper/ and do { undef $opt->{class}; $opt->{forName} = 'uc'; BREAK} or /^tolower/ and do { undef $opt->{class}; $opt->{forName} = 'lc'; BREAK} or /^(?:no|sensitive)/ and do { undef $opt->{class}; undef $opt->{forName}; BREAK} or croak "Option 'case' may be set only to:\n\t'lower', 'upper', 'preserve', 'toupper', 'tolower' or 'no'\n"; } if ($opt->{class} and $opt->{class} ne 'Hash::Case::LowerX') { my $class = $opt->{class}; my $file = $class; $file =~ s{::}{/}g; if (!$INC{$file.'.pm'}) { eval "use $class;\n1" or croak "ERROR autoloading $class : $@"; } } if ($opt->{withdefaults} and !$INC{'Hash/WithDefaults.pm'}) { eval "use Hash::WithDefaults;\n1" or croak "ERROR autoloading Hash::WithDefaults : $@"; } } if (! $opt->{heredoc}) { $opt->{heredoc} = 0; } elsif (lc($opt->{heredoc}) eq 'perl') { $opt->{heredoc} = 'perl' } else { $opt->{heredoc} = 1; } if (defined $opt->{systemvars} and $opt->{systemvars}) { $opt->{systemvars} = \%ENV unless (ref $opt->{systemvars}); } else { $opt->{systemvars} = 0; } if (! ref $opt->{comment}) { $opt->{comment} = qr/^\s*[$opt->{comment}]/; } if (ref $opt->{allowmultiple}) { croak "The allowmultiple option must be a true or false scalar or a reference to a hash of arrays, hashes, regexps or comma separated lists of names!" unless ref $opt->{allowmultiple} eq 'HASH'; foreach my $section (values %{$opt->{allowmultiple}}) { if (! ref $section) { $section = {map( ($_ => undef), split( /\s*,\s*/, $section))}; } elsif (ref $section eq 'ARRAY') { $section = {map( ($_ => undef), @$section)}; } elsif (ref $section eq 'Regexp') { } elsif (ref $section ne 'HASH') { croak "The allowmultiple option must be a true or false scalar or a reference to a hash of arrays, hashes, regexps or comma separated lists of names!" } } } } sub ReadINI { my $file = shift; my %opt; if (@_ == 1 and ref $_[0]) { %opt = %{$_[0]}; } elsif (@_ % 2 == 0) { %opt = @_; } else { croak("ReadINI expects the filename plus either a reference to a hash of options or a list with even number of items!"); } prepareOpt(\%opt); my $hash; if ($opt{hash}) { $hash = $opt{hash}; } else { $hash = {}; tie %$hash, $opt{class} if $opt{class}; } my $section = ''; my $IN; if (ref $file) { my $ref = ref $file; if ($ref eq 'SCALAR') { if (is_utf8($$file)) { $opt{layer} .= ':utf8' unless $opt{layer} =~ /\butf-?8\b/i; } open $IN, "<$opt{layer}", $file; # will read from the referenced scalar } elsif ($ref eq 'ARRAY') { my $data = join "\n", map {s/\r?\n/\n/;chomp;$_} @$file; if (is_utf8($data)) { $opt{layer} .= ':utf8' unless $opt{layer} =~ /\butf-?8\b/i; } open $IN, "<$opt{layer}",\$data; # will read from the referenced scalar } elsif ($ref eq 'HASH') { croak "ReadINI cannot accept a HASH reference as it's parameter!"; } else { $IN = $file; #assuming it's a glob or an object that'll know what to do } } else { if ($opt{layer}) { open $IN, "<$opt{layer}", $file or return undef; } else { open $IN, $file or return undef; } my $bom = <$IN>; if ($bom =~ /\r/) { $opt{layer} .= ':crlf'; } if (substr($bom, 0, 3) eq "\xEF\xBB\xBF") { $opt{layer} .= ':utf8'; close $IN; open $IN, "<$opt{layer}", $file or return undef; read $IN, $bom, 1; } elsif (substr($bom, 0, 1) eq "\x{feff}") { seek($IN,2,0); } else { seek($IN,0,0); } } my ($lc,$uc) = ( (defined $opt{forName} and $opt{forName} eq 'lc'), (defined $opt{forName} and $opt{forName} eq 'uc')); if ($opt{sectionorder}) { my $arrayref; if (ref $opt{sectionorder}) { $arrayref = $opt{sectionorder} } else { $arrayref = $hash->{'__SECTIONS__'} = []; } if ($opt{case} eq 'lower' or $opt{case} eq 'tolower') { $opt{sectionorder} = sub {push @$arrayref, lc($_[0])} } elsif ($opt{case} eq 'upper' or $opt{case} eq 'toupper') { $opt{sectionorder} = sub {push @$arrayref, uc($_[0])} } else { $opt{sectionorder} = sub {push @$arrayref, $_[0]} } } my $forValue = $opt{forValue}; while (<$IN>) { $_ =~ $opt{comment} and next; if (/^\[(.*)\]/) { $section = $1; $opt{sectionorder}->($section) if $opt{sectionorder}; if ($lc) { $section = lc $section} elsif ($uc) { $section = uc $section }; unless ($hash->{$section}) { my %tmp = (); if ($opt{withdefaults}) { tie %tmp, 'Hash::WithDefaults', $opt{case}; } else { tie %tmp, $opt{class} if $opt{class}; } $hash->{$section} = \%tmp; } next; } if (/^([^=]*?)\s*=\s*(.*?)\s*$/) { my ($name,$value) = ($1,$2); if ($opt{heredoc} eq 'perl' and $value =~ /^<<(['"])?(.+)\1\s*$/) { my $type = $1; my $terminator = $2; $value = ''; while (<$IN>) { chomp; last if $_ eq $terminator; $value .= "\n".$_; } croak "Heredoc value for [$section]$name not closed at end of file!" unless defined $_; substr ($value, 0, 1) = ''; if ($type eq '') { $value =~ s/%([^%]*)%/exists($opt{systemvars}{$1}) ? $opt{systemvars}{$1} : "%$1%"/eg if $opt{systemvars}; } elsif ($type eq q{"}) { if ($opt{systemvars}) { $value =~ s/%([^%]*)%/$opt{systemvars}{$1}/g; } else { $value =~ s/%([^%]*)%/$ENV{$1}/g; } } } elsif ($opt{heredoc} and $value =~ /^<<(.+)\s*$/) { my $terminator = $1; $value = ''; while (<$IN>) { chomp; last if $_ eq $terminator; $value .= "\n".$_; } croak "Heredoc value for [$section]$name not closed at end of file!" unless defined $_; substr ($value, 0, 1) = ''; $value =~ s/%([^%]*)%/exists($opt{systemvars}{$1}) ? $opt{systemvars}{$1} : "%$1%"/eg if $opt{systemvars}; } else { $value =~ s/%([^%]*)%/exists($opt{systemvars}{$1}) ? $opt{systemvars}{$1} : "%$1%"/eg if $opt{systemvars}; } if ($lc) { $name = lc $name} elsif ($uc) { $name = uc $name }; if ($forValue) { $value = $forValue->($name, $value, $section, $hash); } if (defined $value) { if (!$opt{allowmultiple}) { $hash->{$section}{$name} = $value; # overwrite } elsif (!ref $opt{allowmultiple}) { if (exists $hash->{$section}{$name}) { if (ref $hash->{$section}{$name}) { push @{$hash->{$section}{$name}}, $value; } else { $hash->{$section}{$name} = [ $hash->{$section}{$name}, $value]; # second value } } else { $hash->{$section}{$name} = $value; # set } } else { if (exists $opt{allowmultiple}{$section}{$name} or exists $opt{allowmultiple}{'*'}{$name}) { push @{$hash->{$section}{$name}}, $value; } else { $hash->{$section}{$name} = $value; # set } } } } } close $IN; return $hash; } sub WriteINI { my ($file,$hash) = @_; open my $OUT, ">$file" or return undef; if (exists $hash->{'__SECTIONS__'}) { my $all_have_order = (scalar(@{$hash->{'__SECTIONS__'}}) == scalar(keys %$hash)-1); foreach my $section (@{$hash->{'__SECTIONS__'}}) { print $OUT "[$section]\n"; my $sec; if (exists $hash->{$section}) { my $sec = $hash->{$section}; foreach my $key (sort keys %{$hash->{$section}}) { if ($key =~ /^[#';]/ and ! defined($sec->{$key})) { print $OUT "$key\n"; } elsif ($sec->{$key} =~ /\n/) { print $OUT "$key=<<*END_$key*\n$sec->{$key}\n*END_$key*\n"; } else { print $OUT "$key=$sec->{$key}\n"; } } } else { $all_have_order = 0; } print $OUT "\n"; } if (!$all_have_order) { my %ordered; @ordered{@{$hash->{'__SECTIONS__'}}} = (); foreach my $section (keys %$hash) { next if exists($ordered{$section}) or $section eq '__SECTIONS__'; print $OUT "[$section]\n"; my $sec = $hash->{$section}; foreach my $key (sort keys %{$hash->{$section}}) { if ($key =~ /^[#';]/ and ! defined($sec->{$key})) { print $OUT "$key\n"; } elsif ($sec->{$key} =~ /\n/) { print $OUT "$key=<<*END_$key*\n$sec->{$key}\n*END_$key*\n"; } else { print $OUT "$key=$sec->{$key}\n"; } } print $OUT "\n"; } } } else { foreach my $section (keys %$hash) { print $OUT "[$section]\n"; my $sec = $hash->{$section}; foreach my $key (keys %{$hash->{$section}}) { if ($key =~ /^[#';]/ and ! defined($sec->{$key})) { print $OUT "$key\n"; } elsif ($sec->{$key} =~ /\n/) { print $OUT "$key=<<*END_$key*\n$sec->{$key}\n*END_$key*\n"; } else { print $OUT "$key=$sec->{$key}\n"; } } print $OUT "\n"; } } close $OUT; return 1; } *PrintINI = \&WriteINI; sub AddDefaults { my ($ini, $section, $defaults) = @_; croak "$section doesn't exist in the hash!" unless exists $ini->{$section}; croak "You can call AddDefaults ONLY on hashes created with\n\$Config::IniHash::withdefaults=1 !" unless tied(%{$ini->{$section}}) and tied(%{$ini->{$section}})->isa('Hash::WithDefaults'); if (ref $defaults) { croak "The defaults must be a section name or a hash ref!" unless ref $defaults eq 'HASH'; tied(%{$ini->{$section}})->AddDefault($defaults); } else { croak "$defaults doesn't exist in the hash!" unless exists $ini->{$defaults}; tied(%{$ini->{$section}})->AddDefault($ini->{$defaults}); } } sub ReadSection { my $text = shift; my %opt = @_; prepareOpt(\%opt); my $hash= {}; if ($opt{withdefaults}) { tie %$hash, 'Hash::WithDefaults', $opt{case}; } else { tie %$hash, $opt{class} if $opt{class}; } open my $IN, '<', \$text; my ($lc,$uc) = ( $opt{forName} eq 'lc', $opt{forName} eq 'uc'); my $forValue = $opt{forValue}; while (<$IN>) { /^\s*;/ and next; if (/^([^=]*?)\s*=\s*(.*?)\s*$/) { my ($name,$value) = ($1,$2); if ($opt{heredoc} and $value =~ /^<<(.+)$/) { my $terminator = $1; $value = ''; while (<$IN>) { chomp; last if $_ eq $terminator; $value .= "\n".$_; } croak "Heredoc value for $name not closed at end of string!" unless defined $_; substr ($value, 0, 1) = ''; } $value =~ s/%(.*?)%/$opt{systemvars}{$1}/g if $opt{systemvars}; if ($lc) { $name = lc $name} elsif ($uc) { $name = uc $name }; if ($forValue) { $value = $forValue->($name, $value, undef, $hash); } $hash->{$name} = $value; } } close $IN; return $hash; } package Hash::Case::LowerX; use base 'Hash::Case'; use strict; use Carp; sub init($) { my ($self, $args) = @_; $self->SUPER::native_init($args); croak "No options possible for ".__PACKAGE__ if keys %$args; $self; } sub FETCH($) { $_[0]->{($_[1] eq '__SECTIONS__' ? $_[1] : lc $_[1])} } sub STORE($$) { $_[0]->{($_[1] eq '__SECTIONS__' ? $_[1] : lc $_[1])} = $_[2] } sub EXISTS($) { exists $_[0]->{($_[1] eq '__SECTIONS__' ? $_[1] : lc $_[1])} } sub DELETE($) { delete $_[0]->{($_[1] eq '__SECTIONS__' ? $_[1] : lc $_[1])} } 1; __END__ =head1 NAME Config::IniHash - Perl extension for reading and writing INI files =head1 VERSION Version 3.00.05 =head1 SYNOPSIS use Config::IniHash; $Config = ReadINI 'c:\some\file.ini'; =head1 DESCRIPTION This module reads and writes INI files. =head2 Functions =head3 ReadINI $hashreference = ReadINI ($filename, %options) $hashreference = ReadINI (\$data, %options) $hashreference = ReadINI (\@data, %options) $hashreference = ReadINI ($filehandle, %options) The returned hash contains a reference to a hash for each section of the INI. [section] name=value leads to $hash->{section}->{name} = value; The available options are: =over 4 =item heredoc - controls whether the module supports the heredoc syntax : name=<{section}{name} will be '<{section}{name} will be "the\nmany lines\nlong value" The Perl-lie extensions of name=<<"END" and <<'END' are not supported! 'Perl' : heredocs are supported, $data->{section}{name} will be "the\nmany lines\nlong value" The Perl-lie extensions of name=<<"END" and <<'END' are supported. The <<'END' never interpolates %variables%, the "END" always interpolates variables, unlike in other values, the %variables% that are not defined do not stay in the string! Default: 0 = OFF =item systemvars - controls whether the (system) variables enclosed in %% are interpolated and optionaly contains the values in a hash ref. name=%USERNAME% leads to $data->{section}->{name} = "Jenda" systemvars = 1 - yes, take values from %ENV systemvars = \%hash - yes, take values from %hash systemvars = 0 - no =item case - controls whether the created hash is case insensitive. The possible values are sensitive - the hash will be case sensitive tolower - the hash will be case sensitive, all keys are made lowercase toupper - the hash will be case sensitive, all keys are made uppercase preserve - the hash will be case insensitive, the case is preserved (tied) lower - the hash will be case insensitive, all keys are made lowercase (tied) upper - the hash will be case insensitive, all keys are made uppercase (tied) =item withdefaults - controls whether the created section hashes support defaults. See L. =item class - allows you to specify the class into which to tie the created hashes. This option overwrites the "case" and "withdefaults" options! You may for example use class => 'Tie::IxHash', to store the sections in hashes that remember the insertion order. =item sectionorder - if set to a true value then created hash will contain $config->{'__SECTIONS__'} = [ 'the', 'names', 'of', 'the', 'sections', 'in', 'the', 'order', 'they', 'were', 'specified', 'in', 'the', 'INI file']; - if set to an array ref, then the list will be stored in that array, and no $config->{'__SECTIONS__'} is created. The case of the section names stored in this array is controled by the "case" option even in case you specify the "class". =item allowmultiple - if set to a true scalar value then multiple items with the same names in a section do not overwrite each other, but result in an array of the values. - if set to a hash of hashes (or hash of arrays or hash of comma separated item names) specifies what items in what sections will end up as hashes containing the list of values. All the specified items will be arrays, even if there is just a single value. To affect the items in all sections use section name '*'. By default false. =item forValue - allows you to install a callback that will be called for each value as soon as it is read but before it is stored in the hash. The function is called like this: $value = $forValue->($name, $value, $sectionname, $INIhashref); If the callback returns an undef, the value will not be stored. =item comment - regular expression used to identify comments or a string containing the list of characters starting a comment. Each line is tested against the regexp is ignored if matches. If you specify a string a regexp like this will be created: qr/^\s*[the_list]/ The default is qr/^\s*[#;] =item layer - the IO layer(s) to use when opening the file. See perldoc C. If the file is in UTF8 and starts with a BOM it will be automaticaly opened in UTF8 mode and the BOM will be stripped. If it doesn't start with the BOM you have to specify the utf8 layer! =back You may also set the defaults for the options by modifying the $Config::IniHash::optionname variables. These default settings will be used if you do not specify the option in the ReadINI() or ReadSection() call. =head3 AddDefaults AddDefaults( $config, 'normal section name', 'default section name'); AddDefaults( $config, 'normal section name', \%defaults); This subroutine adds a some default values into a section. The values are NOT copied into the section, but rather the section knows to look up the missing options in the default section or hash. Eg. if (exists $config->{':default'}) { foreach my $section (keys %$config) { next if $section =~ /^:/; AddDefaults( $config, $section, ':default'); } } =head3 ReadSection $hashreference = ReadSection ($string) This function parses a string as if it was a section of an INI file and creates a hash with the values. It accepts the same options as ReadINI. =head3 WriteINI WriteINI ($filename, $hashreference) Writes the hash of hashes to a file. =head3 PrintINI The same as WriteINI(). =head1 AUTHOR Jan Krynicky http://Jenda.Krynicky.cz =head1 COPYRIGHT Copyright (c) 2002-2005 Jan Krynicky . All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut