2

I'm trying to use Pod::Simple in perl, but I'm not getting any output. I can get output with Pod::Simple::Text. Here is a short test program:

use English;
use strict;
use Pod::Simple;
use Pod::Simple::Text;

my $pod_document = <<END_POD;
=pod

=head1 NAME

something

=head1 SYNOPSIS

something else

=cut
END_POD

my $pod_parser = new Pod::Simple();
my $pod_output;
if  ($ARGV[0] == 1) {$pod_parser->output_fh(*STDOUT);}
if  ($ARGV[0] == 2) {$pod_parser->output_fh(\*STDOUT);}
if  ($ARGV[0] == 3) {$pod_parser->output_fh(*STDOUT{IO});}
if  ($ARGV[0] == 4) {$pod_parser->output_string(\$pod_output);}
if  ($ARGV[0] == 5) {Pod::Simple::Text->filter(\$pod_document);}
$pod_parser->parse_string_document(\$pod_document);
if  ($ARGV[0] == 4) {print $pod_output;}

exit 0;

I put this perl code into a file named pod-test.pl. If I run it with the command line argument 1, 2, 3, or 4, I get no output. 'perl pod-test.pl 5' works fine.

How am I supposed to call the output_fh or output_string methods?

Kara
  • 6,115
  • 16
  • 50
  • 57
David Levner
  • 341
  • 1
  • 8

1 Answers1

4

The Pod::Simple module is intended to be used as a base class for a Pod formatter subclass that you write yourself. The subclass provides the methods that generate the final document, so without it Pod::Simple won't produce any output at all, as you have seen.

If all you want is simple text output, then a subclass has already been written for you in Pod::Simple::Text. You would use it like this

use strict;
use warnings;

use English;
use strict;
use Pod::Simple::Text;

my $pod_document = <<END_POD;
=pod

=head1 NAME

something

=head1 SYNOPSIS

something else

=cut
END_POD

my $pod_parser = Pod::Simple::Text->new;
$pod_parser->output_fh(*STDOUT);
$pod_parser->parse_string_document($pod_document);

output

NAME

    something

SYNOPSIS

    something else
Borodin
  • 126,100
  • 9
  • 70
  • 144
  • Thanks for chiming in with one of your standard quality answers. Always appreciate learning new things. – Miller May 29 '14 at 04:51
  • Thanks. I made the changes and the code now works in my environment. The other mistake I made was passing a scalar reference to the parse_string_document method, $pod_parser->parse_string_document(\$pod_document), instead of simply passing a scalar, $pod_parser->parse_string_document($pod_document), as you did. – David Levner May 29 '14 at 13:06
  • @DavidLevner: I'm pleased that you got it going. What troubles me is that you say in your question, *"I can get output with `Pod::Simple::Text`"*, which I overlooked when I wrote my solution. So it seems you may have had the answer already and I wonder why you wanted to get it working a different way? – Borodin May 29 '14 at 13:15