Skip to content

Commit

Permalink
Support manpages by default in Pod::Simple
Browse files Browse the repository at this point in the history
  • Loading branch information
dafrito committed Aug 16, 2011
1 parent f32d9fd commit 3b4c4dc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
44 changes: 40 additions & 4 deletions lib/Pod/Simple/HTML.pm
Expand Up @@ -5,7 +5,7 @@ use strict;
use Pod::Simple::PullParser ();
use vars qw(
@ISA %Tagmap $Computerese $LamePad $Linearization_Limit $VERSION
$Perldoc_URL_Prefix $Perldoc_URL_Postfix
$Perldoc_URL_Prefix $Perldoc_URL_Postfix $Man_URL_Prefix $Man_URL_Postfix
$Title_Prefix $Title_Postfix $HTML_EXTENSION %ToIndex
$Doctype_decl $Content_decl
);
Expand Down Expand Up @@ -36,6 +36,10 @@ $Perldoc_URL_Prefix = 'http://search.cpan.org/perldoc?'
$Perldoc_URL_Postfix = ''
unless defined $Perldoc_URL_Postfix;


$Man_URL_Prefix = 'http://man.he.net/man';
$Man_URL_Postfix = '';

$Title_Prefix = '' unless defined $Title_Prefix;
$Title_Postfix = '' unless defined $Title_Postfix;
%ToIndex = map {; $_ => 1 } qw(head1 head2 head3 head4 ); # item-text
Expand All @@ -51,6 +55,12 @@ __PACKAGE__->_accessorize(
'perldoc_url_postfix',
# what to put after "Foo%3a%3aBar" in the URL. Normally "".

'man_url_prefix',
# In turning L<crontab(5)> into http://whatever/man/1/crontab, what
# to put before the "1/crontab".
'man_url_postfix',
# what to put after the "1/crontab" in the URL. Normally "".

'batch_mode', # whether we're in batch mode
'batch_mode_current_level',
# When in batch mode, how deep the current module is: 1 for "LWP",
Expand Down Expand Up @@ -179,6 +189,8 @@ sub new {

$new->perldoc_url_prefix( $Perldoc_URL_Prefix );
$new->perldoc_url_postfix( $Perldoc_URL_Postfix );
$new->man_url_prefix( $Man_URL_Prefix );
$new->man_url_postfix( $Man_URL_Postfix );
$new->title_prefix( $Title_Prefix );
$new->title_postfix( $Title_Postfix );

Expand Down Expand Up @@ -554,9 +566,20 @@ sub do_link {

sub do_url_link { return $_[1]->attr('to') }

sub do_man_link { return undef }
# But subclasses are welcome to override this if they have man
# pages somewhere URL-accessible.
sub do_man_link {
my ($self, $link) = @_;
my $to = $link->attr('to');
my $frag = $link->attr('section');

return undef unless defined $to and length $to; # should never happen

$frag = $self->section_escape($frag)
if defined $frag and length($frag .= ''); # (stringify)

DEBUG and print "Resolving \"$to/$frag\"\n\n";

return $self->resolve_man_page_link($to, $frag);
}


sub do_pod_link {
Expand Down Expand Up @@ -646,6 +669,7 @@ sub section_name_tidy {

sub section_url_escape { shift->general_url_escape(@_) }
sub pagepath_url_escape { shift->general_url_escape(@_) }
sub manpage_url_escape { shift->general_url_escape(@_) }

sub general_url_escape {
my($self, $string) = @_;
Expand Down Expand Up @@ -719,6 +743,18 @@ sub batch_mode_rectify_path {
return;
}

sub resolve_man_page_link {
my ($self, $to, $frag) = @_;
my ($page, $section) = $to =~ /^([^(]+)(?:[(](\d+)[)])?$/;

return undef unless defined $page and length $page;
$section ||= 1;

return $self->man_url_prefix . "$section/"
. $self->manpage_url_escape($page)
. $self->man_url_postfix;
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sub resolve_pod_link_by_table {
Expand Down
12 changes: 12 additions & 0 deletions lib/Pod/Simple/XHTML.pm
Expand Up @@ -76,6 +76,16 @@ to put before the "Foo%3a%3aBar". The default value is
What to put after "Foo%3a%3aBar" in the URL. This option is not set by
default.
=head2 man_url_prefix
In turning C<< L<crontab(5)> >> into http://whatever/man/1/crontab, what
to put before the "1/crontab". The default value is
"http://man.he.net/man".
=head2 man_url_postfix
What to put after "1/crontab" in the URL. This option is not set by default.
=head2 title_prefix, title_postfix
What to put before and after the title in the head. The values should
Expand Down Expand Up @@ -148,6 +158,8 @@ index for the sake of tradition).
__PACKAGE__->_accessorize(
'perldoc_url_prefix',
'perldoc_url_postfix',
'man_url_prefix',
'man_url_postfix',
'title_prefix', 'title_postfix',
'html_css',
'html_javascript',
Expand Down

0 comments on commit 3b4c4dc

Please sign in to comment.