1package Pod::Tree::PerlMap;
2use 5.006;
3use strict;
4use warnings;
5
6our $VERSION = '1.31';
7
8sub new {
9	my ($class) = @_;
10
11	my $perl_map = { prefix => '' };
12
13	bless $perl_map, $class;
14}
15
16sub set_depth {
17	my ( $perl_map, $depth ) = @_;
18
19	$perl_map->{prefix} = '../' x $depth;
20}
21
22sub add_page {
23	my ( $perl_map, $page, $file ) = @_;
24
25	$perl_map->{page}{$page} = $file;
26}
27
28sub add_func {
29	my ( $perl_map, $func, $file ) = @_;
30
31	$perl_map->{func}{$func} = $file;
32}
33
34sub force_func {
35	my ( $perl_map, $force_func ) = @_;
36
37	$perl_map->{force_func} = $force_func;
38}
39
40sub map {
41	my ( $perl_map, $base, $page, $section ) = @_;
42
43	# print "map $base, $page, $section ->";
44
45	my $prefix     = $perl_map->{prefix};
46	my $force_func = $perl_map->{force_func};
47	my $func       = ( split m(\s+), $section )[0];    # e.g.  L<"eval BLOCK">
48	my $file       = $perl_map->{func}{$func};
49
50	if ( ( $page eq 'perlfunc' or $page eq '' and $force_func ) and $file ) {
51		$page    = $prefix . 'pod/func/' . $file;
52		$section = '';
53	}
54	elsif ( $perl_map->{page}{$page} ) {
55		$page = $prefix . $perl_map->{page}{$page};
56	}
57
58	# print "$base, $page, $section\n";
59	( $base, $page, $section );
60}
61
621
63
64__END__
65
66=head1 NAME
67
68Pod::Tree::PerlMap - map names to URLs
69
70=head1 SYNOPSIS
71
72  $perl_map = new Pod::Tree::PerlMap;
73
74  $perl_map->add_page  ($name, $file);
75  $perl_map->add_func  ($func, $file);
76  $perl_map->force_func(0);
77  $perl_map->force_func(1);
78  $perl_map->set_depth ($depth);
79
80  ($base, $page, $section) = $perl_map->map($base, $page, $section);
81
82=head1 DESCRIPTION
83
84C<Pod::Tree::PerlMap> maps LE<lt>E<gt> markups to URLs.
85
86The C<Pod::Tree::Perl*> translators make entries in the map.
87C<Pod::Tree::HTML> uses the map to translate links before it emits
88them.
89
90=head1 METHODS
91
92=over 4
93
94=item I<$perl_map>->C<add_page>(I<$name>, I<$file>)
95
96Map I<$name> to I<$file>.
97I<$name> is the name of a POD, as used in LE<lt>E<gt> markups.
98I<$file> is the path to the HTML file that is the target of the link.
99
100=item I<$perl_map>->C<add_func>(I<$func>, I<$file>)
101
102Maps I<$func> to I<$file>.
103I<$func> is the name of a function described in F<perlfunc.pod>.
104I<$file> is the name of the HTML file where it is described.
105
106=item I<$perl_map>->C<force_func>(I<$state>)
107
108Controls interpretation of links of the form LE<lt>funcE<gt>.
109
110If I<$state> is true, calls to C<map> will interpret
111LE<lt>funcE<gt> as LE<lt>perlfunc/funcE<gt>.
112
113If I<$state> is false, calls to C<map> will interpret
114LE<lt>funcE<gt> normally.
115
116=item I<$perl_map>->C<set_depth>(I<$depth>)
117
118Informs I<$perl_map> of the depth of the referring page in the HTML
119directory tree.
120I<$perl_map> needs to know this so that it can construct
121relative links.
122
123=item (I<$base>, I<$page>, I<$section>) =
124I<$perl_map>->C<map>(I<$base>, I<$page>, I<$section>)
125
126Remaps a link.
127
128I<$base> is the base URL for the HTML page, if any.
129I<$page> is the page given in an LE<lt>E<gt> markup.
130I<$section> is the section given in the LE<lt>E<gt> markup, if any.
131
132C<map> returns a new I<$base>, I<$page>, and I<$section>
133that can be used to construct a link to the HTML page.
134
135=back
136
137=head1 REQUIRES
138
139Nothing.
140
141=head1 EXPORTS
142
143Nothing.
144
145=head1 AUTHOR
146
147Steven McDougall, swmcd@world.std.com
148
149=head1 COPYRIGHT
150
151Copyright (c) 2000 by Steven McDougall.  This module is free software;
152you can redistribute it and/or modify it under the same terms as Perl.
153
154