lib/Chj/tempdir.pm

filter: Statementstmt 85.7% 24 / 28 Branchbran 33.3% 2 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 77.5% 31 / 40 CC 4 SCAR 11.6
CC
4
Cov
76%
tempdir
5.4
BEGIN
1.0
BEGIN
1.0
CRAP 3.2
« lib/FP/Cmp.pm ↑ Summary lib/FP/Failure.pm »
1 #
2 # Copyright 2013-2020 by Christian Jaeger, ch at christianjaeger ch
3 # This is free software, offered under the terms of the MIT License.
4 # See the file COPYING that came bundled with this file.
5 #
6  
7 =head1 NAME
8  
9 Chj::tempdir
10  
11 =head1 SYNOPSIS
12  
13 =head1 DESCRIPTION
14  
15 A simple tempdir procedure, without auto cleanup.
16  
17 =head1 NOTE
18  
19 This is alpha software! Read the status section in the package README
20 or on the L<website|http://functional-perl.org/>.
21  
22 =cut
23  
24 package Chj::tempdir;
25 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use Exporter "import";
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 2 our @EXPORT = qw(tempdir);
30 2 our @EXPORT_OK = qw();
31 2 our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
32  
33 2 ▶use FP::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 ▶sub tempdir {
Subroutine tempdir: called CC=4 SCAR=16.9
Pod undocumented
36 1 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 1 0 1
37 1 my ($base) = @_;
38 1 my $tries = 0;
39 1 my $perhapsrnd = "";
40 TRY: {
41 1 my $path = "$base-${$}${perhapsrnd}";
42 1 ▶ if (mkdir $path, 0700) {
Branch: 1 branch
BranchTrueFalseTotal
if (mkdir $path, 448) { } 1 0 1
43 1 return $path
44 } else {
45 0 $tries++;
46 0 $perhapsrnd = "-" . substr(rand, 2, 7);
47 0 ▶ redo TRY if ($tries < 10);
Branch: 1 branch
BranchTrueFalseTotal
if $tries < 10 0 0 0
48 0 die "can't mkdir '$path': $!";
49 }
50 }
51 }
52  
53 2 1
« lib/FP/Cmp.pm ↑ Summary lib/FP/Failure.pm »