Re: [Module::Build] any pod2html action?
Status: Beta
Brought to you by:
kwilliams
|
From: Randy K. <ra...@th...> - 2004-01-15 17:22:13
|
On Thu, 15 Jan 2004, Uri Guttman wrote:
> i was looking for an action that would do pod2html on all
> the pm files and i can't seem to find one. would this be a
> good thing to have? if none exists i will probably write
> my own and post it here.
Coincidentally, this was just being discussed - here's a
diff that adds an 'html' target that runs pod2html on the
pods under blib/, and puts the results also under blib/
(which will be included in the 'ppm_dist' archive). There's
also an 'htmlinstall' target that would install the html
files locally to $Config{installhtmldir}, if that exists.
I tried to make it not assume too much about the
ActiveState html directory structure, but some things
may need tweaking to function outside of an ActiveState
distribution.
Note that a couple of new requirements - Pod::Find and
Pod::Html - are added.
In case you were wondering, the gymnastics concerning file
paths within the html action (using File::Spec->Unix and the
like) are mainly due to getting a '/' to be used as the
directory separator in a url when building things on
non-Unix (Win32 in particular).
==============================================================
Index: lib/Module/Build/Base.pm
===================================================================
RCS file: /cvsroot/module-build/Module-Build/lib/Module/Build/Base.pm,v
retrieving revision 1.240
diff -u -r1.240 Base.pm
--- lib/Module/Build/Base.pm 15 Jan 2004 04:18:46 -0000 1.240
+++ lib/Module/Build/Base.pm 15 Jan 2004 16:57:55 -0000
@@ -1360,6 +1360,73 @@
return '';
}
+sub ACTION_html {
+ require Pod::Find;
+ require Pod::Html;
+ my $self = shift;
+ $self->depends_on('build');
+ my $cwd = $self->cwd;
+ $cwd =~ s!^\w:!!;
+ $cwd =~ s!(\\|:)!/!g;
+ my $html_base = $Config{installhtmldir} ?
+ File::Basename::basename($Config{installhtmldir}) : 'html';
+ my $blib = File::Spec::Unix->catdir($cwd, 'blib');
+ my $html = File::Spec::Unix->catdir($blib, $html_base);
+ my $script = File::Spec::Unix->catdir($blib, 'script');
+ unless (-d $html) {
+ File::Path::mkpath($html, 1, 0755) or die "Couldn't mkdir $html: $!";
+ }
+ my %pods = Pod::Find::pod_find({-verbose => 1}, $blib);
+ if (-d $script) {
+ File::Find::finddepth( sub
+ {$pods{$File::Find::name} =
+ "script::" . basename($File::Find::name)
+ if (-f $_ and not /\.bat$/ and $self->contains_pod($_));
+ }, $script);
+ }
+
+ my $backlink = '__top';
+ my $css = ($^O =~ /Win32/) ? 'Active.css' : '';
+ foreach my $pod (keys %pods){
+ my @dirs = split /::/, $pods{$pod};
+ my $isbin = shift @dirs eq 'script';
+ my $infile = File::Spec::Unix->abs2rel($pod);
+ my $outfile = (pop @dirs) . '.html';
+
+ my @rootdirs = $isbin? ('bin') : ('site', 'lib');
+ my $path2root = "../" x (@rootdirs+@dirs);
+ $path2root =~ s!/$!!;
+
+ my $fulldir = File::Spec::Unix->catfile($html, @rootdirs, @dirs);
+ unless (-d $fulldir){
+ File::Path::mkpath($fulldir, 1, 0755)
+ or die "Couldn't mkdir $fulldir: $!";
+ }
+ $outfile = File::Spec::Unix->catfile($fulldir, $outfile);
+
+ my $htmlroot = File::Spec::Unix->catdir($path2root, 'site', 'lib');
+ my $podpath = join ":" => map { File::Spec::Unix->catdir($blib, $_) }
+ ($isbin ? qw(bin lib) : qw(lib));
+ (my $package = $pods{$pod}) =~ s!^(lib|script)::!!;
+ my $abstract = $self->dist_abstract($infile);
+ my $title = $abstract ? "$package - $abstract" : $package;
+ my @opts = (
+ '--header',
+ '--flush',
+ "--backlink=$backlink",
+ "--title=$title",
+ "--podpath=$podpath",
+ "--infile=$infile",
+ "--outfile=$outfile",
+ "--podroot=$blib",
+ "--htmlroot=$htmlroot",
+ );
+ push @opts, "--css=$path2root/$css" if $css;
+ print "pod2html @opts\n";
+ Pod::Html::pod2html(@opts);# or warn "pod2html @opts failed: $!";
+ }
+}
+
# Adapted from ExtUtils::MM_Unix
sub man1page_name {
my $self = shift;
@@ -1452,6 +1519,33 @@
my %onlyargs = map {exists($self->{args}{$_}) ? ($_ => $self->{args}{$_}) : ()}
qw(version versionlib);
only::install::install(%onlyargs);
+}
+
+sub ACTION_htmlinstall {
+ return unless my $destdir = $Config{installhtmldir};
+ my $self = shift;
+ $self->depends_on('html');
+ my $cwd = $self->cwd;
+ my $blib = File::Spec->catdir($cwd, 'blib');
+ my $html_base = File::Spec->catdir($blib,
+ File::Basename::basename($destdir));
+ my @files;
+ File::Find::finddepth(sub
+ {push @files, $File::Find::name
+ if $File::Find::name =~ /\.html$/
+ }, $html_base);
+ foreach my $file (@files) {
+ (my $relative_to = $file) =~ s!\Q$html_base!!;
+ $relative_to =~ s!^/!!;
+ my $to = File::Spec->catfile($destdir, $relative_to);
+ my $base_dir = File::Basename::dirname($to);
+ unless (-d $base_dir) {
+ File::Path::mkpath($base_dir, 1, 0755)
+ or die "Cannot mkpath $base_dir: $!";
+ }
+ File::Copy::copy($file, $to)
+ or warn "Cannot copy '$file' to '$to': $!";
+ }
}
sub ACTION_clean {
================================================================
--
best regards,
randy kobes
|