Plack つかうとこういうの簡単にかけてよい。
use common::sense;
use autodie;
use Plack::Runner;
use Plack::App::Directory;
use FindBin;
use Filesys::Notify::Simple;
use Parallel::Runner;
my $docsdir = "$FindBin::Bin/../../docs/";
my $htdocs = "$docsdir/_build/html/";
die "missing $htdocs" unless -d $htdocs;
my $runner = Parallel::Runner->new(2);
$runner->run(sub {
my $app = Plack::App::Directory->new({ root => $htdocs })->to_app;
my $runner = Plack::Runner->new();
$runner->parse_options(@ARGV);
$runner->run($app);
});
$runner->run(sub {
chdir $docsdir;
my $watcher = Filesys::Notify::Simple->new( ['.'] );
while (1) {
$watcher->wait(
sub {
system "make html";
}
);
}
});
$runner->finish();