File: TempDir.pm

package info (click to toggle)
liblocal-lib-perl 2.000019-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 344 kB
  • ctags: 81
  • sloc: perl: 928; makefile: 13
file content (31 lines) | stat: -rw-r--r-- 803 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package TempDir;
use strict;
use warnings;

use base 'Exporter';
our @EXPORT = qw(mk_temp_dir);

use local::lib ();
use Cwd;
use File::Temp qw(tempdir);

$File::Temp::KEEP_ALL = 1
  if $ENV{LOCAL_LIB_TEST_DEBUG};

sub mk_temp_dir
{
    my $name_template = shift;

    mkdir 't/temp';
    my $path = tempdir($name_template, DIR => Cwd::abs_path('t/temp'), CLEANUP => 1);
    local::lib->ensure_dir_structure_for($path, { quiet => 1 });
    # On Win32 the path where the distribution is built usually contains
    # spaces. This is a problem for some parts of the CPAN toolchain, so
    # local::lib uses the GetShortPathName trick do get an alternate
    # representation of the path that doesn't constain spaces.
    return ($^O eq 'MSWin32')
         ? Win32::GetShortPathName($path)
    : $path
}

1;