Leser: 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
#!/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{<meta http-equiv="Content-Type" content="text/html; charset=$charset" >}; ######################################################################## 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 <<EOH if(!$nohelp); USAGE: $0 [-hv] [-e <path/to/modules>] [-c <charset>] [-d <output/dir>] [-m <Module::A>] [<Module::B> [<Module::C> ...] ] 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'; }
2010-08-14T07:55:33 GwenDragonSchönes Programm;
2010-08-14T07:55:33 GwenDragonnur dein Englisch in den Fehlermeldungen und POD ist sehr kreativ ;) .
Quotecreatet
QuoteConvert POD to HTML convert "sub"-Packages as local files
and set the links korrect.
QuoteConvert POD to HTML convert "sub"-Packages as local files
and set the links korrect.
OPTIONS:
-d | -o | --dir | --outputdir
Set the dir to write the HTM-Files in.
the default directory is the actual
-c | --charset
Set the character encoding in the HTML-Document
UTF-8 is set as default. if available the Enviroment Var
MM_CHARSET or HTML_CHARSET will be used.
-m | --module
Set one or more Modules witch POD should be converted
-e | --env
Set one or more dirs in witch Modules can be found
-h | --help
Show this text
-v | --verbose
verbose output