Skip to content

Instantly share code, notes, and snippets.

/-

Created April 3, 2017 07:42
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/9604bd5f3c9c4f3620d0daedbdab975d to your computer and use it in GitHub Desktop.
Save anonymous/9604bd5f3c9c4f3620d0daedbdab975d 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';
use IO::Select;
has _inotify => sub {
my $self = shift;
my $i = Linux::Inotify2->new();
$i->watch($_, IN_MODIFY)
or die "Could not watch $_: $!"
for grep { -e $_ }
map { path($_)->list_tree({dir => 1})->each, $_ } @{$self->watch};
$i->blocking(0);
return $i;
};
sub modified_files {
my $self = shift;
my $select = IO::Select->new($self->_inotify->fileno);
$select->can_read($self->watch_timeout);
return [map { $_->{w}{name} } $self->_inotify->read];
}
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