line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################# |
2
|
|
|
|
|
|
|
# File/MkTempO.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::MkTempO; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1032
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
1090
|
use FileHandle; |
|
1
|
|
|
|
|
16300
|
|
|
1
|
|
|
|
|
7
|
|
12
|
1
|
|
|
1
|
|
492
|
use File::Spec; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
13
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
57
|
|
14
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
706
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$File::MkTemp::VERSION = '1.0.6'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
1
|
|
|
1
|
0
|
40
|
my $pkg = shift; |
20
|
|
|
|
|
|
|
|
21
|
1
|
50
|
33
|
|
|
11
|
croak("Usage: \$var = new File::MkTempO('templateXXXXXX',['dir']) ") |
22
|
|
|
|
|
|
|
unless(@_ == 1 || @_ == 2); |
23
|
|
|
|
|
|
|
|
24
|
1
|
50
|
|
|
|
7
|
croak("The template must end with at least 6 uppercase letter X") |
25
|
|
|
|
|
|
|
if (substr($_[0], -6, 6) ne 'XXXXXX'); |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
4
|
my $me = bless {}, $pkg; |
28
|
1
|
|
|
|
|
10
|
$me->{'template'} = $_[0]; |
29
|
1
|
50
|
|
|
|
7
|
$me->{'dir'} = $_[1] if @_ == 2; |
30
|
1
|
|
|
|
|
3
|
$me; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub mktemp { |
34
|
2
|
|
|
2
|
0
|
12
|
my $me = shift; |
35
|
2
|
|
|
|
|
4
|
my ($template,$dir,$keepgen,$lookup); |
36
|
0
|
|
|
|
|
0
|
my (@template,@letters); |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
3
|
$template = $me->{'template'}; |
39
|
2
|
|
|
|
|
4
|
$dir = $me->{'dir'}; |
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
12
|
@template = split //, $template; |
42
|
|
|
|
|
|
|
|
43
|
2
|
50
|
|
|
|
6
|
if ($dir){ |
44
|
2
|
50
|
|
|
|
41
|
croak("The directory in which you wish to test for duplicates, $dir, does not exist") unless (-e $dir); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
|
|
32
|
@letters = split(//,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
5
|
$keepgen = 1; |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
7
|
while ($keepgen){ |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
66
|
|
|
13
|
for (my $i = $#template; $i >= 0 && ($template[$i] eq 'X'); $i--){ |
54
|
12
|
|
|
|
|
92
|
$template[$i] = $letters[int(rand 52)]; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
16
|
$template = pack "a" x @template, @template; |
58
|
|
|
|
|
|
|
|
59
|
2
|
50
|
|
|
|
6
|
if ($me->{'dir'}){ |
60
|
2
|
|
|
|
|
36
|
$lookup = File::Spec->catfile($dir, $template); |
61
|
2
|
50
|
|
|
|
50
|
$keepgen = 0 unless (-e $lookup); |
62
|
|
|
|
|
|
|
}else{ |
63
|
0
|
|
|
|
|
0
|
$keepgen = 0; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
2
|
50
|
|
|
|
9
|
next if $keepgen == 0; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
14
|
return($template); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub mkstemp { |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
1
|
0
|
11
|
my $me = shift; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
4
|
my $dir = $me->{'dir'}; |
78
|
|
|
|
|
|
|
|
79
|
1
|
50
|
|
|
|
3
|
croak("You must specify a directory when creating the object in order to use mkstemp") |
80
|
|
|
|
|
|
|
unless $dir; |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
3
|
my $template = $me->mktemp; |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
|
|
9
|
my $openup = File::Spec->catfile($dir, $template); |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
24
|
my $fh = new FileHandle ">$openup"; #and say ahhh. |
87
|
|
|
|
|
|
|
|
88
|
1
|
50
|
|
|
|
185
|
croak("Could not open file: $openup") |
89
|
|
|
|
|
|
|
unless(defined $fh); |
90
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
3
|
$me->{'fhtmpl'} = $template; |
92
|
1
|
|
|
|
|
2
|
$me->{'fhdirtmpl'} = $openup; |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
3
|
return($fh); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
2
|
|
|
2
|
0
|
16
|
sub template { my $me=shift; return $me->{'template'}; } |
|
2
|
|
|
|
|
5
|
|
98
|
2
|
|
|
2
|
0
|
35
|
sub dir { my $me=shift; return $me->{'dir'}; } |
|
2
|
|
|
|
|
6
|
|
99
|
2
|
|
|
2
|
0
|
45
|
sub fhtmpl { my $me=shift; return $me->{'fhtmpl'}; } |
|
2
|
|
|
|
|
25
|
|
100
|
3
|
|
|
3
|
0
|
83
|
sub fhdirtmpl { my $me=shift; return $me->{'fhdirtmpl'}; } |
|
3
|
|
|
|
|
30
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |