Sunday, June 29, 2008

Fast Perl HTML POD Creation On Linux and Unix

Hey There,

For our "Lazy Sunday" Post this week, we're going to look at some more, hopefully, useful and easy html creation, like we've done many times in the past with posts on listing out Linux or Unix crontabs and a few others. Today's Bash shell script will produce an index.html file (and a whole lot of others) that should end up as your one-stop-shop for the documentation that came with your system's Perl distribution. It's nothing fancy (although you can make it that way if you want) but it should serve its purpose well enough right out-of-the-box.

Of course, you should edit the POD_HTML_DIR variable, at the least, so that the script can find your Perl modules and use pod2html to convert them. Other than that, running it straight-up, like so:

host # ./

should produce output like below, in the following two pictures (click on them to make them larger if you need to :)

Perl Module Repository Index Page
Perl Module Repository Module Page

Hope you enjoy the script and it brings you some convenience! Note that I'm 100% aware that there is no error handling done for files that can't be created (i.e. when pod2html fails, a blank html page is hyperlinked to rather than no hyperlink, or html, being created), but that should make the whole experience more educational if you want to add that. You can refer to our earlier posts on Bash's implementation of errno and the Bash-specific PIPESTATUS variable to help handle those errors and do what you want with them ;)

Happy Sunday,

Creative Commons License

This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License


# - make perdocs into one html repository
# 2008 - Mike Golvach -
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License

trap 'cd $PWD;rm -rf $POD_HTML_DIR;exit 2' 1 2 3 15


if [ -d $POD_HTML_DIR ]
rm -rf $POD_HTML_DIR

mkdir podhtml
echo -n "Working on it..."

find $PERL_MANPAGE_BASE -name "*.pm"|while read line do
echo -n "."
output=`echo $line|sed 's/^.*\/\(.*\)$/\1/'`
pod2html $line >podhtml/${output}.html 2>/dev/null;


echo "<html><head><title>Perl Module Document Repository</title></head><body>" >$INDEX_PAGE
ls |grep html|while read line
echo "<a href=\"$line\">$line</a><br>" >>$INDEX_PAGE

echo "</body></html>" >> $INDEX_PAGE
echo "done"

, Mike