Skip to content

Commit

Permalink
Remove :$CWD param in IO::Path.dir
Browse files Browse the repository at this point in the history
Fixes RT#132675: https://rt.perl.org/Ticket/Display.html?id=132675

It was never documented and not specced in any released language.
We already have perfectly usable $!CWD for the purpose and the
bug in the ticket was caused precisely by the confusion having
two CWD knobs to tweak brings.

For &dir, We already have two ways to change CWD: $*CWD that'd affect
how given Str arg would be IO::Path-ified as well as $.CWD
attribute on IO::Path objects themselves.
  • Loading branch information
zoffixznet committed Jan 2, 2018
1 parent 00b7832 commit b3e73b6
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/core/IO/Path.pm
Expand Up @@ -549,11 +549,7 @@ my class IO::Path is Cool does IO {
}

proto method dir(|) {*} # make it possible to augment with multies from modulespace
multi method dir(IO::Path:D:
Mu :$test = $*SPEC.curupdir,
:$CWD = $*CWD,
) {

multi method dir(IO::Path:D: Mu :$test = $*SPEC.curupdir) {
CATCH { default {
fail X::IO::Dir.new(
:path($.absolute), :os-error(.Str) );
Expand All @@ -576,21 +572,21 @@ my class IO::Path is Cool does IO {

my Mu $dirh := nqp::opendir(nqp::unbox_s($.absolute));
gather {
# set $*CWD inside gather for $test.ACCEPTS to use correct
# $*CWD the user gave us, instead of whatever $*CWD is
# when the gather is actually evaluated. We use a temp var
# so that .IO coercer doesn't use the nulled `$*CWD` for
# $!CWD attribute and we don't use `temp` for this, because
# it's about 2x slower than using a temp var.
my $cwd = $CWD.IO;
# set $*CWD inside gather for $test.ACCEPTS to use correct
# $*CWD the user gave us, instead of whatever $*CWD is
# when the gather is actually evaluated. We use a temp var
# so that .IO coercer doesn't use the nulled `$*CWD` for
# $!CWD attribute and we don't use `temp` for this, because
# it's about 2x slower than using a temp var.
my $cwd = $!CWD.IO;
{ my $*CWD = $cwd;
#?if jvm
for <. ..> -> $elem {
$test.ACCEPTS($elem) && (
$absolute
?? take IO::Path!new-from-absolute-path(
$abspath ~ $elem,:$!SPEC,:$CWD)
!! take IO::Path.new($path ~ $elem,:$!SPEC,:$CWD)
$abspath ~ $elem,:$!SPEC,:$!CWD)
!! take IO::Path.new($path ~ $elem,:$!SPEC,:$!CWD)
);
}
#?endif
Expand All @@ -602,9 +598,9 @@ my class IO::Path is Cool does IO {
nqp::if(
$absolute,
(take IO::Path!new-from-absolute-path(
nqp::concat($abspath,$str-elem),:$!SPEC,:$CWD)),
nqp::concat($abspath,$str-elem),:$!SPEC,:$!CWD)),
(take IO::Path.new(
nqp::concat($path,$str-elem),:$!SPEC,:$CWD)),)));
nqp::concat($path,$str-elem),:$!SPEC,:$!CWD)),)));
nqp::closedir($dirh);
}
}
Expand Down

0 comments on commit b3e73b6

Please sign in to comment.