| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 48 | 0 | die "can't mkdir '$path': $!"; | |||||||||
| 49 | } | ||||||||||
| 50 | } | ||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 2 | 1 | |||||||||