diff --git a/lib/Test2/Util.pm b/lib/Test2/Util.pm index 9ce991ccf..a19e5a219 100644 --- a/lib/Test2/Util.pm +++ b/lib/Test2/Util.pm @@ -36,6 +36,8 @@ our @EXPORT_OK = qw{ try_sig_mask clone_io + + _env_get }; BEGIN { require Exporter; our @ISA = qw(Exporter) } @@ -43,6 +45,17 @@ BEGIN { *IS_WIN32 = ($^O eq 'MSWin32') ? sub() { 1 } : sub() { 0 }; } +# check for key existence before fetching from %ENV to avoid +# locked hash issues. If it does not exist, or it does and the +# value is undefined return $_[1] instead, thus allowing +# a default value to be supplied if required. +sub _env_get { + my ($key,$default) = @_; + my $got = exists($ENV{$key}) ? $ENV{$key} : undef; + $got = $default unless defined $got; + return $got; +} + sub _can_thread { return 0 unless $] >= 5.008001; return 0 unless $Config{'useithreads'};