Search code examples
perlstdoutperl-pod

No output from Pod::Simple


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?


Solution

  • 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