#!/usr/bin/perl use strict; use warnings; use File::Spec; use Getopt::Long; use POSIX qw(:errno_h); my $verbose=0; my $charset='UTF-8'; my $output_base='.'; my @modules=(); my @env_dirs=(); $charset=$ENV{MM_CHARSET} if($ENV{MM_CHARSET}); $charset=$ENV{HTML_CHARSET} if($ENV{HTML_CHARSET}); GetOptions ( "charset=s" => \$charset, "outdir|dir=s" => \$output_base, "env=s" => \@env_dirs, "module=s" => \@modules, "help" => sub{ usage(); }, "verbose" => \$verbose, ) || usage('Unkown option',0,EINVAL()); @modules=@ARGV if(@ARGV); unshift(@INC,@env_dirs); usage('No Modul !',0,EINVAL()) unless(@modules); $Pod::Simple::HTML::Content_decl = qq{}; ######################################################################## for my $module (@modules) { my $path=get_filename($module); if($path && -f $path ) { print qq|Read Pod from $module ($path)\n| if($verbose); my $pod=Pod::Simple::HTML::Local->new(); my $html=''; $pod->output_string(\$html); $pod->set_module_match_ref(\@modules); $pod->set_source( $path ); $pod->run; if($html) { print "HTML created \n" if($verbose); my $outputname=File::Spec->join($output_base,Pod::Simple::HTML::Local::convert_module_name($module)); print qq(Write HTML to file "$outputname" \n) if($verbose); create_path($outputname) or usage(qq|ERROR create "$outputname" ($!)\n|,1,EACCES()); open(my $fh, '>', $outputname) or usage(qq|ERROR create "$outputname" ($!)\n|,1,EACCES()); print $fh $html; close($fh); } else { print "NO HTML created\n" if($verbose); } } else { usage(qq(File for Module "$module" not found!),1,ENOENT()); } } ######################################################################## # Funktionen ######################################################################## sub usage { my $msg=shift || ''; my $nohelp=shift || 0; my $exit=shift || 0; my $out=\*STDOUT; if($msg) { $out=\*STDERR; print $out "ERROR: $msg\n"; $exit=255 unless($exit); } print $out <] [-c ] [-d ] [-m ] [ [ ...] ] Convert POD to HTML with subpackages as local files and set links correctly. OPTIONS: -d | -o | --dir | --outputdir Set destination directory for HTM files. Default directory is the current. -c | --charset Set the character encoding in HTML document. UTF-8 is set as default. If available the enviroment variable MM_CHARSET or HTML_CHARSET will be used. -m | --module Set one or more modules whose POD should be converted -e | --env Set one or more directories where modules can be found -h | --help Show this text -v | --verbose verbose output EOH exit($exit); } sub get_filename { my $module=shift; my $name=undef; if( -f $module) { $name=$module; } else { my @dirs=split('::',$module); my $path=File::Spec->join(@dirs); $path.='.pm'; for my $base (@INC) { my $fullpath=File::Spec->join($base,$path); if(-f $fullpath) { $name=$fullpath; last; } } unless($name) { my $fullpath=File::Spec->rel2abs($path); $name=$fullpath if(-f $fullpath); } } return $name; } sub create_path { my $path=shift; return 0 unless($path); $path=File::Spec->rel2abs($path); return 0 unless($path); my ($run,$directories,undef) = File::Spec->splitpath( $path ); for my $dir (File::Spec->splitdir( $directories )) { $run=File::Spec->join($run,$dir); unless(-d $run) { return 0 unless(mkdir($run)); } } return 1; } ######################################################################## # Pod::Simple::HTML::Local ######################################################################## package Pod::Simple::HTML::Local; use base 'Pod::Simple::HTML'; # Links anders verarbeiten # das mache ich mit dem Überschreiben der passenden Funktion in # Pod::Simple::HTML sub set_module_match_ref { my $self=shift; my $ref=shift; return 0 if(ref($ref) ne 'ARRAY'); $self->{MODULE_MATCH}=$ref; return 1; } # Modify Links sub resolve_pod_page_link { my ($self,$it)=@_; $self->{MODULE_MATCH}=[] unless($self->{MODULE_MATCH} && ref($self->{MODULE_MATCH}) eq "ARRAY"); # Das Modul ist in der Liste if(grep{$_ eq $it}@{$self->{MODULE_MATCH}}) { #print "$it\n"; return convert_module_name($it); } # Das Modul gehört zum selben Paket elsif(grep{$it=~m!^\Q$_!}@{$self->{MODULE_MATCH}}) { push(@{$self->{MODULE_MATCH}},$it); return convert_module_name($it); } # Modul verweist woanders hin: # den normalen Aufruf machen. else { $self->SUPER::resolve_pod_page_link($it); } } ######################################################################## sub convert_module_name { my $module=shift || ''; $module=~s/::/_/g; $module.='.html'; }