Skip Menu |

This queue is for tickets about the File-Temp CPAN distribution.

Report information
The Basics
Id: 15733
Status: resolved
Priority: 0/
Queue: File-Temp

People
Owner: Nobody in particular
Requestors: jkeenan [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 0.19



Subject: Wishlist: Tempdirs that get deleted at end of a block
(Excerpted from my review of File::Temp on cpanratings.org.) Having used File::Temp's object-oriented interface and gotten accustomed to having my tempfiles be deleted when the object goes out of scope, I long for the same facility with respect to tempdirs. As of v0.16, 'tempdir' is available only through the functional interface and you must explicitly call CLEANUP => 1 to get the tempdirs so created deleted at the end of the *program*. I would love to have a function/method that automatically deletes tempdirs at the end of their *enclosing scope/block*. This would, for example, enable me to create a tempdir within a block, test for its existence, have the tempdir deleted automatically when the block is closed, then test again for its non-existence. AFAICT, I can not currently run that second test because any tempdir I create lives until the end of the test program.
On Sat Nov 12 13:51:03 2005, JKEENAN wrote: Show quoted text
> (Excerpted from my review of File::Temp on cpanratings.org.) Having > used File::Temp's object-oriented interface and gotten accustomed > to having my tempfiles be deleted when the object goes out of > scope, I long for the same facility with respect to tempdirs. As of > v0.16, 'tempdir' is available only through the functional interface
I've been worrying about this since I wrote the OO layer. I'm thinking about names since it does not seem right to have to do "File::Temp->newdir()" or even "File::Tempdir->new()". Dir::Temp would seem to be better. Any preferences?
From: JKEENAN [...] cpan.org
On Fri Aug 18 19:11:43 2006, TJENNESS wrote: Show quoted text
> > I've been worrying about this since I wrote the OO layer. I'm thinking > about names since it does > not seem right to have to do "File::Temp->newdir()" or even > "File::Tempdir->new()". Dir::Temp > would seem to be better. Any preferences? >
I would be perfectly content with the following interface: use File::Temp (); $fh = File::Temp->new(); $tdir = $fh->tempdir(); I would only have to swap in the 3 lines above in any of my *many* uses of File::Temp::tempdir(). That would assume that the current File::Temp object contains the information needed to generate tempdir() method. If not, and a new object were required, I would recommend the following: use File::Temp::Tempdir; $tdir = File::Tempdir->new(); Only 2 lines, but you would have to include a new package in the File::Temp distribution. Since this functionality is a very logical extension of File::Temp's current functionality, I don't think creating a new second-level namespace (File::Tempdir) is needed. (BTW: v0.17 downloaded and installed successfully on 5.8.7 on Darwin osvers 7.9.0 (Mac OS X 10.4).) Jim Keenan
From: DAGOLDEN [...] cpan.org
On Sat Aug 19 07:27:15 2006, JKEENAN wrote: Show quoted text
> use File::Temp::Tempdir; > $tdir = File::Tempdir->new();
I'd rather just see Dir::Temp and distribute it as part of the File-Temp package. I worked up my own version of this in File::pushd with the function "tempd" for when I wanted to create and enter a temporary directory for a limited scope: # original pwd { my $wd = tempd; # pwd is a tempdir # do stuff here } # back to original pwd and tempdir is gone
From: JKEENAN [...] cpan.org
On Sun Oct 08 07:04:41 2006, DAGOLDEN wrote: Show quoted text
> > I'd rather just see Dir::Temp and distribute it as part of the File-Temp > package. >
But since in one sense the 'File-Temp package' is Perl 5.8, wouldn't that mean getting a separate Dir::Temp package into the core distribution? That would be a more complicated bureaucratic process. jimk
On Sat Aug 19 07:27:15 2006, JKEENAN wrote: Show quoted text
> On Fri Aug 18 19:11:43 2006, TJENNESS wrote:
> > > > I've been worrying about this since I wrote the OO layer. I'm
> thinking
> > about names since it does > > not seem right to have to do "File::Temp->newdir()" or even > > "File::Tempdir->new()". Dir::Temp > > would seem to be better. Any preferences? > >
> > I would be perfectly content with the following interface: > > use File::Temp (); > $fh = File::Temp->new(); > $tdir = $fh->tempdir(); > > I would only have to swap in the 3 lines above in any of my *many* > uses of > File::Temp::tempdir(). > > That would assume that the current File::Temp object contains the > information needed to > generate tempdir() method. If not, and a new object were required, I > would recommend the > following: > > use File::Temp::Tempdir; > $tdir = File::Tempdir->new(); > > Only 2 lines, but you would have to include a new package in the > File::Temp distribution. >
I see that a File::Tempdir is now on CPAN (since August 2006) so I'm not sure whether to bother integrating a version into File::Temp itself (although File::Tempdir suffers from the forking problem that was fixed in File::Temp in v0.18 - see RT #27020)
Object Oriented interface now implemented File::Temp->newdir() as of V0.19