Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the File-chdir CPAN distribution.

Report information
The Basics
Id: 53064
Status: resolved
Priority: 0/
Queue: File-chdir

People
Owner: Nobody in particular
Requestors: THEPLER [...] cpan.org
Cc: andreas.marienborg [...] gmail.com
AdminCc:

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



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();
We'll look into it, though it may be a while before we do. Thanks for the report, so we don't lose track of the issue.
There is something similar happening if the other package uses local on $CWD. I've attached a simple test-case for that as well. It might be the same issue, but I figured more information as a good thing.
Subject: chdir.t
#!/usr/bin/perl -w package Other; use Moose; use File::chdir; sub do_something { local $CWD; } package main; use strict; use Test::More tests => 2; use File::chdir; my $other = Other->new(); my $cwd = $CWD . ""; { local $CWD; $CWD = '/tmp'; $other->do_something(); } is($CWD, $cwd, "Before and after is correct for sub that also uses File::chdir");
I think the problem in both cases is that you can't localize an imported variable unless it has been exported as a glob (see http://perldoc.perl.org/perlmod.html). So either refer to $CWD by its fully qualified name $File::chdir::CWD, or modify File/chdir.pm, changing @EXPORT = qw($CWD @CWD); to @EXPORT = qw(*CWD); David
Subject: Re: [rt.cpan.org #53064] cross package assignment prevents restoring $CWD
Date: Wed, 02 Nov 2011 10:50:33 -0700
To: bug-File-chdir [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
Looks about right. I've sent David a pull request. https://github.com/dagolden/file-chdir/pull/1
Thank you. Released to CPAN as 0.1005.
On Wed Nov 02 13:50:50 2011, schwern@pobox.com wrote: Show quoted text
> Looks about right. I've sent David a pull request. > https://github.com/dagolden/file-chdir/pull/1
Regardless, this seems an awful lot like a bug in perl: sub TIESCALAR{bless[], $_[0]} sub FETCH { warn fetching; $_[0][0] } sub STORE { warn "storing $_[1]"; $_[0][0] = $_[1] } tie $b, ""; *a = \$b; $b = "one"; { local $b = "two"; { my $x = "$a"; # my $x = $a; } } warn "\$b is now $b"; __END__ my $x = "$a" isn’t calling FETCH. I know this will re-open the ticket. Please just close it again. I just thought this note would be good for future reference.
Subject: Re: [rt.cpan.org #53064] cross package assignment prevents restoring $CWD
Date: Wed, 02 Nov 2011 14:00:06 -0700
To: bug-File-chdir [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
On 2011.11.2 12:35 PM, Father Chrysostomos via RT wrote: Show quoted text
> Regardless, this seems an awful lot like a bug in perl:
I fully agree. And you're just the monk to tackle it!