Well I think I found the problem. In the walktree code,
it is passing a directory name and an array into your the
dirfunc callback. The callback that is in the current
code doesn't account for the incoming list so previous
values are removed.
The workaround code works because it using a strange and
dangerous scoping of @files. That is the @files is defined
prior to the sub so it is in scope when the sub is created
and the values are added to it inside of the $dirfunc callback
in walktree, but since its scope is not limited to the $dirfunc
callback it could cause problems in the future. So I rewrote
the callback to this:
### THIS RETURNS ONLY A SINGLE DIRECTORY, no object reference !???
undef @files;
$dirfunc = sub {
return undef unless $_[0]; # Mac specific
my ($dir,@val) = @_;
if( $filter ) {
$dir =~ /$filter/o and FileFinder->new( name => $dir )
}
else {
push @val, FileFinder->new( name => $dir );
return @val;
}
};
This is only slightly different from the workaround that you present,
but it avoids the issues with possible variable scoping issues I think.