| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Alien::Build::Temp; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 59 |  |  | 59 |  | 235836 | use strict; | 
|  | 59 |  |  |  |  | 120 |  | 
|  | 59 |  |  |  |  | 1744 |  | 
| 4 | 59 |  |  | 59 |  | 291 | use warnings; | 
|  | 59 |  |  |  |  | 109 |  | 
|  | 59 |  |  |  |  | 1292 |  | 
| 5 | 59 |  |  | 59 |  | 865 | use 5.008004; | 
|  | 59 |  |  |  |  | 198 |  | 
| 6 | 59 |  |  | 59 |  | 350 | use Carp (); | 
|  | 59 |  |  |  |  | 122 |  | 
|  | 59 |  |  |  |  | 1801 |  | 
| 7 | 59 |  |  | 59 |  | 3476 | use Path::Tiny (); | 
|  | 59 |  |  |  |  | 46035 |  | 
|  | 59 |  |  |  |  | 1252 |  | 
| 8 | 59 |  |  | 59 |  | 1103 | use File::Temp (); | 
|  | 59 |  |  |  |  | 20413 |  | 
|  | 59 |  |  |  |  | 1017 |  | 
| 9 | 59 |  |  | 59 |  | 304 | use File::Spec (); | 
|  | 59 |  |  |  |  | 152 |  | 
|  | 59 |  |  |  |  | 20007 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | # ABSTRACT: Temp Dir support for Alien::Build | 
| 12 |  |  |  |  |  |  | our $VERSION = '2.45'; # 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 thabn alllll the places that we need | 
| 22 |  |  |  |  |  |  | # temp directories. | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | my %root; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub _root | 
| 27 |  |  |  |  |  |  | { | 
| 28 | 308 | 50 |  | 308 |  | 1526 | return File::Spec->tmpdir if $^O eq 'MSWin32'; | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 308 | 50 |  |  |  | 5998 | my $root = Path::Tiny->new(-d "_alien" ? "_alien/tmp" : ".tmp")->absolute; | 
| 31 | 308 | 100 |  |  |  | 39125 | unless(-d $root) | 
| 32 |  |  |  |  |  |  | { | 
| 33 | 7 | 50 |  |  |  | 370 | mkdir $root or die "unable to create temp root $!"; | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | # TODO: doesn't account for fork... | 
| 37 | 308 |  |  |  |  | 10204 | my $lock = $root->child("l$$"); | 
| 38 | 308 | 100 |  |  |  | 11773 | unless(-f $lock) | 
| 39 |  |  |  |  |  |  | { | 
| 40 | 47 |  |  |  |  | 2594 | open my $fh, '>', $lock; | 
| 41 | 47 |  |  |  |  | 9013 | close $fh; | 
| 42 |  |  |  |  |  |  | } | 
| 43 | 308 |  |  |  |  | 5850 | $root{"$root"} = 1; | 
| 44 | 308 |  |  |  |  | 4497 | $root; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | END { | 
| 48 | 59 |  |  | 59 |  | 509552 | foreach my $root (keys %root) | 
| 49 |  |  |  |  |  |  | { | 
| 50 | 47 |  |  |  |  | 500 | my $lock = Path::Tiny->new($root)->child("l$$"); | 
| 51 | 47 |  |  |  |  | 3578 | unlink $lock; | 
| 52 |  |  |  |  |  |  | # try to delete if possible. | 
| 53 |  |  |  |  |  |  | # if not possible then punt | 
| 54 | 47 | 50 |  |  |  | 6009 | rmdir $root if -d $root; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | sub newdir | 
| 59 |  |  |  |  |  |  | { | 
| 60 | 307 |  |  | 307 | 0 | 967 | my $class = shift; | 
| 61 | 307 | 50 |  |  |  | 1271 | Carp::croak "uneven" if @_ % 2; | 
| 62 | 307 |  |  |  |  | 1152 | File::Temp->newdir(DIR => _root, @_); | 
| 63 |  |  |  |  |  |  | } | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | sub new | 
| 66 |  |  |  |  |  |  | { | 
| 67 | 1 |  |  | 1 | 0 | 8227 | my $class = shift; | 
| 68 | 1 | 50 |  |  |  | 18 | Carp::croak "uneven" if @_ % 2; | 
| 69 | 1 |  |  |  |  | 5 | File::Temp->new(DIR => _root, @_); | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | 1; | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | __END__ |