Skip to content

Instantly share code, notes, and snippets.

@jberger
Last active April 5, 2017 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jberger/1badbc7b8b6eb0daea4aa5d63743a6c8 to your computer and use it in GitHub Desktop.
Save jberger/1badbc7b8b6eb0daea4aa5d63743a6c8 to your computer and use it in GitHub Desktop.
package Mojo::Server::Morbo::Backend::Win32;
use Mojo::Base 'Mojo::Server::Morbo::Backend';
use File::Spec;
use Win32::ChangeNotify;
use constant MODE => 'ATTRIBUTES|DIR_NAME|FILE_NAME|LAST_WRITE|SECURITY|SIZE';
sub modified_files {
my $self = shift;
$self->{watched} ||= [
map {
my $path = File::Spec->canonpath($_);
{ path => $path, watcher => Win32::ChangeNotify->new($path, 1, MODE) }
} @{ $self->watch }
];
my @w = map { $_->{watcher}->reset; $_->{watcher} } @{ $self->{watched} };
my $n = Win32::ChangeNotify::wait_any(@w, $self->watch_timeout);
return [] unless $n > 0;
return [ $self->{watched}[$n-1]{path} ];
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment