Pod-Tree
view release on metacpan or search on metacpan
lib/Pod/Tree/PerlFunc.pm view on Meta::CPAN
sub translate {
my $perl_func = shift;
$perl_func->report1("translate");
my $html_dir = $perl_func->{html_dir};
my $pod_dir = $perl_func->{pod_dir};
my $func_dir = $perl_func->{func_dir};
$perl_func->mkdir("$html_dir/$pod_dir/$func_dir");
my $perl_dir = $perl_func->{perl_dir};
my $funcs = $perl_func->{funcs};
my $options = $perl_func->{options};
my $link_map = $options->{link_map};
$link_map->set_depth(2);
$link_map->force_func(1);
$options->{toc} = 0;
while (@$funcs) {
my @items = Shift_Items($funcs);
my ( $func, $file ) = Parse_Name( $items[0] );
$perl_func->report2("func/$file");
my $tree = Pod::Tree->new;
$tree->load_string("=head1 $func\n\n=over 4\n\n=back");
my $list = $tree->get_root->get_children->[1];
$list->set_children( \@items );
$list->_set_list_type;
$options->{title} = $func;
my $dest = "$html_dir/$pod_dir/$func_dir/$file.html";
my $html = Pod::Tree::HTML->new( $tree, $dest, %$options );
$html->translate;
}
$link_map->force_func(0);
}
sub Shift_Items {
my $funcs = shift;
my @items;
while (@$funcs) {
my $item = shift @$funcs;
push @items, $item;
@$funcs or last;
my ($func0) = Parse_Name($item);
my ($func1) = Parse_Name( $funcs->[0] );
my $sibs0 = $item->get_siblings;
$func0 eq $func1 or @$sibs0 == 0 or last;
}
@items;
}
sub Parse_Name {
my $item = shift;
my $text = $item->get_deep_text;
my @words = split m([^\w\-]+), $text;
my $func = $words[0];
my $file = $func;
$file =~ tr(A-Za-z0-9_-)()cd;
( $func, $file );
}
1
__END__
=head1 NAME
Pod::Tree::PerlFunc - translate F<perlfunc.pod> to HTML
=head1 SYNOPSIS
$perl_map = Pod::Tree::PerlMap->new;
$perl_func = Pod::Tree::PerlFunc->new($perl_dir, $HTML_dir, $perl_map, %opts);
$perl_func->scan;
$perl_func->index;
$perl_func->translate;
=head1 DESCRIPTION
C<Pod::Tree::PerlFunc> translates F<perlfunc.pod> to HTML.
It creates a separate HTML page for each function description in
F<perlfunc.pod>. The pages for the individual descriptions are
named after the function and written to a F<func/> subdirectory.
F<perlfunc.html> is generated as an index to all the pages in
F<func/>.
C<Pod::Tree::PerlFunc> generates and uses an index of the functions
that it finds in F<perlfunc.pod> to construct HTML links.
Other modules can also use this index.
=head1 METHODS
=over 4
=item I<$perl_func> = C<new> C<Pod::Tree::PerlFunc> I<$perl_dir>,
I<$HTML_dir>, I<$perl_map>, I<%options>
Creates and returns a new C<Pod::Tree::PerlFunc> object.
I<$perl_dir> is the root of the Perl source tree.
I<$HTML_dir> is the directory where HTML files will be written.
I<$perl_map> maps function names to URLs.
I<%options> are passed through to C<Pod::Tree::HTML>.
=item I<$perl_func>->C<scan>
Reads F<perlfunc.pod> and identifies all the functions in it.
Each function that is identified is entered into I<$perl_map>.
( run in 0.817 second using v1.01-cache-2.11-cpan-71847e10f99 )