lib/App/Greple/find.pm

filter: Statementstmt 43.9% 18 / 41 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 2 totaltotal 29.4% 23 / 78 CC 15 SCAR 47.4
CC
15
Cov
26%
initialize
182.0
set
12.0
BEGIN
1.0
CRAP 114.6
↑ Summary lib/App/Greple/Util.pm »
1 =head1 NAME
2  
3 find - Greple module to use find command
4  
5 =head1 SYNOPSIS
6  
7 greple -Mfind find-options -- greple-options ...
8  
9 =head1 DESCRIPTION
10  
11 Provide B<find> command option with ending C<-->.
12  
13 B<Greple> will invoke B<find> command with provided options and read
14 its output from STDIN, with option B<--readlist>. So
15  
16 greple -Mfind . -type f -- pattern
17  
18 is equivalent to:
19  
20 find . -type f | greple --readlist pattern
21  
22 If the first argument start with C<!>, it is taken as a command name
23 and executed in place of B<find>. You can search git managed files
24 like this:
25  
26 greple -Mfind !git ls-files -- pattern
27  
28 =head1 SEE ALSO
29  
30 L<App::Greple>
31  
32 L<App::Greple::dig>
33  
34 L<App::Greple::select>
35  
36 =cut
37  
38  
39 package App::Greple::find;
40  
41 1 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 1 ▶use App::Greple::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 1 my $path;
49 my $chdir;
50 1 my $debug;
51 1 my @pid;
52  
53 0 ▶sub set {
Subroutine set: not called CC=3 SCAR=24.8
Pod undocumented
54 0 my %arg = @_;
55 0 ▶ $path = $arg{path} if defined $arg{path};
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg{"path"} 0 0 0
56 0 ▶ $chdir = $arg{chdir} if defined $arg{chdir};
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg{"chdir"} 0 0 0
57 }
58  
59 0 ▶sub initialize {
Subroutine initialize: not called CC=13 SCAR=52.0
Pod undocumented
60 0 my $module = shift;
61 0 my $argv = shift;
62  
63 0 ▶ if ($chdir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chdir) 0 0 0
64 0 ▶ chdir $chdir or die "chdir: $!";
Branch: 1 branch
BranchTrueFalseTotal
chdir $chdir or die "chdir: $!" 0 0 0
65 }
66  
67 0 my @find;
68 0 ▶ while (@$argv) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$argv) 0 0 0
69 0 ▶ last if $argv->[0] =~ /^--(man|show)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $argv->[0] =~ /^--(man|show)$/u 0 0 0
70 0 my $arg = shift @$argv;
71 0 ▶ last if $arg eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "--" 0 0 0
72 0 push @find, $arg;
73 }
74 0 ▶ return unless @find;
Branch: 1 branch
BranchTrueFalseTotal
unless @find 0 0 0
75  
76 0 my $pid = open STDIN, '-|' // croak "process fork failed";
77 0 push @pid, $pid;
78 0 ▶ return if $pid;
Branch: 1 branch
BranchTrueFalseTotal
if $pid 0 0 0
79  
80 0 ▶ unless ($find[0] =~ s/^!//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($find[0] =~ s/^!//u) 0 0 0
81 0 ▶ unshift @find, $path if defined $path;
Branch: 1 branch
BranchTrueFalseTotal
if defined $path 0 0 0
82 0 unshift @find, 'find';
83 }
84 0 ▶ if (@pid > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pid > 1) 0 0 0
85 0 ▶ print while <>;
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline ARGV) and do { print $_ } 0 0 0
86 }
87 0 ▶ exec @find or croak "Can't exec $find[0]";
Branch: 1 branch
BranchTrueFalseTotal
exec @find or croak("Can't exec $find[0]") 0 0 0
88 }
89  
90 1 1;
91  
92 __DATA__
↑ Summary lib/App/Greple/Util.pm »