Skip to content

Instantly share code, notes, and snippets.

@sugar84
Created February 13, 2012 12:07
Show Gist options
  • Save sugar84/1816344 to your computer and use it in GitHub Desktop.
Save sugar84/1816344 to your computer and use it in GitHub Desktop.
Example of AnyEvent::Filesys::Notify
#!/usr/bin/env perl
use common::sense;
use AnyEvent::Filesys::Notify;
use AnyEvent;
my $src = "/my/proj/path/htdocs";
my $dst = "/var/www/html";
my $cv = AnyEvent->condvar;
my $notifier = AnyEvent::Filesys::Notify->new(
dirs => [$src],
interval => 0.5,
filter => sub {
my $item = shift;
return $item =~ /\.(css|js)$/ && $item !~ /svn/;
},
cb => sub {
my @events = @_;
for my $event (@events) {
next if $event->type ne 'modified';
my $item = $event->path;
if ($item =~ /css$/) {
system("cp $item ${dst}/css");
}
elsif ($item =~ /js$/) {
system("cp $item ${dst}/js");
}
}
},
);
$cv->recv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment