10 my $cv = AnyEvent->condvar;
13 my $inotify = Linux::Inotify2->new;
14 $inotify->watch("/srv/analysis.sesse.net/analysis.json", IN_MODIFY, sub {
19 my $inotify_w = AnyEvent->io (
20 fh => $inotify->fileno, poll => 'r', cb => sub { $inotify->poll }
22 my $wait = AnyEvent->timer (
24 cb => sub { $cv->send; },
28 if (exists($ENV{'HTTP_IF_MODIFIED_SINCE'})) {
29 my $date = Date::Manip::Date->new;
30 $date->parse($ENV{'HTTP_IF_MODIFIED_SINCE'});
31 $ims = $date->printf("%s");
33 my $time = (stat("/srv/analysis.sesse.net/analysis.json"))[9];
35 # If we have something that's modified since IMS, send it out at once
41 # If not, wait, then send. Apache will deal with the 304-ing.
42 if (defined($cgi->param('first')) && $cgi->param('first') != 1) {
48 my $time = (stat("/srv/analysis.sesse.net/analysis.json"))[9];
49 my $lm_str = POSIX::strftime("%a, %d %b %Y %H:%M:%S %z", localtime($time));
51 print CGI->header(-type=>'text/json',
52 -last_modified=>$lm_str,
53 -access_control_allow_origin=>'http://analysis.sesse.net',
55 open my $fh, "<", "/srv/analysis.sesse.net/analysis.json"
56 or die "/srv/analysis.sesse.net/analysis.json: $!";