[MKDoc-commit] Added code to work around a change in Encode behavior.

sam at mkdoc.demon.co.uk sam at mkdoc.demon.co.uk
Mon Jun 19 22:35:08 BST 2006


Log Message:
-----------
Added code to work around a change in Encode behavior.

Tags:
----
mkdoc-1-6

Modified Files:
--------------
    mkd/flo:
        Component.pm

-------------- next part --------------
Index: Component.pm
===================================================================
RCS file: /var/spool/cvs/mkd/flo/Component.pm,v
retrieving revision 1.3.2.40
retrieving revision 1.3.2.41
diff -Lflo/Component.pm -Lflo/Component.pm -u -r1.3.2.40 -r1.3.2.41
--- flo/Component.pm
+++ flo/Component.pm
@@ -647,9 +647,11 @@
             $res;
         };
 
-        for (keys %{$obj})
-        {
-            $self->{$_} = Encode::decode_utf8  ($obj->{$_} );
+        # decode UTF8 in the returned structure
+        _decode_hash($obj);
+        
+        for (keys %{$obj}) {
+            $self->{$_} = $obj->{$_};
         }
 
         $self->__on_load() if ($self->can ('__on_load'));
@@ -658,6 +660,22 @@
     $@ and warn "== $@ ==";
 }
 
+# passes all scalars in a hash-ref through decode_utf8, recursing on
+# included hashes and ignoring other refs.  This is needed because as
+# of Encode v2.10 references will get stringified instead of being
+# passed-through as in earlier versions.
+sub _decode_hash {
+    my $hash = shift;
+    foreach my $key (keys %$hash) {
+        my $ref = ref $hash->{$key};
+        if ($ref and $ref eq 'HASH') {
+            _decode_hash($hash->{$key});
+        } elsif (not $ref) {
+            $hash->{$key} = Encode::decode_utf8($hash->{$key});
+        }
+    }
+}
+
 # determine contents of the Move button target select list, correcting
 # for placement, minimum and maximum
 sub move_targets {


More information about the MKDoc-commit mailing list