ExtUtils-MakeMaker

 view release on metacpan or  search on metacpan

t/lib/MakeMaker/Test/Utils.pm  view on Meta::CPAN

created with L<File::Temp> and then automatically deleted after. It ends
by C<chdir>ing back to where it started.

If the given code throws an exception, it will be re-thrown after the
re-C<chdir>.

Returns the return value of the given code.

=cut

sub in_dir(&;$) {
    my $code = shift;
    require File::Temp;
    my $dir = shift || File::Temp::tempdir(TMPDIR => 1, CLEANUP => 1);
    # chdir to the new directory
    my $orig_dir = getcwd();
    chdir $dir or die "Can't chdir to $dir: $!";
    # Run the code, but trap the error so we can chdir back
    my $return;
    my $ok = eval { $return = $code->(); 1; };
    my $err = $@;



( run in 1.535 second using v1.01-cache-2.11-cpan-49f99fa48dc )