From: Zefram Date: Tue, 15 Dec 2009 10:17:35 +0000 (+0100) Subject: [perl #68640] Wrong error for undef constant name X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=15dc519fb7cb1c4b51fbc196af8ecf273c534ad1;p=p5sagit%2Fp5-mst-13.2.git [perl #68640] Wrong error for undef constant name --- diff --git a/dist/constant/lib/constant.pm b/dist/constant/lib/constant.pm index a51ee7f..3ee1a6f 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.19'; +$VERSION = '1.20'; #======================================================================= @@ -60,15 +60,14 @@ sub import { } $constants = shift; } else { - $constants->{+shift} = undef; - } - - foreach my $name ( keys %$constants ) { - unless (defined $name) { + unless (defined $_[0]) { require Carp; Carp::croak("Can't use undef as constant name"); } + $constants->{+shift} = undef; + } + foreach my $name ( keys %$constants ) { # Normal constant name if ($name =~ $normal_constant_name and !$forbidden{$name}) { # Everything is okay diff --git a/dist/constant/t/constant.t b/dist/constant/t/constant.t index a42b7d2..85a9355 100644 --- a/dist/constant/t/constant.t +++ b/dist/constant/t/constant.t @@ -9,7 +9,7 @@ END { @warnings && print STDERR join "\n- ", "accumulated warnings:", @warnings use strict; -use Test::More tests => 95; +use Test::More tests => 96; my $TB = Test::More->builder; BEGIN { use_ok('constant'); } @@ -341,3 +341,9 @@ $kloong = 'schlozhauer'; is ($@, ''); is_deeply (\@value, []); } + +{ + local $SIG{'__WARN__'} = sub { die "WARNING: $_[0]" }; + eval 'use constant undef, 5; 1'; + like $@, qr/\ACan't use undef as constant name at /; +}