Skip to content

Commit

Permalink
Added do_empty, APP_GITFIND_CMDLINE_SHOW_AST
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher White committed Oct 8, 2019
1 parent 88cb5ef commit 0d376f1
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 193 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ foo
foo.*
TODO
TODO*
tags

# Fatpacker
fatpack*
Expand Down
17 changes: 15 additions & 2 deletions lib/App/GitFind/Actions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,24 @@ sub argdetails {

# }}}1
# === Tests/actions === {{{1
# The order matches that in App::GitFind::Actions
# The order matches that above.

=head1 TESTS/ACTIONS
The C<do_*> functions implement the tests and actions. They are called from
L<App::GitFind::ProcessEntry/process>. Each is invoked as:
my $processor = App::GitFind::ProcessEntry->new(...);
do_whatever $processor, $file_entry, $params_if_any;
Each returns truthy or falsy as documented in find(1) or L<App::GitFind>.
=cut

# No-argument tests {{{2

# empty
sub do_empty { $_[1]->size == 0 }

# executable

sub do_false { false }
Expand Down
53 changes: 44 additions & 9 deletions lib/App/GitFind/ProcessEntry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use warnings;
our $VERSION = '0.000002';

use parent 'App::GitFind::Class';
use Class::Tiny qw(expr searchbase);
use Class::Tiny qw(expr);

# Imports
use App::GitFind::Base;
Expand All @@ -20,19 +20,37 @@ use File::Spec; # TODO use facilities from A::GF::PathClassMicro instead?

=head1 NAME
App::GitFind::ProcessEntry - Test a file against a set of criteria
App::GitFind::ProcessEntry - Test a file's entry against a set of criteria
=head1 SYNOPSIS
my $hrArgs = App::GitFind::cmdline::Parse(\@ARGV);
my $runner = App::GitFind::ProcessEntry->new(-expr => $hrArgs->{expr});
$runner->process($some_entry_or_other);
=head1 FUNCTIONS
=head2 Constructor
The constructor (provided by L<App::GitFind::Class>) accepts one argument:
C<expr>. The C<expr> is an expression including tests and actions, e.g., as
provided by L<App::GitFind::cmdline/Parse>.
=cut

# }}}1
# === Main interpreter === {{{1

# Coderefs of the handlers for the logical operators, and a regex to check
# for a valid operator
my (%_logops, $_valid_logops);
BEGIN {
%_logops = (AND=>undef, OR=>undef, NOT=>undef, SEQ=>undef);
$_valid_logops = join '|', map { quotemeta } keys %_logops;
$_valid_logops = qr{^(?:$_valid_logops)$};
say STDERR "# $_valid_logops";
}

=head2 process
Process a single file, represented as an L<App::GitFind::Entry> instance.
Expand Down Expand Up @@ -66,18 +84,21 @@ sub _process {
push @arg, @{$expr->{params}} if $expr->{params};

} else { # SEQ, AND, OR, NOT
my $operation = (keys %{$expr})[0];

# Assertions. These can be removed in production.
die "Invalid logical expression $operation"
if $operation !~ $_valid_logops;
die "Logical expression has more than one key: " . ddc($expr)
if scalar keys %{$expr} > 1;
my $operation = (keys %{$expr})[0];
$func = $self->can("process_$operation");
# TODO remove the can() check once everything is implemented

# Set up to do the work
$func = $_logops{$operation};
@arg = ($entry, $expr->{$operation});
}

die "I don't know how to process the expression: " . ddc($expr)
unless $func;

return $self->$func(@arg);
@_ = ($self, @arg);
goto &$func;
} #_process()

=head2 callback
Expand Down Expand Up @@ -209,6 +230,20 @@ sub process_SEQ {
return $retval;
} #process_SEQ()

# }}}1
# === Constructor === {{{1

=head2 BUILD
Initializes internal structures. Not to be called directly.
=cut

sub BUILD {
my $self = shift;
$_logops{$_} = $self->can("process_$_") foreach keys %_logops;
} #BUILD()

# }}}1

1; # End of App::GitFind::ProcessEntry
Expand Down
Loading

0 comments on commit 0d376f1

Please sign in to comment.