App-SocialSKK
view release on metacpan or search on metacpan
inc/File/Find/Rule.pm view on Meta::CPAN
sub _call_find {
my $self = shift;
File::Find::find( @_ );
}
sub _compile {
my $self = shift;
my $subs = shift; # [1]
return '1' unless @{ $self->{rules} };
my $code = join " && ", map {
if (ref $_->{code}) {
push @$subs, $_->{code};
"\$subs[$#{$subs}]->(\@args) # $_->{rule}\n";
}
else {
"( $_->{code} ) # $_->{rule}\n";
}
} @{ $self->{rules} };
return $code;
}
#line 629
sub start {
my $self = _force_object shift;
$self->{iterator} = [ $self->in( @_ ) ];
$self;
}
#line 642
sub match {
my $self = _force_object shift;
return shift @{ $self->{iterator} };
}
1;
__END__
#line 752
Implementation notes:
[0] Currently we use an array of anonymous subs, and call those
repeatedly from match. It'll probably be way more effecient to
instead eval-string compile a dedicated matching sub, and call that to
avoid the repeated sub dispatch.
[1] Though [0] isn't as true as it once was, I'm not sure that the
subs stack is exposed in quite the right way. Maybe it'd be better as
a private global hash. Something like $subs{$self} = []; and in
C<DESTROY>, delete $subs{$self}.
That'd make compiling subrules really much easier (no need to pass
@subs in for context), and things that work via a mix of callbacks and
code fragments are possible (you'd probably want this for the stat
tests).
Need to check this currently working version in before I play with
that though.
[*] There's probably a win to be made with the current model in making
stat calls use C<_>. For
find( file => size => "> 20M" => size => "< 400M" );
up to 3 stats will happen for each candidate. Adding a priming _
would be a bit blind if the first operation was C< name => 'foo' >,
since that can be tested by a single regex. Simply checking what the
next type of operation doesn't work since any arbritary exec sub may
or may not stat. Potentially worse, they could stat something else
like so:
# extract from the worlds stupidest make(1)
find( exec => sub { my $f = $_; $f =~ s/\.c$/.o/ && !-e $f } );
Maybe the best way is to treat C<_> as invalid after calling an exec,
and doc that C<_> will only be meaningful after stat and -X tests if
they're wanted in exec blocks.
( run in 1.011 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )