NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Here's an implementation (Score:1)
Here's a simple implementation. (I think Env::Constant is a better name than Env::Export) You can find it with some basic tests and docs at http://svn.ali.as/cpan/trunk/Env-Constant [svn.ali.as]. Contact Adam Kennedy if you want commit access to that repository*.
package Env::Constant;
use 5.006001;
use strict;
use warnings;
use Carp qw/croak/;
our $VERSION = '0.01';
sub import {
my $class = shift;
my $matching_keys = shift;
$matching_keys = eval {qr/$matching_keys/}
if defined $matching_keys and not ref($matching_keys) eq 'Regexp';
croak("Invalid regular expression specified: $@")
if $@;
my ($calling_pkg) = caller();
croak("Could not determine caller package")
if not defined $calling_pkg or $calling_pkg eq '';
foreach my $envkey (keys %ENV) { /\W/) { /\\w/ for exporting";
next if defined $matching_keys and $envkey !~ $matching_keys;
if ($envkey =~
warn "The environment variable '$envkey' contains invalid characters. Must match
next;
}
my $varname = "${calling_pkg}::ENV_$envkey";
my $value = $ENV{$envkey};
no strict 'refs';
*$varname = sub () { $value };
}
}
* On an aside: nobody dare give me a "SVN sucks" rant on this.
Reply to This
Re: (Score:2)
I certainly won't give you grief for Subversion. If it's good enough for you, that's fine. It's when people tell other people that "my solution should be your solution" that it's worth asking if that solution is optimal.
Re: (Score:1)
Oh, my comment wasn't targetted at you specifically. What you're saying is exactly my point of view. I even think that perl moving to git was one of the best things to happen to it in the past years.
Re: (Score:2)
I can actually think of ways this can be useful (beyond what others in this thread have dismissed), and might actually craft something as a proof-of-concept. Do you mind if I borrow/adapt some of your code as a starting point?
--rjray
Re: (Score:1)
Hi Randy,
feel free to use whatever you like. I'd suggest taking it from SVN where there's also a bit of documentation and a few basic tests.
Cheers,
Steffen