Pod-Tree

 view release on metacpan or  search on metacpan

lib/Pod/Tree/PerlMap.pm  view on Meta::CPAN

package Pod::Tree::PerlMap;
use 5.006;
use strict;
use warnings;

our $VERSION = '1.31';

sub new {
	my ($class) = @_;

	my $perl_map = { prefix => '' };

	bless $perl_map, $class;
}

sub set_depth {
	my ( $perl_map, $depth ) = @_;

	$perl_map->{prefix} = '../' x $depth;
}

sub add_page {
	my ( $perl_map, $page, $file ) = @_;

	$perl_map->{page}{$page} = $file;
}

sub add_func {
	my ( $perl_map, $func, $file ) = @_;

	$perl_map->{func}{$func} = $file;
}

sub force_func {
	my ( $perl_map, $force_func ) = @_;

	$perl_map->{force_func} = $force_func;
}

sub map {
	my ( $perl_map, $base, $page, $section ) = @_;

	# print "map $base, $page, $section ->";

	my $prefix     = $perl_map->{prefix};
	my $force_func = $perl_map->{force_func};
	my $func       = ( split m(\s+), $section )[0];    # e.g.  L<"eval BLOCK">
	my $file       = $perl_map->{func}{$func};

	if ( ( $page eq 'perlfunc' or $page eq '' and $force_func ) and $file ) {
		$page    = $prefix . 'pod/func/' . $file;
		$section = '';
	}
	elsif ( $perl_map->{page}{$page} ) {
		$page = $prefix . $perl_map->{page}{$page};
	}

	# print "$base, $page, $section\n";
	( $base, $page, $section );
}

1

__END__

=head1 NAME

Pod::Tree::PerlMap - map names to URLs

=head1 SYNOPSIS

  $perl_map = new Pod::Tree::PerlMap;
  
  $perl_map->add_page  ($name, $file);
  $perl_map->add_func  ($func, $file);
  $perl_map->force_func(0);
  $perl_map->force_func(1);
  $perl_map->set_depth ($depth);
  
  ($base, $page, $section) = $perl_map->map($base, $page, $section);

=head1 DESCRIPTION

C<Pod::Tree::PerlMap> maps LE<lt>E<gt> markups to URLs.

The C<Pod::Tree::Perl*> translators make entries in the map.
C<Pod::Tree::HTML> uses the map to translate links before it emits
them.

=head1 METHODS

=over 4

=item I<$perl_map>->C<add_page>(I<$name>, I<$file>)

Map I<$name> to I<$file>.
I<$name> is the name of a POD, as used in LE<lt>E<gt> markups.
I<$file> is the path to the HTML file that is the target of the link.

=item I<$perl_map>->C<add_func>(I<$func>, I<$file>)

Maps I<$func> to I<$file>.
I<$func> is the name of a function described in F<perlfunc.pod>.
I<$file> is the name of the HTML file where it is described.

=item I<$perl_map>->C<force_func>(I<$state>)



( run in 0.474 second using v1.01-cache-2.11-cpan-71847e10f99 )