Skip Menu |

This queue is for tickets about the Directory-Scratch CPAN distribution.

Report information
The Basics
Id: 20518
Status: resolved
Priority: 0/
Queue: Directory-Scratch

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

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



What's the benefit of this module over tempdir() from File::Temp? N
Subject: rationale for Directory::Scratch's existence
From: JROCKWAY [...] cpan.org
On Mon Jul 17 16:58:57 2006, NIKC wrote: Show quoted text
> What's the benefit of this module over tempdir() from File::Temp?
Convenience. To use tempdir (which is what the module does), you have to load the module, create the tempdir, then every time you want to do something, you have to properly concatenate the filename onto the directory. Since perl builtins don't throw exceptions, you have to error check, too. All in all, it's a lot of lines of code to do something very simple. I give an example in the RATIONALE section of the POD: "Before": (11 lines) use Test::More tests => 42; use Foo::Bar; my $TESTDIR = "/tmp/test.$$"; my $FILE = "$TESTDIR/file"; mkdir $TESTDIR; open(my $file, '>', $FILE); print {$file} "test\n"; close($file); ok(-e $FILE); # tests END { `rm -rf $TESTDIR` } After: (7 lines) use Test::More tests => 42; use Foo::Bar; use Directory::Scratch; my $tmp = Directory::Scratch->new; my $FILE = $tmp->touch('file'); ok(-e $FILE) # tests All of my CPAN modules (and non-CPAN perl software; see www.jrock.us/trac for those) are file-based, and I needed a fast and convenient way to make lots of files and directories. Directory::Scratch has made my test-writing life 100x better :) I thought that I'm not the only one that does this, hence I released the module to CPAN. Regards, -- Jonathan Rockway <jrockway@cpan.org>
CC: NIKC [...] cpan.org
Subject: Re: [rt.cpan.org #20518] rationale for Directory::Scratch's existence
Date: Tue, 18 Jul 2006 09:04:05 +0100
To: bug-Directory-Scratch [...] rt.cpan.org
From: Nik Clayton <nik [...] ngo.org.uk>
Jonathan Rockway via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=20518 > > > On Mon Jul 17 16:58:57 2006, NIKC wrote:
>> What's the benefit of this module over tempdir() from File::Temp?
> > Convenience. To use tempdir (which is what the module does), you have > to load the module, create the tempdir, then every time you want to do > something, you have to properly concatenate the filename onto the > directory. Since perl builtins don't throw exceptions, you have to > error check, too. All in all, it's a lot of lines of code to do > something very simple. > > I give an example in the RATIONALE section of the POD: > > "Before": (11 lines) > use Test::More tests => 42; > use Foo::Bar; > > my $TESTDIR = "/tmp/test.$$"; > my $FILE = "$TESTDIR/file"; > mkdir $TESTDIR; > open(my $file, '>', $FILE); > print {$file} "test\n"; > close($file); > ok(-e $FILE); > > # tests > > END { `rm -rf $TESTDIR` } > > After: (7 lines) > use Test::More tests => 42; > use Foo::Bar; > use Directory::Scratch; > > my $tmp = Directory::Scratch->new; > my $FILE = $tmp->touch('file'); > ok(-e $FILE) > > # tests
Eh? If you want to create a file in a temporary directory you do this: use Test::More tests => 42; use Foo::Bar; use File::Temp; my $tmp = File::Temp->new(); my $FILE = $tmp->filename(); ok(-e $FILE); That's the same number of lines, same functionality (the file will be automatically removed when the program ends). Show quoted text
> Since perl builtins don't throw exceptions,
perldoc Fatal N
Subject: Re: [rt.cpan.org #20518] rationale for Directory::Scratch's existence
Date: Tue, 18 Jul 2006 11:19:32 -0500
To: bug-Directory-Scratch [...] rt.cpan.org
From: Jonathan Rockway <jon [...] jrock.us>
Good, but still not what I want. I need to test filenames with weird names (spaces, dots, UTF-8 characters) and I often need entire directory hierarchies. Take a look at the test suite for File::Attributes::Recursive, for example: http://search.cpan.org/src/JROCKWAY/File-Attributes-Recursive-0.01/t/01-attributes.t File::Temp is the right thing to do inside an application, I agree, but in my tests I need something a little different. Regards, Jonathan Rockway