Find By Contents

August 11, 2004

This will recursively search all the files, with a certain filename pattern (in this case *.h) in a certain directory, that contains a certain text pattern in its contents (in this case ‘DeviceDriver’).

find . -name '*.h' -print0 \
| xargs -0 grep -n -e DeviceDriver

CGI To Display Module Documentation

August 2, 2004

Here’s a CGI to display a module’s POD. The module has to be in the $INC. This is great for providing documentation to internal modules.


# save this as showdoc.cgi
#!/usr/local/bin/perl
use strict;

use Pod::Html;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

# Send out the header
print "Content-type: text/html", "\n\n";

my $q = new CGI;

my $module = $q->param('module');
require $module;

$| = 1;

chdir ("/tmp");

my $fullpath = $INC{$module}
    or die "$module not found";

pod2html("--infile=$fullpath", "--flush");

# Clean up the junk left by pod2html
END {
        unlink("pod2html-dircache");
        unlink("pod2html-itemcache");
}

To use this, say you want to view POD for Data::Dumper:


http://localhost/cgi-bin/showdoc.cgi?module=Data/Dumper.pm

Bad Behavior has blocked 14 access attempts in the last 7 days.