blib/lib/App/rpgrep.pm

filter: Statementstmt 51.7% 30 / 58 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 8 / 10 Podpod n/a totaltotal 42.2% 38 / 90 CC 11 SCAR 32.4
CC
11
Cov
38%
__ANON__
42.0
__ANON__
42.0
BEGIN
1.0
CRAP 25.6
↑ Summary
1 ## no critic: InputOutput::RequireBriefOpen
2  
3 package App::rpgrep;
4  
5 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
6 1 our $DATE = '2020-02-09'; # DATE
7 1 our $DIST = 'App-rpgrep'; # DIST
8 1 our $VERSION = '0.002'; # VERSION
9  
10 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use App::RegexpPatternUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use AppBase::Grep;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Perinci::Sub::Util qw(gen_modified_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Regexp::Pattern;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 our %SPEC;
21  
22 gen_modified_sub(
23 output_name => 'rpgrep',
24 base_name => 'AppBase::Grep::grep',
25 summary => 'Print lines matching a Regexp::Pattern pattern',
26 description => <<'_',
27  
28 _
29 remove_args => [
30 'regexps',
31 'pattern',
32 ],
33 add_args => {
34 %App::RegexpPatternUtils::args_common_get_pattern,
35 files => {
36 'x.name.is_plural' => 1,
37 'x.name.singular' => 'file',
38 schema => ['array*', of=>'filename*'],
39 pos => 1,
40 greedy => 1,
41 },
42 # XXX recursive (-r)
43 },
44 0 ▶ output_code => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
45 0 my %args = @_;
46 0 my ($fh, $file);
47  
48 0 ▶ my @files = @{ delete($args{files}) // [] };
Condition0%0/2
delete $args{"files"} // []
l!l
00
MC/DC0%0/1
delete $args{"files"} // []
delete $args{"files"}
Truth table0%0/2
A
A= delete $args{"files"}
Aresult
11
00
49 0 ▶ my %gen_args = %{ delete($args{gen_args}) // {} };
Condition0%0/2
delete $args{"gen_args"} // {}
l!l
00
MC/DC0%0/1
delete $args{"gen_args"} // {}
delete $args{"gen_args"}
Truth table0%0/2
A
A= delete $args{"gen_args"}
Aresult
11
00
50 0 ▶ $gen_args{-anchor} = 1 if delete $args{anchor};
Branch: 1 branch
BranchTrueFalseTotal
if delete $args{"anchor"} 0 0 0
51 0 $args{pattern} = re($args{pattern}, \%gen_args);
52  
53 # XXX remove code duplication with App::abgrep
54  
55 0 my $show_label = 0;
56 0 ▶ if (!@files) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @files) { } 0 0 0
elsif (@files > 1) { } 0 0 0
57 0 $fh = \*STDIN;
58 } elsif (@files > 1) {
59 0 $show_label = 1;
60 }
61  
62 0 ▶ $args{_source} = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
63 READ_LINE:
64 {
65 0 ▶ if (!defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fh) 0 0 0
66 0 ▶ return unless @files;
Branch: 1 branch
BranchTrueFalseTotal
unless @files 0 0 0
67 0 $file = shift @files;
68 0 log_trace "Opening $file ...";
69 0 ▶ open $fh, "<", $file or do {
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $file or do { warn "rpgrep: Can't open '${file}': $!, skipped\n"; undef $fh } 0 0 0
70 0 warn "rpgrep: Can't open '$file': $!, skipped\n";
71 0 undef $fh;
72 };
73 0 redo READ_LINE;
74 }
75  
76 0 my $line = <$fh>;
77 0 ▶ if (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) { } 0 0 0
78 0 ▶ return ($line, $show_label ? $file : undef);
Branch: 1 branch
BranchTrueFalseTotal
$show_label ? : 0 0 0
79 } else {
80 0 undef $fh;
81 0 redo READ_LINE;
82 }
83 }
84 0 };
85  
86 0 AppBase::Grep::grep(%args);
87 },
88 1 );
89  
90 1 1;
91 # ABSTRACT: Print lines matching a Regexp::Pattern pattern
92  
93 __END__
↑ Summary