better location for test temp files
[p5sagit/local-lib.git] / t / lib / TempDir.pm
CommitLineData
663a8675 1package TempDir;
2use strict;
3use warnings;
4
dff0f4de 5use base 'Exporter';
663a8675 6our @EXPORT = qw(mk_temp_dir);
7
8use local::lib ();
9use Cwd;
10use File::Temp qw(tempdir);
11
243595dc 12$File::Temp::KEEP_ALL = 1
13 if $ENV{LOCAL_LIB_TEST_DEBUG};
14
663a8675 15sub mk_temp_dir
16{
17 my $name_template = shift;
18
243595dc 19 mkdir 't/temp';
20 my $path = tempdir($name_template, DIR => Cwd::abs_path('t/temp'), CLEANUP => 1);
663a8675 21 local::lib->ensure_dir_structure_for($path);
22 # On Win32 the path where the distribution is built usually contains
23 # spaces. This is a problem for some parts of the CPAN toolchain, so
24 # local::lib uses the GetShortPathName trick do get an alternate
25 # representation of the path that doesn't constain spaces.
26 return ($^O eq 'MSWin32')
27 ? Win32::GetShortPathName($path)
28 : $path
29}
30
311;