summaryrefslogtreecommitdiff
path: root/lib/Symbol.pm
diff options
context:
space:
mode:
authorYitzchak Scott-Thoennes <sthoenna@efn.org>2002-02-25 07:04:57 -0800
committerJarkko Hietaniemi <jhi@iki.fi>2002-02-26 01:01:13 +0000
commitae716a98930f0a80b96ee5d383780578d69d0830 (patch)
treec182c19694d8914c09ea20973f4634046ed4eec0 /lib/Symbol.pm
parente48df184541995015048bca83e39a89859aa31ce (diff)
downloadperl-ae716a98930f0a80b96ee5d383780578d69d0830.tar.gz
Perl interface to newIO()
Message-ID: <ZMse8gzkg6oQ092yn@efn.org> p4raw-id: //depot/perl@14878
Diffstat (limited to 'lib/Symbol.pm')
-rw-r--r--lib/Symbol.pm19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/Symbol.pm b/lib/Symbol.pm
index 8739bd2b31..d5318085d8 100644
--- a/lib/Symbol.pm
+++ b/lib/Symbol.pm
@@ -15,6 +15,12 @@ Symbol - manipulate Perl symbols and their names
ungensym $sym; # no effect
+ # localize *FOO IO handle but not $FOO, %FOO, etc.
+ my $save_fooio = *FOO{IO} || geniosym;
+ *FOO = geniosym;
+ use_foo();
+ *FOO{IO} = $save_fooio;
+
print qualify("x"), "\n"; # "Test::x"
print qualify("x", "FOO"), "\n" # "FOO::x"
print qualify("BAR::x"), "\n"; # "BAR::x"
@@ -42,6 +48,10 @@ For backward compatibility with older implementations that didn't
support anonymous globs, C<Symbol::ungensym> is also provided.
But it doesn't do anything.
+C<Symbol::geniosym> creates an anonymous IO handle. This can be
+assigned into an existing glob without affecting the non-IO portions
+of the glob.
+
C<Symbol::qualify> turns unqualified symbol names into qualified
variable names (e.g. "myvar" -E<gt> "MyPackage::myvar"). If it is given a
second parameter, C<qualify> uses it as the default package;
@@ -68,7 +78,7 @@ 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.04;
@@ -89,6 +99,13 @@ sub gensym () {
$ref;
}
+sub geniosym () {
+ my $sym = gensym();
+ # force the IO slot to be filled
+ select(select $sym);
+ *$sym{IO};
+}
+
sub ungensym ($) {}
sub qualify ($;$) {