Upgrade to podlators 2.1.2
[p5sagit/p5-mst-13.2.git] / lib / Pod / Text.pm
1 # Pod::Text -- Convert POD data to formatted ASCII text.
2 #
3 # Copyright 1999, 2000, 2001, 2002, 2004, 2006, 2008
4 #     Russ Allbery <rra@stanford.edu>
5 #
6 # This program is free software; you may redistribute it and/or modify it
7 # under the same terms as Perl itself.
8 #
9 # This module converts POD to formatted text.  It replaces the old Pod::Text
10 # module that came with versions of Perl prior to 5.6.0 and attempts to match
11 # its output except for some specific circumstances where other decisions
12 # seemed to produce better output.  It uses Pod::Parser and is designed to be
13 # very easy to subclass.
14 #
15 # Perl core hackers, please note that this module is also separately
16 # maintained outside of the Perl core as part of the podlators.  Please send
17 # me any patches at the address above in addition to sending them to the
18 # standard Perl mailing lists.
19
20 ##############################################################################
21 # Modules and declarations
22 ##############################################################################
23
24 package Pod::Text;
25
26 require 5.004;
27
28 use strict;
29 use vars qw(@ISA @EXPORT %ESCAPES $VERSION);
30
31 use Carp qw(carp croak);
32 use Exporter ();
33 use Pod::Simple ();
34
35 @ISA = qw(Pod::Simple Exporter);
36
37 # We have to export pod2text for backward compatibility.
38 @EXPORT = qw(pod2text);
39
40 $VERSION = 3.09;
41
42 ##############################################################################
43 # Initialization
44 ##############################################################################
45
46 # This function handles code blocks.  It's registered as a callback to
47 # Pod::Simple and therefore doesn't work as a regular method call, but all it
48 # does is call output_code with the line.
49 sub handle_code {
50     my ($line, $number, $parser) = @_;
51     $parser->output_code ($line . "\n");
52 }
53
54 # Initialize the object and set various Pod::Simple options that we need.
55 # Here, we also process any additional options passed to the constructor or
56 # set up defaults if none were given.  Note that all internal object keys are
57 # in all-caps, reserving all lower-case object keys for Pod::Simple and user
58 # arguments.
59 sub new {
60     my $class = shift;
61     my $self = $class->SUPER::new;
62
63     # Tell Pod::Simple to handle S<> by automatically inserting &nbsp;.
64     $self->nbsp_for_S (1);
65
66     # Tell Pod::Simple to keep whitespace whenever possible.
67     if ($self->can ('preserve_whitespace')) {
68         $self->preserve_whitespace (1);
69     } else {
70         $self->fullstop_space_harden (1);
71     }
72
73     # The =for and =begin targets that we accept.
74     $self->accept_targets (qw/text TEXT/);
75
76     # Ensure that contiguous blocks of code are merged together.  Otherwise,
77     # some of the guesswork heuristics don't work right.
78     $self->merge_text (1);
79
80     # Pod::Simple doesn't do anything useful with our arguments, but we want
81     # to put them in our object as hash keys and values.  This could cause
82     # problems if we ever clash with Pod::Simple's own internal class
83     # variables.
84     my %opts = @_;
85     my @opts = map { ("opt_$_", $opts{$_}) } keys %opts;
86     %$self = (%$self, @opts);
87
88     # Initialize various things from our parameters.
89     $$self{opt_alt}      = 0  unless defined $$self{opt_alt};
90     $$self{opt_indent}   = 4  unless defined $$self{opt_indent};
91     $$self{opt_margin}   = 0  unless defined $$self{opt_margin};
92     $$self{opt_loose}    = 0  unless defined $$self{opt_loose};
93     $$self{opt_sentence} = 0  unless defined $$self{opt_sentence};
94     $$self{opt_width}    = 76 unless defined $$self{opt_width};
95
96     # Figure out what quotes we'll be using for C<> text.
97     $$self{opt_quotes} ||= '"';
98     if ($$self{opt_quotes} eq 'none') {
99         $$self{LQUOTE} = $$self{RQUOTE} = '';
100     } elsif (length ($$self{opt_quotes}) == 1) {
101         $$self{LQUOTE} = $$self{RQUOTE} = $$self{opt_quotes};
102     } elsif ($$self{opt_quotes} =~ /^(.)(.)$/
103              || $$self{opt_quotes} =~ /^(..)(..)$/) {
104         $$self{LQUOTE} = $1;
105         $$self{RQUOTE} = $2;
106     } else {
107         croak qq(Invalid quote specification "$$self{opt_quotes}");
108     }
109
110     # If requested, do something with the non-POD text.
111     $self->code_handler (\&handle_code) if $$self{opt_code};
112
113     # Return the created object.
114     return $self;
115 }
116
117 ##############################################################################
118 # Core parsing
119 ##############################################################################
120
121 # This is the glue that connects the code below with Pod::Simple itself.  The
122 # goal is to convert the event stream coming from the POD parser into method
123 # calls to handlers once the complete content of a tag has been seen.  Each
124 # paragraph or POD command will have textual content associated with it, and
125 # as soon as all of a paragraph or POD command has been seen, that content
126 # will be passed in to the corresponding method for handling that type of
127 # object.  The exceptions are handlers for lists, which have opening tag
128 # handlers and closing tag handlers that will be called right away.
129 #
130 # The internal hash key PENDING is used to store the contents of a tag until
131 # all of it has been seen.  It holds a stack of open tags, each one
132 # represented by a tuple of the attributes hash for the tag and the contents
133 # of the tag.
134
135 # Add a block of text to the contents of the current node, formatting it
136 # according to the current formatting instructions as we do.
137 sub _handle_text {
138     my ($self, $text) = @_;
139     my $tag = $$self{PENDING}[-1];
140     $$tag[1] .= $text;
141 }
142
143 # Given an element name, get the corresponding method name.
144 sub method_for_element {
145     my ($self, $element) = @_;
146     $element =~ tr/-/_/;
147     $element =~ tr/A-Z/a-z/;
148     $element =~ tr/_a-z0-9//cd;
149     return $element;
150 }
151
152 # Handle the start of a new element.  If cmd_element is defined, assume that
153 # we need to collect the entire tree for this element before passing it to the
154 # element method, and create a new tree into which we'll collect blocks of
155 # text and nested elements.  Otherwise, if start_element is defined, call it.
156 sub _handle_element_start {
157     my ($self, $element, $attrs) = @_;
158     my $method = $self->method_for_element ($element);
159
160     # If we have a command handler, we need to accumulate the contents of the
161     # tag before calling it.
162     if ($self->can ("cmd_$method")) {
163         push (@{ $$self{PENDING} }, [ $attrs, '' ]);
164     } elsif ($self->can ("start_$method")) {
165         my $method = 'start_' . $method;
166         $self->$method ($attrs, '');
167     }
168 }
169
170 # Handle the end of an element.  If we had a cmd_ method for this element,
171 # this is where we pass along the text that we've accumulated.  Otherwise, if
172 # we have an end_ method for the element, call that.
173 sub _handle_element_end {
174     my ($self, $element) = @_;
175     my $method = $self->method_for_element ($element);
176
177     # If we have a command handler, pull off the pending text and pass it to
178     # the handler along with the saved attribute hash.
179     if ($self->can ("cmd_$method")) {
180         my $tag = pop @{ $$self{PENDING} };
181         my $method = 'cmd_' . $method;
182         my $text = $self->$method (@$tag);
183         if (defined $text) {
184             if (@{ $$self{PENDING} } > 1) {
185                 $$self{PENDING}[-1][1] .= $text;
186             } else {
187                 $self->output ($text);
188             }
189         }
190     } elsif ($self->can ("end_$method")) {
191         my $method = 'end_' . $method;
192         $self->$method ();
193     }
194 }
195
196 ##############################################################################
197 # Output formatting
198 ##############################################################################
199
200 # Wrap a line, indenting by the current left margin.  We can't use Text::Wrap
201 # because it plays games with tabs.  We can't use formline, even though we'd
202 # really like to, because it screws up non-printing characters.  So we have to
203 # do the wrapping ourselves.
204 sub wrap {
205     my $self = shift;
206     local $_ = shift;
207     my $output = '';
208     my $spaces = ' ' x $$self{MARGIN};
209     my $width = $$self{opt_width} - $$self{MARGIN};
210     while (length > $width) {
211         if (s/^([^\n]{0,$width})\s+// || s/^([^\n]{$width})//) {
212             $output .= $spaces . $1 . "\n";
213         } else {
214             last;
215         }
216     }
217     $output .= $spaces . $_;
218     $output =~ s/\s+$/\n\n/;
219     return $output;
220 }
221
222 # Reformat a paragraph of text for the current margin.  Takes the text to
223 # reformat and returns the formatted text.
224 sub reformat {
225     my $self = shift;
226     local $_ = shift;
227
228     # If we're trying to preserve two spaces after sentences, do some munging
229     # to support that.  Otherwise, smash all repeated whitespace.
230     if ($$self{opt_sentence}) {
231         s/ +$//mg;
232         s/\.\n/. \n/g;
233         s/\n/ /g;
234         s/   +/  /g;
235     } else {
236         s/\s+/ /g;
237     }
238     return $self->wrap ($_);
239 }
240
241 # Output text to the output device.
242 sub output {
243     my ($self, $text) = @_;
244     $text =~ tr/\240\255/ /d;
245     print { $$self{output_fh} } $text;
246 }
247
248 # Output a block of code (something that isn't part of the POD text).  Called
249 # by preprocess_paragraph only if we were given the code option.  Exists here
250 # only so that it can be overridden by subclasses.
251 sub output_code { $_[0]->output ($_[1]) }
252
253 ##############################################################################
254 # Document initialization
255 ##############################################################################
256
257 # Set up various things that have to be initialized on a per-document basis.
258 sub start_document {
259     my $self = shift;
260     my $margin = $$self{opt_indent} + $$self{opt_margin};
261
262     # Initialize a few per-document variables.
263     $$self{INDENTS} = [];       # Stack of indentations.
264     $$self{MARGIN}  = $margin;  # Default left margin.
265     $$self{PENDING} = [[]];     # Pending output.
266
267     return '';
268 }
269
270 ##############################################################################
271 # Text blocks
272 ##############################################################################
273
274 # This method is called whenever an =item command is complete (in other words,
275 # we've seen its associated paragraph or know for certain that it doesn't have
276 # one).  It gets the paragraph associated with the item as an argument.  If
277 # that argument is empty, just output the item tag; if it contains a newline,
278 # output the item tag followed by the newline.  Otherwise, see if there's
279 # enough room for us to output the item tag in the margin of the text or if we
280 # have to put it on a separate line.
281 sub item {
282     my ($self, $text) = @_;
283     my $tag = $$self{ITEM};
284     unless (defined $tag) {
285         carp "Item called without tag";
286         return;
287     }
288     undef $$self{ITEM};
289
290     # Calculate the indentation and margin.  $fits is set to true if the tag
291     # will fit into the margin of the paragraph given our indentation level.
292     my $indent = $$self{INDENTS}[-1];
293     $indent = $$self{opt_indent} unless defined $indent;
294     my $margin = ' ' x $$self{opt_margin};
295     my $fits = ($$self{MARGIN} - $indent >= length ($tag) + 1);
296
297     # If the tag doesn't fit, or if we have no associated text, print out the
298     # tag separately.  Otherwise, put the tag in the margin of the paragraph.
299     if (!$text || $text =~ /^\s+$/ || !$fits) {
300         my $realindent = $$self{MARGIN};
301         $$self{MARGIN} = $indent;
302         my $output = $self->reformat ($tag);
303         $output =~ s/^$margin /$margin:/ if ($$self{opt_alt} && $indent > 0);
304         $output =~ s/\n*$/\n/;
305
306         # If the text is just whitespace, we have an empty item paragraph;
307         # this can result from =over/=item/=back without any intermixed
308         # paragraphs.  Insert some whitespace to keep the =item from merging
309         # into the next paragraph.
310         $output .= "\n" if $text && $text =~ /^\s*$/;
311
312         $self->output ($output);
313         $$self{MARGIN} = $realindent;
314         $self->output ($self->reformat ($text)) if ($text && $text =~ /\S/);
315     } else {
316         my $space = ' ' x $indent;
317         $space =~ s/^$margin /$margin:/ if $$self{opt_alt};
318         $text = $self->reformat ($text);
319         $text =~ s/^$margin /$margin:/ if ($$self{opt_alt} && $indent > 0);
320         my $tagspace = ' ' x length $tag;
321         $text =~ s/^($space)$tagspace/$1$tag/ or warn "Bizarre space in item";
322         $self->output ($text);
323     }
324 }
325
326 # Handle a basic block of text.  The only tricky thing here is that if there
327 # is a pending item tag, we need to format this as an item paragraph.
328 sub cmd_para {
329     my ($self, $attrs, $text) = @_;
330     $text =~ s/\s+$/\n/;
331     if (defined $$self{ITEM}) {
332         $self->item ($text . "\n");
333     } else {
334         $self->output ($self->reformat ($text . "\n"));
335     }
336     return '';
337 }
338
339 # Handle a verbatim paragraph.  Just print it out, but indent it according to
340 # our margin.
341 sub cmd_verbatim {
342     my ($self, $attrs, $text) = @_;
343     $self->item if defined $$self{ITEM};
344     return if $text =~ /^\s*$/;
345     $text =~ s/^(\n*)(\s*\S+)/$1 . (' ' x $$self{MARGIN}) . $2/gme;
346     $text =~ s/\s*$/\n\n/;
347     $self->output ($text);
348     return '';
349 }
350
351 # Handle literal text (produced by =for and similar constructs).  Just output
352 # it with the minimum of changes.
353 sub cmd_data {
354     my ($self, $attrs, $text) = @_;
355     $text =~ s/^\n+//;
356     $text =~ s/\n{0,2}$/\n/;
357     $self->output ($text);
358     return '';
359 }
360
361 ##############################################################################
362 # Headings
363 ##############################################################################
364
365 # The common code for handling all headers.  Takes the header text, the
366 # indentation, and the surrounding marker for the alt formatting method.
367 sub heading {
368     my ($self, $text, $indent, $marker) = @_;
369     $self->item ("\n\n") if defined $$self{ITEM};
370     $text =~ s/\s+$//;
371     if ($$self{opt_alt}) {
372         my $closemark = reverse (split (//, $marker));
373         my $margin = ' ' x $$self{opt_margin};
374         $self->output ("\n" . "$margin$marker $text $closemark" . "\n\n");
375     } else {
376         $text .= "\n" if $$self{opt_loose};
377         my $margin = ' ' x ($$self{opt_margin} + $indent);
378         $self->output ($margin . $text . "\n");
379     }
380     return '';
381 }
382
383 # First level heading.
384 sub cmd_head1 {
385     my ($self, $attrs, $text) = @_;
386     $self->heading ($text, 0, '====');
387 }
388
389 # Second level heading.
390 sub cmd_head2 {
391     my ($self, $attrs, $text) = @_;
392     $self->heading ($text, $$self{opt_indent} / 2, '==  ');
393 }
394
395 # Third level heading.
396 sub cmd_head3 {
397     my ($self, $attrs, $text) = @_;
398     $self->heading ($text, $$self{opt_indent} * 2 / 3 + 0.5, '=   ');
399 }
400
401 # Fourth level heading.
402 sub cmd_head4 {
403     my ($self, $attrs, $text) = @_;
404     $self->heading ($text, $$self{opt_indent} * 3 / 4 + 0.5, '-   ');
405 }
406
407 ##############################################################################
408 # List handling
409 ##############################################################################
410
411 # Handle the beginning of an =over block.  Takes the type of the block as the
412 # first argument, and then the attr hash.  This is called by the handlers for
413 # the four different types of lists (bullet, number, text, and block).
414 sub over_common_start {
415     my ($self, $attrs) = @_;
416     $self->item ("\n\n") if defined $$self{ITEM};
417
418     # Find the indentation level.
419     my $indent = $$attrs{indent};
420     unless (defined ($indent) && $indent =~ /^\s*[-+]?\d{1,4}\s*$/) {
421         $indent = $$self{opt_indent};
422     }
423
424     # Add this to our stack of indents and increase our current margin.
425     push (@{ $$self{INDENTS} }, $$self{MARGIN});
426     $$self{MARGIN} += ($indent + 0);
427     return '';
428 }
429
430 # End an =over block.  Takes no options other than the class pointer.  Output
431 # any pending items and then pop one level of indentation.
432 sub over_common_end {
433     my ($self) = @_;
434     $self->item ("\n\n") if defined $$self{ITEM};
435     $$self{MARGIN} = pop @{ $$self{INDENTS} };
436     return '';
437 }
438
439 # Dispatch the start and end calls as appropriate.
440 sub start_over_bullet { $_[0]->over_common_start ($_[1]) }
441 sub start_over_number { $_[0]->over_common_start ($_[1]) }
442 sub start_over_text   { $_[0]->over_common_start ($_[1]) }
443 sub start_over_block  { $_[0]->over_common_start ($_[1]) }
444 sub end_over_bullet { $_[0]->over_common_end }
445 sub end_over_number { $_[0]->over_common_end }
446 sub end_over_text   { $_[0]->over_common_end }
447 sub end_over_block  { $_[0]->over_common_end }
448
449 # The common handler for all item commands.  Takes the type of the item, the
450 # attributes, and then the text of the item.
451 sub item_common {
452     my ($self, $type, $attrs, $text) = @_;
453     $self->item if defined $$self{ITEM};
454
455     # Clean up the text.  We want to end up with two variables, one ($text)
456     # which contains any body text after taking out the item portion, and
457     # another ($item) which contains the actual item text.  Note the use of
458     # the internal Pod::Simple attribute here; that's a potential land mine.
459     $text =~ s/\s+$//;
460     my ($item, $index);
461     if ($type eq 'bullet') {
462         $item = '*';
463     } elsif ($type eq 'number') {
464         $item = $$attrs{'~orig_content'};
465     } else {
466         $item = $text;
467         $item =~ s/\s*\n\s*/ /g;
468         $text = '';
469     }
470     $$self{ITEM} = $item;
471
472     # If body text for this item was included, go ahead and output that now.
473     if ($text) {
474         $text =~ s/\s*$/\n/;
475         $self->item ($text);
476     }
477     return '';
478 }
479
480 # Dispatch the item commands to the appropriate place.
481 sub cmd_item_bullet { my $self = shift; $self->item_common ('bullet', @_) }
482 sub cmd_item_number { my $self = shift; $self->item_common ('number', @_) }
483 sub cmd_item_text   { my $self = shift; $self->item_common ('text',   @_) }
484 sub cmd_item_block  { my $self = shift; $self->item_common ('block',  @_) }
485
486 ##############################################################################
487 # Formatting codes
488 ##############################################################################
489
490 # The simple ones.
491 sub cmd_b { return $_[0]{alt} ? "``$_[2]''" : $_[2] }
492 sub cmd_f { return $_[0]{alt} ? "\"$_[2]\"" : $_[2] }
493 sub cmd_i { return '*' . $_[2] . '*' }
494 sub cmd_x { return '' }
495
496 # Apply a whole bunch of messy heuristics to not quote things that don't
497 # benefit from being quoted.  These originally come from Barrie Slaymaker and
498 # largely duplicate code in Pod::Man.
499 sub cmd_c {
500     my ($self, $attrs, $text) = @_;
501
502     # A regex that matches the portion of a variable reference that's the
503     # array or hash index, separated out just because we want to use it in
504     # several places in the following regex.
505     my $index = '(?: \[.*\] | \{.*\} )?';
506
507     # Check for things that we don't want to quote, and if we find any of
508     # them, return the string with just a font change and no quoting.
509     $text =~ m{
510       ^\s*
511       (?:
512          ( [\'\`\"] ) .* \1                             # already quoted
513        | \` .* \'                                       # `quoted'
514        | \$+ [\#^]? \S $index                           # special ($^Foo, $")
515        | [\$\@%&*]+ \#? [:\'\w]+ $index                 # plain var or func
516        | [\$\@%&*]* [:\'\w]+ (?: -> )? \(\s*[^\s,]\s*\) # 0/1-arg func call
517        | [+-]? ( \d[\d.]* | \.\d+ ) (?: [eE][+-]?\d+ )? # a number
518        | 0x [a-fA-F\d]+                                 # a hex constant
519       )
520       \s*\z
521      }xo && return $text;
522
523     # If we didn't return, go ahead and quote the text.
524     return $$self{opt_alt}
525         ? "``$text''"
526         : "$$self{LQUOTE}$text$$self{RQUOTE}";
527 }
528
529 # Links reduce to the text that we're given, wrapped in angle brackets if it's
530 # a URL.
531 sub cmd_l {
532     my ($self, $attrs, $text) = @_;
533     return $$attrs{type} eq 'url' ? "<$text>" : $text;
534 }
535
536 ##############################################################################
537 # Backwards compatibility
538 ##############################################################################
539
540 # The old Pod::Text module did everything in a pod2text() function.  This
541 # tries to provide the same interface for legacy applications.
542 sub pod2text {
543     my @args;
544
545     # This is really ugly; I hate doing option parsing in the middle of a
546     # module.  But the old Pod::Text module supported passing flags to its
547     # entry function, so handle -a and -<number>.
548     while ($_[0] =~ /^-/) {
549         my $flag = shift;
550         if    ($flag eq '-a')       { push (@args, alt => 1)    }
551         elsif ($flag =~ /^-(\d+)$/) { push (@args, width => $1) }
552         else {
553             unshift (@_, $flag);
554             last;
555         }
556     }
557
558     # Now that we know what arguments we're using, create the parser.
559     my $parser = Pod::Text->new (@args);
560
561     # If two arguments were given, the second argument is going to be a file
562     # handle.  That means we want to call parse_from_filehandle(), which means
563     # we need to turn the first argument into a file handle.  Magic open will
564     # handle the <&STDIN case automagically.
565     if (defined $_[1]) {
566         my @fhs = @_;
567         local *IN;
568         unless (open (IN, $fhs[0])) {
569             croak ("Can't open $fhs[0] for reading: $!\n");
570             return;
571         }
572         $fhs[0] = \*IN;
573         $parser->output_fh ($fhs[1]);
574         my $retval = $parser->parse_file ($fhs[0]);
575         my $fh = $parser->output_fh ();
576         close $fh;
577         return $retval;
578     } else {
579         return $parser->parse_file (@_);
580     }
581 }
582
583 # Reset the underlying Pod::Simple object between calls to parse_from_file so
584 # that the same object can be reused to convert multiple pages.
585 sub parse_from_file {
586     my $self = shift;
587     $self->reinit;
588
589     # Fake the old cutting option to Pod::Parser.  This fiddings with internal
590     # Pod::Simple state and is quite ugly; we need a better approach.
591     if (ref ($_[0]) eq 'HASH') {
592         my $opts = shift @_;
593         if (defined ($$opts{-cutting}) && !$$opts{-cutting}) {
594             $$self{in_pod} = 1;
595             $$self{last_was_blank} = 1;
596         }
597     }
598
599     # Do the work.
600     my $retval = $self->Pod::Simple::parse_from_file (@_);
601
602     # Flush output, since Pod::Simple doesn't do this.  Ideally we should also
603     # close the file descriptor if we had to open one, but we can't easily
604     # figure this out.
605     my $fh = $self->output_fh ();
606     my $oldfh = select $fh;
607     my $oldflush = $|;
608     $| = 1;
609     print $fh '';
610     $| = $oldflush;
611     select $oldfh;
612     return $retval;
613 }
614
615 # Pod::Simple failed to provide this backward compatibility function, so
616 # implement it ourselves.  File handles are one of the inputs that
617 # parse_from_file supports.
618 sub parse_from_filehandle {
619     my $self = shift;
620     $self->parse_from_file (@_);
621 }
622
623 ##############################################################################
624 # Module return value and documentation
625 ##############################################################################
626
627 1;
628 __END__
629
630 =head1 NAME
631
632 Pod::Text - Convert POD data to formatted ASCII text
633
634 =for stopwords
635 alt Allbery Sean Burke's
636
637 =head1 SYNOPSIS
638
639     use Pod::Text;
640     my $parser = Pod::Text->new (sentence => 0, width => 78);
641
642     # Read POD from STDIN and write to STDOUT.
643     $parser->parse_from_filehandle;
644
645     # Read POD from file.pod and write to file.txt.
646     $parser->parse_from_file ('file.pod', 'file.txt');
647
648 =head1 DESCRIPTION
649
650 Pod::Text is a module that can convert documentation in the POD format (the
651 preferred language for documenting Perl) into formatted ASCII.  It uses no
652 special formatting controls or codes whatsoever, and its output is therefore
653 suitable for nearly any device.
654
655 As a derived class from Pod::Simple, Pod::Text supports the same methods and
656 interfaces.  See L<Pod::Simple> for all the details; briefly, one creates a
657 new parser with C<< Pod::Text->new() >> and then normally calls parse_file().
658
659 new() can take options, in the form of key/value pairs, that control the
660 behavior of the parser.  The currently recognized options are:
661
662 =over 4
663
664 =item alt
665
666 If set to a true value, selects an alternate output format that, among other
667 things, uses a different heading style and marks C<=item> entries with a
668 colon in the left margin.  Defaults to false.
669
670 =item code
671
672 If set to a true value, the non-POD parts of the input file will be included
673 in the output.  Useful for viewing code documented with POD blocks with the
674 POD rendered and the code left intact.
675
676 =item indent
677
678 The number of spaces to indent regular text, and the default indentation for
679 C<=over> blocks.  Defaults to 4.
680
681 =item loose
682
683 If set to a true value, a blank line is printed after a C<=head1> heading.
684 If set to false (the default), no blank line is printed after C<=head1>,
685 although one is still printed after C<=head2>.  This is the default because
686 it's the expected formatting for manual pages; if you're formatting
687 arbitrary text documents, setting this to true may result in more pleasing
688 output.
689
690 =item margin
691
692 The width of the left margin in spaces.  Defaults to 0.  This is the margin
693 for all text, including headings, not the amount by which regular text is
694 indented; for the latter, see the I<indent> option.  To set the right
695 margin, see the I<width> option.
696
697 =item quotes
698
699 Sets the quote marks used to surround CE<lt>> text.  If the value is a
700 single character, it is used as both the left and right quote; if it is two
701 characters, the first character is used as the left quote and the second as
702 the right quoted; and if it is four characters, the first two are used as
703 the left quote and the second two as the right quote.
704
705 This may also be set to the special value C<none>, in which case no quote
706 marks are added around CE<lt>> text.
707
708 =item sentence
709
710 If set to a true value, Pod::Text will assume that each sentence ends in two
711 spaces, and will try to preserve that spacing.  If set to false, all
712 consecutive whitespace in non-verbatim paragraphs is compressed into a
713 single space.  Defaults to true.
714
715 =item width
716
717 The column at which to wrap text on the right-hand side.  Defaults to 76.
718
719 =back
720
721 The standard Pod::Simple method parse_file() takes one argument, the file or
722 file handle to read from, and writes output to standard output unless that
723 has been changed with the output_fh() method.  See L<Pod::Simple> for the
724 specific details and for other alternative interfaces.
725
726 =head1 DIAGNOSTICS
727
728 =over 4
729
730 =item Bizarre space in item
731
732 =item Item called without tag
733
734 (W) Something has gone wrong in internal C<=item> processing.  These
735 messages indicate a bug in Pod::Text; you should never see them.
736
737 =item Can't open %s for reading: %s
738
739 (F) Pod::Text was invoked via the compatibility mode pod2text() interface
740 and the input file it was given could not be opened.
741
742 =item Invalid quote specification "%s"
743
744 (F) The quote specification given (the quotes option to the constructor) was
745 invalid.  A quote specification must be one, two, or four characters long.
746
747 =back
748
749 =head1 NOTES
750
751 This is a replacement for an earlier Pod::Text module written by Tom
752 Christiansen.  It has a revamped interface, since it now uses Pod::Simple,
753 but an interface roughly compatible with the old Pod::Text::pod2text()
754 function is still available.  Please change to the new calling convention,
755 though.
756
757 The original Pod::Text contained code to do formatting via termcap
758 sequences, although it wasn't turned on by default and it was problematic to
759 get it to work at all.  This rewrite doesn't even try to do that, but a
760 subclass of it does.  Look for L<Pod::Text::Termcap>.
761
762 =head1 SEE ALSO
763
764 L<Pod::Simple>, L<Pod::Text::Termcap>, L<pod2text(1)>
765
766 The current version of this module is always available from its web site at
767 L<http://www.eyrie.org/~eagle/software/podlators/>.  It is also part of the
768 Perl core distribution as of 5.6.0.
769
770 =head1 AUTHOR
771
772 Russ Allbery <rra@stanford.edu>, based I<very> heavily on the original
773 Pod::Text by Tom Christiansen <tchrist@mox.perl.com> and its conversion to
774 Pod::Parser by Brad Appleton <bradapp@enteract.com>.  Sean Burke's initial
775 conversion of Pod::Man to use Pod::Simple provided much-needed guidance on
776 how to use Pod::Simple.
777
778 =head1 COPYRIGHT AND LICENSE
779
780 Copyright 1999, 2000, 2001, 2002, 2004, 2006, 2008 Russ Allbery
781 <rra@stanford.edu>.
782
783 This program is free software; you may redistribute it and/or modify it
784 under the same terms as Perl itself.
785
786 =cut