more complete File::Spec support for Mac and VMS, tests (from
[p5sagit/p5-mst-13.2.git] / lib / Env.pm
index 2187090..b0afc3b 100644 (file)
@@ -2,14 +2,18 @@ package Env;
 
 =head1 NAME
 
-Env - Perl module that imports environment variables
+Env - perl module that imports environment variables
+
+=head1 SYNOPSIS
+
+    use Env;
+    use Env qw(PATH HOME TERM);
 
 =head1 DESCRIPTION
 
-Perl maintains environment variables in a pseudo-associative-array
-named %ENV.  For when this access method is inconvenient, the Perl
-module C<Env> allows environment variables to be treated as simple
-variables.
+Perl maintains environment variables in a pseudo-hash named %ENV.  For
+when this access method is inconvenient, the Perl module C<Env> allows
+environment variables to be treated as simple variables.
 
 The Env::import() function ties environment variables with suitable
 names to global Perl variables with the same names.  By default it
@@ -34,17 +38,21 @@ the environment, assign it the undefined value
 
 =head1 AUTHOR
 
-Chip Salzenberg <chip@fin.uucp>
+Chip Salzenberg E<lt>F<chip@fin.uucp>E<gt>
 
 =cut
 
 sub import {
     my ($callpack) = caller(0);
     my $pack = shift;
-    my @vars = @_ ? @_ : keys(%ENV);
+    my @vars = grep /^[A-Za-z_]\w*$/, (@_ ? @_ : keys(%ENV));
+    return unless @vars;
 
+    eval "package $callpack; use vars qw("
+        . join(' ', map { '$'.$_ } @vars) . ")";
+    die $@ if $@;
     foreach (@vars) {
-       tie ${"${callpack}::$_"}, Env, $_ if /^[A-Za-z_]\w*$/;
+       tie ${"${callpack}::$_"}, Env, $_;
     }
 }