Upgrade to Pod::Perldoc 3.09.
[p5sagit/p5-mst-13.2.git] / lib / Pod / Perldoc / ToMan.pm
CommitLineData
1a67fee7 1
2require 5;
3package Pod::Perldoc::ToMan;
4use strict;
5use warnings;
6
7# This class is unlike ToText.pm et al, because we're NOT paging thru
a60a0c74 8# the output in our particular format -- we make the output and
1a67fee7 9# then we run nroff (or whatever) on it, and then page thru the
10# (plaintext) output of THAT!
11
12use base qw(Pod::Perldoc::BaseTo);
13sub is_pageable { 1 }
14sub write_with_binmode { 0 }
15sub output_extension { 'txt' }
16
17sub __filter_nroff { shift->_perldoc_elem('__filter_nroff' , @_) }
18sub __nroffer { shift->_perldoc_elem('__nroffer' , @_) }
19sub __bindir { shift->_perldoc_elem('__bindir' , @_) }
20sub __pod2man { shift->_perldoc_elem('__pod2man' , @_) }
21sub __output_file { shift->_perldoc_elem('__output_file' , @_) }
22
23sub center { shift->_perldoc_elem('center' , @_) }
24sub date { shift->_perldoc_elem('date' , @_) }
25sub fixed { shift->_perldoc_elem('fixed' , @_) }
26sub fixedbold { shift->_perldoc_elem('fixedbold' , @_) }
27sub fixeditalic { shift->_perldoc_elem('fixeditalic' , @_) }
28sub fixedbolditalic { shift->_perldoc_elem('fixedbolditalic', @_) }
29sub quotes { shift->_perldoc_elem('quotes' , @_) }
30sub release { shift->_perldoc_elem('release' , @_) }
31sub section { shift->_perldoc_elem('section' , @_) }
32
33sub new { return bless {}, ref($_[0]) || $_[0] }
34
35use File::Spec::Functions qw(catfile);
36
37sub parse_from_file {
38 my $self = shift;
39 my($file, $outfh) = @_;
40
41 my $render = $self->{'__nroffer'} || die "no nroffer set!?";
42
43 # turn the switches into CLIs
44 my $switches = join ' ',
45 map qq{"--$_=$self->{$_}"},
46 grep !m/^_/s,
47 keys %$self
48 ;
49
50 my $command =
51 catfile(
52 ($self->{'__bindir'} || die "no bindir set?!" ),
53 ($self->{'__pod2man'} || die "no pod2man set?!" ),
54 )
55 . " $switches --lax $file | $render -man"
56 ; # no temp file, just a pipe!
a60a0c74 57
58 # I hear persistent reports that adding a -c switch to $render
59 # solves many people's problems. But I also hear that some mans
60 # don't have a -c switch, so that adding it here would presumably
61 # be a Bad Thing -- sburke@cpan.org
62
1a67fee7 63 $command .= " | col -x" if $^O =~ /hpux/;
64
65 defined(&Pod::Perldoc::DEBUG)
66 and Pod::Perldoc::DEBUG()
67 and print "About to run $command\n";
68 ;
69
70 my $rslt = `$command`;
71
72 my $err;
73
74 if( $self->{'__filter_nroff'} ) {
75 defined(&Pod::Perldoc::DEBUG)
76 and &Pod::Perldoc::DEBUG()
77 and print "filter_nroff is set, so filtering...\n";
78 $rslt = $self->___Do_filter_nroff($rslt);
79 } else {
80 defined(&Pod::Perldoc::DEBUG)
81 and Pod::Perldoc::DEBUG()
82 and print "filter_nroff isn't set, so not filtering.\n";
83 }
84
85 if (($err = $?)) {
86 defined(&Pod::Perldoc::DEBUG)
87 and Pod::Perldoc::DEBUG()
88 and print "Nonzero exit ($?) while running $command.\n",
89 "Falling back to Pod::Perldoc::ToPod\n ",
90 ;
91 # A desperate fallthru:
92 require Pod::Perldoc::ToPod;
93 return Pod::Perldoc::ToPod->new->parse_from_file(@_);
94
95 } else {
96 print $outfh $rslt
97 or die "Can't print to $$self{__output_file}: $!";
98 }
99
100 return;
101}
102
103
104sub ___Do_filter_nroff {
105 my $self = shift;
106 my @data = split /\n{2,}/, shift;
107
108 shift @data while @data and $data[0] !~ /\S/; # Go to header
109 shift @data if @data and $data[0] =~ /Contributed\s+Perl/; # Skip header
110 pop @data if @data and $data[-1] =~ /^\w/; # Skip footer, like
111 # 28/Jan/99 perl 5.005, patch 53 1
112 join "\n\n", @data;
113}
114
1151;
116
117__END__
118
119=head1 NAME
120
121Pod::Perldoc::ToMan - let Perldoc render Pod as man pages
122
123=head1 SYNOPSIS
124
125 perldoc -o man Some::Modulename
126
127=head1 DESCRIPTION
128
129This is a "plug-in" class that allows Perldoc to use
130Pod::Man and C<nroff> for reading Pod pages.
131
132The following options are supported: center, date, fixed, fixedbold,
133fixeditalic, fixedbolditalic, quotes, release, section
134
135(Those options are explained in L<Pod::Man>.)
136
137For example:
138
139 perldoc -o man -w center:Pod Some::Modulename
140
141=head1 CAVEAT
142
143This module may change to use a different pod-to-nroff formatter class
144in the future, and this may change what options are supported.
145
146=head1 SEE ALSO
147
148L<Pod::Man>, L<Pod::Perldoc>, L<Pod::Perldoc::ToNroff>
149
150=head1 COPYRIGHT AND DISCLAIMERS
151
152Copyright (c) 2002 Sean M. Burke. All rights reserved.
153
154This library is free software; you can redistribute it and/or modify it
155under the same terms as Perl itself.
156
157This program is distributed in the hope that it will be useful, but
158without any warranty; without even the implied warranty of
159merchantability or fitness for a particular purpose.
160
161=head1 AUTHOR
162
163Sean M. Burke C<sburke@cpan.org>
164
165=cut
166