Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 50 lines (36 sloc) 0.965 kb
ff7a10d @kappa Import Dancer skeleton
authored
1 package cpanhubble;
2 use Dancer;
3
8da717f @kappa First shot at actual web iface
authored
4 use lib './lib';
5 use CpanHub;
6 use AnyEvent;
8f3a334 @kappa Implement cacheing
authored
7 use Encode;
8 use CHI;
9
10 my $cache = CHI->new(driver => 'FastMmap', root_dir => '/tmp/hubble-cache', cache_size => '10m');
8da717f @kappa First shot at actual web iface
authored
11
ff7a10d @kappa Import Dancer skeleton
authored
12 get '/' => sub {
4dea552 @kappa Implement sane index
authored
13 template 'index';
ff7a10d @kappa Import Dancer skeleton
authored
14 };
15
8da717f @kappa First shot at actual web iface
authored
16 get '/search' => sub {
17 my ($cpan, $gh);
18
4fa03ae I cannot use "warning" from inside my libs
Alex Kapranoff authored
19 $SIG{__WARN__} = sub { warning $_[0] };
20
8f3a334 @kappa Implement cacheing
authored
21 my $cache_miss;
22 my $res = $cache->get(params->{q});
23 unless ($res) {
24 $cache_miss = 1;
25
26 my $cv = AnyEvent->condvar;
27 $cv->begin;
28 cpan_search_req(params->{q}, sub {
29 $cpan = $_[0];
30 $cv->end;
31 });
32
33 $cv->begin;
34 github_search_req(params->{q}, sub {
35 $gh = $_[0];
36 $cv->end;
37 });
8da717f @kappa First shot at actual web iface
authored
38
8f3a334 @kappa Implement cacheing
authored
39 $cv->recv;
8da717f @kappa First shot at actual web iface
authored
40
8f3a334 @kappa Implement cacheing
authored
41 $res = merge_cpan_and_github($cpan, $gh, params->{q});
8da717f @kappa First shot at actual web iface
authored
42
8f3a334 @kappa Implement cacheing
authored
43 $cache->set(params->{q}, $res, '2 days');
44 }
8da717f @kappa First shot at actual web iface
authored
45
8f3a334 @kappa Implement cacheing
authored
46 template 'serp', { res => $res, cache_miss => $cache_miss };
8da717f @kappa First shot at actual web iface
authored
47 };
48
ff7a10d @kappa Import Dancer skeleton
authored
49 true;
Something went wrong with that request. Please try again.