App-GitFind
view release on metacpan or search on metacpan
lib/App/GitFind/Actions.pm view on Meta::CPAN
use 5.010;
use strict;
use warnings;
our $VERSION = '0.000002';
use parent 'Exporter';
use vars::i '@EXPORT_OK' => qw(ARGTEST argdetails);
use vars::i '%EXPORT_TAGS' => { all => [@EXPORT_OK] };
# Imports
use App::GitFind::Base;
use Math::Cartesian::Product;
# === Documentation === {{{1
=head1 NAME
App::GitFind::Actions - Worker functions for App::GitFind
=head1 SYNOPSIS
TODO
=head1 FUNCTIONS
=cut
# }}}1
# Definitions of supported command-line arguments {{{1
# NOTE: import() also adds data to these hashrefs.
# Helpers for defining these
sub _a { ($_[0] => { token => 'ACTION', nparam => ($_[1]||0) }) }
sub _t { ($_[0] => { token => 'TEST', nparam => ($_[1]||0), index => ($_[2]||false) }) }
# A map from argument name to a details hashref. Valid keys in the hashref are:
# token: The token type
# nparam: - if a regex, the argument ends with an @ARGV element matching
# that regex.
# - if an integer, the argument takes that many parameters (>=0).
# index: (for tests only) Whether that test can be evaluated using only
# information from the index
# code: A coderef --- the do_*() function that implements that test.
# The {code} field is added by _inflate(), called by import().
my %ARGS=(
# TODO find(1) positional options, global options?
# No-argument tests -- all happen to be index tests
map( { _t $_, 0, true }
qw(empty executable false nogroup nouser readable true writeable) ),
# No-argument actions
map( { _a $_ } qw(delete ls print print0 prune quit) ),
# One-argument index tests
map( { _t $_, 1, true } qw(
cmin cnewer ctime
gid group ilname iname inum ipath iregex iwholename level
mmin mtime name
path
regex
size type uid
user wholename
) ),
# One-argument detailed tests
map( { _t $_, 1 } _qwc <<'EOT' ),
amin anewer atime fstype
links lname # Actually index tests?
newer
perm # Actually index test?
ref rev # Maybe not detailed tests - TODO investigate this
samefile # Actually index test?
used
EOT
# -newerXY forms - all are detailed tests
map( { _t('newer' . join('', @$_), 1) }
cartesian {1} [qw(a B c m)], [qw(a B c m t)] ),
# -amin n
# -anewer file
# -atime n
# -cmin n
# -cnewer file
# -ctime n
# -fstype type
# -gid n
# -group gname
# -ilname pattern
# -iname pattern
# -inum n
# -ipath pattern
# -iregex pattern
# -iwholename pattern
# -level n # not in find(1) - succeed if the item is at level n
# -links n
# -lname pattern
# -mmin n
# -mtime n
# -name pattern
# -newer file
# -newerXY reference
# -path pattern
# -perm [-/+]?mode
# -ref revspec # not in find(1) - specify a git ref OR REV
# (identical to -rev so you don't have to
# remember which)
# -regex pattern
# -rev revspec # not in find(1) - specify a git rev OR REF
# (identical to -ref)
# -samefile name
# -size n
# -type c
# -uid n
# -used n
# -user uname
# -wholename pattern
# -xtype c # Not supported for now
# -context pattern # Not supported for now
# Actions with a fixed number of arguments
map( { _a $_, 1 } qw(fls fprint fprint0 printf) ),
map( { _a $_, 2 } qw(fprintf) ),
# -fls file
# -fprint file
# -fprint0 file
# -fprintf file format
# -printf format
# Actions with a delimited argument list
# -exec command [;+]
# -execdir command [;+]
# -ok command ;
# -okdir command ;
map( { _a $_, qr/^[;+]$/ } qw(exec execdir) ),
map( { _a $_, qr/^;$/ } qw(ok okdir) ),
);
# }}}1
# === Argument-validation functions === {{{1
# Special validators for ok, okdir, exec, and execdir.
# Validators return undefined if validation passes, and an error message
# otherwise. Validators take the command and the located parameters
# in @_.
sub _validate_exec {
( run in 0.845 second using v1.01-cache-2.11-cpan-ceb78f64989 )