Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move FILETEST-D to Rakudo::Internals
Also, no longer booleanify for internal usage.
  • Loading branch information
lizmat committed Jan 11, 2016
1 parent 8fb2088 commit 7054a2c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
9 changes: 3 additions & 6 deletions src/core/IO.pm
Expand Up @@ -43,7 +43,7 @@ sub CHANGE-DIRECTORY($path,$base,&test) {
my $abspath = Rakudo::Internals.MAKE-CLEAN-PARTS(
Rakudo::Internals.MAKE-ABSOLUTE-PATH($path,$base)).join('/');
Rakudo::Internals.FILETEST-E($abspath)
&& FILETEST-D($abspath)
&& Rakudo::Internals.FILETEST-D($abspath)
&& test($abspath)
?? IO::Path.new-from-absolute-path($abspath.chop)
!! fail X::IO::Chdir.new(
Expand Down Expand Up @@ -122,9 +122,6 @@ sub REMOVE-DIR(Str $path --> True) {
} }
}

sub FILETEST-D(Str $abspath) {
nqp::p6bool( nqp::stat(nqp::unbox_s($abspath),nqp::const::STAT_ISDIR) );
}
sub FILETEST-F(Str $abspath) {
nqp::p6bool( nqp::stat(nqp::unbox_s($abspath),nqp::const::STAT_ISREG) );
}
Expand Down Expand Up @@ -240,7 +237,7 @@ sub FILETEST-ALL(Str $path, *@tests) {
sub DIR-GATHER(Str $abspath,Mu $test) {
gather {
for MAKE-DIR-LIST($abspath,$test) -> $elem {
take FILETEST-D($elem)
take Rakudo::Internals.FILETEST-D($elem)
?? IO::Dir.new(:abspath($elem ~ '/'))
!! IO::File.new(:abspath($elem));
}
Expand All @@ -250,7 +247,7 @@ sub DIR-GATHER(Str $abspath,Mu $test) {
sub DIR-GATHER-STR(Str $abspath,Mu $test) {
gather {
for MAKE-DIR-LIST($abspath,$test) -> $elem {
take FILETEST-D($elem)
take Rakudo::Internals.FILETEST-D($elem)
?? $elem ~ '/'
!! $elem;
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/IO/Dir.pm
Expand Up @@ -5,7 +5,8 @@ my class IO::Dir is Cool does IO::Local {
if $check { # should really be .resolve, but we don't have that yet
@!parts = Rakudo::Internals.MAKE-CLEAN-PARTS($!abspath);
$!abspath = @!parts.join('/');
fail "$!abspath is not a directory" unless FILETEST-D($!abspath);
fail "$!abspath is not a directory"
unless Rakudo::Internals.FILETEST-D($!abspath);
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/core/IO/Path.pm
Expand Up @@ -532,11 +532,13 @@ my class IO::Path is Cool {
self.open(|c).words(:close);
}

method e() { $!e //= ?Rakudo::Internals.FILETEST-E($.abspath) }

method d() {
fail X::IO::DoesNotExist.new(:path(self.Str),:trying<d>) if !$.e;
FILETEST-D($!abspath);
method e(--> Bool) {
$!e //= ?Rakudo::Internals.FILETEST-E($.abspath) # must be $.abspath
}
method d(--> Bool) {
$.e
?? ?Rakudo::Internals.FILETEST-D($!abspath)
!! fail X::IO::DoesNotExist.new(:path(~self),:trying<d>)
}

method f() {
Expand Down
4 changes: 4 additions & 0 deletions src/core/Rakudo/Internals.pm
Expand Up @@ -1005,6 +1005,10 @@ my class Rakudo::Internals {
method FILETEST-E(Str:D \abspath) {
nqp::stat(nqp::unbox_s(abspath),nqp::const::STAT_EXISTS)
}

method FILETEST-D(Str:D \abspath) {
nqp::stat(nqp::unbox_s(abspath),nqp::const::STAT_ISDIR)
}
}

# vim: ft=perl6 expandtab sw=4

0 comments on commit 7054a2c

Please sign in to comment.