blib/lib/Alien/Build/Temp.pm

filter: Statementstmt 100% 43 / 43 Branchbran 62.5% 10 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 2 totaltotal 88.8% 64 / 72 CC 10 SCAR 11.1
CC
10
Cov
90%
_root
6.1
END
3.0
newdir
2.0
CRAP 3.0
« blib/lib/alienfile.pm ↑ Summary blib/lib/Alien/Build/Plugin/Core/Legacy.pm »
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
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 372 372
34  
35 372 ▶ my $root = Path::Tiny->new(-d "_alien" ? "_alien/tmp" : ".tmp")->absolute;
Branch: 1 branch
BranchTrueFalseTotal
-d '_alien' ? : 0 372 372
36 372 ▶ unless(-d $root)
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $root) 7 365 372
37 {
38 7 ▶ mkdir $root or die "unable to create temp root $!";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $root or die "unable to create temp root $!" 7 0 7
39 }
40  
41 # TODO: doesn't account for fork...
42 372 my $lock = $root->child("l$$");
43 372 ▶ unless(-f $lock)
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $lock) 57 315 372
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
BranchTrueFalseTotal
if -d $root 57 0 57
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
BranchTrueFalseTotal
if @_ % 2 0 371 371
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
BranchTrueFalseTotal
if @_ % 2 0 1 1
74 1 File::Temp->new(DIR => _root, @_);
75 }
76  
77 67 1;
78  
79 __END__
« blib/lib/alienfile.pm ↑ Summary blib/lib/Alien/Build/Plugin/Core/Legacy.pm »