lib/Pod/Perldoc/ToMan.pm

filter: Statementstmt 15.5% 39 / 251 Branchbran 15.0% 12 / 80 Conditioncond 14.2% 3 / 21 MC/DCmcdc 16.6% 2 / 12 Subroutinesub 19.3% 11 / 57 Podpod 0.0% 0 / 16 totaltotal 15.3% 67 / 437 CC 49 SCAR 29.5
CC
49
Cov
15%
_filter_through_nroff
80.9
_collect_nroff_switches
72.0
_get_device_switches
42.0
CRAP 19.2
« lib/Pod/Perldoc/BaseTo.pm ↑ Summary lib/Pod/Perldoc/ToANSI.pm »
1 2 require 5.006;
2 package Pod::Perldoc::ToMan;
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use parent qw(Pod::Perldoc::BaseTo);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 $VERSION = '3.28';
9  
10 2 ▶use File::Spec::Functions qw(catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Pod::Man 2.18;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 # This class is unlike ToText.pm et al, because we're NOT paging thru
13 # the output in our particular format -- we make the output and
14 # then we run nroff (or whatever) on it, and then page thru the
15 # (plaintext) output of THAT!
16  
17 sub SUCCESS () { 1 }
18 sub FAILED () { 0 }
19  
20 0 ▶sub is_pageable { 1 }
Subroutine is_pageable: not called CC=1 SCAR=6.9
Pod undocumented
21 0 ▶sub write_with_binmode { 0 }
Subroutine write_with_binmode: not called CC=1 SCAR=6.9
Pod undocumented
22 0 ▶sub output_extension { 'txt' }
Subroutine output_extension: not called CC=1 SCAR=6.9
Pod undocumented
23  
24 0 ▶sub __filter_nroff { shift->_perldoc_elem('__filter_nroff' , @_) }
Subroutine __filter_nroff: not called CC=1 SCAR=6.9
25 0 ▶sub __nroffer { shift->_perldoc_elem('__nroffer' , @_) }
Subroutine __nroffer: not called CC=1 SCAR=6.9
26 0 ▶sub __bindir { shift->_perldoc_elem('__bindir' , @_) }
Subroutine __bindir: not called CC=1 SCAR=6.9
27 0 ▶sub __pod2man { shift->_perldoc_elem('__pod2man' , @_) }
Subroutine __pod2man: not called CC=1 SCAR=6.9
28 0 ▶sub __output_file { shift->_perldoc_elem('__output_file' , @_) }
Subroutine __output_file: not called CC=1 SCAR=6.9
29  
30 0 ▶sub center { shift->_perldoc_elem('center' , @_) }
Subroutine center: not called CC=1 SCAR=6.9
Pod undocumented
31 0 ▶sub date { shift->_perldoc_elem('date' , @_) }
Subroutine date: not called CC=1 SCAR=6.9
Pod undocumented
32 0 ▶sub fixed { shift->_perldoc_elem('fixed' , @_) }
Subroutine fixed: not called CC=1 SCAR=6.9
Pod undocumented
33 0 ▶sub fixedbold { shift->_perldoc_elem('fixedbold' , @_) }
Subroutine fixedbold: not called CC=1 SCAR=6.9
Pod undocumented
34 0 ▶sub fixeditalic { shift->_perldoc_elem('fixeditalic' , @_) }
Subroutine fixeditalic: not called CC=1 SCAR=6.9
Pod undocumented
35 0 ▶sub fixedbolditalic { shift->_perldoc_elem('fixedbolditalic', @_) }
Subroutine fixedbolditalic: not called CC=1 SCAR=6.9
Pod undocumented
36 0 ▶sub name { shift->_perldoc_elem('name' , @_) }
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
37 0 ▶sub quotes { shift->_perldoc_elem('quotes' , @_) }
Subroutine quotes: not called CC=1 SCAR=6.9
Pod undocumented
38 0 ▶sub release { shift->_perldoc_elem('release' , @_) }
Subroutine release: not called CC=1 SCAR=6.9
Pod undocumented
39 0 ▶sub section { shift->_perldoc_elem('section' , @_) }
Subroutine section: not called CC=1 SCAR=6.9
Pod undocumented
40  
41 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
42 0 my( $either ) = shift;
43 0 ▶ my $self = bless {}, ref($either) || $either;
Condition0%0/3
ref $either || $either
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $either || $either
ref $either $either
Truth table0%0/3
A || B
A= ref $eitherB= $either
ABresult
1X1
011
000
44 0 $self->init( @_ );
45 0 return $self;
46 }
47  
48 0 ▶sub init {
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
49 0 my( $self, @args ) = @_;
50  
51 0 ▶ unless( $self->__nroffer ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__nroffer) { } 0 0 0
52 0 my $roffer = $self->_find_roffer( $self->_roffer_candidates );
53 0 $self->debug( "Using $roffer\n" );
54 0 $self->__nroffer( $roffer );
55 }
56 else {
57 0 $self->debug( "__nroffer is " . $self->__nroffer() . "\n" );
58 }
59  
60 0 $self->_check_nroffer;
61 }
62  
63 0 ▶sub _roffer_candidates {
Subroutine _roffer_candidates: not called CC=4 SCAR=30.0
64 0 my( $self ) = @_;
65  
66 0 ▶ if( $self->is_openbsd || $self->is_freebsd || $self->is_bitrig ) { qw( mandoc groff nroff ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_openbsd or $self->is_freebsd or $self->is_bitrig) { } 0 0 0
Condition0%0/6
$self->is_openbsd or $self->is_freebsd or $self->is_bitrig
l!l&&r!l&&!r
000
$self->is_openbsd or $self->is_freebsd
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->is_openbsd or $self->is_freebsd or $self->is_bitrig
$self->is_openbsd $self->is_freebsd $self->is_bitrig
Truth table0%0/4
A or B or C
A= $self->is_openbsdB= $self->is_freebsdC= $self->is_bitrig
ABCresult
1XX1
01X1
0011
0000
67 0 else { qw( groff nroff mandoc ) }
68 }
69  
70 0 ▶sub _find_roffer {
Subroutine _find_roffer: not called CC=3 SCAR=24.8
71 0 my( $self, @candidates ) = @_;
72  
73 0 my @found = ();
74 0 foreach my $candidate ( @candidates ) {
75 0 push @found, $self->_find_executable_in_path( $candidate );
76 }
77  
78 0 ▶ return wantarray ? @found : $found[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
79 }
80  
81 0 ▶sub _check_nroffer {
Subroutine _check_nroffer: not called CC=1 SCAR=6.9
82 0 return 1;
83 # where is it in the PATH?
84  
85 # is it executable?
86  
87 # what is its real name?
88  
89 # what is its version?
90  
91 # does it support the flags we need?
92  
93 # is it good enough for us?
94 }
95  
96 0 ▶sub _get_stty { `stty -a` }
Subroutine _get_stty: not called CC=1 SCAR=6.9
97  
98 22 ▶sub _get_columns_from_stty {
Subroutine _get_columns_from_stty: called CC=3 SCAR=11.0
99 22 my $output = $_[0]->_get_stty;
100  
101 22 ▶ if( $output =~ /\bcolumns\s+(\d+)/ ) { return $1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($output =~ /\bcolumns\s+(\d+)/) { } 10 12 22
elsif ($output =~ /;\s*(\d+)\s+columns;/) { } 6 6 12
102 6 elsif( $output =~ /;\s*(\d+)\s+columns;/ ) { return $1 }
103 6 else { return 0 }
104 }
105  
106 24 ▶sub _get_columns_from_manwidth {
Subroutine _get_columns_from_manwidth: called CC=5 SCAR=17.0
107 24 my( $self ) = @_;
108  
109 24 ▶ return 0 unless defined $ENV{MANWIDTH};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV{"MANWIDTH"} 14 10 24
110  
111 10 ▶ unless( $ENV{MANWIDTH} =~ m/\A\d+\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"MANWIDTH"} =~ /\A\d+\z/) 6 4 10
112 6 $self->warn( "Ignoring non-numeric MANWIDTH ($ENV{MANWIDTH})\n" );
113 6 return 0;
114 }
115  
116 4 ▶ if( $ENV{MANWIDTH} == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"MANWIDTH"} == 0) 0 4 4
117 0 $self->warn( "Ignoring MANWIDTH of 0. Really? Why even run the program? :)\n" );
118 0 return 0;
119 }
120  
121 4 ▶ if( $ENV{MANWIDTH} =~ m/\A(\d+)\z/ ) { return $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"MANWIDTH"} =~ /\A(\d+)\z/) 4 0 4
122  
123 0 return 0;
124 }
125  
126 3 ▶sub _get_default_width {
Subroutine _get_default_width: called CC=1 SCAR=0.0
127 3 73
128 }
129  
130 12 ▶sub _get_columns {
Subroutine _get_columns: called CC=3 SCAR=11.0
131 12 ▶ $_[0]->_get_columns_from_manwidth ||
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->_get_columns_from_manwidth or $_[0]->_get_columns_from_stty or $_[0]->_get_default_width 9 3 12
Condition100%3/3
$_[0]->_get_columns_from_manwidth or $_[0]->_get_columns_from_stty
l!l&&r!l&&!r
273
MC/DC100%2/2
$_[0]->_get_columns_from_manwidth or $_[0]->_get_columns_from_stty
$_[0]->_get_columns_from_manwidth $_[0]->_get_columns_from_stty
Truth table100%3/3
A or B
A= $_[0]->_get_columns_from_manwidthB= $_[0]->_get_columns_from_stty
ABresult
1X1
011
000
132 $_[0]->_get_columns_from_stty ||
133 $_[0]->_get_default_width;
134 }
135  
136 0 ▶sub _get_podman_switches {
Subroutine _get_podman_switches: not called CC=1 SCAR=6.9
137 0 my( $self ) = @_;
138  
139 0 my @switches = map { $_, $self->{$_} } grep !m/^_/s, keys %$self;
140  
141 # There needs to be a cleaner way to handle setting
142 # the UTF-8 flag, but for now, comment out this
143 # line because it often does the wrong thing.
144 #
145 # See RT #77465
146 #
147 #push @switches, 'utf8' => 1;
148  
149 0 $self->debug( "Pod::Man switches are [@switches]\n" );
150  
151 0 return @switches;
152 }
153  
154 0 ▶sub _parse_with_pod_man {
Subroutine _parse_with_pod_man: not called CC=3 SCAR=24.8
155 0 my( $self, $file ) = @_;
156  
157 #->output_fh and ->output_string from Pod::Simple aren't
158 # working, apparently, so there's this ugly hack:
159 0 local *STDOUT;
160 0 open STDOUT, '>', $self->{_text_ref};
161 0 my $parser = Pod::Man->new( $self->_get_podman_switches );
162 0 $self->debug( "Parsing $file\n" );
163 0 $parser->parse_from_file( $file );
164 0 $self->debug( "Done parsing $file\n" );
165 0 close STDOUT;
166  
167 $self->die( "No output from Pod::Man!\n" )
168 0 ▶ unless length $self->{_text_ref};
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"_text_ref"} 0 0 0
169  
170 0 ▶ $self->_save_pod_man_output if $self->debugging;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debugging 0 0 0
171  
172 0 return SUCCESS;
173 }
174  
175 0 ▶sub _save_pod_man_output {
Subroutine _save_pod_man_output: not called CC=2 SCAR=17.9
176 0 my( $self, $fh ) = @_;
177  
178 0 ▶ $fh = do {
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 0 0
179 0 my $file = "podman.out.$$.txt";
180 0 $self->debug( "Writing $file with Pod::Man output\n" );
181 0 open my $fh2, '>', $file;
182 0 $fh2;
183 } unless $fh;
184  
185 0 print { $fh } ${ $self->{_text_ref} };
186 }
187  
188 0 ▶sub _have_groff_with_utf8 {
Subroutine _have_groff_with_utf8: not called CC=3 SCAR=24.8
189 0 my( $self ) = @_;
190  
191 0 ▶ return 0 unless $self->_is_groff;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_groff 0 0 0
192 0 my $roffer = $self->__nroffer;
193  
194 0 my $minimum_groff_version = '1.20.1';
195  
196 0 my $version_string = `$roffer -v`;
197 0 my( $version ) = $version_string =~ /\(?groff\)? version (\d+\.\d+(?:\.\d+)?)/;
198 0 $self->debug( "Found groff $version\n" );
199  
200 # is a string comparison good enough?
201 0 ▶ if( $version lt $minimum_groff_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version lt $minimum_groff_version) 0 0 0
202 0 $self->warn(
203 "You have an old groff." .
204 " Update to version $minimum_groff_version for good Unicode support.\n" .
205 "If you don't upgrade, wide characters may come out oddly.\n"
206 );
207 }
208  
209 0 $version ge $minimum_groff_version;
210 }
211  
212 0 ▶sub _have_mandoc_with_utf8 {
Subroutine _have_mandoc_with_utf8: not called CC=2 SCAR=17.9
213 0 my( $self ) = @_;
214  
215 0 ▶ $self->_is_mandoc and not system 'mandoc -Tlocale -V > /dev/null 2>&1';
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_mandoc and not system("mandoc -Tlocale -V > /dev/null 2>&1") 0 0 0
216 }
217  
218 0 ▶sub _collect_nroff_switches {
Subroutine _collect_nroff_switches: not called CC=8 SCAR=42.8
219 0 my( $self ) = shift;
220  
221 0 my @render_switches = ('-man', $self->_get_device_switches);
222  
223 # Thanks to Brendan O'Dea for contributing the following block
224 0 ▶ if( $self->_is_roff and -t STDOUT and my ($cols) = $self->_get_columns ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_roff and -t STDOUT and my($cols) = $self->_get_columns) 0 0 0
Condition0%0/6
$self->_is_roff and -t STDOUT and my($cols) = $self->_get_columns
!ll&&!rl&&r
000
$self->_is_roff and -t STDOUT
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_is_roff and -t STDOUT and my($cols) = $self->_get_columns
$self->_is_roff -t STDOUT my($cols) = $self->_get_columns
Truth table0%0/4
A and B and C
A= $self->_is_roffB= -t STDOUTC= my($cols) = $self->_get_columns
ABCresult
0XX0
10X0
1100
1111
225 0 my $c = $cols * 39 / 40;
226 0 ▶ $cols = $c > $cols - 2 ? $c : $cols -2;
Branch: 1 branch
BranchTrueFalseTotal
$c > $cols - 2 ? : 0 0 0
227 0 ▶ push @render_switches, '-rLL=' . (int $c) . 'n' if $cols > 80;
Branch: 1 branch
BranchTrueFalseTotal
if $cols > 80 0 0 0
228 }
229  
230 # I hear persistent reports that adding a -c switch to $render
231 # solves many people's problems. But I also hear that some mans
232 # don't have a -c switch, so that unconditionally adding it here
233 # would presumably be a Bad Thing -- sburke@cpan.org
234 0 ▶ push @render_switches, '-c' if( $self->_is_roff and $self->is_cygwin );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_roff and $self->is_cygwin 0 0 0
Condition0%0/3
$self->_is_roff and $self->is_cygwin
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_roff and $self->is_cygwin
$self->_is_roff $self->is_cygwin
Truth table0%0/3
A and B
A= $self->_is_roffB= $self->is_cygwin
ABresult
0X0
100
111
235  
236 0 return @render_switches;
237 }
238  
239 0 ▶sub _get_device_switches {
Subroutine _get_device_switches: not called CC=6 SCAR=37.4
240 0 my( $self ) = @_;
241  
242 0 ▶ if( $self->_is_nroff ) { qw() }
Branch: 5 branches
BranchTrueFalseTotal
if ($self->_is_nroff) { } 0 0 0
elsif ($self->_have_groff_with_utf8) { } 0 0 0
elsif ($self->_is_ebcdic) { } 0 0 0
elsif ($self->_have_mandoc_with_utf8) { } 0 0 0
elsif ($self->_is_mandoc) { } 0 0 0
243 0 elsif( $self->_have_groff_with_utf8 ) { qw(-Kutf8 -Tutf8) }
244 0 elsif( $self->_is_ebcdic ) { qw(-Tcp1047) }
245 0 elsif( $self->_have_mandoc_with_utf8 ) { qw(-Tlocale) }
246 0 elsif( $self->_is_mandoc ) { qw() }
247 0 else { qw(-Tlatin1) }
248 }
249  
250 0 ▶sub _is_roff {
Subroutine _is_roff: not called CC=2 SCAR=17.9
251 0 my( $self ) = @_;
252  
253 0 ▶ $self->_is_nroff or $self->_is_groff;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_nroff or $self->_is_groff 0 0 0
254 }
255  
256 0 ▶sub _is_nroff {
Subroutine _is_nroff: not called CC=1 SCAR=6.9
257 0 my( $self ) = @_;
258  
259 0 $self->__nroffer =~ /\bnroff\b/;
260 }
261  
262 0 ▶sub _is_groff {
Subroutine _is_groff: not called CC=1 SCAR=6.9
263 0 my( $self ) = @_;
264  
265 0 $self->__nroffer =~ /\bgroff\b/;
266 }
267  
268 0 ▶sub _is_mandoc {
Subroutine _is_mandoc: not called CC=1 SCAR=6.9
269 0 my ( $self ) = @_;
270  
271 0 $self->__nroffer =~ /\bmandoc\b/;
272 }
273  
274 0 ▶sub _is_ebcdic {
Subroutine _is_ebcdic: not called CC=1 SCAR=6.9
275 0 my( $self ) = @_;
276  
277 0 return 0;
278 }
279
280 0 ▶sub _filter_through_nroff {
Subroutine _filter_through_nroff: not called CC=9 SCAR=43.9
281 0 my( $self ) = shift;
282 0 $self->debug( "Filtering through " . $self->__nroffer() . "\n" );
283  
284 # Maybe someone set rendering switches as part of the opt_n value
285 # Deal with that here.
286  
287 0 my ($render, $switches) = $self->__nroffer() =~ /\A([\/a-zA-Z0-9_\.-]+)\b(.+)?\z/;
288  
289 0 ▶ $self->die("no nroffer!?") unless $render;
Branch: 1 branch
BranchTrueFalseTotal
unless $render 0 0 0
290 0 my @render_switches = $self->_collect_nroff_switches;
291  
292 0 ▶ if ( $switches ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($switches) 0 0 0
293 # Eliminate whitespace
294 0 $switches =~ s/\s//g;
295  
296 # Then separate the switches with a zero-width positive
297 # lookahead on the dash.
298 #
299 # See:
300 # http://www.effectiveperlprogramming.com/blog/1411
301 # for a good discussion of this technique
302  
303 0 push @render_switches, split(/(?=-)/, $switches);
304 }
305  
306 0 $self->debug( "render is $render\n" );
307 0 $self->debug( "render options are @render_switches\n" );
308  
309 0 require Symbol;
310 0 require IPC::Open3;
311 0 require IO::Handle;
312  
313 0 my $pid = IPC::Open3::open3(
314 my $writer,
315 my $reader,
316 my $err = Symbol::gensym(),
317 $render,
318 @render_switches
319 );
320  
321 0 $reader->autoflush(1);
322  
323 2 ▶ use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
324 0 my $selector = IO::Select->new( $reader );
325  
326 0 $self->debug( "Writing to pipe to $render\n" );
327  
328 0 my $offset = 0;
329 0 my $chunk_size = 4096;
330 0 my $length = length( ${ $self->{_text_ref} } );
331 0 my $chunks = $length / $chunk_size;
332 0 my $done;
333 my $buffer;
334 0 ▶ while( $offset <= $length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset <= $length) 0 0 0
335 0 $self->debug( "Writing chunk $chunks\n" ); $chunks++;
336 0 ▶ syswrite $writer, ${ $self->{_text_ref} }, $chunk_size, $offset
Branch: 1 branch
BranchTrueFalseTotal
syswrite $writer, ${$self->{"_text_ref"};}, $chunk_size, $offset or $self->die($!) 0 0 0
337 or $self->die( $! );
338 0 $offset += $chunk_size;
339 0 $self->debug( "Checking read\n" );
340 READ: {
341 0 ▶ last READ unless $selector->can_read( 0.01 );
Branch: 1 branch
BranchTrueFalseTotal
unless $selector->can_read("0.01") 0 0 0
342 0 $self->debug( "Reading\n" );
343 0 my $bytes = sysread $reader, $buffer, 4096;
344 0 $self->debug( "Read $bytes bytes\n" );
345 0 $done .= $buffer;
346 0 $self->debug( sprintf "Output is %d bytes\n",
347 length $done
348 );
349 0 next READ;
350 }
351 }
352 0 close $writer;
353 0 $self->debug( "Done writing\n" );
354  
355 # read any leftovers
356 0 $done .= do { local $/; <$reader> };
357 0 $self->debug( sprintf "Done reading. Output is %d bytes\n",
358 length $done
359 );
360  
361 0 ▶ if( $? ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 0 0 0
362 0 $self->warn( "Error from pipe to $render!\n" );
363 0 $self->debug( 'Error: ' . do { local $/; <$err> } );
364 }
365  
366  
367 0 close $reader;
368 0 ▶ if( my $err = $? ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $?) 0 0 0
369 0 $self->debug(
370 "Nonzero exit ($?) while running `$render @render_switches`.\n" .
371 "Falling back to Pod::Perldoc::ToPod\n"
372 );
373 0 return $self->_fallback_to_pod( @_ );
374 }
375  
376 0 $self->debug( "Output:\n----\n$done\n----\n" );
377  
378 0 ${ $self->{_text_ref} } = $done;
379  
380 0 ▶ return length ${ $self->{_text_ref} } ? SUCCESS : FAILED;
Branch: 1 branch
BranchTrueFalseTotal
length ${$self->{'_text_ref'};} ? : 0 0 0
381 }
382  
383 0 ▶sub parse_from_file {
Subroutine parse_from_file: not called CC=3 SCAR=24.8
Pod undocumented
384 0 my( $self, $file, $outfh) = @_;
385  
386 # We have a pipeline of filters each affecting the reference
387 # in $self->{_text_ref}
388 0 $self->{_text_ref} = \my $output;
389  
390 0 $self->_parse_with_pod_man( $file );
391 # so far, nroff is an external command so we ensure it worked
392 0 my $result = $self->_filter_through_nroff;
393 0 ▶ return $self->_fallback_to_pod( @_ ) unless $result == SUCCESS;
Branch: 1 branch
BranchTrueFalseTotal
unless $result == 1 0 0 0
394  
395 0 $self->_post_nroff_processing;
396  
397 0 ▶ print { $outfh } $output or
Branch: 1 branch
BranchTrueFalseTotal
print {$outfh;} $output or $self->die(qq[Can't print to $self->{"__output_file"}: $!]) 0 0 0
398 $self->die( "Can't print to $$self{__output_file}: $!" );
399  
400 0 return;
401 }
402  
403 0 ▶sub _fallback_to_pod {
Subroutine _fallback_to_pod: not called CC=1 SCAR=6.9
404 0 my( $self, @args ) = @_;
405 0 $self->warn( "Falling back to Pod because there was a problem!\n" );
406 0 require Pod::Perldoc::ToPod;
407 0 return Pod::Perldoc::ToPod->new->parse_from_file(@_);
408 }
409  
410 # maybe there's a user setting we should check?
411 0 ▶sub _get_tab_width { 4 }
Subroutine _get_tab_width: not called CC=1 SCAR=6.9
412  
413 0 ▶sub _expand_tabs {
Subroutine _expand_tabs: not called CC=1 SCAR=6.9
414 0 my( $self ) = @_;
415  
416 0 my $tab_width = ' ' x $self->_get_tab_width;
417  
418 0 ${ $self->{_text_ref} } =~ s/\t/$tab_width/g;
419 }
420  
421 0 ▶sub _post_nroff_processing {
Subroutine _post_nroff_processing: not called CC=3 SCAR=24.8
422 0 my( $self ) = @_;
423  
424 0 ▶ if( $self->is_hpux ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_hpux) 0 0 0
425 0 $self->debug( "On HP-UX, I'm going to expand tabs for you\n" );
426 # this used to be a pipe to `col -x` for HP-UX
427 0 $self->_expand_tabs;
428 }
429  
430 0 ▶ if( $self->{'__filter_nroff'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'__filter_nroff'}) { } 0 0 0
431 0 $self->debug( "filter_nroff is set, so filtering\n" );
432 0 $self->_remove_nroff_header;
433 0 $self->_remove_nroff_footer;
434 }
435 else {
436 0 $self->debug( "filter_nroff is not set, so not filtering\n" );
437 }
438  
439 0 $self->_handle_unicode;
440  
441 0 return 1;
442 }
443  
444 # I don't think this does anything since there aren't two consecutive
445 # newlines in the Pod::Man output
446 0 ▶sub _remove_nroff_header {
Subroutine _remove_nroff_header: not called CC=1 SCAR=6.9
447 0 my( $self ) = @_;
448 0 $self->debug( "_remove_nroff_header is still a stub!\n" );
449 0 return 1;
450  
451 # my @data = split /\n{2,}/, shift;
452 # shift @data while @data and $data[0] !~ /\S/; # Go to header
453 # shift @data if @data and $data[0] =~ /Contributed\s+Perl/; # Skip header
454 }
455  
456 # I don't think this does anything since there aren't two consecutive
457 # newlines in the Pod::Man output
458 0 ▶sub _remove_nroff_footer {
Subroutine _remove_nroff_footer: not called CC=1 SCAR=6.9
459 0 my( $self ) = @_;
460 0 $self->debug( "_remove_nroff_footer is still a stub!\n" );
461 0 return 1;
462 0 ${ $self->{_text_ref} } =~ s/\n\n+.*\w.*\Z//m;
463  
464 # my @data = split /\n{2,}/, shift;
465 # pop @data if @data and $data[-1] =~ /^\w/; # Skip footer, like
466 # 28/Jan/99 perl 5.005, patch 53 1
467 }
468  
469 0 ▶sub _unicode_already_handled {
Subroutine _unicode_already_handled: not called CC=2 SCAR=17.9
470 0 my( $self ) = @_;
471  
472 0 ▶ $self->_have_groff_with_utf8 ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_have_groff_with_utf8 or 1 0 0 0
473 1 # so, we don't have a case that needs _handle_unicode
474 ;
475 }
476  
477 0 ▶sub _handle_unicode {
Subroutine _handle_unicode: not called CC=2 SCAR=17.9
478 # this is the job of preconv
479 # we don't need this with groff 1.20 and later.
480 0 my( $self ) = @_;
481  
482 0 ▶ return 1 if $self->_unicode_already_handled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_unicode_already_handled 0 0 0
483  
484 0 require Encode;
485  
486 # it's UTF-8 here, but we need character data
487 0 my $text = Encode::decode( 'UTF-8', ${ $self->{_text_ref} } ) ;
488  
489 # http://www.mail-archive.com/groff@gnu.org/msg01378.html
490 # http://linux.die.net/man/7/groff_char
491 # http://www.gnu.org/software/groff/manual/html_node/Using-Symbols.html
492 # http://lists.gnu.org/archive/html/groff/2011-05/msg00007.html
493 # http://www.simplicidade.org/notes/archives/2009/05/fixing_the_pod.html
494 # http://lists.freebsd.org/pipermail/freebsd-questions/2011-July/232239.html
495 0 $text =~ s/(\P{ASCII})/
496 0 sprintf '\\[u%04X]', ord $1
497 /eg;
498  
499 # should we encode?
500 0 ${ $self->{_text_ref} } = $text;
501 }
502  
503 2 1;
504  
505 __END__
« lib/Pod/Perldoc/BaseTo.pm ↑ Summary lib/Pod/Perldoc/ToANSI.pm »