File: TmpFile.pm

package info (click to toggle)
debconf 1.5.91
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,180 kB
  • sloc: perl: 8,500; sh: 262; python: 182; makefile: 144
file content (69 lines) | stat: -rw-r--r-- 876 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl

=head1 NAME

Debconf::TmpFile - temporary file creator

=cut

package Debconf::TmpFile;
use warnings;
use strict;
use IO::File;
use Fcntl;
use File::Temp;

=head1 DESCRIPTION

This module helps debconf make safe temporary files. At least, I think
they're safe, if /tmp is not on NFS.

=head1 METHODS

=over 4

=item open

Open a temporary file for writing. Returns an open file descriptor.
Optionally a file extension may be passed to it.

=cut

my $filename;

sub open {
	my $fh; # will be autovivified
	my $ext=shift || '';
	($fh, $filename) = File::Temp::tempfile(SUFFIX => $ext);
	return $fh;
}

=item filename

Returns the name of the last opened temp file.

=cut

sub filename {
	return $filename;
}

=item cleanup

Unlinks the last opened tempfile.

=cut

sub cleanup {
	unlink $filename;
}

=back

=head1 AUTHOR

Joey Hess <joeyh@debian.org>

=cut

1