Skip to content

Commit

Permalink
Fix bug that makes X<>'s contents show up in node()
Browse files Browse the repository at this point in the history
  • Loading branch information
marcgreen committed Oct 18, 2011
1 parent d233f19 commit f4e1f0f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
43 changes: 22 additions & 21 deletions cpan/Pod-Parser/lib/Pod/Checker.pm
Expand Up @@ -570,6 +570,7 @@ collapsed to a single blank.
sub node {
my ($self,$text) = @_;
if(defined $text) {
$text =~ s/\s+$//s; # strip trailing whitespace
$text =~ s/\s+/ /gs; # collapse whitespace
# add node, order important!
push(@{$self->{'_nodes'}}, $text);
Expand All @@ -594,6 +595,7 @@ of whitespace is collapsed to a single blank.
sub idx {
my ($self,$text) = @_;
if(defined $text) {
$text =~ s/\s+$//s; # strip trailing whitespace
$text =~ s/\s+/ /gs; # collapse whitespace
# add node, order important!
push(@{$self->{'_index'}}, $text);
Expand Down Expand Up @@ -724,6 +726,8 @@ sub _check_angles {
sub handle_text { $_[0]->_check_angles($_[0]{'_thispara'} .= $_[1]) }

# whiteline is a seemingly blank line that matches /[\t ]/
# XXX too strict -- should only warn if whiteline is at end of paragraph (what is that?)
# or is it?
sub handle_whiteline {
my ($line, $line_n, $self) = @_;
$self->poderror({
Expand Down Expand Up @@ -804,18 +808,7 @@ sub end_head {
my $arg = $self->{'_head_text'} = $self->{'_thispara'};
$self->{'_cmds_since_head'} = 0;
my $h = $self->{'_head_num'};

#warn $arg;

# XXX Fcodes have their content extracted and placed in $arg.
# This is bad news for X<...>, as that should not be visible
# also, L<>s should be formatted differently
# splice '_thispara' in end_X maybe
# OR, have each fcode generate text (L would be 'Y in Z')
# and X would be '', and use that to make up _thispara
# test this in podchkinter.t
$self->node($arg); # remember this node

if ($arg eq '') {
$self->poderror({ -line => $self->{'_line'},
-severity => 'ERROR',
Expand Down Expand Up @@ -882,8 +875,7 @@ sub end_item {

my $list = $self->{'_list_stack'}->[0];
$list->item($self->{'_thispara'}); # add item to list
# XXX compare new pod::checker interface to old one
# specifically, are there leading *s and numbers in item()s?
# XXX add tests to podchkinter.t for =item and node()

$self->node($self->{'_thispara'}); # remember this node
}
Expand Down Expand Up @@ -913,13 +905,21 @@ sub end_Document {
$self->num_errors(-1) && return unless $self->content_seen;

my %nodes;
$nodes{$_}++ for $self->node();
# XXX Pod::Checker did something if node had whitespace, or if node was idx
# -- do I need that here?

# XXX will $link->node() and $self->node() be E<> escaped, etc?
for ($self->node()) {
$nodes{$_} = 1;
if(/^(\S+)\s+\S/) {
# we have more than one word. Use the first as a node, too.
# This is used heavily in perlfunc.pod
$nodes{$1} ||= 2; # derived node
}
}
for ($self->idx()) {
$nodes{$_} = 3; # index node
}

# XXX update unresolved internal link POD -- single word not enclosed in ""?
# I don't know what I was thinking when I made the above TODO, and I don't
# know what it means

for ($self->hyperlink()) {
my ($line, $link) = @$_;
Expand Down Expand Up @@ -1012,9 +1012,10 @@ sub start_X {
}
sub end_X {
my $self = shift;
# extract contents of X<>
my $x = substr($self->{'_thispara'},
pop $self->{'_fcode_pos'}); # start at the beginning of X<>
# extract contents of X<> and replace with ''
my $start = pop $self->{'_fcode_pos'}; # start at the beginning of X<>
my $end = length($self->{'_thispara'}) - $start; # end at end of X<>
my $x = substr($self->{'_thispara'}, $start, $end, '');
unless ($x) {
$self->poderror({ -line => $self->{'_line'},
-severity => 'ERROR',
Expand Down
7 changes: 4 additions & 3 deletions cpan/Pod-Parser/t/pod/podchkinter.t
Expand Up @@ -5,14 +5,14 @@ use 5.14.0;
use Pod::Checker;
use Data::Dumper;
use Test::More;
BEGIN { plan tests => 85 };
BEGIN { plan tests => 88 };

my ($infile, $outfile) = ("tempin.tmp", "tempout.tmp");

my $pods = [
{in => "=head2 easy warning\n\nX<random>",
{in => "=head2 easy X<id> warning\n\nX<random>",
node => ["easy warning"],
idx => ["random"],
idx => [qw/id random/],
warn => 1,
},
{in => "=head1 h1\n\n=head2 h2\n\n=over\n\n=item i1\n\n=item i2\n\n=back",
Expand All @@ -34,6 +34,7 @@ my $pods = [
idx => [qw/i1 i2 i3/],
errs => 2,
warn => 2,
node => ['', 'h1'],
},
];

Expand Down

0 comments on commit f4e1f0f

Please sign in to comment.