annotate auto-weave.pl @ 11:24ff8a9c76c4

all day for three lines
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 08:00:48 -0700
parents d09937a6cb4b
children be73e58d4b24
rev   line source
rlm@6 1 #!/usr/bin/perl
rlm@6 2
rlm@6 3 use Linux::Inotify2;
rlm@11 4 use WWW::Mechanize::Firefox;
rlm@11 5 my $mech = WWW::Mechanize::Firefox->new();
rlm@6 6
rlm@6 7 my $inotify = new Linux::Inotify2
rlm@6 8 or die "unable to create new inotify object: $!";
rlm@6 9
rlm@6 10
rlm@6 11 @org_files = glob("./org/*.org");
rlm@6 12
rlm@6 13 $" = "\n";
rlm@8 14 print "@org_files\n";
rlm@6 15
rlm@9 16 $ignore_next = 0;
rlm@9 17
rlm@6 18
rlm@6 19 foreach(@org_files){
rlm@6 20 # add watchers
rlm@6 21 $inotify->watch ($_, IN_MODIFY, sub
rlm@6 22 {
rlm@9 23 print ("IGNORE : $ignore_next\n");
rlm@9 24 # ok, for some reason this get's called exactly
rlm@9 25 # twice every time the file is saved from emacs.
rlm@9 26 # so ignore every other invocation.
rlm@9 27 if ($ignore_next) {
rlm@9 28 $ignore_next = 0;
rlm@9 29 return;
rlm@9 30 }
rlm@9 31
rlm@9 32 my $e = shift;
rlm@9 33 my $name = $e->fullname;
rlm@9 34 print "$name was modified\n" if $e->IN_MODIFY;
rlm@9 35 $output = `weave $name`;
rlm@9 36 print ("$name\n");
rlm@9 37 $path = `readlink -f $name`;
rlm@9 38 $path =~ s|/home/r/proj|http://aurellem.localhost|;
rlm@9 39 print ("$path\n");
rlm@9 40 $path =~ s|org|html|g;
rlm@9 41 print ("$path\n");
rlm@9 42 #system ("firefox $path");
rlm@11 43 $mech->get($path);
rlm@9 44 $ignore_next = 1;
rlm@8 45
rlm@6 46 });
rlm@6 47 }
rlm@6 48
rlm@6 49
rlm@6 50
rlm@6 51
rlm@6 52 # integration into AnyEvent (works with EV, Glib, Tk, POE...)
rlm@8 53 #my $inotify_w = AnyEvent->io
rlm@8 54 # (
rlm@8 55 # fh => $inotify->fileno, poll => 'r', cb => sub { $inotify->poll }
rlm@8 56 # );
rlm@6 57
rlm@6 58 # manual event loop
rlm@6 59 1 while $inotify->poll;