some versions of mingw32 have __int64, define iff it isn't
[p5sagit/p5-mst-13.2.git] / lib / Pod / Text.pm
CommitLineData
6055f9d4 1# Pod::Text -- Convert POD data to formatted ASCII text.
27f805f4 2# $Id: Text.pm,v 2.1 1999/09/20 11:53:33 eagle Exp $
6055f9d4 3#
4# Copyright 1999 by Russ Allbery <rra@stanford.edu>
5#
6# This program is free software; you can redistribute it and/or modify it
7# under the same terms as Perl itself.
8#
27f805f4 9# This module is intended to be a replacement for Pod::Text, and attempts to
10# match its output except for some specific circumstances where other
11# decisions seemed to produce better output. It uses Pod::Parser and is
12# designed to be very easy to subclass.
6055f9d4 13
14############################################################################
15# Modules and declarations
16############################################################################
69e00e79 17
6055f9d4 18package Pod::Text;
69e00e79 19
6055f9d4 20require 5.004;
21
27f805f4 22use Carp qw(carp croak);
23use Pod::Select ();
6055f9d4 24
25use strict;
26use vars qw(@ISA %ESCAPES $VERSION);
27
27f805f4 28# We inherit from Pod::Select instead of Pod::Parser so that we can be used
29# by Pod::Usage.
30@ISA = qw(Pod::Select);
6055f9d4 31
27f805f4 32($VERSION = (split (' ', q$Revision: 2.1 $ ))[1]) =~ s/\.(\d)$/.0$1/;
6055f9d4 33
34
35############################################################################
36# Table of supported E<> escapes
37############################################################################
38
9741dab0 39# This table is taken near verbatim from Pod::PlainText in Pod::Parser,
27f805f4 40# which got it near verbatim from the original Pod::Text. It is therefore
41# credited to Tom Christiansen, and I'm glad I didn't have to write it. :)
6055f9d4 42%ESCAPES = (
43 'amp' => '&', # ampersand
44 'lt' => '<', # left chevron, less-than
45 'gt' => '>', # right chevron, greater-than
46 'quot' => '"', # double quote
47
48 "Aacute" => "\xC1", # capital A, acute accent
49 "aacute" => "\xE1", # small a, acute accent
50 "Acirc" => "\xC2", # capital A, circumflex accent
51 "acirc" => "\xE2", # small a, circumflex accent
52 "AElig" => "\xC6", # capital AE diphthong (ligature)
53 "aelig" => "\xE6", # small ae diphthong (ligature)
54 "Agrave" => "\xC0", # capital A, grave accent
55 "agrave" => "\xE0", # small a, grave accent
56 "Aring" => "\xC5", # capital A, ring
57 "aring" => "\xE5", # small a, ring
58 "Atilde" => "\xC3", # capital A, tilde
59 "atilde" => "\xE3", # small a, tilde
60 "Auml" => "\xC4", # capital A, dieresis or umlaut mark
61 "auml" => "\xE4", # small a, dieresis or umlaut mark
62 "Ccedil" => "\xC7", # capital C, cedilla
63 "ccedil" => "\xE7", # small c, cedilla
64 "Eacute" => "\xC9", # capital E, acute accent
65 "eacute" => "\xE9", # small e, acute accent
66 "Ecirc" => "\xCA", # capital E, circumflex accent
67 "ecirc" => "\xEA", # small e, circumflex accent
68 "Egrave" => "\xC8", # capital E, grave accent
69 "egrave" => "\xE8", # small e, grave accent
70 "ETH" => "\xD0", # capital Eth, Icelandic
71 "eth" => "\xF0", # small eth, Icelandic
72 "Euml" => "\xCB", # capital E, dieresis or umlaut mark
73 "euml" => "\xEB", # small e, dieresis or umlaut mark
74 "Iacute" => "\xCD", # capital I, acute accent
75 "iacute" => "\xED", # small i, acute accent
76 "Icirc" => "\xCE", # capital I, circumflex accent
77 "icirc" => "\xEE", # small i, circumflex accent
78 "Igrave" => "\xCD", # capital I, grave accent
79 "igrave" => "\xED", # small i, grave accent
80 "Iuml" => "\xCF", # capital I, dieresis or umlaut mark
81 "iuml" => "\xEF", # small i, dieresis or umlaut mark
82 "Ntilde" => "\xD1", # capital N, tilde
83 "ntilde" => "\xF1", # small n, tilde
84 "Oacute" => "\xD3", # capital O, acute accent
85 "oacute" => "\xF3", # small o, acute accent
86 "Ocirc" => "\xD4", # capital O, circumflex accent
87 "ocirc" => "\xF4", # small o, circumflex accent
88 "Ograve" => "\xD2", # capital O, grave accent
89 "ograve" => "\xF2", # small o, grave accent
90 "Oslash" => "\xD8", # capital O, slash
91 "oslash" => "\xF8", # small o, slash
92 "Otilde" => "\xD5", # capital O, tilde
93 "otilde" => "\xF5", # small o, tilde
94 "Ouml" => "\xD6", # capital O, dieresis or umlaut mark
95 "ouml" => "\xF6", # small o, dieresis or umlaut mark
96 "szlig" => "\xDF", # small sharp s, German (sz ligature)
97 "THORN" => "\xDE", # capital THORN, Icelandic
98 "thorn" => "\xFE", # small thorn, Icelandic
99 "Uacute" => "\xDA", # capital U, acute accent
100 "uacute" => "\xFA", # small u, acute accent
101 "Ucirc" => "\xDB", # capital U, circumflex accent
102 "ucirc" => "\xFB", # small u, circumflex accent
103 "Ugrave" => "\xD9", # capital U, grave accent
104 "ugrave" => "\xF9", # small u, grave accent
105 "Uuml" => "\xDC", # capital U, dieresis or umlaut mark
106 "uuml" => "\xFC", # small u, dieresis or umlaut mark
107 "Yacute" => "\xDD", # capital Y, acute accent
108 "yacute" => "\xFD", # small y, acute accent
109 "yuml" => "\xFF", # small y, dieresis or umlaut mark
110
111 "lchevron" => "\xAB", # left chevron (double less than)
112 "rchevron" => "\xBB", # right chevron (double greater than)
113);
69e00e79 114
69e00e79 115
6055f9d4 116############################################################################
117# Initialization
118############################################################################
69e00e79 119
6055f9d4 120# Initialize the object. Must be sure to call our parent initializer.
121sub initialize {
122 my $self = shift;
69e00e79 123
6055f9d4 124 $$self{alt} = 0 unless defined $$self{alt};
125 $$self{indent} = 4 unless defined $$self{indent};
126 $$self{loose} = 0 unless defined $$self{loose};
127 $$self{sentence} = 0 unless defined $$self{sentence};
128 $$self{width} = 76 unless defined $$self{width};
69e00e79 129
6055f9d4 130 $$self{INDENTS} = []; # Stack of indentations.
131 $$self{MARGIN} = $$self{indent}; # Current left margin in spaces.
69e00e79 132
6055f9d4 133 $self->SUPER::initialize;
134}
69e00e79 135
69e00e79 136
6055f9d4 137############################################################################
138# Core overrides
139############################################################################
140
141# Called for each command paragraph. Gets the command, the associated
142# paragraph, the line number, and a Pod::Paragraph object. Just dispatches
143# the command to a method named the same as the command. =cut is handled
144# internally by Pod::Parser.
145sub command {
146 my $self = shift;
147 my $command = shift;
148 return if $command eq 'pod';
149 return if ($$self{EXCLUDE} && $command ne 'end');
150 $self->item ("\n") if defined $$self{ITEM};
151 $command = 'cmd_' . $command;
152 $self->$command (@_);
153}
69e00e79 154
6055f9d4 155# Called for a verbatim paragraph. Gets the paragraph, the line number, and
156# a Pod::Paragraph object. Just output it verbatim, but with tabs converted
157# to spaces.
158sub verbatim {
159 my $self = shift;
160 return if $$self{EXCLUDE};
161 $self->item if defined $$self{ITEM};
162 local $_ = shift;
163 return if /^\s*$/;
164 s/^(\s*\S+)/(' ' x $$self{MARGIN}) . $1/gme;
165 $self->output ($_);
166}
69e00e79 167
6055f9d4 168# Called for a regular text block. Gets the paragraph, the line number, and
169# a Pod::Paragraph object. Perform interpolation and output the results.
170sub textblock {
27f805f4 171 my $self = shift;
6055f9d4 172 return if $$self{EXCLUDE};
27f805f4 173 $self->output ($_[0]), return if $$self{VERBATIM};
174 local $_ = shift;
175 my $line = shift;
6055f9d4 176
177 # Perform a little magic to collapse multiple L<> references. This is
27f805f4 178 # here mostly for backwards-compatibility. We'll just rewrite the whole
179 # thing into actual text at this part, bypassing the whole internal
180 # sequence parsing thing.
6055f9d4 181 s{
182 (
183 L< # A link of the form L</something>.
184 /
185 (
186 [:\w]+ # The item has to be a simple word...
187 (\(\))? # ...or simple function.
188 )
189 >
190 (
191 ,?\s+(and\s+)? # Allow lots of them, conjuncted.
192 L<
193 /
194 (
195 [:\w]+
196 (\(\))?
197 )
198 >
199 )+
200 )
201 } {
202 local $_ = $1;
203 s%L</([^>]+)>%$1%g;
204 my @items = split /(?:,?\s+(?:and\s+)?)/;
205 my $string = "the ";
206 my $i;
207 for ($i = 0; $i < @items; $i++) {
208 $string .= $items[$i];
209 $string .= ", " if @items > 2 && $i != $#items;
210 $string .= " and " if ($i == $#items - 1);
211 }
212 $string .= " entries elsewhere in this document";
213 $string;
214 }gex;
215
216 # Now actually interpolate and output the paragraph.
217 $_ = $self->interpolate ($_, $line);
218 s/\s+$/\n/;
219 if (defined $$self{ITEM}) {
220 $self->item ($_ . "\n");
221 } else {
222 $self->output ($self->reformat ($_ . "\n"));
223 }
224}
69e00e79 225
6055f9d4 226# Called for an interior sequence. Gets the command, argument, and a
227# Pod::InteriorSequence object and is expected to return the resulting text.
228# Calls code, bold, italic, file, and link to handle those types of
229# sequences, and handles S<>, E<>, X<>, and Z<> directly.
230sub interior_sequence {
231 my $self = shift;
232 my $command = shift;
233 local $_ = shift;
234 return '' if ($command eq 'X' || $command eq 'Z');
69e00e79 235
6055f9d4 236 # Expand escapes into the actual character now, carping if invalid.
237 if ($command eq 'E') {
238 return $ESCAPES{$_} if defined $ESCAPES{$_};
239 carp "Unknown escape: E<$_>";
240 return "E<$_>";
241 }
69e00e79 242
6055f9d4 243 # For all the other sequences, empty content produces no output.
27f805f4 244 return if $_ eq '';
69e00e79 245
6055f9d4 246 # For S<>, compress all internal whitespace and then map spaces to \01.
247 # When we output the text, we'll map this back.
248 if ($command eq 'S') {
249 s/\s{2,}/ /g;
250 tr/ /\01/;
251 return $_;
252 }
69e00e79 253
6055f9d4 254 # Anything else needs to get dispatched to another method.
255 if ($command eq 'B') { return $self->seq_b ($_) }
256 elsif ($command eq 'C') { return $self->seq_c ($_) }
257 elsif ($command eq 'F') { return $self->seq_f ($_) }
258 elsif ($command eq 'I') { return $self->seq_i ($_) }
259 elsif ($command eq 'L') { return $self->seq_l ($_) }
260 else { carp "Unknown sequence $command<$_>" }
261}
f02a87df 262
6055f9d4 263# Called for each paragraph that's actually part of the POD. We take
264# advantage of this opportunity to untabify the input.
265sub preprocess_paragraph {
266 my $self = shift;
267 local $_ = shift;
268 1 while s/^(.*?)(\t+)/$1 . ' ' x (length ($2) * 8 - length ($1) % 8)/me;
269 $_;
270}
3ec07288 271
69e00e79 272
6055f9d4 273############################################################################
274# Command paragraphs
275############################################################################
f2506fb2 276
6055f9d4 277# All command paragraphs take the paragraph and the line number.
69e00e79 278
6055f9d4 279# First level heading.
280sub cmd_head1 {
281 my $self = shift;
282 local $_ = shift;
283 s/\s+$//;
27f805f4 284 $_ = $self->interpolate ($_, shift);
6055f9d4 285 if ($$self{alt}) {
286 $self->output ("\n==== $_ ====\n\n");
287 } else {
288 $_ .= "\n" if $$self{loose};
289 $self->output ($_ . "\n");
290 }
291}
69e00e79 292
6055f9d4 293# Second level heading.
294sub cmd_head2 {
295 my $self = shift;
296 local $_ = shift;
297 s/\s+$//;
27f805f4 298 $_ = $self->interpolate ($_, shift);
6055f9d4 299 if ($$self{alt}) {
300 $self->output ("\n== $_ ==\n\n");
301 } else {
302 $self->output (' ' x ($$self{indent} / 2) . $_ . "\n\n");
303 }
304}
69e00e79 305
6055f9d4 306# Start a list.
307sub cmd_over {
308 my $self = shift;
309 local $_ = shift;
310 unless (/^[-+]?\d+\s+$/) { $_ = $$self{indent} }
311 push (@{ $$self{INDENTS} }, $$self{MARGIN});
312 $$self{MARGIN} += ($_ + 0);
313}
69e00e79 314
6055f9d4 315# End a list.
316sub cmd_back {
317 my $self = shift;
318 $$self{MARGIN} = pop @{ $$self{INDENTS} };
319 unless (defined $$self{MARGIN}) {
320 carp "Unmatched =back";
321 $$self{MARGIN} = $$self{indent};
322 }
69e00e79 323}
324
6055f9d4 325# An individual list item.
326sub cmd_item {
327 my $self = shift;
328 if (defined $$self{ITEM}) { $self->item }
329 local $_ = shift;
330 s/\s+$//;
331 $$self{ITEM} = $self->interpolate ($_);
332}
69e00e79 333
27f805f4 334# Begin a block for a particular translator. Setting VERBATIM triggers
335# special handling in textblock().
6055f9d4 336sub cmd_begin {
337 my $self = shift;
338 local $_ = shift;
339 my ($kind) = /^(\S+)/ or return;
27f805f4 340 if ($kind eq 'text') {
341 $$self{VERBATIM} = 1;
342 } else {
343 $$self{EXCLUDE} = 1;
344 }
6055f9d4 345}
f2506fb2 346
6055f9d4 347# End a block for a particular translator. We assume that all =begin/=end
27f805f4 348# pairs are properly closed.
6055f9d4 349sub cmd_end {
350 my $self = shift;
27f805f4 351 $$self{EXCLUDE} = 0;
352 $$self{VERBATIM} = 0;
6055f9d4 353}
354
355# One paragraph for a particular translator. Ignore it unless it's intended
27f805f4 356# for text, in which case we treat it as a verbatim text block.
6055f9d4 357sub cmd_for {
358 my $self = shift;
359 local $_ = shift;
360 my $line = shift;
27f805f4 361 return unless s/^text\b[ \t]*\n?//;
362 $self->verbatim ($_, $line);
6055f9d4 363}
f2506fb2 364
69e00e79 365
6055f9d4 366############################################################################
367# Interior sequences
368############################################################################
69e00e79 369
6055f9d4 370# The simple formatting ones. These are here mostly so that subclasses can
371# override them and do more complicated things.
27f805f4 372sub seq_b { return $_[0]{alt} ? "``$_[1]''" : $_[1] }
373sub seq_c { return $_[0]{alt} ? "``$_[1]''" : "`$_[1]'" }
374sub seq_f { return $_[0]{alt} ? "\"$_[1]\"" : $_[1] }
6055f9d4 375sub seq_i { return '*' . $_[1] . '*' }
69e00e79 376
6055f9d4 377# The complicated one. Handle links. Since this is plain text, we can't
378# actually make any real links, so this is all to figure out what text we
379# print out.
380sub seq_l {
381 my $self = shift;
382 local $_ = shift;
69e00e79 383
6055f9d4 384 # Smash whitespace in case we were split across multiple lines.
385 s/\s+/ /g;
69e00e79 386
6055f9d4 387 # If we were given any explicit text, just output it.
388 if (/^([^|]+)\|/) { return $1 }
389
390 # Okay, leading and trailing whitespace isn't important; get rid of it.
391 s/^\s+//;
392 s/\s+$//;
6055f9d4 393
394 # Default to using the whole content of the link entry as a section
395 # name. Note that L<manpage/> forces a manpage interpretation, as does
396 # something looking like L<manpage(section)>. The latter is an
397 # enhancement over the original Pod::Text.
398 my ($manpage, $section) = ('', $_);
399 if (/^"\s*(.*?)\s*"$/) {
400 $section = '"' . $1 . '"';
401 } elsif (m/^[-:.\w]+(?:\(\S+\))?$/) {
402 ($manpage, $section) = ($_, '');
403 } elsif (m%/%) {
404 ($manpage, $section) = split (/\s*\/\s*/, $_, 2);
8c634b6e 405 }
406
6055f9d4 407 # Now build the actual output text.
408 my $text = '';
409 if (!length $section) {
410 $text = "the $manpage manpage" if length $manpage;
411 } elsif ($section =~ /^[:\w]+(?:\(\))?/) {
412 $text .= 'the ' . $section . ' entry';
413 $text .= (length $manpage) ? " in the $manpage manpage"
414 : " elsewhere in this document";
415 } else {
416 $section =~ s/^\"\s*//;
417 $section =~ s/\s*\"$//;
418 $text .= 'the section on "' . $section . '"';
419 $text .= " in the $manpage manpage" if length $manpage;
69e00e79 420 }
6055f9d4 421 $text;
69e00e79 422}
423
6055f9d4 424
425############################################################################
426# List handling
427############################################################################
428
429# This method is called whenever an =item command is complete (in other
430# words, we've seen its associated paragraph or know for certain that it
431# doesn't have one). It gets the paragraph associated with the item as an
432# argument. If that argument is empty, just output the item tag; if it
433# contains a newline, output the item tag followed by the newline.
434# Otherwise, see if there's enough room for us to output the item tag in the
435# margin of the text or if we have to put it on a separate line.
436sub item {
437 my $self = shift;
438 local $_ = shift;
439 my $tag = $$self{ITEM};
440 unless (defined $tag) {
441 carp "item called without tag";
442 return;
69e00e79 443 }
6055f9d4 444 undef $$self{ITEM};
445 my $indent = $$self{INDENTS}[-1];
446 unless (defined $indent) { $indent = $$self{indent} }
447 my $space = ' ' x $indent;
448 $space =~ s/^ /:/ if $$self{alt};
449 if (!$_ || /^\s+$/ || ($$self{MARGIN} - $indent < length ($tag) + 1)) {
27f805f4 450 my $margin = $$self{MARGIN};
451 $$self{MARGIN} = $indent;
452 my $output = $self->reformat ($tag);
453 $output =~ s/\n*$/\n/;
454 $self->output ($output);
455 $$self{MARGIN} = $margin;
6055f9d4 456 $self->output ($self->reformat ($_)) if /\S/;
457 } else {
458 $_ = $self->reformat ($_);
459 s/^ /:/ if ($$self{alt} && $indent > 0);
460 my $tagspace = ' ' x length $tag;
461 s/^($space)$tagspace/$1$tag/ or warn "Bizarre space in item";
462 $self->output ($_);
69e00e79 463 }
464}
465
69e00e79 466
6055f9d4 467############################################################################
468# Output formatting
469############################################################################
69e00e79 470
6055f9d4 471# Wrap a line, indenting by the current left margin. We can't use
472# Text::Wrap because it plays games with tabs. We can't use formline, even
473# though we'd really like to, because it screws up non-printing characters.
474# So we have to do the wrapping ourselves.
475sub wrap {
476 my $self = shift;
477 local $_ = shift;
478 my $output = '';
479 my $spaces = ' ' x $$self{MARGIN};
480 my $width = $$self{width} - $$self{MARGIN};
481 while (length > $width) {
482 if (s/^([^\n]{0,$width})\s+// || s/^([^\n]{$width})//) {
483 $output .= $spaces . $1 . "\n";
484 } else {
485 last;
486 }
69e00e79 487 }
6055f9d4 488 $output .= $spaces . $_;
489 $output =~ s/\s+$/\n\n/;
490 $output;
69e00e79 491}
492
6055f9d4 493# Reformat a paragraph of text for the current margin. Takes the text to
494# reformat and returns the formatted text.
495sub reformat {
496 my $self = shift;
497 local $_ = shift;
69e00e79 498
6055f9d4 499 # If we're trying to preserve two spaces after sentences, do some
500 # munging to support that. Otherwise, smash all repeated whitespace.
501 if ($$self{sentence}) {
502 s/ +$//mg;
503 s/\.\n/. \n/g;
504 s/\n/ /g;
505 s/ +/ /g;
69e00e79 506 } else {
6055f9d4 507 s/\s+/ /g;
69e00e79 508 }
6055f9d4 509 $self->wrap ($_);
69e00e79 510}
511
6055f9d4 512# Output text to the output device.
513sub output { $_[1] =~ tr/\01/ /; print { $_[0]->output_handle } $_[1] }
69e00e79 514
69e00e79 515
6055f9d4 516############################################################################
27f805f4 517# Backwards compatibility
518############################################################################
519
520# The old Pod::Text module did everything in a pod2text() function. This
521# tries to provide the same interface for legacy applications.
522sub pod2text {
523 my @args;
524
525 # This is really ugly; I hate doing option parsing in the middle of a
526 # module. But the old Pod::Text module supported passing flags to its
527 # entry function, so handle -a and -<number>.
528 while ($_[0] =~ /^-/) {
529 my $flag = shift;
530 if ($flag eq '-a') { push (@args, alt => 1) }
531 elsif ($flag =~ /^-(\d+)$/) { push (@args, width => $1) }
532 else {
533 unshift (@_, $flag);
534 last;
535 }
536 }
537
538 # Now that we know what arguments we're using, create the parser.
539 my $parser = Pod::Text->new (@args);
540
541 # If two arguments were given, the second argument is going to be a file
542 # handle. That means we want to call parse_from_filehandle(), which
543 # means we need to turn the first argument into a file handle. Magic
544 # open will handle the <&STDIN case automagically.
545 if (defined $_[1]) {
546 local *IN;
547 unless (open (IN, $_[0])) {
548 croak ("Can't open $_[0] for reading: $!\n");
549 return;
550 }
551 $_[0] = \*IN;
552 return $parser->parse_from_filehandle (@_);
553 } else {
554 return $parser->parse_from_file (@_);
555 }
556}
557
558
559############################################################################
6055f9d4 560# Module return value and documentation
561############################################################################
69e00e79 562
6055f9d4 5631;
564__END__
69e00e79 565
6055f9d4 566=head1 NAME
69e00e79 567
6055f9d4 568Pod::Text - Convert POD data to formatted ASCII text
69e00e79 569
6055f9d4 570=head1 SYNOPSIS
69e00e79 571
6055f9d4 572 use Pod::Text;
573 my $parser = Pod::Text->new (sentence => 0, width => 78);
69e00e79 574
6055f9d4 575 # Read POD from STDIN and write to STDOUT.
576 $parser->parse_from_filehandle;
69e00e79 577
6055f9d4 578 # Read POD from file.pod and write to file.txt.
579 $parser->parse_from_file ('file.pod', 'file.txt');
69e00e79 580
6055f9d4 581=head1 DESCRIPTION
5491a304 582
27f805f4 583Pod::Text is a module that can convert documentation in the POD format (the
584preferred language for documenting Perl) into formatted ASCII. It uses no
585special formatting controls or codes whatsoever, and its output is therefore
586suitable for nearly any device.
69e00e79 587
27f805f4 588As a derived class from Pod::Parser, Pod::Text supports the same methods and
589interfaces. See L<Pod::Parser> for all the details; briefly, one creates a
590new parser with C<Pod::Text-E<gt>new()> and then calls either
591parse_from_filehandle() or parse_from_file().
6055f9d4 592
27f805f4 593new() can take options, in the form of key/value pairs, that control the
6055f9d4 594behavior of the parser. The currently recognized options are:
595
596=over 4
597
598=item alt
599
600If set to a true value, selects an alternate output format that, among other
601things, uses a different heading style and marks C<=item> entries with a
602colon in the left margin. Defaults to false.
603
604=item indent
605
606The number of spaces to indent regular text, and the default indentation for
607C<=over> blocks. Defaults to 4.
608
609=item loose
610
611If set to a true value, a blank line is printed after a C<=head1> heading.
612If set to false (the default), no blank line is printed after C<=head1>,
613although one is still printed after C<=head2>. This is the default because
614it's the expected formatting for manual pages; if you're formatting
615arbitrary text documents, setting this to true may result in more pleasing
616output.
617
618=item sentence
619
27f805f4 620If set to a true value, Pod::Text will assume that each sentence ends in two
621spaces, and will try to preserve that spacing. If set to false, all
6055f9d4 622consecutive whitespace in non-verbatim paragraphs is compressed into a
623single space. Defaults to true.
624
625=item width
626
627The column at which to wrap text on the right-hand side. Defaults to 76.
628
629=back
630
27f805f4 631The standard Pod::Parser method parse_from_filehandle() takes up to two
6055f9d4 632arguments, the first being the file handle to read POD from and the second
633being the file handle to write the formatted output to. The first defaults
634to STDIN if not given, and the second defaults to STDOUT. The method
27f805f4 635parse_from_file() is almost identical, except that its two arguments are the
636input and output disk files instead. See L<Pod::Parser> for the specific
637details.
6055f9d4 638
639=head1 DIAGNOSTICS
640
641=over 4
642
27f805f4 643=item Bizarre space in item
644
645(W) Something has gone wrong in internal C<=item> processing. This message
646indicates a bug in Pod::Text; you should never see it.
647
648=item Can't open %s for reading: %s
649
650(F) Pod::Text was invoked via the compatibility mode pod2text() interface
651and the input file it was given could not be opened.
652
6055f9d4 653=item Unknown escape: %s
654
27f805f4 655(W) The POD source contained an C<EE<lt>E<gt>> escape that Pod::Text didn't
656know about.
6055f9d4 657
658=item Unknown sequence: %s
659
27f805f4 660(W) The POD source contained a non-standard internal sequence (something of
661the form C<XE<lt>E<gt>>) that Pod::Text didn't know about.
6055f9d4 662
663=item Unmatched =back
664
27f805f4 665(W) Pod::Text encountered a C<=back> command that didn't correspond to an
6055f9d4 666C<=over> command.
667
668=back
669
27f805f4 670=head1 RESTRICTIONS
671
672Embedded Ctrl-As (octal 001) in the input will be mapped to spaces on
673output, due to an internal implementation detail.
674
6055f9d4 675=head1 NOTES
676
27f805f4 677This is a replacement for an earlier Pod::Text module written by Tom
678Christiansen. It has a revamped interface, since it now uses Pod::Parser,
679but an interface roughly compatible with the old Pod::Text::pod2text()
680function is still available. Please change to the new calling convention,
681though.
6055f9d4 682
683The original Pod::Text contained code to do formatting via termcap
684sequences, although it wasn't turned on by default and it was problematic to
27f805f4 685get it to work at all. This rewrite doesn't even try to do that, but a
686subclass of it does. Look for L<Pod::Text::Termcap|Pod::Text::Termcap>.
6055f9d4 687
688=head1 SEE ALSO
689
27f805f4 690L<Pod::Parser|Pod::Parser>, L<Pod::Text::Termcap|Pod::Text::Termcap>,
691pod2text(1)
6055f9d4 692
693=head1 AUTHOR
694
695Russ Allbery E<lt>rra@stanford.eduE<gt>, based I<very> heavily on the
696original Pod::Text by Tom Christiansen E<lt>tchrist@mox.perl.comE<gt> and
697its conversion to Pod::Parser by Brad Appleton
698E<lt>bradapp@enteract.comE<gt>.
699
700=cut