| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | $pattern .= '(?i)' if $opt_i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | if ($opt_p) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | unless ($pager = $ENV{PAGER}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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'
MC/DC0%0/1
$Config::Config{'pager'} || 'more'
$Config::Config{'pager'}
Truth table0%0/2
A
A= $Config::Config{'pager'}
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | if ($opt_f) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ($opt_p) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 2772 | ▶ | if ($inpod && /^=cut/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$inpod and /^=cut/
MC/DC100%2/2
$inpod and /^=cut/
$inpod
/^=cut/
Truth table100%3/3
A and B
A= $inpodB= /^=cut/
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | $inmatch = $inpod = 0; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 2771 | ▶ | if (! $inpod && /^=(?!cut)\w+/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $inpod and /^=(?!cut)\w+/
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+/
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | $inpod = 1; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 2771 | ▶ | if ($inmatch && /^=\w+/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$inmatch and /^=\w+/
MC/DC100%2/2
$inmatch and /^=\w+/
$inmatch
/^=\w+/
Truth table100%3/3
A and B
A= $inmatchB= /^=\w+/
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 5 | $inmatch = 0; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 2771 | ▶ | if ($inpod && !$inmatch && /$pattern/o) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$inpod and not $inmatch and /$pattern/o
$inpod and not $inmatch
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
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 6 | ▶ | print "=head1 $ARGV chunk $.\n\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$file eq $ARGV and $chunk + 1 == $.
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 == $.
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 2765 | ▶ | print if $inmatch; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | } continue { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 2772 | ▶ | if (eof) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||