Ken Williams wrote:
On Jan 29, 2008 8:34 AM, David Golden <[EMAIL PROTECTED]> wrote:
On Jan 29, 2008 3:44 AM, Michael G Schwern <[EMAIL PROTECTED]> wrote:
Module::Build. I prefer the descriptive local_chdir() over the very Unixy and
cryptic pushd().
I've been thinking about adding a feature to Path::Class that lets you
perform an action in a certain directory, and be guaranteed of being
back where you started afterwards. Hopefully could use fchdir() to be
bulletproof.
The possible interfaces include:
$dir->do_something( \&what_to_do );
This seems the sanest and most obvious approach with the simplest error
handling. chdir_and_do() seems a descriptive name.
or the DESTROY trick like yours:
{
my $sentinel = $dir->scoped_chdir();
...do your stuff...
}
There's already a module to do this, File::pushd, and the sentinel approach is
a little wonky. There's also File::chdir for another way to do it. Both will
happily accept a Path::Class::Dir so I don't see what's to be gained.
The ideal situation would be if we could hook into perl's actual
scoping mechanisms and eliminate the sentinel:
{
$dir->local_chdir();
...do your stuff...
}
but that's probably out of my ken.
If you could figure out how to do that I think a lot of people would like to
know.
--
...they shared one last kiss that left a bitter yet sweet taste in her
mouth--kind of like throwing up after eating a junior mint.
-- Dishonorable Mention, 2005 Bulwer-Lytton Fiction Contest
by Tami Farmer