Skip to content

Instantly share code, notes, and snippets.

/-

Created April 3, 2017 07:09
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 anonymous/30b2427cf088cb4fbfd3a13c5004118c to your computer and use it in GitHub Desktop.
Save anonymous/30b2427cf088cb4fbfd3a13c5004118c to your computer and use it in GitHub Desktop.
package Mojo::Server::Morbo::Backend::Inotify;
use Mojo::Base 'Mojo::Server::Morbo::Backend';
use Linux::Inotify2;
use Mojo::File 'path';
has _inotify => sub {
my $self = shift;
my $i = Linux::Inotify2->new();
$i->watch($_, IN_MODIFY)
or die "Could not watch $_: $!"
for grep { warn $_; -e $_ } map { path($_)->list_tree({dir=>1})->each, $_ } @{$self->watch};
$i->blocking(0);
return $i;
};
sub modified_files {
my $self = shift;
sleep $self->watch_timeout;
my @events = $self->_inotify->read;
return @events ? [map { $_->{w}{name} } @events] : [];
}
1;
=encoding utf8
=head1 NAME
Mojo::Server::Morbo::Backend::Inotify - Sample Morbo Inotify watcher
=head1 SYNOPSIS
my $backend=Mojo::Server::Morbo::Backend::Inotify->new();
if ($backend->modified_files) {...}
=head1 DESCRIPTION
Sample
=head1 METHODS
L<Mojo::Server::Morbo::Backend::Inotify> inherits all methods from
L<Mojo::Server::Morbo::Backend>.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicious.org>.
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment