note
etcshadow
Interesting...
<p>
Honestly, I'd really rather not see yet another implementation of directory traversal in perl. What I think would be the ideal is to have <i>just one</i> implementation (let it stay File::Find, everyone already knows it!), but have that implementation be usable with each of these types of interface:
<ol>
<li>callbacks
<li>declaratively (by that I mean: <code>my @files = File::Find::find(...);</code> or something similar)
<li>iterator
</ol>
<p>
Presently, File::Find provides 1, directly. [cpan://File::Find::Rule] and its ilk provide 2 (as a wrapper around File::Find... which is great, because that means no one has to replicate the directory traversal code for that). The thing that's missing is a good iterator interface, and, again, that can't be built as a wrapper around File::Find.
<p>
So of course, the best possible thing (in my opinion) would be if someone rewrote File::Find so that it (internally) had an iterator interface:
<code>
my $finder = File::Find->new($opts, @dirs);
while (my $file = $finder->next) {
# do stuff
}
</code>
And then, finally, to change the old familiar <code>File::Find::find(...)</code> to be implemented as a simple wrapper around File::Find's iterator interface:
<code>
# simplified a lot, but basically
sub find {
my ($opts, @dirs) = @_;
$opts = wrap_wanted ($opts);
my $wanted = $opts->{wanted};
my $finder = File::Find->new($opts, @dirs);
while (my $file = $finder->next) {
local $_ = $file;
local ... # etcetera
&$wanted
}
}
</code>
So you'd get:
<ul>
<li>all the benefits of each type of interface
<li>the directory traversal written (and optimized and maintained, etc) only once
<li>nothing gets broken (all we've done is to refactor and to add new functionality)
</ul>
<p>
Of course, I feel bad demanding this, without volunteering to do it, but honestly, it would create legal complications if I were to do so (I've got one of those contracts where my employer owns everything I do... at least for the moment, but I've been promised that that will change at least somewhat by the end of july). But I still think that the "most best" approach is clear enough that it's worth setting down (even if I'm not going to go off and implement it myself).
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-296575">
<code>
------------
:Wq
Not an editor command: Wq
</code>
</div></div>
370566
370966