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