blib/lib/App/GitFind/Actions.pm

filter: Statementstmt 98.1% 52 / 53 Branchbran n/a Conditioncond 70.0% 7 / 10 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 93.3% 14 / 15 Podpod 100% 2 / 2 totaltotal 91.7% 78 / 85 CC 7 SCAR 7.6
CC
7
Cov
94%
argdetails
6.0
_qwc
3.0
_t
3.0
CRAP 2.1
« blib/lib/App/GitFind/FileStatLs.pm ↑ Summary blib/lib/App/GitFind/Class.pm »
1 package App::GitFind::Actions;
2  
3 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.000001';
8  
9 1 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use vars::i '@EXPORT_OK' => qw(ARGTEST argdetails);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use vars::i '%EXPORT_TAGS' => { all => [@EXPORT_OK] };
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use constant true => !!1;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use constant false => !!0;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # Imports
17 1 ▶use Math::Cartesian::Product;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # === Documentation === {{{1
20  
21 =head1 NAME
22  
23 App::GitFind::Actions - Worker functions for App::GitFind
24  
25 =head1 SYNOPSIS
26  
27 TODO
28  
29 =head1 FUNCTIONS
30  
31 =cut
32  
33 # }}}1
34 # Definitions of supported command-line arguments {{{1
35  
36 # Helpers for defining these
37 15 ▶sub _a { ($_[0] => { token => 'ACTION', nparam => ($_[1]||0) }) }
Subroutine _a: called CC=2 SCAR=6.9
Condition100%2/2
$_[1] || 0
l!l
96
MC/DC100%1/1
$_[1] || 0
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
38 62 ▶sub _t { ($_[0] => { token => 'TEST', nparam => ($_[1]||0), index => ($_[2]||false) }) }
Subroutine _t: called CC=3 SCAR=11.0
Condition100%4/4
$_[1] || 0
l!l
548
$_[2] || 0
l!l
3032
MC/DC100%1/1
$_[1] || 0
$_[1]
MC/DC100%1/1
$_[2] || 0
$_[2]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
Truth table100%2/2
A
A= $_[2]
Aresult
11
00
39  
40 # qw(), but permitting comments. Call as _qwc(<<EOT). Thanks to ideas at
41 # https://www.perlmonks.org/?node=qw%20comments .
42 sub _qwc ($) {
43 1 ▶ my @retval;
Subroutine _qwc: called CC=3 SCAR=11.0
44 1 ▶ for(split "\n", $_[0]//'') {
Condition50%1/2
$_[0] // ""
l!l
10
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
45 7 chomp;
46 7 s{#.*$}{}; # Remove comments
47 7 s{(?:^\s+)|(?:\s+$)}{}g; # Remove leading/trailing ws
48 7 push @retval, grep { length } split /\s+/;
49 }
50 1 return @retval;
51 } #_qwc()
52  
53 # A map from argument name to a details hashref. Valid keys in the hashref are:
54 # token: The token type
55 # nparam: - if a regex, the argument ends with an @ARGV element matching
56 # that regex.
57 # - if an integer, the argument takes that many parameters (>=0).
58 # index: (for tests only) Whether that test can be evaluated using only
59 # information from the index
60  
61 my %ARGS=(
62 # TODO find(1) positional options, global options?
63  
64 # No-argument tests -- all happen to be index tests
65 8 map( { _t $_, 0, true }
66 qw(empty executable false nogroup nouser readable true writeable) ),
67  
68 # No-argument actions
69 6 map( { _a $_ } qw(delete ls print print0 prune quit) ),
70  
71 # One-argument index tests
72 22 map( { _t $_, 1, true } qw(
73 cmin cnewer ctime
74 gid group ilname iname inum ipath iregex iwholename level
75 mmin mtime name
76 path
77 regex
78 size type uid
79 user wholename
80 ) ),
81  
82 # One-argument detailed tests
83 12 map( { _t $_, 1 } _qwc <<'EOT' ),
84 amin anewer atime fstype
85 links lname # Actually index tests?
86 newer
87 perm # Actually index test?
88 ref rev # Maybe not detailed tests - TODO investigate this
89 samefile # Actually index test?
90 used
91 EOT
92  
93 # -newerXY forms - all are detailed tests
94 20 map( { _t('newer' . join('', @$_), 1) }
95 20 ▶ cartesian {1} [qw(a B c m)], [qw(a B c m t)] ),
Subroutine __ANON__: called CC=1 SCAR=0.0
96  
97 # -amin n
98 # -anewer file
99 # -atime n
100 # -cmin n
101 # -cnewer file
102 # -ctime n
103 # -fstype type
104 # -gid n
105 # -group gname
106 # -ilname pattern
107 # -iname pattern
108 # -inum n
109 # -ipath pattern
110 # -iregex pattern
111 # -iwholename pattern
112 # -level n # not in find(1) - succeed if the item is at level n
113 # -links n
114 # -lname pattern
115 # -mmin n
116 # -mtime n
117 # -name pattern
118 # -newer file
119 # -newerXY reference
120 # -path pattern
121 # -perm [-/+]?mode
122 # -ref revspec # not in find(1) - specify a git ref OR REV
123 # (identical to -rev so you don't have to
124 # remember which)
125 # -regex pattern
126 # -rev revspec # not in find(1) - specify a git rev OR REF
127 # (identical to -ref)
128 # -samefile name
129 # -size n
130 # -type c
131 # -uid n
132 # -used n
133 # -user uname
134 # -wholename pattern
135 # -xtype c # Not supported for now
136 # -context pattern # Not supported for now
137  
138 # Actions with a fixed number of arguments
139 4 map( { _a $_, 1 } qw(fls fprint fprint0 printf) ),
140 1 map( { _a $_, 2 } qw(fprintf) ),
141  
142 # -fls file
143 # -fprint file
144 # -fprint0 file
145 # -fprintf file format
146 # -printf format
147  
148 # Actions with a delimited argument list
149 # -exec command [;+]
150 # -execdir command [;+]
151 # -ok command ;
152 # -okdir command ;
153 2 map( { _a $_, qr/^[;+]$/ } qw(exec execdir) ),
154 1 map( { _a $_, qr/^;$/ } qw(ok okdir) ),
155 );
156  
157 # }}}1
158 # === Accessors for argument information === {{{1
159  
160 =head2 ARGTEST
161  
162 Returns a regex that will match any arg, with C<-> or C<--> prefix. The arg
163 is captured into $1. Prototyped as C<()>.
164  
165 =cut
166  
167 sub ARGTEST ()
168 { # Make a regex that will match any arg, with - or --.
169 1 ▶ my $x = join '|', map { quotemeta } keys %ARGS;
Subroutine ARGTEST: called CC=1 SCAR=0.0
Pod documented
170 1 return qr{^--?($x)$};
171 } #ARGTEST
172  
173 =head2 argdetails
174  
175 Returns a hashref of details about the arg, or undef. Example:
176  
177 my $hr = argdetails('true');
178  
179 =cut
180  
181 sub argdetails {
182 0 ▶ return $ARGS{$_[0]//''};
Subroutine argdetails: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/2
$_[0] // ""
l!l
00
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
183 }
184  
185 # }}}1
186  
187 1 1; # End of App::GitFind::Actions
188 __END__
« blib/lib/App/GitFind/FileStatLs.pm ↑ Summary blib/lib/App/GitFind/Class.pm »