develooper Front page | perl.perl5.porters | Postings from April 2011

Re: constant.pm under utf8: another 5.14 blocker?

Thread Next
From:
Jesse Vincent
Date:
April 17, 2011 19:42
Subject:
Re: constant.pm under utf8: another 5.14 blocker?
Message ID:
20110418024238.GG5337@puppy



On Sun 17.Apr'11 at 17:15:39 -0700, Father Chrysostomos wrote:
> There is this bug report against constant.pm that was recently posted:
> 
> https://rt.cpan.org/Public/Bug/Display.html?id=67525
> 
> Basically, ‘use constant π => 3’ worked under 5.8.x, but not in 5.10 and higher. That means that in some cases Unicode support is worse than before. :-(
> 
> I have a patch that is really simple (attached). It does not fix the underlying bug (which would be too intrusive for 5.14), but works around it in constant.pm. It should be perfectly safe.

"Perfectly safe" is always famous last words ;) but in this case I'll
accept it for 5.12.0.

Thanks!


> I think perl bug #88742 is the same bug. But the RT web interface is down, so I don’t know for sure.
> 

> From 98ad3eb844d5362822510061a478dc1f936a079d Mon Sep 17 00:00:00 2001
> From: Father Chrysostomos <sprout@cpan.org>
> Date: Sun, 17 Apr 2011 16:09:36 -0700
> Subject: [PATCH] Make Unicode constants under use utf8 work again
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> 
> 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.
> 
> diff --git a/MANIFEST b/MANIFEST
> index c804dea..5855917 100644
> --- a/MANIFEST
> +++ b/MANIFEST
> @@ -2869,6 +2869,7 @@ dist/B-Lint/t/lint.t				See if B::Lint works
>  dist/B-Lint/t/pluglib/B/Lint/Plugin/Test.pm	See if B::Lint works
>  dist/constant/lib/constant.pm	For "use constant"
>  dist/constant/t/constant.t	See if compile-time constants work
> +dist/constant/t/utf8.t		Test Unicode constants under utf8 pragma
>  dist/Cwd/Cwd.pm				Various cwd routines (getcwd, fastcwd, chdir)
>  dist/Cwd/Cwd.xs				Cwd extension external subroutines
>  dist/Cwd/lib/File/Spec/Cygwin.pm	portable operations on Cygwin file names
> diff --git a/dist/constant/lib/constant.pm b/dist/constant/lib/constant.pm
> index 3ee1a6f..22566ce 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 0000000..c8830c3
> --- /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()';
> +


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About