Subject: | cross package assignment prevents restoring $CWD |
The attached test shows the problem.
It seems to only manifest when calling a function in another package
that also used File::chdir, when that function assigns $CWD to a
variable (even though that variable goes out of scope). Though it is
not a problem if you assign "$CWD" (note the quotes) to that variable.
I'm not 100% sure this is a bug. If it's not, I think the docs should
at least note the caveat of assigning $CWD to a variable.
Thanks,
-Todd
Subject: | cross_package_my.t |
package P1;
use File::chdir;
sub x {
# this causes fail
my $cwd = $CWD;
# however, the following does not cause fail
# my $cwd = "$CWD";
}
package P2;
use File::chdir;
use Test::More;
sub x {
my $orig = $CWD;
{
local $CWD = "/tmp";
P1::x();
}
cmp_ok( $CWD, 'eq', $orig, '$CWD changed back' );
}
package main;
use Test::More tests => 1;
P2::x();