App-GitFind

 view release on metacpan or  search on metacpan

lib/App/GitFind/Actions.pm  view on Meta::CPAN


sub _validate_ok {
    return "need at least a command name" unless $#_>1;
    return undef;
}

# }}}1
# === Accessors for argument information === {{{1

=head2 ARGTEST

Returns a regex that will match any arg, with C<-> or C<--> prefix.  The arg
is captured into $1.  Prototyped as C<()>.

=cut

sub ARGTEST ()
{   # Make a regex that will match any arg, with - or --.
    my $x = join '|', map { quotemeta } keys %ARGS;
    return qr{^--?($x)$};
} #ARGTEST

=head2 argdetails

Returns a hashref of details about the arg, or undef.  Example:

    my $hr = argdetails('true');

=cut

sub argdetails {
    return $ARGS{$_[0]//''};
}

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

# No-argument tests {{{2

# empty
# executable

sub do_false { false }

# nogroup
# nouser
# readable

sub do_true { true }

# writeable

# }}}2
# No-argument actions {{{2

# delete

sub do_ls {
    state $loaded = (require App::GitFind::FileStatLs, true);
    print App::GitFind::FileStatLs::ls_stat($_[1]->path);
    true
}
    # TODO optimization?  Pull the stat() results from $_[1] rather than
    # re-statting.  May not be an issue.

sub do_print {
    say $_[0]->dot_relative_path($_[1]);
    true
}

sub do_print0 { print $_[0]->dot_relative_path($_[1]), "\0"; true }

# prune

# quit
# This appears to be a GNU extension.  It should:
#   - Finish any child processes
#       (empirical): do not kill -9 ---
#       find . -name LICENSE -exec sh -c 'sleep 2' {} + -o -name README -quit
#       does not terminate the `sleep` early.
#   - Run any queued -execdir {} + commands
#   - (empirical) Do not run any queued -exec {} + commands?
#       E.g., GNU
#           find . \( -name LICENSE -quit -o -name README \) -exec ls -l {} +
#       prints nothing.  However, POSIX
#       (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html)
#       says that "The utility ... shall be invoked ... after the last
#       pathname in the set is aggregated, and shall be completed
#       **before the find utility exits**" (emphasis added).


# }}}2
# One-argument index tests
# TODO

# }}}2
# One-argument detailed tests
# TODO

# }}}2
# -newerXY forms (all are one-argument detailed tests)
# TODO

# }}}2
# -newerXY forms (all are one-argument detailed tests)
# TODO

# }}}2
# Actions with a fixed number of arguments

# fls file
# fprint file
# fprint0 file
# fprintf file format

sub do_printf { # -printf format.  No newline at the end.
    my ($self, %args) = getparameters('self',[qw(entry format)], @_);
    print "printf($args{format}, $args{entry})";    # TODO
} #do_printf()

# }}}2
# Actions with a delimited argument list



( run in 1.267 second using v1.01-cache-2.11-cpan-39bf76dae61 )