Skip Menu |

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

Report information
The Basics
Id: 21120
Status: resolved
Worked: 2 hours (120 min)
Priority: 0/
Queue: Directory-Scratch

People
Owner: jrockway [...] cpan.org
Requestors: tobeya [...] cpan.org
Cc:
AdminCc:

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



Subject: patch - features & bugfixes
I was about to write a very similar module, but I found yours on CPAN and it's very close to what I want to use it for. I wrote the attached patch this morning that adds most of what I had in mind that was missing. It was easiest for me to generate the patch by just creating a 0.06 directory and make my changes. Edit to taste ;) What it does: * removes dependency on File::Slurp * implements the prepend() method (probably slow) * allows calling new() on an object to get a new scratch directory that is a child (subdirectory of the parent) * added a cleanup() method to explicitly blow away an object recursively with File::Path::rmtree() * allows passing some arguments through new() to File::Temp - DIR, TEMPLATE, and CLEANUP * fixes ls(): (undef) is not an empty list; () or [] are - fixed warnings from File::Spec when called in 0-arg form * adds openfile() method which hooks touch() but returns the filehandle * optimizes away a couple needless array copies - @_ is nice and fast since it aliases the caller's variables rather than copying
Subject: directory_scratch-0.06.patch

Message body is not shown because it is too large.

Thanks for the patch! I cleaned up the constructor a bit and added some additional tests (and added your name to ACKNOWLEDGEMENTS), and have uploaded the module to CPAN. In the mean time, you can check out my svn version: https://svn.jrock.us/cpan_modules/Directory-Scratch The only thing I don't like is the copy constructor. I'm not sure why it's necessary. If it is useful to you, I'd rather call is "clone" as per Perl Best Practices. Anyway, your version of "new" is in 0.06, but it might change in 0.07 :) Again, thanks very much, and I look forward to additional feedback :) Regards, -- Jonathan Rockway <jrockway@cpan.org>
You're absolutely right, clone() would be better. I was tired and feeling crafty at the same time. Bad combo. If I get ambitious again soon, I'll throw another patch together. By the way, I'm using your module in a code publishing tool I'm writing for my employer. No word yet about open sourcing it, but I'll try to give you a peek soon so you can see the use case. Another extremely handy feature would be to have the object stringify as $object->base. So, "My directory is " . $object->base; # becomes: "My directory is $object"; I think PBP and Advanced Perl explain how to do this. This is another feature I might just do because it'll save me a lot of typing and look better. Another handy feature I'll probably add is a randfile() method (maybe with a better name) something like: # generate a file with random data in it my $file = $scratch->randfile(1024, 1024000); I've wanted that a bajillion times while testing various things. I do stuff like this in some of the tests though (in-progress pseudo code): my $scratch = Directory::Scratch->new( CLEANUP => 0 ); my $repo1 = $scratch->clone; SVN::Repos->create( $repo1->base, undef, undef, undef, undef ); my @files_expected; my $import = $scratch->clone; push @files_expected, $import->randfile(); # random filename/data push @files_expected, $import->randfile(); # another random file SVN::Repos->import( 'file://'.$repo1->base ); my $svn = SVN::Client->new; my @files = $svn->ls( ... ); # list the newly imported repo ok( ... ); # test if the files got imported The program I'm writing will do similar operations to the above thousands of times a day. It's actually a rewrite of an older program using CVS+rsync to use SVN and Oracle but be more extendable.
OK, I'll make the clone() and stringification fixes now. Expect to see them in svn Real Soon (tm). On Tue Aug 22 14:30:37 2006, TOBEYA wrote: Show quoted text
> You're absolutely right, clone() would be better. I was tired and > feeling crafty at the same time. Bad combo. > > If I get ambitious again soon, I'll throw another patch together. > > By the way, I'm using your module in a code publishing tool I'm writing > for my employer. No word yet about open sourcing it, but I'll try to > give you a peek soon so you can see the use case. > > Another extremely handy feature would be to have the object stringify as > $object->base. So, > "My directory is " . $object->base; > # becomes: > "My directory is $object"; > > I think PBP and Advanced Perl explain how to do this. This is another > feature I might just do because it'll save me a lot of typing and look > better. > > Another handy feature I'll probably add is a randfile() method (maybe > with a better name) something like: > # generate a file with random data in it > my $file = $scratch->randfile(1024, 1024000); > > I've wanted that a bajillion times while testing various things. > > I do stuff like this in some of the tests though (in-progress pseudo
code): Show quoted text
> > my $scratch = Directory::Scratch->new( CLEANUP => 0 ); > my $repo1 = $scratch->clone; > > SVN::Repos->create( $repo1->base, undef, undef, undef, undef ); > > my @files_expected; > my $import = $scratch->clone; > push @files_expected, $import->randfile(); # random filename/data > push @files_expected, $import->randfile(); # another random file > > SVN::Repos->import( 'file://'.$repo1->base ); > > my $svn = SVN::Client->new; > my @files = $svn->ls( ... ); # list the newly imported repo > > ok( ... ); # test if the files got imported > > The program I'm writing will do similar operations to the above > thousands of times a day. It's actually a rewrite of an older program > using CVS+rsync to use SVN and Oracle but be more extendable.
-- Jonathan Rockway <jrockway@cpan.org>