Skip to content

Commit

Permalink
Merge pull request #161 from labster/nom
Browse files Browse the repository at this point in the history
make dir() lazy; written while waiting for plane to YAPCNA
  • Loading branch information
labster committed Jun 2, 2013
2 parents d670aaa + 4c6ef79 commit 9557da2
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/core/IO.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -405,27 +405,25 @@ my class IO::Path::Cygwin is IO::Path { method SPEC { IO::Spec::Cygwin }; }




sub dir(Cool $path = '.', Mu :$test = none('.', '..')) { 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 Mu $RSA := pir::new__PS('OS').readdir(nqp::unbox_s($path.Str));
my int $elems = nqp::elems($RSA); my int $elems = nqp::elems($RSA);
my @res; my @res;
my ($volume, $directory) = IO::Spec.splitpath(~$path, :nofile); 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( my Str $file := nqp::p6box_s(pir::trans_encoding__Ssi(
nqp::atpos_s($RSA, $i), nqp::atpos_s($RSA, $i),
pir::find_encoding__Is('utf8'))); pir::find_encoding__Is('utf8')));
if $file ~~ $test { if $file ~~ $test {
#this should be like IO::Path.child(:basename($file)) because of :volume take IO::Path.new(:basename($file), :$directory, :$volume);
@res.push: IO::Path.new(:basename($file), :$directory, :$volume);
}
}
return @res.list;

CATCH {
default {
X::IO::Dir.new(
:$path,
os-error => .Str,
).throw;
} }
} }
} }
Expand Down

0 comments on commit 9557da2

Please sign in to comment.