File Coverage

/usr/local/bin/pod2text
Criterion Covered Total %
statement 38 53 71.7
branch 11 28 39.2
condition 2 9 22.2
subroutine 4 4 100.0
pod n/a
total 55 94 58.5


line stmt bran cond sub pod time code
1             #!/usr/local/bin/perl
2 1 50       5 eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
3             if $running_under_some_shell;
4              
5             # pod2text -- Convert POD data to formatted ASCII text.
6             #
7             # Copyright 1999, 2000, 2001, 2004, 2006, 2008, 2010, 2012, 2013
8             # Russ Allbery
9             #
10             # This program is free software; you may redistribute it and/or modify it
11             # under the same terms as Perl itself.
12             #
13             # The driver script for Pod::Text, Pod::Text::Termcap, and Pod::Text::Color,
14             # invoked by perldoc -t among other things.
15              
16 1         27 require 5.004;
17              
18 1     1   1088 use Getopt::Long qw(GetOptions);
  1         14022  
  1         5  
19 1     1   2481 use Pod::Text ();
  1         58866  
  1         32  
20 1     1   2036 use Pod::Usage qw(pod2usage);
  1         3314  
  1         73  
21              
22 1     1   6 use strict;
  1         1  
  1         2109  
23              
24             # Clean up $0 for error reporting.
25 1         54 $0 =~ s%.*/%%;
26              
27             # Take an initial pass through our options, looking for one of the form
28             # -. We turn that into -w for compatibility with the
29             # original pod2text script.
30 1         6 for (my $i = 0; $i < @ARGV; $i++) {
31 1 50       7 last if $ARGV[$i] =~ /^--$/;
32 1 50       7 if ($ARGV[$i] =~ /^-(\d+)$/) {
33 0         0 splice (@ARGV, $i++, 1, '-w', $1);
34             }
35             }
36              
37             # Insert -- into @ARGV before any single dash argument to hide it from
38             # Getopt::Long; we want to interpret it as meaning stdin (which Pod::Simple
39             # does correctly).
40 1         2 my $stdin;
41 1 50 33     3 @ARGV = map { $_ eq '-' && !$stdin++ ? ('--', $_) : $_ } @ARGV;
  1         8  
42              
43             # Parse our options. Use the same names as Pod::Text for simplicity, and
44             # default to sentence boundaries turned off for compatibility.
45 1         2 my %options;
46 1         2 $options{sentence} = 0;
47 1         7 Getopt::Long::config ('bundling');
48 1 50       44 GetOptions (\%options, 'alt|a', 'code', 'color|c', 'errors=s', 'help|h',
49             'indent|i=i', 'loose|l', 'margin|left-margin|m=i', 'nourls',
50             'overstrike|o', 'quotes|q=s', 'sentence|s', 'stderr', 'termcap|t',
51             'utf8|u', 'width|w=i')
52             or exit 1;
53 1 50       948 pod2usage (1) if $options{help};
54              
55             # Figure out what formatter we're going to use. -c overrides -t.
56 1         7 my $formatter = 'Pod::Text';
57 1 50       6 if ($options{color}) {
    50          
    50          
58 0         0 $formatter = 'Pod::Text::Color';
59 0         0 eval { require Term::ANSIColor };
  0         0  
60 0 0       0 if ($@) { die "-c (--color) requires Term::ANSIColor be installed\n" }
  0         0  
61 0         0 require Pod::Text::Color;
62             } elsif ($options{termcap}) {
63 0         0 $formatter = 'Pod::Text::Termcap';
64 0         0 require Pod::Text::Termcap;
65             } elsif ($options{overstrike}) {
66 0         0 $formatter = 'Pod::Text::Overstrike';
67 0         0 require Pod::Text::Overstrike;
68             }
69 1         3 delete @options{'color', 'termcap', 'overstrike'};
70              
71             # If neither stderr nor errors is set, default to errors = die.
72 1 50 33     8 if (!defined $options{stderr} && !defined $options{errors}) {
73 1         3 $options{errors} = 'die';
74             }
75              
76             # Initialize and run the formatter.
77 1         12 my $parser = $formatter->new (%options);
78 1         210 my $status = 0;
79 1         2 do {
80 1         2 my ($input, $output) = splice (@ARGV, 0, 2);
81 1         6 $parser->parse_from_file ($input, $output);
82 1 50       111871 if ($parser->{CONTENTLESS}) {
83 0         0 $status = 1;
84 0         0 warn "$0: unable to format $input\n";
85 0 0 0     0 if (defined ($output) and $output ne '-') {
86 0 0       0 unlink $output unless (-s $output);
87             }
88             }
89             } while (@ARGV);
90 1         0 exit $status;
91              
92             __END__