X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2FDBICTest%2FUtil.pm;h=3f489c21849ae380c074460436e11a15f077a010;hb=8d6b1478d8fa6f7c76e313ee72a72d5eb4c24d03;hp=9f5e98575b559c97734cddf0286c907aa297f448;hpb=d9bd51956470404b3960871d3413fa98f16961d2;p=dbsrgits%2FDBIx-Class.git diff --git a/t/lib/DBICTest/Util.pm b/t/lib/DBICTest/Util.pm index 9f5e985..3f489c2 100644 --- a/t/lib/DBICTest/Util.pm +++ b/t/lib/DBICTest/Util.pm @@ -5,9 +5,32 @@ use strict; use Carp; use Scalar::Util qw/isweak weaken blessed reftype refaddr/; +use Config; use base 'Exporter'; -our @EXPORT_OK = qw/stacktrace populate_weakregistry assert_empty_weakregistry/; +our @EXPORT_OK = qw/local_umask stacktrace populate_weakregistry assert_empty_weakregistry/; + +sub local_umask { + return unless defined $Config{d_umask}; + + die 'Calling local_umask() in void context makes no sense' + if ! defined wantarray; + + my $old_umask = umask(shift()); + die "Setting umask failed: $!" unless defined $old_umask; + + return bless \$old_umask, 'DBICTest::Util::UmaskGuard'; +} +{ + package DBICTest::Util::UmaskGuard; + sub DESTROY { + local ($@, $!); + eval { defined (umask ${$_[0]}) or die }; + warn ( "Unable to reset old umask ${$_[0]}: " . ($!||'Unknown error') ) + if ($@ || $!); + } +} + sub stacktrace { my $frame = shift;