line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
203659
|
use strict; |
|
3
|
|
|
|
|
27
|
|
|
3
|
|
|
|
|
94
|
|
2
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
143
|
|
3
|
|
|
|
|
|
|
package Test::TempDir; # git description: v0.10-11-g629f4d3 |
4
|
|
|
|
|
|
|
# ABSTRACT: (DEPRECATED) Temporary files support for testing |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
905
|
use File::Temp (); |
|
3
|
|
|
|
|
22513
|
|
|
3
|
|
|
|
|
68
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
901
|
use Test::TempDir::Factory; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
237
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
|
|
79
|
use Sub::Exporter -setup => { |
13
|
|
|
|
|
|
|
exports => [qw(temp_root tempdir tempfile scratch)], |
14
|
|
|
|
|
|
|
groups => { |
15
|
|
|
|
|
|
|
default => [qw(temp_root tempdir tempfile)], |
16
|
|
|
|
|
|
|
}, |
17
|
3
|
|
|
3
|
|
30
|
}; |
|
3
|
|
|
|
|
6
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our ( $factory, $dir ); |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
33
|
2
|
|
41
|
sub _factory { $factory ||= Test::TempDir::Factory->new } |
22
|
4
|
|
66
|
4
|
|
78
|
sub _dir { $dir ||= _factory->create } |
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
3
|
|
9491
|
END { undef $dir; undef $factory }; |
|
3
|
|
|
|
|
428
|
|
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
4
|
1
|
244
|
sub temp_root () { _dir->dir } |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
2
|
|
6
|
sub _temp_args { DIR => temp_root()->stringify, CLEANUP => 0 } |
29
|
|
|
|
|
|
|
sub _template_args { |
30
|
1
|
50
|
|
1
|
|
5
|
if ( @_ % 2 == 0 ) { |
31
|
1
|
|
|
|
|
4
|
return ( _temp_args, @_ ); |
32
|
|
|
|
|
|
|
} else { |
33
|
0
|
|
|
|
|
0
|
return ( $_[0], _temp_args, @_[1 .. $#_] ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
0
|
1
|
0
|
sub tempdir { File::Temp::tempdir( _template_args(@_) ) } |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
1
|
321
|
sub tempfile { File::Temp::tempfile( _template_args(@_) ) } |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub scratch { |
42
|
1
|
|
|
1
|
1
|
11
|
require Directory::Scratch; |
43
|
1
|
|
|
|
|
5
|
Directory::Scratch->new( _temp_args, @_ ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__PACKAGE__ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=pod |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=encoding UTF-8 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Test::TempDir - (DEPRECATED) Temporary files support for testing |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 VERSION |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
version 0.11 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 DEPRECATION NOTICE |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
There have been numerous issues found with this module, particularly with its |
66
|
|
|
|
|
|
|
use of locks (unreliable, may result in your entire C<$TMPDIR> being deleted) |
67
|
|
|
|
|
|
|
and MSWin32 compatibility. As well, it uses Moose, which is nowadays considered |
68
|
|
|
|
|
|
|
to be heavier than necessary. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
L<Test::TempDir::Tiny> was written as a replacement. Please use it instead! |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 SYNOPSIS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
use Test::TempDir; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $test_tempdir = temp_root(); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my ( $fh, $file ) = tempfile(); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $directory_scratch_obj = scratch(); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 DESCRIPTION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Test::TempDir provides temporary directory creation with testing in mind. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
The differences between using this and using L<File::Temp> are: |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=over 4 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item * |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=for stopwords creatable |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
If C<t/tmp> is available (writable, creatable, etc) it's preferred over |
95
|
|
|
|
|
|
|
C<$ENV{TMPDIR}> etc. Otherwise a temporary directory will be used. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This is C<temp_root> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item * |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Lock files are used on C<t/tmp>, to prevent race conditions when running under a |
102
|
|
|
|
|
|
|
parallel test harness. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item * |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
The C<temp_root> is cleaned at the end of a test run, but not if tests failed. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
C<temp_root> is emptied at the beginning of a test run unconditionally. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
The default policy is not to clean the individual C<tempfiles> and C<tempdirs> |
115
|
|
|
|
|
|
|
within C<temp_root>, in order to aid in debugging of failed tests. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=back |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 EXPORTS |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 C<temp_root> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
The root of the temporary stuff. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 C<tempfile> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 C<tempdir> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Wrappers for the L<File::Temp> functions of the same name. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=for stopwords overridable |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
The default options are changed to use C<temp_root> for C<DIR> and disable |
134
|
|
|
|
|
|
|
C<CLEANUP>, but these are overridable. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 C<scratch> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Loads L<Directory::Scratch> and instantiates a new one, with the same default |
139
|
|
|
|
|
|
|
options as C<tempfile> and C<tempdir>. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 SEE ALSO |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over 4 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
L<File::Temp>, |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item * |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
L<Directory::Scratch> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
L<Path::Class> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=back |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 SUPPORT |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Test-TempDir> |
162
|
|
|
|
|
|
|
(or L<bug-Test-TempDir@rt.cpan.org|mailto:bug-Test-TempDir@rt.cpan.org>). |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
165
|
|
|
|
|
|
|
L<http://lists.perl.org/list/perl-qa.html>. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
168
|
|
|
|
|
|
|
L<C<#perl> on C<irc.perl.org>|irc://irc.perl.org/#perl-qa>. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 AUTHOR |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=for stopwords Karen Etheridge Florian Ragwitz |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=over 4 |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=back |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
This software is copyright (c) 2006 by יובל קוג'מן (Yuval Kogman). |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
195
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |