Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Pod-Simple CPAN distribution.

Report information
The Basics
Id: 105220
Status: resolved
Priority: 0/
Queue: Pod-Simple

People
Owner: Nobody in particular
Requestors: VDB [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 3.29
Fixed in: 3.32



Subject: There is no simple way to get POD errors.
If parser finds any errors in POD, it either send them to stderr, or creates a special section at the end. Caller does not have a simple way to get error messages. I am working on a plugin for a third-party system. Plugin should report any errors via $logger->log( $message ), so neither stderr nor added section is convenient to me. I would like to have some method to get parsing errors, for example: $parser->no_errata_section( 0 ); $parser->complain_stderr( 0 ); $parser->parse_...( ... ); if ( $parser->any_errata_seen() ) { $logger->log( $parser->errata_seen() ); }
I was able to achieve my goal by redefining _complain_warn function: no warnings 'redefine'; local *Pod::Simple::_complain_warn = sub { my ( $self, $line, $complaint ) = @_; $logger->log( sprintf( ... ) ); }; However, it looks like a dirty hack, not a solution: _complain_warn is not documented. The hack works for current version, but there is no guarantee it will work in the next one.
Subject: Test::Pod::No404s has similar problem
Note that I am not the only person who faced this issue. Look at Test::Pod::No404s module by Apocalypse, line ~69 # is POD well-formed? if ( $parser->any_errata_seen ) { ... # TODO ugly, but there is no other way to get at it? foreach my $l ( keys %{ $parser->{errata} } ) { $Test->diag( " * errors seen in line $l:" ); $Test->diag( " * $_" ) for @{ $parser->{errata}{$l} }; } } https://metacpan.org/source/APOCAL/Test-Pod-No404s-0.02/lib/Test/Pod/No404s.pm
Unless I'm reading the ticket wrong, it is invalid. Suppose there were really no feature in Pod::Simple that allows access to the messages, as claimed. One can direct the output to STDERR, as the ticket mentions, and then use something like this to collect them: package Tie_Array_to_FH { # So printing actually goes to an array my %array; sub TIEHANDLE { my $class = shift; my $array_ref = shift; my $self = bless \do{ my $anonymous_scalar }, $class; $array{Scalar::Util::refaddr $self} = $array_ref; return $self; } sub PRINT { my $self = shift; push @{$array{Scalar::Util::refaddr $self}}, @_; return 1; } } But the premise is wrong. One can use my $errata = $parser->errata_seen(); foreach my $line_number (sort { $a <=> $b } keys %$errata) { foreach my $err_msg (sort @{$errata->{$line_number}}) { # $err_msg contains an error message for $line_number } } to get all the generated warnings. So, unless I hear otherwise within a month, I will close this ticket
On Sun May 20 14:00:49 2018, khw wrote: Show quoted text
> One can use > > my $errata = $parser->errata_seen(); > ... > to get all the generated warnings.
Your analysis is a bit late. This ticket was created on 2015-06-13. errata_seen method was introduced in v3.32 released on 2015-11-02 (in order to fulfill this request).