bin/podgrep

filter: Statementstmt 87.1% 54 / 62 Branchbran 70.5% 24 / 34 Conditioncond 85.0% 17 / 20 MC/DCmcdc 75.0% 9 / 12 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 81.8% 108 / 132 CC 1 SCAR 0.0
CC
1
Cov
82%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« bin/pmls ↑ Summary bin/pmload »
1 #!/usr/bin/env perl
2 # podgrep -- grep in pod sections only
3  
4 # ------ pragmas
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Getopt::Std qw(getopts);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '2.2.0';
10  
11 # ------ define variables
12 2 my $chunk = undef; # chunk count
13 2 my $file = undef; # file name
14 2 my $inmatch = undef; # TRUE if inside match
15 2 my $inpod = undef; # TRUE if inside POD
16 2 my $only_header = undef; # copy of $opt_h
17 2 our $opt_f = undef; # output plain text, paged if -p
18 2 our $opt_h = undef; # output only POD headers
19 2 our $opt_i = undef; # case-insensitive pattern
20 2 our $opt_p = undef; # use $ENV{PAGER} to page output
21 2 my $orig_pattern = undef; # original pattern to search for
22 2 my $pager = undef; # contents of $ENV{PAGER}
23 2 my $pattern = undef; # pattern to search for
24  
25  
26 2 ▶getopts("fhpi")
Branch: 1 branch
BranchTrueFalseTotal
&getopts("fhpi") or die "usage: $0 [-i] [-f] [-h] [-p] pattern [podfiles ...]" 2 0 2
27 || die "usage: $0 [-i] [-f] [-h] [-p] pattern [podfiles ...]";
28  
29 2 $/ = '';
30 2 $only_header = $opt_h;
31 2 $orig_pattern = $pattern = shift;
32 2 ▶$pattern = '^=.*' . $pattern if $only_header;
Branch: 1 branch
BranchTrueFalseTotal
if $only_header 1 1 2
33 2 ▶$pattern .= '(?i)' if $opt_i;
Branch: 1 branch
BranchTrueFalseTotal
if $main::opt_i 0 2 2
34  
35 2 ▶if ($opt_p) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::opt_p) 0 2 2
36 0 ▶ unless ($pager = $ENV{PAGER}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pager = $ENV{"PAGER"}) 0 0 0
37 0 require Config;
38 {
39 0 ▶ no warnings qw(once);
Subroutine BEGIN: called CC=1 SCAR=0.2
40 0 ▶ $pager = $Config::Config{"pager"} || "more";
Condition0%0/2
$Config::Config{'pager'} || 'more'
l!l
00
MC/DC0%0/1
$Config::Config{'pager'} || 'more'
$Config::Config{'pager'}
Truth table0%0/2
A
A= $Config::Config{'pager'}
Aresult
11
00
41 }
42 }
43 }
44  
45 2 ▶if ($opt_f) {
Branch: 2 branches
BranchTrueFalseTotal
if ($main::opt_f) { } 0 2 2
elsif ($main::opt_p) { } 0 2 2
46 0 ▶ if ($opt_p) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::opt_p) { } 0 0 0
47 0 open(STDOUT, "| pod2text | $pager '+/$orig_pattern'");
48 } else {
49 0 open(STDOUT, "| pod2text");
50 }
51  
52 }
53 elsif ($opt_p) {
54 0 open(STDOUT, "| $pager '+/$orig_pattern'");
55 }
56  
57  
58 2 ($file, $chunk) = ('-', 0);
59  
60 2 ▶while (<>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ARGV)) 2772 2 2774
61 2772 ▶ if ($inpod && /^=cut/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inpod and /^=cut/) 1 2771 2772
Condition100%3/3
$inpod and /^=cut/
!ll&&!rl&&r
2227491
MC/DC100%2/2
$inpod and /^=cut/
$inpod /^=cut/
Truth table100%3/3
A and B
A= $inpodB= /^=cut/
ABresult
0X0
100
111
62 1 $inmatch = $inpod = 0;
63 1 next;
64 }
65  
66 2771 ▶ if (! $inpod && /^=(?!cut)\w+/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $inpod and /^=(?!cut)\w+/) 2 2769 2771
Condition100%3/3
not $inpod and /^=(?!cut)\w+/
!ll&&!rl&&r
2749202
MC/DC100%2/2
not $inpod and /^=(?!cut)\w+/
not $inpod /^=(?!cut)\w+/
Truth table100%3/3
not(A) and B
A= not $inpodB= /^=(?!cut)\w+/
ABresult
0X0
100
111
67 2 $inpod = 1;
68 }
69  
70 2771 ▶ if ($inmatch && /^=\w+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inmatch and /^=\w+/) 5 2766 2771
Condition100%3/3
$inmatch and /^=\w+/
!ll&&!rl&&r
276065
MC/DC100%2/2
$inmatch and /^=\w+/
$inmatch /^=\w+/
Truth table100%3/3
A and B
A= $inmatchB= /^=\w+/
ABresult
0X0
100
111
71 5 $inmatch = 0;
72 }
73  
74 2771 ▶ if ($inpod && !$inmatch && /$pattern/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inpod and not $inmatch and /$pattern/o) 6 2765 2771
Condition100%6/6
$inpod and not $inmatch and /$pattern/o
!ll&&!rl&&r
2627396
$inpod and not $inmatch
!ll&&!rl&&r
2062745
MC/DC100%3/3
$inpod and not $inmatch and /$pattern/o
$inpod not $inmatch /$pattern/o
Truth table100%4/4
A and not(B) and C
A= $inpodB= not $inmatchC= /$pattern/o
ABCresult
0XX0
10X0
1100
1111
75 6 ▶ print "=head1 $ARGV chunk $.\n\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $file eq $ARGV and $chunk + 1 == $. 6 0 6
Condition66%2/3
$file eq $ARGV and $chunk + 1 == $.
!ll&&!rl&&r
240
MC/DC0%0/2
$file eq $ARGV and $chunk + 1 == $.
$file eq $ARGV $chunk + 1 == $.
Truth table66%2/3
A and B
A= $file eq $ARGVB= $chunk + 1 == $.
ABresult
0X0
100
111
76 unless $file eq $ARGV && $chunk+1 == $.;
77 6 ($file, $chunk) = ($ARGV, $.);
78 6 print;
79 6 ▶ $inmatch = 1 if $only_header;
Branch: 1 branch
BranchTrueFalseTotal
if $only_header 5 1 6
80 6 next;
81 }
82  
83 2765 ▶ print if $inmatch;
Branch: 1 branch
BranchTrueFalseTotal
if $inmatch 6 2759 2765
84  
85  
86 } continue {
87  
88 2772 ▶ if (eof) {
Branch: 1 branch
BranchTrueFalseTotal
if (eof) 2 2770 2772
89 2 $inmatch = $inpod = 0;
90 2 ($file, $chunk) = ('-', 0);
91 2 close ARGV;
92 }
93  
94 }
95  
96 2 close STDOUT;
97  
98 __END__
« bin/pmls ↑ Summary bin/pmload »