-
-
Save anonymous/30b2427cf088cb4fbfd3a13c5004118c 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::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