X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FEnv.pm;h=f2fe4af422e88de95077737bd2d1dcd0bfdb0277;hb=1b33cabaaf2fbe2e84c6a13a9b0a7fce45959c4f;hp=0e790754a8222f7a8cf99f20fcd5e67746e6b522;hpb=cb1a09d0194fed9b905df7b04a4bc031d354609d;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Env.pm b/lib/Env.pm index 0e79075..f2fe4af 100644 --- a/lib/Env.pm +++ b/lib/Env.pm @@ -11,10 +11,9 @@ Env - perl module that imports environment variables =head1 DESCRIPTION -Perl maintains environment variables in a pseudo-associative-array -named %ENV. For when this access method is inconvenient, the Perl -module C 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 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 @@ -39,7 +38,7 @@ the environment, assign it the undefined value =head1 AUTHOR -Chip Salzenberg +Chip Salzenberg EFE =cut @@ -47,7 +46,11 @@ sub import { my ($callpack) = caller(0); my $pack = shift; my @vars = @_ ? @_ : 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*$/; }