-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.pl
executable file
·58 lines (49 loc) · 1.15 KB
/
server.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/home/acme/perl-5.10.0/bin//perl
use strict;
use warnings;
use lib 'lib';
use HTTP::Engine;
use Kasago;
use Perl6::Say;
my $kasago = Kasago->new( root => 't/kasago' );
my $engine = HTTP::Engine->new(
interface => {
module => 'ServerSimple',
args => {
host => 'localhost',
port => 1978,
},
request_handler => 'main::handle_request',
},
);
$engine->run;
sub handle_request {
my $request = shift;
my $q = $request->parameters->{q};
my $html = qq{
<html>
<head>
<title>search</title>
</head>
<body>
<form method="post" action="/">
<input type="text" name="q" value="$q">
<input type="submit" value="Search">
</form>
};
if ($q) {
$html .= '<ul>';
my $hits = $kasago->search_html($q);
foreach my $hit (@$hits) {
my $filename = $hit->{filename};
my $score = $hit->{score};
my $excerpt = $hit->{excerpt};
#say "* $filename $score";
#say $excerpt;
$html .= "<li> $filename <pre>$excerpt</pre>";
}
$html .= '</ul>';
}
$html .= "</body></html>";
return HTTP::Engine::Response->new( body => $html );
}