Eric Wilhelm wrote:
Hi Ken,
I noticed some traffic in the commits and realized I had this stale
patch laying around.
I see there are still quite a few chdir()s in the test suite and thought
this might be a good way to keep things a little more organized.
I think I just hadn't checked it in because the method names are so
corny (but maybe I just hadn't had a chance to really test it yet.)
Yes, they are. :P
There's File::pushd and File::chdir to do this sort of thing and more
elegantly. They also nest.
File::pushd is simple and a no-frills version can be cut & pasted into
Module::Build. I prefer the descriptive local_chdir() over the very Unixy and
cryptic pushd().
use Cwd;
use Carp;
sub local_chdir {
my ($dest) = @_;
my $orig = cwd;
chdir $dest or croak "Can't chdir to $dest: $!";
my $self = bless \$orig, __PACKAGE__;
return $self;
}
sub DESTROY {
my $self = shift;
chdir $$self or croak "Can't chdir back to $$self: $!";
}
--
On error resume stupid