From: Jarkko Hietaniemi Date: Sat, 18 May 2002 04:14:25 +0000 (+0000) Subject: Make use vars grok UTF-8. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=08cd7fd68a37c0884dd1698ef154f2d6583874ef;p=p5sagit%2Fp5-mst-13.2.git Make use vars grok UTF-8. p4raw-id: //depot/perl@16670 --- diff --git a/lib/vars.pm b/lib/vars.pm index 020568e..a57f479 100644 --- a/lib/vars.pm +++ b/lib/vars.pm @@ -12,36 +12,34 @@ sub import { my ($pack, @imports) = @_; my ($sym, $ch); foreach (@imports) { - # TODO: UTF-8 names: (the unpack is quite wrong, - # /^(.)(.*)/ would probably be better.) While you - # are at it, until declaring empty package is made - # to work the * is too lenient. - ($ch, $sym) = unpack('a1a*', $_); - if ($sym =~ tr/A-Za-z_0-9//c) { - # time for a more-detailed check-up - if ($sym =~ /^\w+[[{].*[]}]$/) { - require Carp; - Carp::croak("Can't declare individual elements of hash or array"); - } elsif (warnings::enabled() and length($sym) == 1 and $sym !~ tr/a-zA-Z//) { - warnings::warn("No need to declare built-in vars"); - } elsif (($^H &= strict::bits('vars'))) { - # TODO: UTF-8 names: be careful to load the UTF-8 - # machinery only if the symbol requires it. - require Carp; - Carp::croak("'$_' is not a valid variable name under strict vars"); + if (($ch, $sym) = /^([\$\@\%\*\&])(.+)/) { + if ($sym =~ /\W/) { + # time for a more-detailed check-up + if ($sym =~ /^\w+[[{].*[]}]$/) { + require Carp; + Carp::croak("Can't declare individual elements of hash or array"); + } elsif (warnings::enabled() and length($sym) == 1 and $sym !~ tr/a-zA-Z//) { + warnings::warn("No need to declare built-in vars"); + } elsif (($^H &= strict::bits('vars'))) { + require Carp; + Carp::croak("'$_' is not a valid variable name under strict vars"); + } } + $sym = "${callpack}::$sym" unless $sym =~ /::/; + *$sym = + ( $ch eq "\$" ? \$$sym + : $ch eq "\@" ? \@$sym + : $ch eq "\%" ? \%$sym + : $ch eq "\*" ? \*$sym + : $ch eq "\&" ? \&$sym + : do { + require Carp; + Carp::croak("'$_' is not a valid variable name"); + }); + } else { + require Carp; + Carp::croak("'$_' is not a valid variable name"); } - $sym = "${callpack}::$sym" unless $sym =~ /::/; - *$sym = - ( $ch eq "\$" ? \$$sym - : $ch eq "\@" ? \@$sym - : $ch eq "\%" ? \%$sym - : $ch eq "\*" ? \*$sym - : $ch eq "\&" ? \&$sym - : do { - require Carp; - Carp::croak("'$_' is not a valid variable name"); - }); } }; diff --git a/t/run/fresh_perl.t b/t/run/fresh_perl.t index 1f8c5ce..3c0a925 100644 --- a/t/run/fresh_perl.t +++ b/t/run/fresh_perl.t @@ -821,3 +821,13 @@ $人++; # a child is born print $人, "\n"; EXPECT 3 +######## example from Camel 5, ch. 15, pp.406 (with use vars) +# SKIP: ord "A" == 193 # EBCDIC +use strict; +use utf8; +use vars qw($人); +$人 = 2; # 0xe4 0xba 0xba: U+4eba, "human" in CJK ideograph +$人++; # a child is born +print $人, "\n"; +EXPECT +3