From: Marc Green Date: Tue, 7 Feb 2012 16:32:54 +0000 (-0500) Subject: Fix bug in pod2html crossreferencing X-Git-Tag: accepted/trunk/20130322.191538~600 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=707a94fe891b3ae9d6e4f5e084d494389e430b6b;p=platform%2Fupstream%2Fperl.git Fix bug in pod2html crossreferencing --- diff --git a/MANIFEST b/MANIFEST index 009cfc2..8fb18d2 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3810,6 +3810,8 @@ ext/Pod-Html/bin/pod2html Translator to turn pod into HTML ext/Pod-Html/lib/Pod/Html.pm Convert POD data to HTML ext/Pod-Html/t/cache.pod ext/Pod-Html/t/cache.t +ext/Pod-Html/t/crossref2.t +ext/Pod-Html/t/crossref3.t ext/Pod-Html/t/crossref.pod ext/Pod-Html/t/crossref.t ext/Pod-Html/t/eol.t test end of line agnosticism diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 9f333bc..e663281 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -3,7 +3,7 @@ use strict; require Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); -$VERSION = 1.14; +$VERSION = 1.15; @ISA = qw(Exporter); @EXPORT = qw(pod2html htmlify); @EXPORT_OK = qw(anchorify); @@ -94,10 +94,13 @@ Displays the usage message. --htmldir=name -Sets the directory in which the resulting HTML file is placed. This -is used to generate relative links to other files. Not passing this -causes all links to be absolute, since this is the value that tells -Pod::Html the root of the documentation tree. +Sets the directory to which all cross references in the resulting +html file will be relative. Not passing this causes all links to be +absolute since this is the value that tells Pod::Html the root of the +documentation tree. + +Do not use this and --htmlroot in the same call to pod2html; they are +mutually exclusive. =item htmlroot @@ -106,6 +109,11 @@ Pod::Html the root of the documentation tree. Sets the base URL for the HTML files. When cross-references are made, the HTML root is prepended to the URL. +Do not use this if relative links are desired: use --htmldir instead. + +Do not pass both this and --htmldir to pod2html; they are mutually +exclusive. + =item index --index @@ -248,7 +256,7 @@ sub init_globals { $Htmlroot = "/"; # http-server base directory from which all # relative paths in $podpath stem. $Htmldir = ""; # The directory to which the html pages - # will (eventually) be written. + # will (eventually) be written. $Htmlfile = ""; # write to stdout by default $Htmlfileurl = ""; # The url that other files would use to # refer to this file. This is only used @@ -637,14 +645,7 @@ sub _save_page { my ($modspec, $modname) = @_; # Remove Podroot from path - foreach my $podpath (@Podpath) { - my $beg_path = File::Spec->catdir($Podroot, $podpath); - if ($beg_path eq substr($modspec, 0, length($beg_path))) { - # Replace $Podroot/$podpath with $podpath - substr($modspec, 0, length($beg_path), $podpath); - last; - } - } + $modspec = File::Spec->abs2rel($modspec, $Podroot); # Convert path to unix style path $modspec = Pod::Html::_unixify($modspec); @@ -721,17 +722,15 @@ sub resolve_pod_page_link { $path = $self->pages->{$to}; } - # The use of catdir here (instead of catfile) ensures there will be one - # '/' between htmlroot and $path; not zero (if htmlroot == ''), not two - # (if htmlroot =~ m#/\z# and $path =~ m#\a/#), just one. - my $url = File::Spec::Unix->catdir( Pod::Html::_unixify($self->htmlroot), + my $url = File::Spec::Unix->catfile(Pod::Html::_unixify($self->htmlroot), $path); + if ($self->htmlfileurl ne '') { # then $self->htmlroot eq '' (by definition of htmlfileurl) so # $self->htmldir needs to be prepended to link to get the absolute path # that will be relativized $url = relativize_url( - File::Spec::Unix->catdir( Pod::Html::_unixify($self->htmldir), $url), + File::Spec::Unix->catdir(Pod::Html::_unixify($self->htmldir), $url), $self->htmlfileurl # already unixified ); } diff --git a/ext/Pod-Html/t/cache.t b/ext/Pod-Html/t/cache.t index f38de45..5a8e1fe 100644 --- a/ext/Pod-Html/t/cache.t +++ b/ext/Pod-Html/t/cache.t @@ -59,7 +59,7 @@ while (<$cache>) { chdir("t"); my %expected_pages = # chop off the .pod and set the path - map { my $f = substr($_, 0, -4); $f => "$cwd/t/$f" } + map { my $f = substr($_, 0, -4); $f => "t/$f" } <*.pod>; chdir($cwd); is_deeply(\%pages, \%expected_pages, "cache contents"); diff --git a/ext/Pod-Html/t/crossref2.t b/ext/Pod-Html/t/crossref2.t new file mode 100644 index 0000000..b4e0f65 --- /dev/null +++ b/ext/Pod-Html/t/crossref2.t @@ -0,0 +1,104 @@ +#!/usr/bin/perl -w # -*- perl -*- + +BEGIN { + require "t/pod2html-lib.pl"; +} + +END { + rem_test_dir(); +} + +use strict; +use Cwd; +use File::Spec; +use File::Spec::Functions; +use Test::More tests => 1; + +SKIP: { + my $output = make_test_dir(); + skip "$output", 1 if $output; + + my $cwd = cwd(); + + convert_n_test("crossref", "cross references", + "--podpath=t:testdir/test.lib", + "--podroot=$cwd", + "--htmldir=$cwd", + "--quiet", + ); +} + +__DATA__ + + + + + + + + + + + + + + + +

NAME

+ +

htmlcrossref - Test HTML cross reference links

+ +

LINKS

+ +

"section1"

+ +

"section 2" in htmllink

+ +

"item1"

+ +

"non existant section"

+ +

var-copy

+ +

"$"" in var-copy

+ +

var-copy

+ +

var-copy/$"

+ +

"First:" in podspec-copy

+ +

podspec-copy/First:

+ +

notperldoc

+ +

TARGETS

+ +

section1

+ +

This is section one.

+ +
+ +
item1
+
+ +

This is item one.

+ +
+
+ + + + + + + diff --git a/ext/Pod-Html/t/crossref3.t b/ext/Pod-Html/t/crossref3.t new file mode 100644 index 0000000..fc1983c --- /dev/null +++ b/ext/Pod-Html/t/crossref3.t @@ -0,0 +1,104 @@ +#!/usr/bin/perl -w # -*- perl -*- + +BEGIN { + require "t/pod2html-lib.pl"; +} + +END { + rem_test_dir(); +} + +use strict; +use Cwd; +use File::Spec; +use File::Spec::Functions; +use Test::More tests => 1; + +SKIP: { + my $output = make_test_dir(); + skip "$output", 1 if $output; + + my $cwd = cwd(); + + convert_n_test("crossref", "cross references", + "--podpath=t:testdir/test.lib", + "--podroot=$cwd", + "--htmlroot=$cwd", + "--quiet", + ); +} + +__DATA__ + + + + + + + + + + + + + + + +

NAME

+ +

htmlcrossref - Test HTML cross reference links

+ +

LINKS

+ +

"section1"

+ +

"section 2" in htmllink

+ +

"item1"

+ +

"non existant section"

+ +

var-copy

+ +

"$"" in var-copy

+ +

var-copy

+ +

var-copy/$"

+ +

"First:" in podspec-copy

+ +

podspec-copy/First:

+ +

notperldoc

+ +

TARGETS

+ +

section1

+ +

This is section one.

+ +
+ +
item1
+
+ +

This is item one.

+ +
+
+ + + + + + +