From: Rafael Garcia-Suarez Date: Mon, 5 Nov 2001 14:26:24 +0000 (+0100) Subject: bugfixes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c74f62b55c858d7cf9ed72589c05484ffce727b0;p=p5sagit%2Fp5-mst-13.2.git bugfixes Message-ID: <20011105142624.C31977@rafael> p4raw-id: //depot/perl@12850 --- diff --git a/lib/Symbol.pm b/lib/Symbol.pm index 15c211c..8739bd2 100644 --- a/lib/Symbol.pm +++ b/lib/Symbol.pm @@ -63,14 +63,14 @@ explicitly. =cut -BEGIN { require 5.002; } +BEGIN { require 5.005; } require Exporter; @ISA = qw(Exporter); @EXPORT = qw(gensym ungensym qualify qualify_to_ref); @EXPORT_OK = qw(delete_package); -$VERSION = 1.03; +$VERSION = 1.04; my $genpkg = "Symbol::"; my $genseq = 0; @@ -95,8 +95,10 @@ sub qualify ($;$) { my ($name) = @_; if (!ref($name) && index($name, '::') == -1 && index($name, "'") == -1) { my $pkg; - # Global names: special character, "^x", or other. - if ($name =~ /^([^a-z])|(\^[a-z])$/i || $global{$name}) { + # Global names: special character, "^xyz", or other. + if ($name =~ /^(([^a-z])|(\^[a-z_]+))\z/i || $global{$name}) { + # RGS 2001-11-05 : translate leading ^X to control-char + $name =~ s/^\^([a-z_])/'qq(\c'.$1.')'/eei; $pkg = "main"; } else { diff --git a/lib/Symbol.t b/lib/Symbol.t index 03449a3..3bac903 100755 --- a/lib/Symbol.t +++ b/lib/Symbol.t @@ -5,26 +5,22 @@ BEGIN { @INC = '../lib'; } -print "1..8\n"; +use Test::More tests => 10; BEGIN { $_ = 'foo'; } # because Symbol used to clobber $_ use Symbol; -# First check $_ clobbering -print "not " if $_ ne 'foo'; -print "ok 1\n"; +ok( $_ eq 'foo', 'check $_ clobbering' ); # First test gensym() $sym1 = gensym; -print "not " if ref($sym1) ne 'GLOB'; -print "ok 2\n"; +ok( ref($sym1) eq 'GLOB', 'gensym() returns a GLOB' ); $sym2 = gensym; -print "not " if $sym1 eq $sym2; -print "ok 3\n"; +ok( $sym1 ne $sym2, 'gensym() returns a different GLOB' ); ungensym $sym1; @@ -36,17 +32,15 @@ package foo; use Symbol qw(qualify); # must import into this package too -qualify("x") eq "foo::x" or print "not "; -print "ok 4\n"; - -qualify("x", "FOO") eq "FOO::x" or print "not "; -print "ok 5\n"; - -qualify("BAR::x") eq "BAR::x" or print "not "; -print "ok 6\n"; - -qualify("STDOUT") eq "main::STDOUT" or print "not "; -print "ok 7\n"; - -qualify("ARGV", "FOO") eq "main::ARGV" or print "not "; -print "ok 8\n"; +::ok( qualify("x") eq "foo::x", 'qualify() with a simple identifier' ); +::ok( qualify("x", "FOO") eq "FOO::x", 'qualify() with a package' ); +::ok( qualify("BAR::x") eq "BAR::x", + 'qualify() with a qualified identifier' ); +::ok( qualify("STDOUT") eq "main::STDOUT", + 'qualify() with a reserved identifier' ); +::ok( qualify("ARGV", "FOO") eq "main::ARGV", + 'qualify() with a reserved identifier and a package' ); +::ok( qualify("_foo") eq "foo::_foo", + 'qualify() with an identifier starting with a _' ); +::ok( qualify("^FOO") eq "main::\cFOO", + 'qualify() with an identifier starting with a ^' );