Skip Menu |

This queue is for tickets about the File-Find-Object-Rule CPAN distribution.

Report information
The Basics
Id: 97223
Status: open
Priority: 0/
Queue: File-Find-Object-Rule

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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!
On Mon Jul 14 17:14:28 2014, https://launchpad.net/~sd-imi wrote: Show quoted text
> 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!
Thanks! I'll consider it. Note that your code is: 1. Not a patch or a pull request. 2. Does not contain tests. 3. Has two-space indentation steps instead of 4-space ones. 4. Uses camelCase. Regards, -- Shlomi Fish