r63608 - in /branches/upstream/libhash-flatten-perl/current: Changes META.yml README lib/Hash/Flatten.pm t/hash_flatten.t
ansgar at users.alioth.debian.org
ansgar at users.alioth.debian.org
Mon Oct 11 14:14:55 UTC 2010
Author: ansgar
Date: Mon Oct 11 14:14:27 2010
New Revision: 63608
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=63608
Log:
[svn-upgrade] new version libhash-flatten-perl (1.19)
Modified:
branches/upstream/libhash-flatten-perl/current/Changes
branches/upstream/libhash-flatten-perl/current/META.yml
branches/upstream/libhash-flatten-perl/current/README
branches/upstream/libhash-flatten-perl/current/lib/Hash/Flatten.pm
branches/upstream/libhash-flatten-perl/current/t/hash_flatten.t
Modified: branches/upstream/libhash-flatten-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhash-flatten-perl/current/Changes?rev=63608&op=diff
==============================================================================
--- branches/upstream/libhash-flatten-perl/current/Changes (original)
+++ branches/upstream/libhash-flatten-perl/current/Changes Mon Oct 11 14:14:27 2010
@@ -1,3 +1,9 @@
+Thu Sep 23 09:52:13 2010 - 1.19
+ * Fix handling of 0 and '' key values (thanks to Fabrice Dulaunoy)
+ * Update docs to reflect behaviour: EscapeSequence=undef
+ doesn't work, you need to use the DisableEscapes Option
+ (thanks to Fischer Ronald)
+
Tue Apr 11 14:44:55 2006 - 1.16
* modified default escape sequence handling (bug fix)
* unit tests now change into t/ directory correctly under windows environment
Modified: branches/upstream/libhash-flatten-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhash-flatten-perl/current/META.yml?rev=63608&op=diff
==============================================================================
--- branches/upstream/libhash-flatten-perl/current/META.yml (original)
+++ branches/upstream/libhash-flatten-perl/current/META.yml Mon Oct 11 14:14:27 2010
@@ -1,12 +1,23 @@
-# http://module-build.sourceforge.net/META-spec.html
-#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
-name: Hash-Flatten
-version: 1.16
-version_from: lib/Hash/Flatten.pm
-installdirs: site
+--- #YAML:1.0
+name: Hash-Flatten
+version: 1.19
+abstract: flatten/unflatten complex data hashes
+author:
+ - British Broadcasting Corporation
+license: unknown
+distribution_type: module
+configure_requires:
+ ExtUtils::MakeMaker: 0
+build_requires:
+ ExtUtils::MakeMaker: 0
requires:
- Log::Trace: 0
- Test::Assertions: 0
-
-distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.17
+ Log::Trace: 0
+ Test::Assertions: 0
+no_index:
+ directory:
+ - t
+ - inc
+generated_by: ExtUtils::MakeMaker version 6.56
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
Modified: branches/upstream/libhash-flatten-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhash-flatten-perl/current/README?rev=63608&op=diff
==============================================================================
--- branches/upstream/libhash-flatten-perl/current/README (original)
+++ branches/upstream/libhash-flatten-perl/current/README Mon Oct 11 14:14:27 2010
@@ -1,4 +1,4 @@
-Hash::Flatten v1.16
+Hash::Flatten v1.19
(c) BBC 2004. This program is free software; you can redistribute it and/or
modify it under the GNU GPL.
Modified: branches/upstream/libhash-flatten-perl/current/lib/Hash/Flatten.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhash-flatten-perl/current/lib/Hash/Flatten.pm?rev=63608&op=diff
==============================================================================
--- branches/upstream/libhash-flatten-perl/current/lib/Hash/Flatten.pm (original)
+++ branches/upstream/libhash-flatten-perl/current/lib/Hash/Flatten.pm Mon Oct 11 14:14:27 2010
@@ -2,7 +2,7 @@
# Purpose : Flatten/Unflatten nested data structures to/from key-value form
# Author : John Alden
# Created : Feb 2002
-# CVS : $Id: Flatten.pm,v 1.16 2006/04/10 08:47:03 mattheww Exp $
+# CVS : $Id: Flatten.pm,v 1.19 2009/05/09 12:42:02 jamiel Exp $
###############################################################################
package Hash::Flatten;
@@ -15,7 +15,7 @@
@ISA = qw(Exporter);
@EXPORT_OK = qw(flatten unflatten);
%EXPORT_TAGS = ('all' => \@EXPORT_OK);
-$VERSION = ('$Revision: 1.16 $' =~ /([\d\.]+)/)[0];
+$VERSION = ('$Revision: 1.19 $' =~ /([\d\.]+)/)[0];
use constant DEFAULT_HASH_DELIM => '.';
use constant DEFAULT_ARRAY_DELIM => ':';
@@ -37,6 +37,7 @@
$self->{HashDelimiter} ||= DEFAULT_HASH_DELIM;
$self->{ArrayDelimiter} ||= DEFAULT_ARRAY_DELIM;
$self->{EscapeSequence} = "\\" unless(defined $self->{EscapeSequence} && length($self->{EscapeSequence}) > 0);
+ $self->{EscapeSequence} = undef if($self->{DisableEscapes});
#Sanity check: delimiters don't contain escape sequence
croak("Hash delimiter cannot contain escape sequence") if($self->{HashDelimiter} =~ /\Q$self->{EscapeSequence}\E/);
@@ -93,7 +94,7 @@
my $value = $hashref->{$key};
my @levels = split(/$regexp/, $key);
- my $finalkey = $self->_unescape(pop(@levels), $self->{EscapeSequence});
+ my $finalkey = $self->_unescape((scalar(@levels) % 2 ? pop(@levels) : ''), $self->{EscapeSequence});
my $ptr = \%expanded;
while (@levels >= 2)
{
@@ -210,7 +211,7 @@
TRACE("_flatten_hash_level: flattening: $k");
my $v = $hashref->{$k};
$k = $self->_escape($k, $self->{EscapeSequence}, [values %$delim]);
- my $flatkey = ($prefix? $prefix.$delim->{'HASH'}.$k : $k);
+ my $flatkey = (defined($prefix) ? $prefix.$delim->{'HASH'}.$k : $k);
push @flat, $self->_flatten($flatkey, $v, $delim);
}
return @flat;
@@ -228,7 +229,7 @@
my @flat;
foreach my $ind (0 .. $#$arrayref)
{
- my $flatkey = ($prefix? $prefix.$delim->{'ARRAY'}.$ind : $ind);
+ my $flatkey = (defined($prefix) ? $prefix.$delim->{'ARRAY'}.$ind : $ind);
my $v = $arrayref->[$ind];
push @flat, $self->_flatten($flatkey, $v, $delim);
}
@@ -413,9 +414,15 @@
=item EscapeSequence
This is the character or sequence of characters that will be used to escape the hash and array delimiters.
-If this is set to undef, no escaping will be done. The default escape sequence is a backslash.
-The escaping strategy is to place the escape sequence in front of delimiter sequences; the escape
-sequence itself is escaped by replacing it with two instances.
+The default escape sequence is '\\'. The escaping strategy is to place the escape sequence in front of
+delimiter sequences; the escape sequence itself is escaped by replacing it with two instances.
+
+=item DisableEscapes
+
+Stop the escaping from happening. No escape sequences will be added to flattened output, nor interpreted on the way back.
+
+B<WARNING:> If your structure has keys that contain the delimiter characters, it will not be possible to unflatten the
+structure correctly.
=back
@@ -430,10 +437,6 @@
C<'foo' =E<gt> $foo>.
You can override this behaviour using the OnRefScalar and OnRefRef constructor option.
-If you set EscapeSequence to undef, unflatten() will produce incorrect results
-if your hash keys contain the delimiter strings, and your hash key will be split up.
-Either set the delimiter strings appropriately to allow for this, or define an EscapeSequence.
-
Recursive structures are detected and cause a fatal error.
=head1 SEE ALSO
@@ -459,7 +462,7 @@
=head1 VERSION
-$Id: Flatten.pm,v 1.16 2006/04/10 08:47:03 mattheww Exp $
+$Id: Flatten.pm,v 1.19 2009/05/09 12:42:02 jamiel Exp $
=head1 AUTHOR
Modified: branches/upstream/libhash-flatten-perl/current/t/hash_flatten.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhash-flatten-perl/current/t/hash_flatten.t?rev=63608&op=diff
==============================================================================
--- branches/upstream/libhash-flatten-perl/current/t/hash_flatten.t (original)
+++ branches/upstream/libhash-flatten-perl/current/t/hash_flatten.t Mon Oct 11 14:14:27 2010
@@ -4,7 +4,7 @@
# Purpose : Unit test for Hash::Flatten
# Author : John Alden
# Created : Feb 2002
-# CVS : $Header: /home/cvs/software/cvsroot/hash_flatten/t/hash_flatten.t,v 1.19 2006/04/11 13:43:30 mattheww Exp $
+# CVS : $Header: /home/cvs/software/cvsroot/hash_flatten/t/hash_flatten.t,v 1.21 2009/05/09 12:42:02 jamiel Exp $
###############################################################################
# -t : trace
# -T : deep trace into modules
@@ -68,6 +68,47 @@
my $unflat = Hash::Flatten::unflatten($flat);
DUMP($unflat);
ASSERT EQUAL($unflat, $data), 'nested hashes unflattened';
+
+#############################################################
+#
+# Nested hashes with weird values
+#
+#############################################################
+
+my $data =
+{
+ 'x' => 1,
+ '0' => {
+ '1' => 2,
+ '' => {
+ '' => 3,
+ 'q' => 4
+ },
+ },
+ 'a' => [1,2,3],
+ '' => [4,5,6],
+};
+
+my $flat_data = {
+ 'x' => 1,
+ '0.1' => 2,
+ '0..' => 3,
+ '0..q' => 4,
+ 'a:0' => 1,
+ 'a:1' => 2,
+ 'a:2' => 3,
+ ':0' => 4,
+ ':1' => 5,
+ ':2' => 6,
+};
+
+my $flat = Hash::Flatten::flatten($data);
+DUMP($flat);
+ASSERT EQUAL($flat, $flat_data), 'nested hashes with weird values';
+
+my $unflat = Hash::Flatten::unflatten($flat);
+DUMP($unflat);
+ASSERT EQUAL($unflat, $data), 'nested hashes with weird values unflattened';
#############################################################
#
@@ -430,7 +471,29 @@
'a:1' => 2
}), "warn mode works as expected");
-# check to ensure passing an undefined escape sequence doesn't die!
-my $escape_seq;
-my $o = Hash::Flatten->new({EscapeSequence => $escape_seq});
-ASSERT($o,"setting an undefined escape sequence didn't cause an error.");
+$rv = Hash::Flatten::flatten({a=>"m:o.o", "o:i.n:k" => {a=>1}},{EscapeSequence => "#", DisableEscapes => 0});
+DUMP($rv);
+ASSERT(
+ EQUAL($rv,{a => 'm:o.o','o#:i#.n#:k.a' => 1}),
+ "Escapes on, returned escaped hash"
+);
+$rv = Hash::Flatten::unflatten({a => 'm:o.o','o#:i#.n#:k.a' => 1},{EscapeSequence => "#", DisableEscapes => 0});
+DUMP($rv);
+ASSERT(
+ EQUAL($rv,{a=>"m:o.o", "o:i.n:k" => {a=>1}}),
+ "Escapes on, unescaped hash correctly"
+);
+
+$rv = Hash::Flatten::flatten({a=>"m:o.o", "o:i.n:k" => {a=>1}},{EscapeSequence => "#", DisableEscapes => 1});
+DUMP($rv);
+ASSERT(
+ EQUAL($rv,{a => 'm:o.o','o:i.n:k.a' => 1}),
+ "Escapes off, returned nonsense"
+);
+$rv = Hash::Flatten::unflatten({a => 'm:o.o','o#:i#.n#:k.a' => 1},{EscapeSequence => "#", DisableEscapes => 1});
+DUMP($rv);
+ASSERT(
+ EQUAL($rv,{a => 'm:o.o','o#' => [{'n#' => [{a => 1}]}]}),
+ "Escapes off, didn't unescape hash"
+);
+
More information about the Pkg-perl-cvs-commits
mailing list