| 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
| |||||||||||
| 56 | 0 | ▶ | $chdir = $arg{chdir} if defined $arg{chdir}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 64 | 0 | ▶ | chdir $chdir or die "chdir: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 0 | my @find; | |||||||||
| 68 | 0 | ▶ | while (@$argv) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | ▶ | last if $argv->[0] =~ /^--(man|show)$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | my $arg = shift @$argv; | |||||||||
| 71 | 0 | ▶ | last if $arg eq '--'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 0 | push @find, $arg; | |||||||||
| 73 | } | ||||||||||
| 74 | 0 | ▶ | return unless @find; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | |||||||||||
| 76 | 0 | my $pid = open STDIN, '-|' // croak "process fork failed"; | |||||||||
| 77 | 0 | push @pid, $pid; | |||||||||
| 78 | 0 | ▶ | return if $pid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | unless ($find[0] =~ s/^!//) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 0 | ▶ | unshift @find, $path if defined $path; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 0 | unshift @find, 'find'; | |||||||||
| 83 | } | ||||||||||
| 84 | 0 | ▶ | if (@pid > 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 0 | ▶ | print while <>; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | } | ||||||||||
| 87 | 0 | ▶ | exec @find or croak "Can't exec $find[0]"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 1 | 1; | |||||||||
| 91 | |||||||||||
| 92 | __DATA__ | ||||||||||