Subject: | Ambiguity about type of search results - strings are returned instead of objects |
This is possibly a documentation bug; but both `->in()`; as well as `->start()` and `->match()` that it uses, actually return strings; I wanted to use `File::Find::Object::Rule`, because I expected the results to be returned as `File::Find::Object::Result`?
Thankfully, that is easily solvable with the following override/extension (I hope `:)`):
# try to replace - add object returning match function
{
package File::Find::Object::Rule;
use File::Find::Object::Rule;
sub matchObj {
my $self = _force_object shift;
my $finder = $self->finder();
my $match_cb = $self->_match_cb();
my $preproc_cb = $self->extras()->{'preprocess'};
while(defined(my $next_obj = $finder->next_obj())) {
if (defined($preproc_cb) && $next_obj->is_dir()) {
$finder->set_traverse_to(
$preproc_cb->(
$self,
[ @{$finder->get_current_node_files_list()} ]
)
);
}
if (defined(my $path = $match_cb->($next_obj, $next_obj->path()))) {
return $next_obj;
}
}
return;
}
1;
}
use Data::Dumper;
my $rule = File::Find::Object::Rule->new;
$rule->file;
$rule->name( '*.pm' );
#my @files = $rule->in( @INC );
$rule->start( @INC );
while ( my $rulefileobj = $rule->matchObj ) {
print(Dumper($rulefileobj));
}
Thanks for the package,
Cheers!