The recent perl6 brouhaha got me to try out pugs again. After grabbing pugs from svn and running the smoke tests (http://xrl.us/bdipe), I noticed some ext/File-Util/t/03.dirs.t was failing and looked like it would be a relatively easy fix.
Diff attached. I worked from the File::Util docs on CPAN and added some tests. I'd be especially interested in any criticism since this is my first real attempt at perl6. -- http://hexmode.com/ GPG Fingerprint: 7E15 362D A32C DFAB E4D2 B37A 735E F10A 2DFC BFF5 My happiness grows in direct proportion to my acceptance, and in inverse proportion to my expectations. -- Michael J. Fox Index: ext/File-Util/t/03.dirs.t =================================================================== --- ext/File-Util/t/03.dirs.t (revision 19284) +++ ext/File-Util/t/03.dirs.t (working copy) @@ -7,7 +7,23 @@ use File::Util; pass "(dummy instead of broken use_ok)"; my $f = File::Util.new; +my $d = 'ext/File-Util/t'; -my @files = $f.list_dir('ext/File-Util/t'); - +my @files = $f.list_dir($d); ok( @files ); + [EMAIL PROTECTED] = $f.list_dir($d, '--no-fsdots'); +ok( @files.grep:{/^\.\.$/} == 0 ); # only .svn + [EMAIL PROTECTED] = $f.list_dir($d, '--dirs-only'); +ok( @files.grep:{$_ ~~ :d} == @files && @files > 1 ); + [EMAIL PROTECTED] = $f.list_dir($d, '--dirs-only', '--no-fsdots'); +ok( @files == 1 && @files.grep:{$_ ~~ :d} == 1 ); # only .svn + [EMAIL PROTECTED] = $f.list_dir($d, '--files-only'); +ok( @files.grep:{"$d/$_" ~~ :f} == @files ); + [EMAIL PROTECTED] = $f.list_dir($d, '--with-paths'); +ok( @files.grep:{$_.substr(0, $d.chars) eqv $d} > 0 && + @files.grep:{$_.substr(0, $d.chars) !eqv $d} == 0 ); Index: ext/File-Util/lib/File/Util.pm =================================================================== --- ext/File-Util/lib/File/Util.pm (revision 19284) +++ ext/File-Util/lib/File/Util.pm (working copy) @@ -159,8 +159,7 @@ } } -method list_dir (Str $dirname, %options?){ - +method list_dir (Str $dirname, [EMAIL PROTECTED]){ # my $maxd = $.maxdives; my $maxd = 12; my $path = $dirname; @@ -196,24 +195,52 @@ my @shadow = @dirs; @dirs = (); + my @files = (); + my @others = (); while @shadow { my $f = @shadow.shift; + if(@options.grep:{$_ eqv '--no-fsdots'}) { next if $f eq '.'; next if $f eq '..'; - next if $f ~~ /^\./; + } + + my $fullpath = $path ~ "/" ~ $f; + my $pathname; + + if(@options.grep:{$_ eqv '--with-paths'}) { + $pathname = $fullpath; + } else { + $pathname = $f; + } - my $pathname = $path ~ "/" ~ $f; - if $pathname ~~ :d { - @dirs.push($path ~ "/" ~ $f); + given $fullpath { + when :d { + @dirs.push($pathname); } + when :f { + @files.push($pathname); } + default { + @others.push($pathname); + } + }; + }; + + my @ret; - for @dirs -> $dir { - self.list_dir($dir); + if(@options.grep:{$_ eqv '--files-only'}) { + @ret.push(@files); + } + elsif(@options.grep:{$_ eqv '--dirs-only'}) { + @ret.push(@dirs); } + else { + @ret.push(@dirs, @files, @others); + } + # for @options -> $option { # } - return @dirs.sort; + return @ret.sort; } method size (Str $filename) {