CC: | jkeenan [...] cpan.org |
Subject: | [RT #115534]: Pod::Usage Failes to Select -sections with Negation |
The following bug report was originally filed in the Perl 5 bug queue at
https://rt.perl.org/rt3/Ticket/Display.html?id=115534. According to
Porting/Maintainers.pl, Pod-Parser, of which Pod::Usage is a component,
is primarily maintained on CPAN. I am therefore moving this report to
this queue. -- Jim Keenan
#####
This is a bug report for perl from david@justatheory.com, generated with
the help of perlbug 1.39 running under perl 5.16.1.
Given this script:
#!/usr/bin/perl -w
use strict;
use Pod::Usage;
my $h2 = shift or die qq{Pass "Foo" or "Bar"\n};
Pod::Usage::pod2usage(
'-verbose' => 99,
'-exitval' => 1,
'-sections' => "Name/$h2/!.+",
);
=head1 Name
Testing
=head2 Foo
This is foo
=head3 Foo bar
This is foo bar.
=head2 Bar
This is bar.
=head3 Bar baz
This is bar baz.
When passed "Foo", it properly outputs:
Foo:
This is foo.
If it's passed "Bar", it outputs nothing. I expect it to output:
Bar:
This is bar.
I think, but am not sure, that the bug is in _handle_element_end(),
where it compares the -sections regular rexpressions to the headers. It
appears that Once it hits an `=head3` (in this case, "Foo bar"), it
never looks at `=head2` sections again. It skips from "Foo bar"
to "Bar baz" without ever looking at "Bar".
Note that if I force Pod::Usage to inherit from Pod::PlainText instead
of Pod::Text that the bug does not appear.
#####
In a follow-up post, I noted that I believe the bug to lie in this part
of Pod::Usage::_handle_element_end():
#####
677 my @headings = @{$$self{USAGE_HEADINGS}};
678 for my $section_spec ( @{$$self{USAGE_SELECT}} ) {
679 my $match = 1;
680 for (my $i = 0; $i < $Pod::Select::MAX_HEADING_LEVEL; ++$i) {
681 $headings[$i] = '' unless defined $headings[$i];
682 my $regex = $section_spec->[$i];
683 my $negated = ($regex =~ s/^\!//);
684 $match &= ($negated ? ($headings[$i] !~ /${regex}/)
685 : ($headings[$i] =~ /${regex}/));
686 last unless ($match);
687 } # end heading levels
688 if ($match) {
689 $$self{USAGE_SKIPPING} = 0;
690 last;
691 }
692 } # end sections
#####
Thank you very much.
Jim Keenan