| 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
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | last if $ARGV[$i] =~ /^--$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | if ($ARGV[$i] =~ /^-(\d+)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$_ eq "-" and not $stdin++
MC/DC0%0/2
$_ eq "-" and not $stdin++
$_ eq "-"
not $stdin++
Truth table33%1/3
A and not(B)
A= $_ eq "-"B= not $stdin++
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $options{"stderr"} or defined $options{"errors"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 76 | 0 | $status = 1; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | if (defined $input) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $output and $output ne "-"
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 "-"
| |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | unlink $output unless (-s $output); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | } while (@ARGV); | ||||||||||||||||||||||||||||
| 87 | 1 | exit $status; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||