Subject: | Calling parse_from_file twice causes errors |
The following code exposes a Pod::Parser crash:
use Pod::Parser;
use IO::String;
use Carp;
$SIG{__DIE__} = \&Carp::confess;
{
my $pod_string = '';
my $handle = IO::String->new( \$pod_string );
my $parser = Pod::Parser->new();
$parser->parse_from_file( $0, $handle );
}
{
my $parser = Pod::Parser->new();
$parser->parse_from_file( $0, '/dev/null' );
}
The result on Perl 5.8.6 on MacOSX 10.4 is:
% perl foo.pl
Can't locate object method "OPEN" via package "IO::String" at
/Users/chris/perl/System/Library/Perl/5.8.6/Pod/Parser.pm line 1239.
at /Users/chris/perl/System/Library/Perl/5.8.6/Pod/Parser.pm line 1239
Pod::Parser::parse_from_file('Pod::Parser=HASH(0x18015a8)',
'foo.pl', '/dev/null') called at foo.pl line 16
So, it appears that the IO::String instance is being cached erroneously
across calls to parse_from_file.
This error occurs in the real world when running Devel::Cover on
Perl::Critic::Violation. The latter uses an IO::String with
Pod::PlainText to extract it's own diagnostics from POD while the former
uses Pod::Parser via Pod::Coverage to count the number of subroutines
which have POD.
I've worked around the problem by using parse_from_filehandle instead of
parse_from_file in Perl::Critic::Violation.