#!/home/perldoc/perldoc-browser/perls/5.45.1/bin/perl eval 'exec /home/perldoc/perldoc-browser/perls/5.45.1/bin/perl -S $0 ${1+"$@"}' if 0; # ^ Run only under a shell # Convert POD data to formatted ASCII text. # # The driver script for Pod::Text, Pod::Text::Termcap, and Pod::Text::Color, # invoked by perldoc -t among other things. # # SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl use 5.012; use warnings; use Getopt::Long qw(GetOptions); use Pod::Text (); use Pod::Usage qw(pod2usage); # Format a single POD file. # # $parser - Pod::Text object to use. # $input - Input file, - or undef for standard input # $output - Output file, - or undef for standard output # # Returns: 0 on no errors, 1 if there was an error sub format_file { my ($parser, $input, $output) = @_; $parser->parse_from_file($input, $output); if ($parser->{CONTENTLESS}) { if (defined($input) && $input ne q{-}) { warn "$0: unable to format $input\n"; } else { warn "$0: unable to format standard input\n"; } if (defined($output) && $output ne q{-} && !-s $output) { unlink($output); } return 1; } return 0; } # Clean up $0 for error reporting. $0 =~ s{ .*/ }{}xms; # For compatibility with the original pod2text script, take an initial pass # through our options, looking for one of the form -. If found, turn # it into -w . ## no critic (ControlStructures::ProhibitCStyleForLoops) for (my $i = 0; $i < @ARGV; $i++) { last if $ARGV[$i] eq q{--}; if ($ARGV[$i] =~ m{ \A -(\d+) \z }xms) { splice(@ARGV, $i++, 1, '-w', $1); } } ## use critic # Insert -- into @ARGV before any single dash argument to hide it from # Getopt::Long; we want to interpret it as meaning stdin (which Pod::Simple # does correctly). my $stdin; local @ARGV = map { $_ eq q{-} && !$stdin++ ? (q{--}, $_) : $_ } @ARGV; # Parse our options. Use the same names as Pod::Text for simplicity. my %options; Getopt::Long::config('bundling'); 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; if ($options{help}) { pod2usage(0); } # Figure out what formatter we're going to use. --color overrides --termcap. my $formatter = 'Pod::Text'; if ($options{color}) { $formatter = 'Pod::Text::Color'; eval { require Term::ANSIColor }; if ($@) { die "-c (--color) requires Term::ANSIColor be installed\n"; } require Pod::Text::Color; } elsif ($options{termcap}) { $formatter = 'Pod::Text::Termcap'; require Pod::Text::Termcap; } elsif ($options{overstrike}) { $formatter = 'Pod::Text::Overstrike'; require Pod::Text::Overstrike; } delete @options{ qw(color termcap overstrike) }; # If neither stderr nor errors is set, default to errors = die rather than the # Pod::Text default of pod. if (!defined($options{stderr}) && !defined($options{errors})) { $options{errors} = 'die'; } # If given no arguments, read from stdin and write to stdout. if (!@ARGV) { push(@ARGV, q{-}); } # Initialize and run the formatter, pulling a pair of input and output off at # a time. For each file, we check whether the document was completely empty # and, if so, remove the created file and exit with a non-zero exit status. my $parser = $formatter->new(%options); my $status = 0; while (@ARGV) { my ($input, $output) = splice(@ARGV, 0, 2); my $result = format_file($parser, $input, $output); $status ||= $result; } exit($status); __END__ =for stopwords -aclostu --alt --stderr Allbery --overstrike overstrike --termcap --utf8 UTF-8 subclasses --nourls EBCDIC unrepresentable =head1 NAME pod2text - Convert POD data to formatted ASCII text =head1 SYNOPSIS pod2text [B<-aclostu>] [B<--code>] S<[B<-e> I]> [B<--errors>=I