Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #161 from labster/nom

make dir() lazy; written while waiting for plane to YAPCNA
  • Loading branch information...
commit 9557da29eb8e6b9fe94b3a5129e2c0e8e955cd2e 2 parents d670aaa + 4c6ef79
@labster labster authored
Showing with 11 additions and 13 deletions.
  1. +11 −13 src/core/IO.pm
View
24 src/core/IO.pm
@@ -405,27 +405,25 @@ my class IO::Path::Cygwin is IO::Path { method SPEC { IO::Spec::Cygwin }; }
sub dir(Cool $path = '.', Mu :$test = none('.', '..')) {
+ CATCH {
+ default {
+ X::IO::Dir.new(
+ :$path,
+ os-error => .Str,
+ ).throw;
+ }
+ }
+
my Mu $RSA := pir::new__PS('OS').readdir(nqp::unbox_s($path.Str));
my int $elems = nqp::elems($RSA);
my @res;
my ($volume, $directory) = IO::Spec.splitpath(~$path, :nofile);
- loop (my int $i = 0; $i < $elems; $i = $i + 1) {
+ gather loop (my int $i = 0; $i < $elems; $i = $i + 1) {
my Str $file := nqp::p6box_s(pir::trans_encoding__Ssi(
nqp::atpos_s($RSA, $i),
pir::find_encoding__Is('utf8')));
if $file ~~ $test {
- #this should be like IO::Path.child(:basename($file)) because of :volume
- @res.push: IO::Path.new(:basename($file), :$directory, :$volume);
- }
- }
- return @res.list;
-
- CATCH {
- default {
- X::IO::Dir.new(
- :$path,
- os-error => .Str,
- ).throw;
+ take IO::Path.new(:basename($file), :$directory, :$volume);
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.