| 1 |
#!/home/ivan/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
no warnings qw(uninitialized); |
| 6 |
use CGI (); |
| 7 |
use Template; |
| 8 |
use lib qw(pod-indexing-snapshot/lib pod-indexing-snapshot/); |
| 9 |
use Pod::Perldoc; |
| 10 |
|
| 11 |
my $cgi = CGI->new; |
| 12 |
print $cgi->header; |
| 13 |
|
| 14 |
my $keyword = $cgi->param('keyword'); |
| 15 |
my $nocase = $cgi->param('nocase'); |
| 16 |
|
| 17 |
my $pod; |
| 18 |
my $err; |
| 19 |
my $out; |
| 20 |
|
| 21 |
if (defined $keyword) { |
| 22 |
open my $fh_out, ">", \$out or die; |
| 23 |
open my $fh_err, ">", \$err or die; |
| 24 |
my $old_stdout = *STDOUT; |
| 25 |
*STDOUT = $fh_out; |
| 26 |
*STDERR = $fh_err; |
| 27 |
push @ARGV, qw(-MPod::Perldoc::ToHTML -T -k), $keyword; |
| 28 |
push @ARGV, '-i' if $nocase; |
| 29 |
eval { Pod::Perldoc->run() }; |
| 30 |
$err .= $@; |
| 31 |
($pod) = $out =~ /<body.*?>(.*)<\/body>/s; |
| 32 |
*STDOUT = $old_stdout; |
| 33 |
} |
| 34 |
|
| 35 |
my $tt = Template->new; |
| 36 |
$tt->process(\*DATA, { |
| 37 |
pod => $pod, |
| 38 |
err => $err, |
| 39 |
keyword => $keyword, |
| 40 |
nocase => $nocase, |
| 41 |
script_name => $0, |
| 42 |
}) or die; |
| 43 |
|
| 44 |
__DATA__ |
| 45 |
<html> |
| 46 |
<head> |
| 47 |
<title>perldoc -k demo</title> |
| 48 |
<link rel="stylesheet" type="text/css" href="http://search.cpan.org/s/style.css"> |
| 49 |
<style type="text/css"> |
| 50 |
.err { color: red } |
| 51 |
.pod { width: 640px; margin-left: 30px } |
| 52 |
.pod h1 { font-size: 130% } |
| 53 |
.pod h2 { font-size: 120% } |
| 54 |
.pod h3 { font-size: 110% } |
| 55 |
.pod h4 { font-size: 100% } |
| 56 |
.k { color: green; font-family: monospace } |
| 57 |
a.u { color:black; text-decoration: none; } |
| 58 |
</style> |
| 59 |
</head> |
| 60 |
<body> |
| 61 |
<div id="header"><a href="/">POD Indexing Project</a></div> |
| 62 |
<h1><i>perldoc -k</i> demo</h1> |
| 63 |
<form action="/[% script_name %]"> |
| 64 |
Keyword to search: <input name="keyword" value="[% keyword | html %]"> |
| 65 |
<input type="submit"> |
| 66 |
<br><input type="checkbox" id="nocase" name="nocase" value="1" [% 'checked="checked"' IF nocase %]> <label for="nocase">Case-insensitive</label> |
| 67 |
</form> |
| 68 |
<hr> |
| 69 |
|
| 70 |
[% IF keyword %] |
| 71 |
<p>Searched for `<span class="k">[% keyword | html %]</span>'</p> |
| 72 |
[% END %] |
| 73 |
|
| 74 |
[% IF err %] |
| 75 |
<div class="err"> |
| 76 |
[% err %] |
| 77 |
</div> |
| 78 |
[% END %] |
| 79 |
|
| 80 |
[% IF pod %] |
| 81 |
<div class="pod">[% pod %]</div> |
| 82 |
[% END %] |
| 83 |
|
| 84 |
</body> |
| 85 |
</html> |