root/lang/perl/Isoginner/trunk/lib/Isoginner/Plugin/Listener/Inotify.pm @ 3381

Revision 3381, 0.9 kB (checked in by yappo, 6 years ago)

lang/perl/Isoginner: fixed to typo s/attache/attach/

Line 
1package Isoginner::Plugin::Listener::Inotify;
2use strict;
3use warnings;
4use base 'Isoginner::Plugin::Listener';
5
6use Linux::Inotify2;
7
8sub init {
9    my $self = shift;
10    $self->{inotify} = Linux::Inotify2->new;
11}
12
13sub 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}
351;
36
Note: See TracBrowser for help on using the browser.