/usr/local/bin/pod2text

filter: Statementstmt 69.0% 38 / 55 Branchbran 40.6% 13 / 32 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 54.2% 58 / 107 CC 1 SCAR 0.0
CC
1
Cov
55%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« bin/pman ↑ Summary bin/pmcheck »
1 #!/usr/local/bin/perl
2 1 eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
3 if 0; # ^ Run only under a shell
4  
5 # Convert POD data to formatted ASCII text.
6 #
7 # The driver script for Pod::Text, Pod::Text::Termcap, and Pod::Text::Color,
8 # invoked by perldoc -t among other things.
9 #
10 # SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
11  
12 1 ▶use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Getopt::Long qw(GetOptions);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Pod::Text ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Pod::Usage qw(pod2usage);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # Clean up $0 for error reporting.
20 1 $0 =~ s%.*/%%;
21  
22 # Take an initial pass through our options, looking for one of the form
23 # -<number>. We turn that into -w <number> for compatibility with the
24 # original pod2text script.
25 1 ▶for (my $i = 0; $i < @ARGV; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @ARGV) 1 1 2
26 1 ▶ last if $ARGV[$i] =~ /^--$/;
Branch: 1 branch
BranchTrueFalseTotal
if $ARGV[$i] =~ /^--$/u 0 1 1
27 1 ▶ if ($ARGV[$i] =~ /^-(\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ARGV[$i] =~ /^-(\d+)$/u) 0 1 1
28 0 splice (@ARGV, $i++, 1, '-w', $1);
29 }
30 }
31  
32 # Insert -- into @ARGV before any single dash argument to hide it from
33 # Getopt::Long; we want to interpret it as meaning stdin (which Pod::Simple
34 # does correctly).
35 1 my $stdin;
36 1 ▶@ARGV = map { $_ eq '-' && !$stdin++ ? ('--', $_) : $_ } @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '-' && !$stdin++ ? : 0 1 1
Condition33%1/3
$_ eq "-" and not $stdin++
!ll&&!rl&&r
100
MC/DC0%0/2
$_ eq "-" and not $stdin++
$_ eq "-" not $stdin++
Truth table33%1/3
A and not(B)
A= $_ eq "-"B= not $stdin++
ABresult
0X0
100
111
37  
38 # Parse our options. Use the same names as Pod::Text for simplicity.
39 1 my %options;
40 1 Getopt::Long::config ('bundling');
41 1 ▶GetOptions (\%options, 'alt|a', 'code', 'color|c', 'encoding|e=s', 'errors=s',
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%options, "alt|a", "code", "color|c", "encoding|e=s", "errors=s", "guesswork=s", "help|h", "indent|i=i", "loose|l", "margin|left-margin|m=i", "nourls", "overstrike|o", "quotes|q=s", "sentence|s", "stderr", "termcap|t", "utf8|u", "width|w=i") or exit 1 1 0 1
42 'guesswork=s', 'help|h', 'indent|i=i', 'loose|l',
43 'margin|left-margin|m=i', 'nourls', 'overstrike|o', 'quotes|q=s',
44 'sentence|s', 'stderr', 'termcap|t', 'utf8|u', 'width|w=i')
45 or exit 1;
46 1 ▶pod2usage (0) if $options{help};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"help"} 0 1 1
47  
48 # Figure out what formatter we're going to use. -c overrides -t.
49 1 my $formatter = 'Pod::Text';
50 1 ▶if ($options{color}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($options{'color'}) { } 0 1 1
elsif ($options{'termcap'}) { } 0 1 1
elsif ($options{'overstrike'}) { } 0 1 1
51 0 $formatter = 'Pod::Text::Color';
52 0 eval { require Term::ANSIColor };
53 0 ▶ if ($@) { die "-c (--color) requires Term::ANSIColor be installed\n" }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
54 0 require Pod::Text::Color;
55 } elsif ($options{termcap}) {
56 0 $formatter = 'Pod::Text::Termcap';
57 0 require Pod::Text::Termcap;
58 } elsif ($options{overstrike}) {
59 0 $formatter = 'Pod::Text::Overstrike';
60 0 require Pod::Text::Overstrike;
61 }
62 1 delete @options{'color', 'termcap', 'overstrike'};
63  
64 # If neither stderr nor errors is set, default to errors = die.
65 1 ▶if (!defined $options{stderr} && !defined $options{errors}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $options{"stderr"} or defined $options{"errors"}) 1 0 1
Condition33%1/3
defined $options{"stderr"} or defined $options{"errors"}
l!l&&r!l&&!r
001
MC/DC0%0/2
defined $options{"stderr"} or defined $options{"errors"}
defined $options{"stderr"} defined $options{"errors"}
Truth table33%1/3
A or B
A= defined $options{"stderr"}B= defined $options{"errors"}
ABresult
1X1
011
000
66 1 $options{errors} = 'die';
67 }
68  
69 # Initialize and run the formatter.
70 1 my $parser = $formatter->new (%options);
71 1 my $status = 0;
72 1 ▶do {
Branch: 1 branch
BranchTrueFalseTotal
@ARGV and do { do { () = splice(@ARGV, 0, 2); $parser->parse_from_file($input, $output); if ($parser->{"CONTENTLESS"}) { $status = 1; if (defined $input) { warn "$0: unable to format $input\n"; } else { warn "$0: unable to format standard input\n"; } ; if (defined $output and $output ne "-") { unlink $output unless -s $output; } ; } } } 0 1 1
73 1 my ($input, $output) = splice (@ARGV, 0, 2);
74 1 $parser->parse_from_file ($input, $output);
75 1 ▶ if ($parser->{CONTENTLESS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->{"CONTENTLESS"}) 0 1 1
76 0 $status = 1;
77 0 ▶ if (defined $input) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $input) { } 0 0 0
78 0 warn "$0: unable to format $input\n";
79 } else {
80 0 warn "$0: unable to format standard input\n";
81 }
82 0 ▶ if (defined ($output) and $output ne '-') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output and $output ne "-") 0 0 0
Condition0%0/3
defined $output and $output ne "-"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $output and $output ne "-"
defined $output $output ne "-"
Truth table0%0/3
A and B
A= defined $outputB= $output ne "-"
ABresult
0X0
100
111
83 0 ▶ unlink $output unless (-s $output);
Branch: 1 branch
BranchTrueFalseTotal
unless -s $output 0 0 0
84 }
85 }
86 } while (@ARGV);
87 1 exit $status;
88  
89 __END__
« bin/pman ↑ Summary bin/pmcheck »