This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl #11560] extraneous msg in viacode
authorKarl Williamson <public@khwilliamson.com>
Tue, 6 Mar 2012 02:33:50 +0000 (19:33 -0700)
committerRicardo Signes <rjbs@cpan.org>
Fri, 23 Mar 2012 14:10:28 +0000 (10:10 -0400)
This refactors to test for the hash element being defined before
attempting to use it.

lib/_charnames.pm
t/lib/charnames/alias

index d29af30..f333234 100644 (file)
@@ -742,20 +742,21 @@ sub viacode {
               && (! defined $H_ref
                   || ! exists $H_ref->{charnames_stringified_inverse_ords});
 
-  my %code_point_aliases = split ',',
+  my %code_point_aliases;
+  if (defined $H_ref->{charnames_stringified_inverse_ords}) {
+    %code_point_aliases = split ',',
                           $H_ref->{charnames_stringified_inverse_ords};
-  if (! exists $code_point_aliases{$hex}) {
+    return $code_point_aliases{$hex} if exists $code_point_aliases{$hex};
+  }
 
-    # If there is an official alias, and no user-defined one, return that
+    # Here there is no user-defined alias, return any official one.
     return $return if defined $return;
 
     if (CORE::hex($hex) > 0x10FFFF) {
         carp "Unicode characters only allocated up to U+10FFFF (you asked for U+$hex)";
     }
     return;
-  }
 
-  return $code_point_aliases{$hex};
 } # _viacode
 
 1;
index fb1a914..75280be 100644 (file)
@@ -338,3 +338,11 @@ charnames::viacode(0x41);
 EXPECT
 OPTIONS regex
 $
+########
+# NAME no extraneous warning [perl #11560]
+use warnings;
+use charnames ();
+print charnames::viacode(0x80), "\n";
+EXPECT
+OPTIONS regex
+PADDING CHARACTER