#
# This software is Copyright 2005 by Elsevier Inc.  You may use it
# under the terms of the license at http://perl.plover.com/hop/LICENSE.txt .
#



###
### dir_walk_filter_iterator
###

## Chapter 4 section 6.1

sub dir_walk_filter {           # recursive version
  my ($top, $code) = @_;
  
  my @sub_iterators = list_iterator($code->($top));
  
  if (-d $top) {
    my $file;
    unless (opendir my($DIR), $top) {
      warn "Couldn't open directory $top: $!; skipping.\n";
      return $sub_iterators[0];
    }
    while ($file = readdir $DIR) {
      next if $file eq '.' || $file eq '..';
      push @sub_iterators, dir_walk_filter("$top/$file", $code);
    }
  }
  return append(@sub_iterators);
}
