X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FEnv.pm;h=b0afc3b2dbf5e1c04ac75baf370b67065b29db1b;hb=4499d6b9d14594604210bc28005c5e4ab2e49947;hp=63beb075088766f91915b80439ad49db9a3b4246;hpb=1fef88e72b0b21420614d87ecab0aaedf3725271;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Env.pm b/lib/Env.pm index 63beb07..b0afc3b 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 @@ -46,10 +45,14 @@ Chip Salzenberg EFE 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, $_; } }