diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-04-17 16:09:36 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-04-17 22:20:12 -0700 |
commit | d12b49d6e531fdc354980af14eb2efa34756c1d8 (patch) | |
tree | ece4beadbfd043d5c37fa96549d19bb446a6ebc2 /dist/constant | |
parent | 23292af314730ff686527208d3274be920724e97 (diff) | |
download | perl-d12b49d6e531fdc354980af14eb2efa34756c1d8.tar.gz |
Make Unicode constants under use utf8 work again
Because sub lookup (and glob lookup in general) ignores the UTF8
flag, such subs are actually ‘correctly’ stored under the utf8-encoded
equivalent of the name, and not the name itself.
Diffstat (limited to 'dist/constant')
-rw-r--r-- | dist/constant/lib/constant.pm | 8 | ||||
-rw-r--r-- | dist/constant/t/utf8.t | 12 |
2 files changed, 19 insertions, 1 deletions
diff --git a/dist/constant/lib/constant.pm b/dist/constant/lib/constant.pm index 3ee1a6f5b0..22566ce28c 100644 --- a/dist/constant/lib/constant.pm +++ b/dist/constant/lib/constant.pm @@ -4,7 +4,7 @@ use strict; use warnings::register; use vars qw($VERSION %declared); -$VERSION = '1.20'; +$VERSION = '1.21'; #======================================================================= @@ -116,6 +116,12 @@ sub import { $declared{$full_name}++; if ($multiple || @_ == 1) { my $scalar = $multiple ? $constants->{$name} : $_[0]; + + # Work around perl bug #xxxxx: Sub names (actually glob + # names in general) ignore the UTF8 flag. So we have to + # turn it off to get the "right" symbol table entry. + utf8::is_utf8 $name and utf8::encode $name; + # The constant serves to optimise this entire block out on # 5.8 and earlier. if (_CAN_PCS && $symtab && !exists $symtab->{$name}) { diff --git a/dist/constant/t/utf8.t b/dist/constant/t/utf8.t new file mode 100644 index 0000000000..c8830c33b2 --- /dev/null +++ b/dist/constant/t/utf8.t @@ -0,0 +1,12 @@ +#!./perl -T + +# Tests for constant.pm that require the utf8 pragma + +use utf8; +use Test::More tests => 2; + +use constant π => 4 * atan2 1, 1; + +ok defined π, 'basic scalar constant with funny name'; +is substr(π, 0, 7), '3.14159', ' in substr()'; + |