rlm@18: #!/usr/bin/perl rlm@18: rlm@18: use Linux::Inotify2; rlm@18: use WWW::Mechanize::Firefox; rlm@18: my $mech = WWW::Mechanize::Firefox->new(); rlm@18: rlm@18: my $inotify = new Linux::Inotify2 rlm@18: or die "unable to create new inotify object: $!"; rlm@18: rlm@18: $html_files = `find /home/r/proj/{cortex,aurellem,pokemon-types} -name "*.html" -print0`; rlm@18: @html_files = split /\0/, $html_files; rlm@18: rlm@18: rlm@18: #@org_files = glob("./org/*.org"); rlm@18: rlm@18: rlm@18: for $file(@html_files){print "$file\n";} rlm@18: rlm@18: $last_page = ""; rlm@18: rlm@18: foreach(@html_files){ rlm@18: $inotify->watch ($_, IN_MODIFY, sub rlm@18: { rlm@18: my $e = shift; rlm@18: my $name = $e->fullname; rlm@18: print "**************************\n"; rlm@18: print "$name was modified\n";## if $e->IN_MODIFY; rlm@18: rlm@18: $path = `readlink -f $name`; rlm@18: $path =~ s|/home/r/proj|http://aurellem.localhost|; rlm@18: #$path =~ s|org|html|g; rlm@18: rlm@18: if ($last_page eq $path){ rlm@18: print "reloading current page : $path\n"; rlm@18: $mech->reload(); rlm@18: } rlm@18: else { rlm@18: print "moving to new page : $path\n"; rlm@18: $last_page = $path; rlm@18: $mech->get($path); rlm@18: } rlm@18: }); rlm@18: } rlm@18: rlm@18: # manual event loop rlm@18: while (1){ rlm@18: print "I'm pollin'!"; rlm@18: $inotify->poll; rlm@18: rlm@18: }