| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package File::Fu::Dir::Temp; |
|
2
|
|
|
|
|
|
|
$VERSION = v0.0.8; |
|
3
|
|
|
|
|
|
|
|
|
4
|
13
|
|
|
13
|
|
66
|
use warnings; |
|
|
13
|
|
|
|
|
107
|
|
|
|
13
|
|
|
|
|
391
|
|
|
5
|
13
|
|
|
13
|
|
62
|
use strict; |
|
|
13
|
|
|
|
|
23
|
|
|
|
13
|
|
|
|
|
411
|
|
|
6
|
13
|
|
|
13
|
|
68
|
use Carp; |
|
|
13
|
|
|
|
|
26
|
|
|
|
13
|
|
|
|
|
849
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=begin shutup_pod_cover |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head2 clone |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head2 XXX |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=end shutup_pod_cover |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
|
17
|
|
|
|
|
|
|
|
|
18
|
13
|
|
|
13
|
|
7495
|
use File::Fu::File::Temp; |
|
|
13
|
|
|
|
|
40
|
|
|
|
13
|
|
|
|
|
866
|
|
|
19
|
|
|
|
|
|
|
*_validate = \&File::Fu::File::Temp::_validate; |
|
20
|
|
|
|
|
|
|
*XXX = \&File::Fu::File::Temp::XXX; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
File::Fu::Dir::Temp - temporary directories |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use File::Fu; |
|
29
|
|
|
|
|
|
|
my $dir = File::Fu->temp_dir; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
|
32
|
|
|
|
|
|
|
|
|
33
|
13
|
|
|
13
|
|
80
|
use base 'File::Fu::Dir'; |
|
|
13
|
|
|
|
|
36
|
|
|
|
13
|
|
|
|
|
15030
|
|
|
34
|
|
|
|
|
|
|
use overload ( |
|
35
|
1
|
|
|
1
|
|
201
|
'/=' => sub {croak("cannot mutate a temp dir");}, |
|
36
|
0
|
|
|
0
|
|
0
|
'+=' => sub {croak("cannot mutate a temp dir");}, |
|
37
|
0
|
|
|
0
|
|
0
|
'.=' => sub {croak("cannot mutate a temp dir");}, |
|
38
|
13
|
|
|
13
|
|
86
|
); |
|
|
13
|
|
|
|
|
78
|
|
|
|
13
|
|
|
|
|
329
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
13
|
|
|
13
|
|
1027
|
use Class::Accessor::Classy; |
|
|
13
|
|
|
|
|
28
|
|
|
|
13
|
|
|
|
|
1461
|
|
|
41
|
|
|
|
|
|
|
rs auto_delete => \(my $set_auto_delete); |
|
42
|
|
|
|
|
|
|
rs dir_class => \(my $set_dir_class); |
|
43
|
13
|
|
|
13
|
|
19328
|
no Class::Accessor::Classy; |
|
|
13
|
|
|
|
|
25
|
|
|
|
13
|
|
|
|
|
69
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 new |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $tmp = File::Fu::Dir::Temp->new($dir, 'foo'); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
{ |
|
52
|
|
|
|
|
|
|
my %argmap = ( |
|
53
|
|
|
|
|
|
|
nocleanup => [UNLINK => 0], |
|
54
|
|
|
|
|
|
|
); |
|
55
|
|
|
|
|
|
|
sub new { |
|
56
|
5
|
|
|
5
|
1
|
15
|
my $proto = shift; |
|
57
|
5
|
100
|
|
|
|
19
|
if(ref($proto)) { # calls to subdir, etc are not in the Temp class |
|
58
|
2
|
|
|
|
|
67
|
return $proto->dir_class->new(@_); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
3
|
|
|
|
|
8
|
my $class = $proto; |
|
61
|
|
|
|
|
|
|
#warn "args: @_"; |
|
62
|
3
|
|
|
|
|
24
|
my ($dir, $send, $opt) = $class->_validate(\%argmap, @_); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
#warn "dir: $dir"; |
|
65
|
|
|
|
|
|
|
#warn "opts: @$send"; |
|
66
|
3
|
|
|
|
|
20
|
my $temp = File::Temp::tempdir(@$send); |
|
67
|
3
|
|
|
|
|
843833
|
my $self = $class->SUPER::new($temp); |
|
68
|
3
|
|
|
|
|
532
|
$self->{$_} = $opt->{$_} for(keys(%$opt)); |
|
69
|
3
|
|
|
|
|
15
|
$self->{_proc} = $$; |
|
70
|
3
|
|
|
|
|
125
|
$self->$set_dir_class(ref($dir)); |
|
71
|
|
|
|
|
|
|
|
|
72
|
3
|
|
|
|
|
33
|
return($self); |
|
73
|
|
|
|
|
|
|
}} # end subroutine new definition |
|
74
|
|
|
|
|
|
|
######################################################################## |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 chdir |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $dir = $dir->chdir; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub chdir { |
|
83
|
1
|
|
|
1
|
1
|
9
|
my $self = shift; |
|
84
|
|
|
|
|
|
|
|
|
85
|
1
|
|
|
|
|
9
|
my $dir = $self->SUPER::chdir; |
|
86
|
1
|
|
|
|
|
4
|
$dir->{temp_parent} = $self; |
|
87
|
1
|
|
|
|
|
9
|
return($dir); |
|
88
|
|
|
|
|
|
|
} # chdir ############################################################## |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=for nit head2 clone |
|
91
|
|
|
|
|
|
|
Because clone doesn't call new :-/ |
|
92
|
|
|
|
|
|
|
$not_temp = $temp->clone; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub clone { |
|
97
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
|
98
|
2
|
|
|
|
|
14
|
$self = $self->SUPER::clone; |
|
99
|
2
|
|
|
|
|
55
|
bless($self, $self->dir_class); |
|
100
|
|
|
|
|
|
|
} # end subroutine clone definition |
|
101
|
|
|
|
|
|
|
######################################################################## |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 rename |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Same as the base rename(), but promotes the temp dir to a regular Dir |
|
106
|
|
|
|
|
|
|
object (prevents any cleanup actions.) |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$temp = $temp->rename($dest); |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub rename { |
|
113
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
114
|
0
|
|
|
|
|
0
|
my $dir_class = $self->dir_class; |
|
115
|
0
|
|
|
|
|
0
|
$self = $self->SUPER::rename(@_); |
|
116
|
0
|
|
|
|
|
0
|
bless($self, $dir_class); |
|
117
|
0
|
|
|
|
|
0
|
return($self); |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# TODO File::Fu->temp_dir->chdir causes immediate deletion? |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 nocleanup |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Disable autocleanup. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$dir->nocleanup; |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# XXX I think this is named wrong -- should probably just delete the |
|
131
|
|
|
|
|
|
|
# dependency on File::Temp because I can't override that END block |
|
132
|
|
|
|
|
|
|
sub nocleanup { |
|
133
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
134
|
0
|
|
|
|
|
0
|
$self->$set_auto_delete(0); |
|
135
|
|
|
|
|
|
|
} # end subroutine nocleanup definition |
|
136
|
|
|
|
|
|
|
######################################################################## |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 DESTROY |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Called automatically when the object goes out of scope. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
$dir->DESTROY; |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub DESTROY { |
|
147
|
3
|
|
|
3
|
|
606
|
my $self = shift; |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# ? should this have: |
|
150
|
3
|
50
|
|
|
|
139
|
return unless($self->auto_delete); |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# forked case |
|
153
|
3
|
50
|
|
|
|
119
|
return unless($$ == $self->{_proc}); |
|
154
|
|
|
|
|
|
|
|
|
155
|
3
|
|
|
|
|
15
|
my $string = $self->stringify; |
|
156
|
|
|
|
|
|
|
#warn "DESTROY ($$/$self->{_proc}", $string; |
|
157
|
|
|
|
|
|
|
# XXX overload stops operating in DESTROY()? |
|
158
|
|
|
|
|
|
|
|
|
159
|
3
|
50
|
|
|
|
69
|
die("$string does not exist") unless(-d $string); |
|
160
|
3
|
|
|
|
|
33
|
$self->remove; |
|
161
|
3
|
|
|
|
|
341
|
$self->{auto_delete} = 0; |
|
162
|
|
|
|
|
|
|
} # end subroutine DESTROY definition |
|
163
|
|
|
|
|
|
|
######################################################################## |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 AUTHOR |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Eric Wilhelm @ |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
http://scratchcomputing.com/ |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 BUGS |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
If you found this module on CPAN, please report any bugs or feature |
|
174
|
|
|
|
|
|
|
requests through the web interface at L. I will be |
|
175
|
|
|
|
|
|
|
notified, and then you'll automatically be notified of progress on your |
|
176
|
|
|
|
|
|
|
bug as I make changes. |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
If you pulled this development version from my /svn/, please contact me |
|
179
|
|
|
|
|
|
|
directly. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Copyright (C) 2008 Eric L. Wilhelm, All Rights Reserved. |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 NO WARRANTY |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Absolutely, positively NO WARRANTY, neither express or implied, is |
|
188
|
|
|
|
|
|
|
offered with this software. You use this software at your own risk. In |
|
189
|
|
|
|
|
|
|
case of loss, no person or entity owes you anything whatsoever. You |
|
190
|
|
|
|
|
|
|
have been warned. |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 LICENSE |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
195
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# vi:ts=2:sw=2:et:sta |
|
200
|
|
|
|
|
|
|
1; |