Last active
April 5, 2017 01:30
-
-
Save jberger/1badbc7b8b6eb0daea4aa5d63743a6c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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