| 1 | #! /bin/perl | ||
| 2 | ############################################################################# | ||
| 3 | # | ||
| 4 | # NOTE: This file under revision control using RCS | ||
| 5 | # Any changes made without RCS will be lost | ||
| 6 | # | ||
| 7 | # $Source: /usr/local/cvsroot/vbtk/VBTK/DynPod2Html.pm,v $ | ||
| 8 | # $Revision: 1.9 $ | ||
| 9 | # $Date: 2002/03/04 20:53:06 $ | ||
| 10 | # $Author: bhenry $ | ||
| 11 | # $Locker: $ | ||
| 12 | # $State: Exp $ | ||
| 13 | # | ||
| 14 | # Purpose: A common perl library used to dynamically generate | ||
| 15 | # HTML from pod's in the perl library paths. | ||
| 16 | # | ||
| 17 | # Copyright (C) 1996 - 2002 Brent Henry | ||
| 18 | # | ||
| 19 | # This program is free software; you can redistribute it and/or | ||
| 20 | # modify it under the terms of version 2 of the GNU General Public | ||
| 21 | # License as published by the Free Software Foundation available at: | ||
| 22 | # http://www.gnu.org/copyleft/gpl.html | ||
| 23 | # | ||
| 24 | # This program is distributed in the hope that it will be useful, | ||
| 25 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 26 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 27 | # GNU General Public License for more details. | ||
| 28 | # | ||
| 29 | ############################################################################# | ||
| 30 | # | ||
| 31 | # | ||
| 32 | # REVISION HISTORY: | ||
| 33 | # | ||
| 34 | # $Log: DynPod2Html.pm,v $ | ||
| 35 | # Revision 1.9 2002/03/04 20:53:06 bhenry | ||
| 36 | # *** empty log message *** | ||
| 37 | # | ||
| 38 | # Revision 1.8 2002/03/04 16:49:09 bhenry | ||
| 39 | # Changed requirement back to perl 5.6.0 | ||
| 40 | # | ||
| 41 | # Revision 1.7 2002/03/02 00:53:54 bhenry | ||
| 42 | # Documentation updates | ||
| 43 | # | ||
| 44 | # Revision 1.6 2002/02/20 19:25:12 bhenry | ||
| 45 | # Fixed bug causing loss of end of html page | ||
| 46 | # | ||
| 47 | # Revision 1.5 2002/02/19 19:06:44 bhenry | ||
| 48 | # *** empty log message *** | ||
| 49 | # | ||
| 50 | # Revision 1.4 2002/02/08 02:16:04 bhenry | ||
| 51 | # *** empty log message *** | ||
| 52 | # | ||
| 53 | # | ||
| 54 | |||
| 55 | package VBTK::DynPod2Html; | ||
| 56 | |||
| 57 | use 5.6.0; | ||
| 58 | use strict; | ||
| 59 | use warnings; | ||
| 60 | # I like using undef as a value so I'm turning off the uninitialized warnings | ||
| 61 | no warnings qw(uninitialized); | ||
| 62 | |||
| 63 | use VBTK::Common qw(error log fatal); | ||
| 64 | use Pod::Find qw(pod_where); | ||
| 65 | use Pod::Html qw(pod2html); | ||
| 66 | use POSIX qw(:sys_wait_h); | ||
| 67 | use FileHandle; | ||
| 68 | |||
| 69 | our $VERBOSE = $ENV{VERBOSE}; | ||
| 70 | our %POD_FILE_MAP; | ||
| 71 | |||
| 72 | #------------------------------------------------------------------------------- | ||
| 73 | # Function: findPodFile | ||
| 74 | # Description: Find the pod file path for the specified package name. | ||
| 75 | # Input Parms: Package Name | ||
| 76 | # Output Parms: Pod File | ||
| 77 | #------------------------------------------------------------------------------- | ||
| 78 | sub findPodFile | ||
| 79 | { | ||
| 80 | my ($pkgName) = (@_); | ||
| 81 | |||
| 82 | # If the package name is passed with '/' in it, then re-format it. | ||
| 83 | $pkgName =~ s-^/|/$--g; | ||
| 84 | $pkgName =~ s-/-::-g; | ||
| 85 | $pkgName =~ s/\.html$//g; | ||
| 86 | |||
| 87 | my($podFile); | ||
| 88 | |||
| 89 | unless ($podFile = $POD_FILE_MAP{$pkgName}) | ||
| 90 | { | ||
| 91 | &log("Looking for pod file for '$pkgName'") if ($VERBOSE > 1); | ||
| 92 | $podFile = pod_where({ -inc => 1 }, $pkgName); | ||
| 93 | $podFile =~ s:\\:/:g; | ||
| 94 | $POD_FILE_MAP{$pkgName} = $podFile; | ||
| 95 | } | ||
| 96 | |||
| 97 | &error("Can't locate POD file for '$pkgName'") unless ($podFile); | ||
| 98 | |||
| 99 | if(wantarray) { ($podFile,$pkgName); } | ||
| 100 | else { $podFile; } | ||
| 101 | } | ||
| 102 | |||
| 103 | #------------------------------------------------------------------------------- | ||
| 104 | # Function: genPodHtml | ||
| 105 | # Description: Generate the HTML from the POD for the specified package | ||
| 106 | # Input Parms: Package Name | ||
| 107 | # Output Parms: POD HTML | ||
| 108 | #------------------------------------------------------------------------------- | ||
| 109 | sub genPodHtml | ||
| 110 | { | ||
| 111 | my ($pkgName,$htmlRoot) = @_; | ||
| 112 | my ($podFile,$pid,@html); | ||
| 113 | |||
| 114 | ($podFile,$pkgName) = &findPodFile($pkgName); | ||
| 115 | return undef unless ($podFile); | ||
| 116 | |||
| 117 | &log("Generating HTML for '$pkgName' from '$podFile'") if ($VERBOSE > 1); | ||
| 118 | |||
| 119 | if($pid = open(CHILD_STDOUT, "-|")) | ||
| 120 | { | ||
| 121 | &log("In parent, waiting for response from child") if ($VERBOSE > 3); | ||
| 122 | @html = <CHILD_STDOUT>; | ||
| 123 | close(CHILD_STDOUT); | ||
| 124 | waitpid $pid, 0; | ||
| 125 | } | ||
| 126 | elsif(defined $pid) | ||
| 127 | { | ||
| 128 | pod2html( | ||
| 129 | "--htmlroot=$htmlRoot", | ||
| 130 | "--header", | ||
| 131 | "--podpath=" . join(':',@INC), | ||
| 132 | "--libpods=VBTK", | ||
| 133 | "--norecurse", | ||
| 134 | "--infile=$podFile", | ||
| 135 | ); | ||
| 136 | |||
| 137 | exit 0; | ||
| 138 | } | ||
| 139 | else | ||
| 140 | { | ||
| 141 | error("genPodHtml: Can't fork"); | ||
| 142 | } | ||
| 143 | |||
| 144 | my $html = join('',@html); | ||
| 145 | |||
| 146 | if (wantarray) { ($html,$pkgName); } | ||
| 147 | else { $html; } | ||
| 148 | } | ||
| 149 | |||
| 150 | 1; | ||
| 151 | __END__ |