diff options
author | Marc Green <marcgreen@cpan.org> | 2011-06-18 11:59:40 -0400 |
---|---|---|
committer | Marc Green <marcgreen@cpan.org> | 2011-10-31 13:26:40 -0400 |
commit | 1be43d30851563082d5dc74b187ae83927bf4bea (patch) | |
tree | 868733caa10c5ed2a0459e7f66d612b0063bdc59 /ext/Pod-Html/lib | |
parent | 8e1ba33ca237189994b1360b50c07cba3eb7b987 (diff) | |
download | perl-1be43d30851563082d5dc74b187ae83927bf4bea.tar.gz |
Move Pod::Simple::XHTML::LocalPodLinks into Pod::Html
Diffstat (limited to 'ext/Pod-Html/lib')
-rw-r--r-- | ext/Pod-Html/lib/Pod/Html.pm | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 619b3cb51e..3e8db16fd2 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -16,7 +16,6 @@ use File::Spec; use File::Spec::Unix; use Getopt::Long; use Pod::Simple::Search; -use Pod::Simple::XHTML::LocalPodLinks; use locale; # make \w work right in non-ASCII lands @@ -497,3 +496,78 @@ sub _save_page { 1; +package Pod::Simple::XHTML::LocalPodLinks; +use strict; +use warnings; +use base 'Pod::Simple::XHTML'; + +use File::Spec; + +__PACKAGE__->_accessorize( + 'htmldir', + 'htmlfileurl', + 'htmlroot', + 'pages', # Page name => relative/path/to/page from root POD dir + 'quiet', + 'verbose', +); + +sub resolve_pod_page_link { + my ($self, $to, $section) = @_; + + return undef unless defined $to || defined $section; + if (defined $section) { + $section = '#' . $self->idify($section, 1); + return $section unless defined $to; + } else { + $section = ''; + } + + unless (exists $self->pages->{$to}) { + warn "Cannot find $to in podpath: cannot resolve link.\n" + unless $self->quiet; + return ''; + } + + my $url = File::Spec->catfile($self->htmlroot, $self->pages->{$to}); + 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($self->htmldir.$url, $self->htmlfileurl); + } + + return $url . ".html$section"; +} + +# +# relativize_url - convert an absolute URL to one relative to a base URL. +# Assumes both end in a filename. +# +sub relativize_url { + my ($dest, $source) = @_; + + # Remove each file from its path + my ($dest_volume, $dest_directory, $dest_file) = + File::Spec::Unix->splitpath( $dest ); + $dest = File::Spec::Unix->catpath( $dest_volume, $dest_directory, '' ); + + my ($source_volume, $source_directory, $source_file) = + File::Spec::Unix->splitpath( $source ); + $source = File::Spec::Unix->catpath( $source_volume, $source_directory, '' ); + + my $rel_path = ''; + if ($dest ne '') { + $rel_path = File::Spec::Unix->abs2rel( $dest, $source ); + } + + if ($rel_path ne '' && substr( $rel_path, -1 ) ne '/') { + $rel_path .= "/$dest_file"; + } else { + $rel_path .= "$dest_file"; + } + + return $rel_path; +} + +1; |