| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
Debconf::TmpFile - temporary file creator |
| 6 |
|
| 7 |
=cut |
| 8 |
|
| 9 |
package Debconf::TmpFile; |
| 10 |
use warnings; |
| 11 |
use strict; |
| 12 |
use IO::File; |
| 13 |
use Fcntl; |
| 14 |
use File::Temp; |
| 15 |
|
| 16 |
=head1 DESCRIPTION |
| 17 |
|
| 18 |
This module helps debconf make safe temporary files. At least, I think |
| 19 |
they're safe, if /tmp is not on NFS. |
| 20 |
|
| 21 |
=head1 METHODS |
| 22 |
|
| 23 |
=over 4 |
| 24 |
|
| 25 |
=item open |
| 26 |
|
| 27 |
Open a temporary file for writing. Returns an open file descriptor. |
| 28 |
Optionally a file extension may be passed to it. |
| 29 |
|
| 30 |
=cut |
| 31 |
|
| 32 |
my $filename; |
| 33 |
|
| 34 |
sub open { |
| 35 |
my $fh; # will be autovivified |
| 36 |
my $ext=shift || ''; |
| 37 |
($fh, $filename) = File::Temp::tempfile(SUFFIX => $ext); |
| 38 |
return $fh; |
| 39 |
} |
| 40 |
|
| 41 |
=item filename |
| 42 |
|
| 43 |
Returns the name of the last opened temp file. |
| 44 |
|
| 45 |
=cut |
| 46 |
|
| 47 |
sub filename { |
| 48 |
return $filename; |
| 49 |
} |
| 50 |
|
| 51 |
=item cleanup |
| 52 |
|
| 53 |
Unlinks the last opened tempfile. |
| 54 |
|
| 55 |
=cut |
| 56 |
|
| 57 |
sub cleanup { |
| 58 |
unlink $filename; |
| 59 |
} |
| 60 |
|
| 61 |
=back |
| 62 |
|
| 63 |
=head1 AUTHOR |
| 64 |
|
| 65 |
Joey Hess <[email protected]> |
| 66 |
|
| 67 |
=cut |
| 68 |
|
| 69 |
1 |