| 1 | package Alien::Build::Temp; | ||||||||||
| 2 | |||||||||||
| 3 | 67 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 67 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 67 | ▶ | use 5.008004; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 67 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 67 | ▶ | use Path::Tiny (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 67 | ▶ | use File::Temp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 67 | ▶ | use File::Spec (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | # ABSTRACT: Temp Dir support for Alien::Build | ||||||||||
| 12 | 67 | our $VERSION = '2.88'; # VERSION | |||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | # problem with vanilla File::Temp is that is often uses | ||||||||||
| 16 | # as /tmp that has noexec turned on. Workaround is to | ||||||||||
| 17 | # create a temp directory in the build directory, but | ||||||||||
| 18 | # we have to be careful about cleanup. This puts all that | ||||||||||
| 19 | # (attempted) carefulness in one place so that when we | ||||||||||
| 20 | # later discover it isn't so careful we can fix it in | ||||||||||
| 21 | # one place rather than all the places that we need | ||||||||||
| 22 | # temp directories. | ||||||||||
| 23 | |||||||||||
| 24 | # we also have a speical case for Windows, which often | ||||||||||
| 25 | # has problems with long paths if we try to use the | ||||||||||
| 26 | # current directory for temp files, so for those we | ||||||||||
| 27 | # use the system tmp directory. | ||||||||||
| 28 | |||||||||||
| 29 | 67 | my %root; | |||||||||
| 30 | |||||||||||
| 31 | sub _root | ||||||||||
| 32 | 372 | ▶ | { | ||||||||
|
Subroutine
_root: called CC=6 SCAR=18.1
| |||||||||||
| 33 | 372 | ▶ | return File::Spec->tmpdir if $^O eq 'MSWin32'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | |||||||||||
| 35 | 372 | ▶ | my $root = Path::Tiny->new(-d "_alien" ? "_alien/tmp" : ".tmp")->absolute; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 372 | ▶ | unless(-d $root) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | { | ||||||||||
| 38 | 7 | ▶ | mkdir $root or die "unable to create temp root $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | # TODO: doesn't account for fork... | ||||||||||
| 42 | 372 | my $lock = $root->child("l$$"); | |||||||||
| 43 | 372 | ▶ | unless(-f $lock) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | { | ||||||||||
| 45 | 57 | open my $fh, '>', $lock; | |||||||||
| 46 | 57 | close $fh; | |||||||||
| 47 | } | ||||||||||
| 48 | 372 | $root{"$root"} = 1; | |||||||||
| 49 | 372 | $root; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 67 | ▶ | END { | ||||||||
|
Subroutine
END: called CC=3 SCAR=11.1
| |||||||||||
| 53 | 67 | foreach my $root (keys %root) | |||||||||
| 54 | { | ||||||||||
| 55 | 57 | my $lock = Path::Tiny->new($root)->child("l$$"); | |||||||||
| 56 | 57 | unlink $lock; | |||||||||
| 57 | # try to delete if possible. | ||||||||||
| 58 | # if not possible then punt | ||||||||||
| 59 | 57 | ▶ | rmdir $root if -d $root; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | } | ||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | sub newdir | ||||||||||
| 64 | 371 | ▶ | { | ||||||||
|
Subroutine
newdir: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 65 | 371 | my $class = shift; | |||||||||
| 66 | 371 | ▶ | Carp::croak "uneven" if @_ % 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 371 | File::Temp->newdir(DIR => _root, @_); | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | sub new | ||||||||||
| 71 | 1 | ▶ | { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 72 | 1 | my $class = shift; | |||||||||
| 73 | 1 | ▶ | Carp::croak "uneven" if @_ % 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 1 | File::Temp->new(DIR => _root, @_); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 67 | 1; | |||||||||
| 78 | |||||||||||
| 79 | __END__ | ||||||||||