Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | From 7671d101baa75d7a79bfbd8c75c1595fbb3f53ba Mon Sep 17 00:00:00 2001 |
| 2 | From: Russ Allbery <rra@cpan.org> |
| 3 | Date: Sat, 7 Feb 2015 19:03:34 -0800 |
| 4 | Subject: Better errors for man pages from standard input |
| 5 | |
| 6 | [Pod::Man] Attempt to detect if the input came from a pipe and |
| 7 | therefore has a completely unhelpful (and nonreproducible) source file |
| 8 | name, and diagnose this as an error. Document that the name option |
| 9 | (--name to pod2man) is required when processing POD source from |
| 10 | standard input. (Debian Bug#777405) |
| 11 | |
| 12 | (backported to Perl 5.20.2 by Niko Tyni <ntyni@debian.org>) |
| 13 | |
| 14 | Origin: upstream, http://git.eyrie.org/?p=perl/podlators.git;a=commitdiff;h=d98872e46c93861b7aba14949e1258712087dc55 |
| 15 | Bug-Debian: https://bugs.debian.org/777405 |
| 16 | Patch-Name: fixes/podman-pipe.diff |
| 17 | --- |
| 18 | cpan/podlators/lib/Pod/Man.pm | 15 +++++++++++++++ |
| 19 | cpan/podlators/scripts/pod2man.PL | 4 ++++ |
| 20 | cpan/podlators/t/devise-title.t | 32 ++++++++++++++++++++++++++++++++ |
| 21 | 3 files changed, 51 insertions(+) |
| 22 | create mode 100755 cpan/podlators/t/devise-title.t |
| 23 | |
| 24 | diff --git a/cpan/podlators/lib/Pod/Man.pm b/cpan/podlators/lib/Pod/Man.pm |
| 25 | index 8997a15..969eaff 100644 |
| 26 | --- a/cpan/podlators/lib/Pod/Man.pm |
| 27 | +++ b/cpan/podlators/lib/Pod/Man.pm |
| 28 | @@ -828,6 +828,17 @@ sub devise_title { |
| 29 | $section = 3 if (!$$self{section} && $name =~ /\.pm\z/i); |
| 30 | $name =~ s/\.p(od|[lm])\z//i; |
| 31 | |
| 32 | + # If Pod::Parser gave us an IO::File reference as the source file name, |
| 33 | + # convert that to the empty string as well. Then, if we don't have a |
| 34 | + # valid name, emit a warning and convert it to STDIN. |
| 35 | + if ($name =~ /^IO::File(?:=\w+)\(0x[\da-f]+\)$/i) { |
| 36 | + $name = ''; |
| 37 | + } |
| 38 | + if ($name eq '') { |
| 39 | + $self->whine (1, 'No name given for document'); |
| 40 | + $name = 'STDIN'; |
| 41 | + } |
| 42 | + |
| 43 | # If the section isn't 3, then the name defaults to just the basename of |
| 44 | # the file. Otherwise, assume we're dealing with a module. We want to |
| 45 | # figure out the full module name from the path to the file, but we don't |
| 46 | @@ -1705,6 +1716,10 @@ module path. If it is, a path like C<.../lib/Pod/Man.pm> is converted into |
| 47 | a name like C<Pod::Man>. This option, if given, overrides any automatic |
| 48 | determination of the name. |
| 49 | |
| 50 | +If generating a manual page from standard input, this option is required, |
| 51 | +since there's otherwise no way for Pod::Man to know what to use for the |
| 52 | +manual page name. |
| 53 | + |
| 54 | =item nourls |
| 55 | |
| 56 | Normally, LZ<><> formatting codes with a URL but anchor text are formatted |
| 57 | diff --git a/cpan/podlators/scripts/pod2man.PL b/cpan/podlators/scripts/pod2man.PL |
| 58 | index 38695f8..43e35df 100644 |
| 59 | --- a/cpan/podlators/scripts/pod2man.PL |
| 60 | +++ b/cpan/podlators/scripts/pod2man.PL |
| 61 | @@ -236,6 +236,10 @@ Note that this option is probably not useful when converting multiple POD |
| 62 | files at once. The convention for Unix man pages for commands is for the |
| 63 | man page title to be in all-uppercase even if the command isn't. |
| 64 | |
| 65 | +When converting POD source from standard input, this option is required, |
| 66 | +since there's otherwise no way to know what to use as the name of the |
| 67 | +manual page. |
| 68 | + |
| 69 | =item B<--nourls> |
| 70 | |
| 71 | Normally, LZ<><> formatting codes with a URL but anchor text are formatted |
| 72 | diff --git a/cpan/podlators/t/devise-title.t b/cpan/podlators/t/devise-title.t |
| 73 | new file mode 100755 |
| 74 | index 0000000..8639441 |
| 75 | --- /dev/null |
| 76 | +++ b/cpan/podlators/t/devise-title.t |
| 77 | @@ -0,0 +1,32 @@ |
| 78 | +#!/usr/bin/perl |
| 79 | +# |
| 80 | +# Tests for the automatic determination of the manual page title if not |
| 81 | +# specified via options to pod2man or the Pod::Man constructor. |
| 82 | + |
| 83 | +use 5.006; |
| 84 | +use strict; |
| 85 | +use warnings; |
| 86 | + |
| 87 | +use File::Spec; |
| 88 | +use IO::File; |
| 89 | +use Test::More tests => 3; |
| 90 | + |
| 91 | +BEGIN { |
| 92 | + use_ok('Pod::Man'); |
| 93 | +} |
| 94 | + |
| 95 | +# Create a parser and set it up with an input source. There isn't a way to do |
| 96 | +# this in Pod::Simple without actually parsing the document, so send the |
| 97 | +# output to a string that we'll ignore. |
| 98 | +my $path = File::Spec->catdir('t', 'data', 'basic.pod'); |
| 99 | +my $handle = IO::File->new($path, 'r'); |
| 100 | +my $parser = Pod::Man->new(errors => 'pod'); |
| 101 | +my $output; |
| 102 | +$parser->output_string(\$output); |
| 103 | +$parser->parse_file($handle); |
| 104 | + |
| 105 | +# Check the results of devise_title for this. We should get back STDIN, and |
| 106 | +# we should have reported an error. |
| 107 | +my ($name, $section) = $parser->devise_title; |
| 108 | +is($name, 'STDIN', 'devise_title uses STDIN for file handle input'); |
| 109 | +ok($parser->errors_seen, '...and errors were seen'); |