#!/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