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