Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

A CGI to read PODS (was Re: CGI perldoc with pod2htm)

by jZed (Prior)
on Jun 14, 2004 at 20:39 UTC ( [id://366684]=note: print w/replies, xml ) Need Help??


in reply to CGI perldoc with pod2htm

Here's what I use:

UPDATE I've added code to handle .pod files as well as .pm files. This means you can put Pod::perl or Pod::perlreftut in the query box to see the HTML equivalents of "perldoc perl" etc. You can also see a directory listing of the Pod:: hierarchy (or any hierarchy) by putting a slash after th the hierarchy name (e.g. mod=Pod/ will display a clickable list of pods in the Pod::* hierarchy).

#!perl -w # # by Jeff Zucker # # may be freely modified and distributred under the same terms as Perl + itself # use strict; use CGI; use CGI::Carp qw/fatalsToBrowser/; use File::Find; use Pod::Html; my $page = new CGI; my $modname = $page->param('mod') || ''; show_form(); if( $modname =~ m#/# ) { show_dir($modname); } else { show_pod( $modname ); } sub show_form { print $page->header, $page->start_html(-title=>'POD FINDER'), $page->start_form, $page->b("Module Name : "), $page->textfield(-name=>'mod'), $page->end_form, $page->end_html, ; } sub show_pod { my $modname = shift; return unless $modname; $modname =~ s#::#/#g; my $filename = findmod( $modname ); pod2html("--quiet","--infile=$filename") if $filename; } sub show_dir { my $dir = shift; $dir =~ s#/$##g; my $scriptname = $page->script_name; for(@INC){ my $fdir = "$_/$dir"; if( -d $fdir ) { opendir(D,$fdir) || die $!; my @files = readdir D; closedir D; for(@files) { next unless /(.*)\.(pm|pod)$/i; print "<a href='$scriptname?mod=$dir\:\:$1'>$dir\:\:$1 +</a><br>"; } } } return ''; } sub findmod { my $mod = shift; if (-e $mod ) { return $mod; } for(@INC){ my $modname = "$_/$mod.pm"; if( -e $modname ) { return $modname; } $modname = "$_/$mod.pod"; if( -e $modname ) { return $modname; } } return ''; } __END__

Replies are listed 'Best First'.
Re: A CGI to read PODS (was Re: CGI perldoc with pod2htm)
by spartan (Pilgrim) on Jun 15, 2004 at 19:59 UTC
    Brilliant! ++ to the poster.
    Although I would like to offer some very minimal constructive criticism. I'm a bit lazy at times, and depending on the complexity of the code I'm looking at, I'll either try to dissect it for my own edification, or just move on (I know shame on me, I'll never learn anything, etc, etc..). To make a long story short, I would have added a print statement in your show_form subroutine and added a line saying to submit a slash "/" to get a listing of all the POD docs on the system.
    Grea code though, I know I'll make use of it.


    Very funny Scotty... Now PLEASE beam down my PANTS!
Re: A CGI to read PODS (was Re: CGI perldoc with pod2htm)
by hmerrill (Friar) on Jun 29, 2004 at 17:18 UTC
    Excellent JZed! The updates fix problems that I was trying to fix myself, but I was unsuccessful. Very nice code.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://366684]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-25 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found