view auto-weave.pl @ 13:be73e58d4b24 v0.1

cleanup
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 08:09:06 -0700
parents 24ff8a9c76c4
children 6ef9ccf7a17e
line wrap: on
line source
1 #!/usr/bin/perl
3 use Linux::Inotify2;
4 use WWW::Mechanize::Firefox;
5 my $mech = WWW::Mechanize::Firefox->new();
7 my $inotify = new Linux::Inotify2
8 or die "unable to create new inotify object: $!";
10 @org_files = glob("./org/*.org");
12 $" = "\n";
13 print "@org_files\n";
15 $ignore_next = 0;
18 foreach(@org_files){
19 # add watchers
20 $inotify->watch ($_, IN_MODIFY, sub
21 {
22 print ("IGNORE : $ignore_next\n");
23 # ok, for some reason this get's called exactly
24 # twice every time the file is saved from emacs.
25 # so ignore every other invocation.
26 if ($ignore_next) {
27 $ignore_next = 0;
28 return;
29 }
30 $ignore_next = 1;
32 my $e = shift;
33 my $name = $e->fullname;
34 print "$name was modified\n" if $e->IN_MODIFY;
35 $output = `weave $name`;
36 $path = `readlink -f $name`;
37 $path =~ s|/home/r/proj|http://aurellem.localhost|;
38 $path =~ s|org|html|g;
39 $mech->get($path);
40 });
41 }
44 # manual event loop
45 1 while $inotify->poll;