MkTemp.pm

filter: Statementstmt 98.2% 57 / 58 Branchbran 60.7% 17 / 28 Conditioncond 66.6% 10 / 15 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 76.8% 93 / 121 CC 20 SCAR 22.7
CC
20
Cov
83%
mktemp
16.0
mkstemp
4.2
mkstempt
4.1
CRAP 9.7
↑ Summary MkTempO.pm »
1 #############################################################
2 # File/MkTemp.pm. Written in 1999|2000 by Travis Gummels.
3 # If you find problems with this please let me know.
4 # travis@gummels.com
5 #############################################################
6  
7 package File::MkTemp;
8  
9 1 require Exporter;
10  
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use vars qw($VERSION @ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 @ISA=qw(Exporter);
20 1 @EXPORT=qw(mktemp mkstemp mkstempt);
21  
22 1 $VERSION = '1.0.6';
23  
24 2 ▶sub mkstempt {
Subroutine mkstempt: called CC=4 SCAR=14.1
Pod undocumented
25 2 my ($template,$openup,$fh);
26 2 my @retval;
27  
28 2 ▶ croak("Usage: mkstempt('templateXXXXXX','dir',['ext']) ")
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 or @_ == 3 0 2 2
Condition66%2/3
@_ == 2 or @_ == 3
l!l&&r!l&&!r
110
MC/DC0%0/2
@_ == 2 or @_ == 3
@_ == 2 @_ == 3
Truth table66%2/3
A or B
A= @_ == 2B= @_ == 3
ABresult
1X1
011
000
29 unless(@_ == 2 || @_ == 3);
30  
31 2 $template = mktemp(@_);
32  
33 2 $openup = File::Spec->catfile($_[1], $template);
34  
35 2 $fh = new FileHandle ">$openup"; #and say ahhh.
36  
37 2 ▶ croak("Could not open file: $openup")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 2 2
38 unless(defined $fh);
39  
40 2 @retval = ($fh,$template);
41  
42 2 return(@retval);
43 }
44  
45 2 ▶sub mkstemp {
Subroutine mkstemp: called CC=4 SCAR=14.2
Pod undocumented
46 2 my ($template,$openup,$fh);
47  
48 2 ▶ croak("Usage: mkstemp('templateXXXXXX','dir',['ext']) ")
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 or @_ == 3 0 2 2
Condition66%2/3
@_ == 2 or @_ == 3
l!l&&r!l&&!r
110
MC/DC0%0/2
@_ == 2 or @_ == 3
@_ == 2 @_ == 3
Truth table66%2/3
A or B
A= @_ == 2B= @_ == 3
ABresult
1X1
011
000
49 unless(@_ == 2 || @_ == 3);
50  
51 2 $template = mktemp(@_);
52  
53 2 $openup = File::Spec->catfile($_[1], $template);
54  
55 2 $fh = new FileHandle ">$openup"; #and say ahhh.
56  
57 2 ▶ croak("Could not open file: $openup")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 2 2
58 unless(defined $fh);
59  
60 2 return($fh);
61 }
62  
63 6 ▶sub mktemp {
Subroutine mktemp: called CC=14 SCAR=27.7
Pod undocumented
64 6 my ($template,$dir,$ext,$keepgen,$lookup);
65 6 my (@template,@letters);
66  
67 6 ▶ croak("Usage: mktemp('templateXXXXXX',['/dir'],['ext']) ")
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 or @_ == 2 or @_ == 3 0 6 6
Condition66%4/6
@_ == 1 or @_ == 2 or @_ == 3
l!l&&r!l&&!r
330
@_ == 1 or @_ == 2
l!l&&r!l&&!r
033
MC/DC0%0/3
@_ == 1 or @_ == 2 or @_ == 3
@_ == 1 @_ == 2 @_ == 3
Truth table50%2/4
A or B or C
A= @_ == 1B= @_ == 2C= @_ == 3
ABCresult
1XX1
01X1
0011
0000
68 unless(@_ == 1 || @_ == 2 || @_ == 3);
69  
70 6 ($template,$dir,$ext) = @_;
71 6 @template = split //, $template;
72  
73 6 ▶ croak("The template must end with at least 6 uppercase letter X")
Branch: 1 branch
BranchTrueFalseTotal
if substr($template, -6, 6) ne "XXXXXX" 0 6 6
74 if (substr($template, -6, 6) ne 'XXXXXX');
75  
76 6 ▶ if ($dir){
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) 6 0 6
77 6 ▶ croak("The directory in which you wish to test for duplicates, $dir, does not exist") unless (-e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 6 6
78 }
79  
80 6 @letters = split(//,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
81  
82 6 $keepgen = 1;
83  
84 6 ▶ while ($keepgen){
Branch: 1 branch
BranchTrueFalseTotal
if ($keepgen) 6 6 12
85 6 ▶ for (my $i = $#template; $i >= 0 && ($template[$i] eq 'X'); $i--){
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0 and $template[$i] eq "X") 36 6 42
Condition66%2/3
$i >= 0 and $template[$i] eq "X"
!ll&&!rl&&r
0636
MC/DC50%1/2
$i >= 0 and $template[$i] eq "X"
$i >= 0 $template[$i] eq "X"
Truth table66%2/3
A and B
A= $i >= 0B= $template[$i] eq "X"
ABresult
0X0
100
111
86 36 $template[$i] = $letters[int(rand 52)];
87 }
88  
89 6 undef $template;
90  
91 6 $template = pack "a" x @template, @template;
92  
93 6 ▶ $template = $template . $ext if ($ext);
Branch: 1 branch
BranchTrueFalseTotal
if $ext 3 3 6
94  
95 6 ▶ if ($dir){
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 6 0 6
96 6 $lookup = File::Spec->catfile($dir, $template);
97 6 ▶ $keepgen = 0 unless (-e $lookup);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $lookup 6 0 6
98 }else{
99 0 $keepgen = 0;
100 }
101  
102 6 ▶ next if $keepgen == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $keepgen == 0 6 0 6
103 }
104  
105 6 return($template);
106 }
107 1 1;
108  
109 __END__
↑ Summary MkTempO.pm »