rra / podlators

Format POD source into various output formats
https://www.eyrie.org/~eagle/software/podlators/
Other
6 stars 11 forks source link

Add parse_from_string function #11

Closed macrotex closed 5 years ago

macrotex commented 5 years ago

I have reason to use Pod::Text with strings rather than files or filehandles. Please add a "parse_from_string" function that would work something like

# Read POD from string and return to a string
my $pod_string = "=pod\n\n\head1 Head 1\n\n...=cut";
my $pod_output = $parser->parse_from_string($pod_string);

While this can be worked around using temporary files, a more direct string version would be helpful.

rra commented 5 years ago

This is already supported and documented in the Pod::Text man page:

You can also call parse_lines() to parse an array of lines or parse_string_document() to parse a document already in memory. As with parse_file(), parse_lines() and parse_string_document() default to sending their output to "STDOUT" unless changed with the output_fh() method.

To put the output from any parse method into a string instead of a file handle, call the output_string() method instead of output_fh().

See Pod::Simple for more specific details on the methods available to all derived parsers.