#!/usr/bin/perl use CGI qw/:standard/; use HTML::Template; use Pod::MyHtml; use Pod::Index; use strict; my ($param,%input); foreach $param (param()) { $input{$param} = param($param); } my $template = HTML::Template->new(filename => '../templates/podindex.tmpl'); my $text; if (defined $input{'terms'}) { $text = search(\%input,$template); } elsif (defined $input{'pod'}) { $input{'pod'} =~ s/\.\.+//g; $input{'pod'} =~ s![^\w/.-]!!; $text = pod2html("/usr/local/perl580/$input{'pod'}"); } else { $text = home(\%input,$template); } print header(); print $text; exit 0; sub search { my ($input,$tmpl) = @_; my $text; # searchtype $input->{'searchtype'} = 'ft' unless defined $input->{'searchtype'}; $input->{'searchtype'} =~ s/\W//g; if ($input->{'searchtype'} eq 'toc') { $tmpl->param(TOC_CHECKED => 'checked'); } else { $input->{'searchtype'} = 'ft'; $tmpl->param(FT_CHECKED => 'checked'); } # maxhits $input->{'maxhits'} = 15 unless defined $input->{'maxhits'}; $input->{'maxhits'} =~ s/\D//g; if ($input->{'maxhits'} =~ /^10|15|20|30$/) { $tmpl->param("SELECTED_$input->{'maxhits'}" => 'selected'); } else { $input->{'maxhits'} = 15; $tmpl->param(SELECTED_15 => 'selected'); } # terms $input->{'terms'} = '' unless defined $input->{'terms'}; $input->{'terms'} =~ s/[^\w ]/ /g; $input->{'terms'} = substr($input->{'terms'},0,255) if length $input->{'terms'} > 256; $tmpl->param(TERMS => $input->{'terms'}); my $results = ""; if ($input->{'terms'}) { my @terms = split ' ', $input->{'terms'}; my $pi_input = { quiet => 2, search => $input->{'searchtype'}, maxhits => $input->{'maxhits'}, terms => \@terms, mode => "filter", }; my $pi = Pod::Index->new($pi_input); my $ret = $pi->search_pods($pi_input); $results .= "\n"; my $cols; if ($input->{'searchtype'} eq 'ft') { $cols = 2; $results .= qq(\n); } else { $cols = 3; $results .= qq(\n); } unless (@{$ret}) { $results .= qq(\n); } else { my $line; foreach $line (@{$ret}) { shift @{$line}; $line->[0] = sprintf('%2.6f',$line->[0]) if $input->{'searchtype'} eq 'ft'; $line->[-1] = qq($line->[-1]); $results .= qq(\n"; } } $results .= "
ScoreLocation
PhraseLineLocation
Sorry. Either your search terms are unknown or too common. Try again.
) . join (qq(),@{$line}) . "
\n"; } else { $results = qq(Please enter on or more valid search terms); } $tmpl->param(RESULTS => qq(
$results
)); return $tmpl->output; } sub home { my ($input,$tmpl) = @_; $tmpl->param(TOC_CHECKED => 'checked'); $tmpl->param(SELECTED_15 => 'selected'); return $tmpl->output; }