rlm@6: #!/usr/bin/perl rlm@6: rlm@6: use Linux::Inotify2; rlm@11: use WWW::Mechanize::Firefox; rlm@11: my $mech = WWW::Mechanize::Firefox->new(); rlm@6: rlm@6: my $inotify = new Linux::Inotify2 rlm@6: or die "unable to create new inotify object: $!"; rlm@6: rlm@6: rlm@6: @org_files = glob("./org/*.org"); rlm@6: rlm@6: $" = "\n"; rlm@8: print "@org_files\n"; rlm@6: rlm@9: $ignore_next = 0; rlm@9: rlm@6: rlm@6: foreach(@org_files){ rlm@6: # add watchers rlm@6: $inotify->watch ($_, IN_MODIFY, sub rlm@6: { rlm@9: print ("IGNORE : $ignore_next\n"); rlm@9: # ok, for some reason this get's called exactly rlm@9: # twice every time the file is saved from emacs. rlm@9: # so ignore every other invocation. rlm@9: if ($ignore_next) { rlm@9: $ignore_next = 0; rlm@9: return; rlm@9: } rlm@9: rlm@9: my $e = shift; rlm@9: my $name = $e->fullname; rlm@9: print "$name was modified\n" if $e->IN_MODIFY; rlm@9: $output = `weave $name`; rlm@9: print ("$name\n"); rlm@9: $path = `readlink -f $name`; rlm@9: $path =~ s|/home/r/proj|http://aurellem.localhost|; rlm@9: print ("$path\n"); rlm@9: $path =~ s|org|html|g; rlm@9: print ("$path\n"); rlm@9: #system ("firefox $path"); rlm@11: $mech->get($path); rlm@9: $ignore_next = 1; rlm@8: rlm@6: }); rlm@6: } rlm@6: rlm@6: rlm@6: rlm@6: rlm@6: # integration into AnyEvent (works with EV, Glib, Tk, POE...) rlm@8: #my $inotify_w = AnyEvent->io rlm@8: # ( rlm@8: # fh => $inotify->fileno, poll => 'r', cb => sub { $inotify->poll } rlm@8: # ); rlm@6: rlm@6: # manual event loop rlm@6: 1 while $inotify->poll;