X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSymbol.pm;h=98fb6763fe6d0412a634d8b9ab14136f85a96367;hb=afdf87ad777c69602cae38888da5fa4053d5b7f7;hp=a95383a5d68cf4783080a173ac47d0278c8d6b86;hpb=4b19af017623bfa3bb72bb164598a517f586e0d3;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Symbol.pm b/lib/Symbol.pm index a95383a..98fb676 100644 --- a/lib/Symbol.pm +++ b/lib/Symbol.pm @@ -15,6 +15,9 @@ Symbol - manipulate Perl symbols and their names ungensym $sym; # no effect + # replace *FOO{IO} handle but not $FOO, %FOO, etc. + *FOO = geniosym; + print qualify("x"), "\n"; # "Test::x" print qualify("x", "FOO"), "\n" # "FOO::x" print qualify("BAR::x"), "\n"; # "BAR::x" @@ -42,6 +45,10 @@ For backward compatibility with older implementations that didn't support anonymous globs, C is also provided. But it doesn't do anything. +C creates an anonymous IO handle. This can be +assigned into an existing glob without affecting the non-IO portions +of the glob. + C turns unqualified symbol names into qualified variable names (e.g. "myvar" -E "MyPackage::myvar"). If it is given a second parameter, C uses it as the default package; @@ -63,14 +70,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); +@EXPORT_OK = qw(delete_package geniosym); -$VERSION = 1.02; +$VERSION = 1.04; my $genpkg = "Symbol::"; my $genseq = 0; @@ -89,14 +96,23 @@ sub gensym () { $ref; } +sub geniosym () { + my $sym = gensym(); + # force the IO slot to be filled + select(select $sym); + *$sym{IO}; +} + sub ungensym ($) {} 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 {