r33091 - in /branches/upstream/libconfig-inifiles-perl/current: Changes MANIFEST META.yml lib/Config/IniFiles.pm t/05hash.t t/11copy-ties-with-array-vals.t t/21multiline-values-in-tied.t t/22trailing-comment-lines.t t/trailing-comments.ini
ansgar-guest at users.alioth.debian.org
ansgar-guest at users.alioth.debian.org
Sun Apr 12 12:00:34 UTC 2009
Author: ansgar-guest
Date: Sun Apr 12 12:00:24 2009
New Revision: 33091
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=33091
Log:
[svn-upgrade] Integrating new upstream version, libconfig-inifiles-perl (2.48)
Added:
branches/upstream/libconfig-inifiles-perl/current/t/22trailing-comment-lines.t
branches/upstream/libconfig-inifiles-perl/current/t/trailing-comments.ini
Removed:
branches/upstream/libconfig-inifiles-perl/current/t/21multiline-values-in-tied.t
Modified:
branches/upstream/libconfig-inifiles-perl/current/Changes
branches/upstream/libconfig-inifiles-perl/current/MANIFEST
branches/upstream/libconfig-inifiles-perl/current/META.yml
branches/upstream/libconfig-inifiles-perl/current/lib/Config/IniFiles.pm
branches/upstream/libconfig-inifiles-perl/current/t/05hash.t
branches/upstream/libconfig-inifiles-perl/current/t/11copy-ties-with-array-vals.t
Modified: branches/upstream/libconfig-inifiles-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libconfig-inifiles-perl/current/Changes?rev=33091&op=diff
==============================================================================
--- branches/upstream/libconfig-inifiles-perl/current/Changes (original)
+++ branches/upstream/libconfig-inifiles-perl/current/Changes Sun Apr 12 12:00:24 2009
@@ -1,3 +1,17 @@
+Version 2.48: ( Tue Apr 7 15:24:55 IDT 2009 )
+------------------------------------------------
+
+* Fixed bug https://rt.cpan.org/Ticket/Display.html?id=30402 :
+- Trailing comments at the end of the file are not written.
+- added a test (t/22trailing-comment-lines.t ) and a test file.
+
+* Reverted the fix to bug #34067 ( "Multiline values returned as array
+references in tied hash interface"), as it could potentially break a lot
+of old code, and was not such a good idea, and was less preferable from
+interface-sanity reasons.
+
+* Documented the old API in regards to bug #34067 - see above.
+
Version 2.47: ( Wed Jan 21 11:32:24 IST 2009 )
------------------------------------------------
Modified: branches/upstream/libconfig-inifiles-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libconfig-inifiles-perl/current/MANIFEST?rev=33091&op=diff
==============================================================================
--- branches/upstream/libconfig-inifiles-perl/current/MANIFEST (original)
+++ branches/upstream/libconfig-inifiles-perl/current/MANIFEST Sun Apr 12 12:00:24 2009
@@ -28,7 +28,7 @@
t/18non-contiguous-groups.t
t/19param-found-outside-section.t
t/20allowedcommentchars.t
-t/21multiline-values-in-tied.t
+t/22trailing-comment-lines.t
t/allowed-comment-chars.ini
t/array.ini
t/bad.ini
@@ -42,3 +42,4 @@
t/lib/Config/IniFiles/Debug.pm
t/non-contiguous-groups.ini
t/test.ini
+t/trailing-comments.ini
Modified: branches/upstream/libconfig-inifiles-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libconfig-inifiles-perl/current/META.yml?rev=33091&op=diff
==============================================================================
--- branches/upstream/libconfig-inifiles-perl/current/META.yml (original)
+++ branches/upstream/libconfig-inifiles-perl/current/META.yml Sun Apr 12 12:00:24 2009
@@ -1,6 +1,6 @@
---
name: Config-IniFiles
-version: 2.47
+version: 2.48
author: []
abstract: A module for reading .ini-style configuration files.
license: perl
@@ -17,8 +17,8 @@
provides:
Config::IniFiles:
file: lib/Config/IniFiles.pm
- version: 2.47
-generated_by: Module::Build version 0.31
+ version: 2.48
+generated_by: Module::Build version 0.32
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.2.html
version: 1.2
Modified: branches/upstream/libconfig-inifiles-perl/current/lib/Config/IniFiles.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libconfig-inifiles-perl/current/lib/Config/IniFiles.pm?rev=33091&op=diff
==============================================================================
--- branches/upstream/libconfig-inifiles-perl/current/lib/Config/IniFiles.pm (original)
+++ branches/upstream/libconfig-inifiles-perl/current/lib/Config/IniFiles.pm Sun Apr 12 12:00:24 2009
@@ -2,7 +2,7 @@
use vars qw($VERSION);
-$VERSION = "2.47";
+$VERSION = "2.48";
require 5.004;
use strict;
@@ -369,6 +369,8 @@
$self->{allowed_comment_char} = ';' unless exists $self->{allowed_comment_char};
# make sure that comment character is always allowed
$self->{allowed_comment_char} .= $self->{comment_char};
+
+ $self->{_comments_at_end_of_file} = [];
# Any other parameters are unkown
while (($k, $v) = each %parms) {
@@ -854,6 +856,8 @@
$self->AddSection($defaultsect);
} # end if
+ $self->_SetEndComments(@cmts);
+
$self->_rollback($fh);
@Config::IniFiles::errors ? undef : 1;
}
@@ -1299,85 +1303,90 @@
# should be set to 1 if writing only delta.
sub OutputConfig {
- my ($self, $delta) = @_;
-
- my($sect, $parm, @cmts);
- my $ors = $self->{line_ends} || $\ || "\n"; # $\ is normally unset, but use input by default
- my $notfirst = 0;
- local $_;
- SECT: foreach $sect (@{$self->{$delta ? "mysects" : "sects"}}) {
- if (!defined $self->{v}{$sect}) {
- if ($delta) {
- print "$self->{comment_char} [$sect] is deleted$ors";
- } else {
- warn "Weird unknown section $sect" if $^W;
- }
- next SECT;
+ my ($self, $delta) = @_;
+
+ my($sect, $parm, @cmts);
+ my $ors = $self->{line_ends} || $\ || "\n"; # $\ is normally unset, but use input by default
+ my $notfirst = 0;
+ local $_;
+ SECT:
+ foreach $sect (@{$self->{$delta ? "mysects" : "sects"}}) {
+ if (!defined $self->{v}{$sect}) {
+ if ($delta) {
+ print "$self->{comment_char} [$sect] is deleted$ors";
+ } else {
+ warn "Weird unknown section $sect" if $^W;
+ }
+ next SECT;
+ }
+ next unless defined $self->{v}{$sect};
+ print $ors if $notfirst;
+ $notfirst = 1;
+ if ((ref($self->{sCMT}{$sect}) eq 'ARRAY') &&
+ (@cmts = @{$self->{sCMT}{$sect}})) {
+ foreach (@cmts) {
+ print "$_$ors";
+ }
+ }
+ print "[$sect]$ors";
+ next unless ref $self->{v}{$sect} eq 'HASH';
+
+ PARM:
+ foreach $parm (@{$self->{$delta ? "myparms" : "parms"}{$sect}}) {
+ if (!defined $self->{v}{$sect}{$parm}) {
+ if ($delta) {
+ print "$self->{comment_char} $parm is deleted$ors";
+ } else {
+ warn "Weird unknown parameter $parm" if $^W;
+ }
+ next PARM;
+ }
+ if ((ref($self->{pCMT}{$sect}{$parm}) eq 'ARRAY') &&
+ (@cmts = @{$self->{pCMT}{$sect}{$parm}})) {
+ foreach (@cmts) {
+ print "$_$ors";
+ }
+ }
+
+ my $val = $self->{v}{$sect}{$parm};
+ next if ! defined ($val); # No parameter exists !!
+ if (ref($val) eq 'ARRAY') {
+ my $eotmark = $self->{EOT}{$sect}{$parm} || 'EOT';
+ print "$parm= <<$eotmark$ors";
+ foreach (@{$val}) {
+ print "$_$ors";
+ }
+ print "$eotmark$ors";
+ } elsif( $val =~ /[$ors]/ ) {
+ # The FETCH of a tied hash is never called in
+ # an array context, so generate a EOT multiline
+ # entry if the entry looks to be multiline
+ my @val = split /[$ors]/, $val, -1;
+ if( @val > 1 ) {
+ my $eotmark = $self->{EOT}{$sect}{$parm} || 'EOT';
+
+ # Make sure the $eotmark does not occur inside the string.
+ my @letters = ('A' .. 'Z');
+ while (index($val, $eotmark) >= 0)
+ {
+ $eotmark .= $letters[rand(@letters)];
+ }
+
+ print "$parm= <<$eotmark$ors";
+ print map "$_$ors", @val;
+ print "$eotmark$ors";
+ } else {
+ print "$parm=$val[0]$ors";
+ } # end if
+ } else {
+ print "$parm=$val$ors";
+ }
+ }
}
- next unless defined $self->{v}{$sect};
- print $ors if $notfirst;
- $notfirst = 1;
- if ((ref($self->{sCMT}{$sect}) eq 'ARRAY') &&
- (@cmts = @{$self->{sCMT}{$sect}})) {
- foreach (@cmts) {
- print "$_$ors";
- }
+ foreach my $comment ($self->_GetEndComments()) {
+ print "$comment$ors";
}
- print "[$sect]$ors";
- next unless ref $self->{v}{$sect} eq 'HASH';
-
- PARM: foreach $parm (@{$self->{$delta ? "myparms" : "parms"}{$sect}}) {
- if (!defined $self->{v}{$sect}{$parm}) {
- if ($delta) {
- print "$self->{comment_char} $parm is deleted$ors";
- } else {
- warn "Weird unknown parameter $parm" if $^W;
- }
- next PARM;
- }
- if ((ref($self->{pCMT}{$sect}{$parm}) eq 'ARRAY') &&
- (@cmts = @{$self->{pCMT}{$sect}{$parm}})) {
- foreach (@cmts) {
- print "$_$ors";
- }
- }
-
- my $val = $self->{v}{$sect}{$parm};
- next if ! defined ($val); # No parameter exists !!
- if (ref($val) eq 'ARRAY') {
- my $eotmark = $self->{EOT}{$sect}{$parm} || 'EOT';
- print "$parm= <<$eotmark$ors";
- foreach (@{$val}) {
- print "$_$ors";
- }
- print "$eotmark$ors";
- } elsif( $val =~ /[$ors]/ ) {
- # The FETCH of a tied hash is never called in
- # an array context, so generate a EOT multiline
- # entry if the entry looks to be multiline
- my @val = split /[$ors]/, $val, -1;
- if( @val > 1 ) {
- my $eotmark = $self->{EOT}{$sect}{$parm} || 'EOT';
-
- # Make sure the $eotmark does not occur inside the string.
- my @letters = ('A' .. 'Z');
- while (index($val, $eotmark) >= 0)
- {
- $eotmark .= $letters[rand(@letters)];
- }
-
- print "$parm= <<$eotmark$ors";
- print map "$_$ors", @val;
- print "$eotmark$ors";
- } else {
- print "$parm=$val[0]$ors";
- } # end if
- } else {
- print "$parm=$val$ors";
- }
- }
- }
- return 1;
+ return 1;
}
=head2 SetSectionComment($section, @comment)
@@ -1531,6 +1540,22 @@
return scalar @comment;
}
+sub _SetEndComments
+{
+ my $self = shift;
+ my @comments = @_;
+
+ $self->{_comments_at_end_of_file} = \@comments;
+
+ return 1;
+}
+
+sub _GetEndComments {
+ my $self = shift;
+
+ return @{$self->{_comments_at_end_of_file}};
+}
+
=head2 GetParameterComment ($section, $parameter)
Gets the comment attached to a parameter. In list context returns all
@@ -1729,12 +1754,9 @@
Returns the value of $parameter in $section.
-Because of limitations in Perl's tie implementation,
-multiline values accessed through a hash will I<always> be returned
-as a single value with each line joined by the default line
-separator ($/). To break them apart you can simple do this:
-
- @lines = split( "$/", $ini{section}{multi_line_parameter} );
+Multiline values accessed through a hash will be returned
+as a list in list context and a concatenated value in scalar
+context.
=head2 $ini{$section}{$parameter} = $value;
@@ -2103,7 +2125,7 @@
# $key The name of the key whose value to get
#
# Description: Returns the value associated with $key. If
-# the value is a list, returns the list joined by $/.
+# the value is a list, returns a list reference.
# ----------------------------------------------------------
# Date Modification Author
# ----------------------------------------------------------
@@ -2114,7 +2136,7 @@
sub FETCH {
my ($self, $key)=@_;
my @retval=$self->{config}->val($self->{section}, $key);
- return (@retval <= 1) ? $retval[0] : join($/, @retval);
+ return (@retval <= 1) ? $retval[0] : \@retval;
} # end FETCH
Modified: branches/upstream/libconfig-inifiles-perl/current/t/05hash.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libconfig-inifiles-perl/current/t/05hash.t?rev=33091&op=diff
==============================================================================
--- branches/upstream/libconfig-inifiles-perl/current/t/05hash.t (original)
+++ branches/upstream/libconfig-inifiles-perl/current/t/05hash.t Sun Apr 12 12:00:24 2009
@@ -27,7 +27,7 @@
# Test 3
# Retrieve array reference
$value = $ini{test1}{mult};
-ok(ref $value ne 'ARRAY');
+ok(ref $value eq 'ARRAY');
# Test 4
# Creating a scalar value using tied hash
@@ -126,7 +126,7 @@
$ini{test1}{multi_2} = ['line 1', 'line 2'];
tied(%ini)->RewriteConfig;
tied(%ini)->ReadConfig;
- at value = split($/, $ini{test1}{multi_2});
+ at value = @{$ini{test1}{multi_2}};
ok( (@value == 2)
&& ($value[0] eq 'line 1')
&& ($value[1] eq 'line 2')
Modified: branches/upstream/libconfig-inifiles-perl/current/t/11copy-ties-with-array-vals.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libconfig-inifiles-perl/current/t/11copy-ties-with-array-vals.t?rev=33091&op=diff
==============================================================================
--- branches/upstream/libconfig-inifiles-perl/current/t/11copy-ties-with-array-vals.t (original)
+++ branches/upstream/libconfig-inifiles-perl/current/t/11copy-ties-with-array-vals.t Sun Apr 12 12:00:24 2009
@@ -18,8 +18,8 @@
%new_sect = %{$ini{Sect}};
- $new_sect{Par} = [1,'A',3];
+ $new_sect{Par}[1] = 'A';
# TEST
- is_deeply ($ini{Sect}{Par}, (1 . $/ . 2 . $/ . 3), '%ini was not modified');
+ is_deeply ($ini{Sect}{Par}, [1,2,3], '%ini was not modified');
}
Added: branches/upstream/libconfig-inifiles-perl/current/t/22trailing-comment-lines.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libconfig-inifiles-perl/current/t/22trailing-comment-lines.t?rev=33091&op=file
==============================================================================
--- branches/upstream/libconfig-inifiles-perl/current/t/22trailing-comment-lines.t (added)
+++ branches/upstream/libconfig-inifiles-perl/current/t/22trailing-comment-lines.t Sun Apr 12 12:00:24 2009
@@ -1,0 +1,47 @@
+#!/usr/bin/perl
+
+# This script attempts to reproduce:
+# https://rt.cpan.org/Ticket/Display.html?id=30402
+#
+# #30402: WriteConfig does not write the last lines of a file if they are comments
+
+use Test::More tests => 1;
+
+use strict;
+use warnings;
+
+use File::Spec;
+
+use Config::IniFiles;
+
+{
+ my $conf = Config::IniFiles->new(
+ -file => File::Spec->catfile(File::Spec->curdir(), 't', 'trailing-comments.ini')
+ );
+
+ my $new_file = File::Spec->catfile(
+ File::Spec->curdir(), 't', 'new-trail.ini'
+ );
+
+ $conf->WriteConfig($new_file);
+
+ my $buffer;
+ {
+ local $/;
+ open my $fh, "<", $new_file;
+ $buffer = <$fh>;
+ close($fh);
+ }
+
+ # TEST
+ like(
+ $buffer,
+ qr{; End Comment 1\n; End Comment 2\n+\z}ms,
+ "WriteConfig() Preserved end comments."
+ );
+
+ # Remove the generated files so they won't pollute the filesystem /
+ # working-copy.
+ unlink($new_file);
+}
+
Added: branches/upstream/libconfig-inifiles-perl/current/t/trailing-comments.ini
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libconfig-inifiles-perl/current/t/trailing-comments.ini?rev=33091&op=file
==============================================================================
--- branches/upstream/libconfig-inifiles-perl/current/t/trailing-comments.ini (added)
+++ branches/upstream/libconfig-inifiles-perl/current/t/trailing-comments.ini Sun Apr 12 12:00:24 2009
@@ -1,0 +1,6 @@
+[test]
+key1=value1
+key2=value2
+; End Comment 1
+; End Comment 2
+
More information about the Pkg-perl-cvs-commits
mailing list