Skip to content

Commit 6366047

Browse files
committed
podcheck.t: Fix multiple link targets bug
podcheck.t would wrongly warn about duplicate link targets. It is ambiguous if you have, say =head1 foo ... =item foo and then try to create a link to 'foo'. Which 'foo' should it go to? So podcheck looks for such ambiguous links. However, it was incorrectly warning on =head1 foo ... =item * foo The latter is a bullet list, which is not an appropriate link target. The logic was flawed in the node() method, when it encountered the second foo, it didn't realize it was for a bullet list, and pushed it onto a list which caused the count to be larger than 1, which caused it later to think there were two link targets with the same name. The solution here is to instead note that linkable targets are only in =headN or definition lists. The acquisition of the names of them are moved to the methods that get called upon the termination of each of these by the parsing routines. The count is incremented at that point. This means the node() method extension no longer does anything useful and is removed; as well as an auxiliary field, linkable_item. We no longer need to distinguish between =headN and =item.
1 parent 0dfde78 commit 6366047

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

t/porting/podcheck.t

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,6 @@ package My::Pod::Checker { # Extend Pod::Checker
697697
my %in_NAME; # true if within NAME section
698698
my %in_begin; # true if within =begin section
699699
my %in_X; # true if in a X<>
700-
my %linkable_item; # Bool: if the latest =item is linkable. It isn't
701-
# for bullet and number lists
702700
my %linkable_nodes; # Pod::Checker adds all =items to its node list,
703701
# but not all =items are linkable-to
704702
my %running_CFL_text; # The current text that is being accumulated until
@@ -726,7 +724,6 @@ package My::Pod::Checker { # Extend Pod::Checker
726724
delete $in_for{$addr};
727725
delete $in_NAME{$addr};
728726
delete $in_X{$addr};
729-
delete $linkable_item{$addr};
730727
delete $linkable_nodes{$addr};
731728
delete $running_CFL_text{$addr};
732729
delete $running_simple_text{$addr};
@@ -750,7 +747,6 @@ package My::Pod::Checker { # Extend Pod::Checker
750747
$in_X{$addr} = 0;
751748
$in_CFL{$addr} = 0;
752749
$in_NAME{$addr} = 0;
753-
$linkable_item{$addr} = 0;
754750
$seen_pod_cmd{$addr} = 0;
755751
return $self;
756752
}
@@ -932,16 +928,11 @@ package My::Pod::Checker { # Extend Pod::Checker
932928
$start_line{$addr} = $_[0]->{start_line};
933929
$running_CFL_text{$addr} = "";
934930
$running_simple_text{$addr} = "";
935-
936931
}
937932
938933
sub start_item_text {
939934
my $self = shift;
940935
start_item($self);
941-
my $addr = refaddr $self;
942-
943-
# This is the only =item that is linkable
944-
$linkable_item{$addr} = 1;
945936
946937
return $self->SUPER::start_item_text(@_);
947938
}
@@ -960,7 +951,34 @@ package My::Pod::Checker { # Extend Pod::Checker
960951
return $self->SUPER::start_item_bullet(@_);
961952
}
962953
963-
sub end_item { # No difference in =item types endings
954+
sub clean_up_node_name_ {
955+
my $text = shift;
956+
$text =~ s/\s+$//; # strip trailing space
957+
$text =~ s/\s{2,}/ /gs; # collapse whitespace
958+
return $text;
959+
}
960+
961+
sub end_head {
962+
my $self = shift;
963+
my $addr = refaddr $self;
964+
$running_simple_text{$addr} =
965+
clean_up_node_name_($running_simple_text{$addr});
966+
$linkable_nodes{$addr}{$running_simple_text{$addr}}++;
967+
968+
return $self->SUPER::end_head(@_);
969+
}
970+
971+
sub end_item_text {
972+
my $self = shift;
973+
my $addr = refaddr $self;
974+
$running_simple_text{$addr} =
975+
clean_up_node_name_($running_simple_text{$addr});
976+
$linkable_nodes{$addr}{$running_simple_text{$addr}}++;
977+
978+
return $self->SUPER::end_item_text(@_);
979+
}
980+
981+
sub end_item {
964982
my $self = shift;
965983
check_see_but_not_link($self);
966984
return $self->SUPER::end_item(@_);
@@ -1378,20 +1396,6 @@ package My::Pod::Checker { # Extend Pod::Checker
13781396
return $self->SUPER::hyperlink($link);
13791397
}
13801398
1381-
sub node {
1382-
my $self = shift;
1383-
my $text = $_[0];
1384-
if($text) {
1385-
$text =~ s/\s+$//s; # strip trailing whitespace
1386-
$text =~ s/\s+/ /gs; # collapse whitespace
1387-
my $addr = refaddr $self;
1388-
push(@{$linkable_nodes{$addr}}, $text) if
1389-
! $current_indent{$addr}
1390-
|| $linkable_item{$addr};
1391-
}
1392-
return $self->SUPER::node($_[0]);
1393-
}
1394-
13951399
sub get_current_indent {
13961400
return $INDENT + $current_indent{refaddr $_[0]};
13971401
}
@@ -1403,7 +1407,7 @@ package My::Pod::Checker { # Extend Pod::Checker
14031407
sub linkable_nodes {
14041408
my $linkables = $linkable_nodes{refaddr $_[0]};
14051409
return undef unless $linkables;
1406-
return @$linkables;
1410+
return $linkables;
14071411
}
14081412
14091413
sub get_skip {
@@ -2048,10 +2052,10 @@ foreach my $filename (@files) {
20482052
}
20492053
20502054
# Go through everything in the file that could be an anchor that
2051-
# could be a link target. Count how many there are of the same name.
2052-
foreach my $node ($checker->linkable_nodes) {
2053-
next FILE if ! $node; # Can be empty is like '=item *'
2054-
$nodes{$name}{$node}++;
2055+
# could be a link target.
2056+
my $linkables = $checker->linkable_nodes;
2057+
foreach my $node (keys $linkables->%*) {
2058+
$nodes{$name}{$node} = $linkables->{$node};
20552059
20562060
# Experiments have shown that cpan search can figure out the
20572061
# target of a link even if the exact wording is incorrect, as long

0 commit comments

Comments
 (0)