--- Perl6/Perldoc/Parser.pm- 2012-12-14 22:41:19.000000000 +0100
+++ Perl6/Perldoc/Parser.pm 2013-01-09 15:31:34.000000000 +0100
@@ -586,6 +586,9 @@
my ($classname, $filehandle, $opt_ref) = @_;
my $filename = undef;
+ # Reset the id generator if asked to
+ Perl6::Perldoc::Root::_reset_id() if $opt_ref->{reset_id};
+
# If filename passed, open it...
if (!ref $filehandle) {
$filename = $filehandle;
@@ -1467,7 +1470,7 @@
: $DEFAULT_LEVEL
;
- my $target = $node+0;
+ my $target = $node->id();
# Create a TOC entry (a list item with a link inside it)...
@this_node = bless {
@@ -1538,14 +1541,23 @@
use strict;
use warnings;
-# Root ctor just blesses the data structure...
+my $id = 1;
+
+# Reset the id in case someone wants reproducible results
+sub _reset_id {
+ $id = 1;
+}
+
+# Root constructor just assigns id and blesses the data structure...
sub new {
my ($classname, $data_ref) = @_;
+ $data_ref->{id} = $id++;
return bless $data_ref, $classname;
}
# Standard read-only accessor methods shared by all DOM components...
+sub id { my ($self) = @_; return $self->{id}; }
sub typename { my ($self) = @_; return $self->{typename}; }
sub style { my ($self) = @_; return $self->{style}; }
sub target { my ($self) = @_; return $self->{target}; }
@@ -2444,6 +2456,15 @@
Defaults to no allowed codes.
+=item C<< reset_id => $status >>
+
+By default, the parser assigns unique identifiers (increasing integers) to
+each created object. These identifiers can later be used, for instance, to
+create unique links.
+
+If $status is true, the parser will reset the identifier generator to start
+again from 1.
+
=back
Text is read from the file and parsed as Perl 6 Pod. The method call
--- Perl6/Perldoc/To/Xhtml.pm- 2012-12-14 22:42:40.000000000 +0100
+++ Perl6/Perldoc/To/Xhtml.pm 2012-12-18 15:34:47.000000000 +0100
@@ -139,7 +139,7 @@
if ($is_target) {
$content = qq{<a name="$name"><a name="}
- . ($self+0)
+ . $self->id()
. qq{">$content</a></a>};
}
@@ -236,7 +236,7 @@
}
$caption = $self->_list_to_xhtml([$caption]);
- my $xhtml = qq{<a name="$caption"><a name="} . ($self+0) . qq{"><table>\n};
+ my $xhtml = qq{<a name="$caption"><a name="} . $self->id() . qq{"><table>\n};
if ($caption) {
$xhtml .= qq{<caption>$caption</caption>\n};
@@ -482,7 +482,7 @@
my $title = $self->_list_to_xhtml(\@title, @_);
return qq{<a name="$title"><a name="}
- . ($self+0)
+ . $self->id()
. qq{"><h1 class="$blockname">$title</h1></a></a>\n}
. $self->_list_to_xhtml([$self->content], @_);
};