|
Revision 3381, 0.9 kB
(checked in by yappo, 6 years ago)
|
|
lang/perl/Isoginner: fixed to typo s/attache/attach/
|
| Line | |
|---|
| 1 | package Isoginner::Plugin::Listener::Inotify; |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | use base 'Isoginner::Plugin::Listener'; |
|---|
| 5 | |
|---|
| 6 | use Linux::Inotify2; |
|---|
| 7 | |
|---|
| 8 | sub init { |
|---|
| 9 | my $self = shift; |
|---|
| 10 | $self->{inotify} = Linux::Inotify2->new; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | sub attach : Hook('listener.attach') { |
|---|
| 14 | my($self, $c) = @_; |
|---|
| 15 | |
|---|
| 16 | my $provider_id = $self->conf->{provider} or return; |
|---|
| 17 | my @providers = $c->listener->by_id($provider_id); |
|---|
| 18 | |
|---|
| 19 | for my $listener (@providers) { |
|---|
| 20 | next unless $listener->type eq 'path'; |
|---|
| 21 | for my $path ($listener->objects) { |
|---|
| 22 | $c->log( debug => "atacched $path by " . $listener->id); |
|---|
| 23 | $self->{inotify}->watch($path, IN_ALL_EVENTS); |
|---|
| 24 | } |
|---|
| 25 | $listener->add_watcher( $self ); |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | $c->call( engine_add_fd => $self->{inotify}->fileno => sub { |
|---|
| 29 | my @events = $self->{inotify}->read; |
|---|
| 30 | for my $event (@events) { |
|---|
| 31 | $c->action($provider_id, $event); |
|---|
| 32 | } |
|---|
| 33 | }); |
|---|
| 34 | } |
|---|
| 35 | 1; |
|---|
| 36 | |
|---|