From: Don Armstrong Date: Fri, 20 Apr 2018 16:41:41 +0000 (-0700) Subject: reuse the same null handle in globify_scalar X-Git-Url: https://git.donarmstrong.com/?p=debbugs.git;a=commitdiff_plain;h=773c964cfcf6ac6ce095ba46b98455b6e4be5e7b;hp=3b3855979305a17e95200a4f4acf6afd7662f6af reuse the same null handle in globify_scalar --- diff --git a/Debbugs/Common.pm b/Debbugs/Common.pm index e16e78c..b135c42 100644 --- a/Debbugs/Common.pm +++ b/Debbugs/Common.pm @@ -1140,6 +1140,8 @@ before. This appears to be a bug in the underlying modules. =cut +our $_NULL_HANDLE; + sub globify_scalar { my ($scalar) = @_; my $handle; @@ -1164,8 +1166,15 @@ sub globify_scalar { else { carp "Given a non-scalar reference, non-glob to globify_scalar; returning /dev/null handle"; } + } + if (not defined $_NULL_HANDLE or + not $_NULL_HANDLE->opened() + ) { + $_NULL_HANDLE = + IO::File->new('/dev/null','>:encoding(UTF-8)') or + die "Unable to open /dev/null for writing: $!"; } - return IO::File->new('/dev/null','>:encoding(UTF-8)'); + return $_NULL_HANDLE; } =head2 cleanup_eval_fail()