<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">--- lib/Hash/Flatten.pm.orig	2007-08-14 08:34:38.000000000 +0200
+++ lib/Hash/Flatten.pm	2007-08-14 08:35:11.000000000 +0200
@@ -19,6 +19,8 @@
 
 use constant DEFAULT_HASH_DELIM =&gt; '.';
 use constant DEFAULT_ARRAY_DELIM =&gt; ':';
+use constant RETURN_EMPTY_HASH_VALUES =&gt; 0;
+use constant DEFAULT_EMPTY_HASH_VALUE =&gt; '';
 
 #Check if we need to support overloaded stringification
 use constant HAVE_OVERLOAD =&gt; eval {
@@ -36,6 +38,8 @@
 	#Defaults
 	$self-&gt;{HashDelimiter} ||= DEFAULT_HASH_DELIM;
 	$self-&gt;{ArrayDelimiter} ||= DEFAULT_ARRAY_DELIM;
+	$self-&gt;{EmptyHashValue} ||= DEFAULT_EMPTY_HASH_VALUE;
+	$self-&gt;{ReturnEmptyHashValues} ||= RETURN_EMPTY_HASH_VALUES;
 	$self-&gt;{EscapeSequence} = "\\" unless(defined $self-&gt;{EscapeSequence} &amp;&amp; length($self-&gt;{EscapeSequence}) &gt; 0);
 	
 	#Sanity check: delimiters don't contain escape sequence
@@ -204,6 +208,7 @@
 		die "Recursive data structure detected at this point in the structure: '$prefix'. Cannot flatten recursive structures.";
 	}
 
+    return ($self-&gt;_flatten($prefix, $self-&gt;{EmptyHashValue}, $delim)) if (not keys %$hashref and $prefix and $self-&gt;{ReturnEmptyHashValues} );
 	my @flat;
 	for my $k (keys %$hashref)
 	{
--- t/hash_flatten.t.orig	2007-08-14 08:35:05.000000000 +0200
+++ t/hash_flatten.t	2007-08-14 08:35:11.000000000 +0200
@@ -71,6 +71,92 @@
 
 #############################################################
 #
+# Nested hashes with empty sub hashes
+#
+#############################################################
+
+my $data =
+{
+	'x' =&gt; 1,
+	'y' =&gt; {
+		'a' =&gt; 2,
+		'b' =&gt; {
+			'p' =&gt; 3,
+			'q' =&gt; 4,
+            'r' =&gt; {},
+		},
+	}
+};
+
+my $flat_data = {
+	'x' =&gt; 1,
+	'y.a' =&gt; 2,
+	'y.b.p' =&gt; 3,
+	'y.b.q' =&gt; 4,
+};
+
+my $flat = Hash::Flatten::flatten($data);
+DUMP($flat);
+ASSERT EQUAL($flat, $flat_data), 'nested hashes with subhashes 1';
+
+# subhashes can not be reconstructed
+my $unflat = Hash::Flatten::unflatten($flat);
+DUMP($unflat);
+ASSERT EQUAL($unflat, {
+                       'x' =&gt; 1,
+                       'y' =&gt; {
+                               'a' =&gt; 2,
+                               'b' =&gt; {
+                                       'p' =&gt; 3,
+                                       'q' =&gt; 4,
+                                      },
+                              }
+                      }), 'nested hashes with subhashes unflattened 1';
+
+#############################################################
+
+my $data =
+{
+	'x' =&gt; 1,
+	'y' =&gt; {
+		'a' =&gt; 2,
+		'b' =&gt; {
+			'p' =&gt; 3,
+			'q' =&gt; 4,
+            'r' =&gt; {},
+		},
+	}
+};
+
+my $flat_data = {
+	'x' =&gt; 1,
+	'y.a' =&gt; 2,
+	'y.b.p' =&gt; 3,
+	'y.b.q' =&gt; 4,
+	'y.b.r' =&gt; ''
+};
+
+$flat = Hash::Flatten::flatten($data, {'ReturnEmptyHashValues' =&gt; 1, 'EmptyHashValue' =&gt; ''});
+DUMP($flat);
+ASSERT EQUAL($flat, $flat_data), 'nested hashes with subhashes 2';
+
+# subhashes can not be reconstructed
+my $unflat = Hash::Flatten::unflatten($flat);
+DUMP($unflat);
+ASSERT EQUAL($unflat, {
+                       'x' =&gt; 1,
+                       'y' =&gt; {
+                               'a' =&gt; 2,
+                               'b' =&gt; {
+                                       'p' =&gt; 3,
+                                       'q' =&gt; 4,
+                                       'r' =&gt; '',
+                                      },
+                              }
+                      }), 'nested hashes with subhashes unflattened 2';
+
+#############################################################
+#
 # Mixed hashes/arrays
 #
 #############################################################
</pre></body></html>