On Wed, 2014-06-25 at 18:05 +0000, John E Guillory wrote:
> Hello,
>
> I thought I wasn’t this new to perl but …
>
> How does one use pod::simple::text to print out a section of POD, say
> the DESCRIPTION section? 

Pod::Simple provides some core POD parsing functionality which is shared
by a number of formatter classes.  There isn't any sort of query API
that would allow you to specify which sections of the POD you want.

If you do want to produce formatted plain-text output of just the
DESCRIPTION section, then probably the easiest way is to slurp in all
the POD source; use a regex to extract the section you want; and then
pass that to a formatter:

  my($pod_source) =
      read_file($source_file) =~ 
          m{^(=head1\s+DESCRIPTION.*?)(?:^=head1.*)?\z}ms;

  my $parser = Pod::Simple::Text->new();
  $parser->parse_string_document($pod_source);

The parser(/formatter) will write its output to STDOUT unless you call
$parser->output_fh with an alternative filehandle.

An alternative approach would be to subclass Pod::Simple::Text and
maintain a flag indicating when the parser is 'in' the DESCRIPTION
section and suppress all output when the flag is not set.  Unfortunately
the "suppress all output" bit is tricky since all the methods that
produce formatted output write directly to the output filehandle.

Regards
Grant


Reply via email to