Linux::Inotify2 1.01 review
Download
|
|
Linux::Inotify2 is a scalable directory/file change notification.
SYNOPSIS
Callback interface
use Linux::Inotify2;
# create a new object
my $inotify = new Linux::Inotify2
or die "Unable to create new inotify object: $!";
# for Event:
Event->io (fd =>$inotify->fileno, poll => 'r', cb => sub { $inotify->poll });
# for Glib:
add_watch Glib::IO $inotify->fileno, in => sub { $inotify->poll };
# manually:
1 while $inotify->poll;
# add watchers
$inotify->watch ("/etc/passwd", IN_ACCESS, sub {
my $e = shift;
my $name = $e->fullname;
print "$name was accessedn" if $e->IN_ACCESS;
print "$name is no longer mountedn" if $e->IN_UNMOUNT;
print "$name is gonen" if $e->IN_IGNORED;
print "events for $name have been lostn" if $e->IN_Q_OVERFLOW;
# cancel this watcher: remove no further events
$e->w->cancel;
});
Streaming Interface
use Linux::Inotify2 ;
# create a new object
my $inotify = new Linux::Inotify2
or die "Unable to create new inotify object: $!" ;
# create watch
$inotify->watch ("/etc/passwd", IN_ACCESS)
or die "watch creation failed" ;
while () {
my @events = $inotify->read;
unless (@events > 0) {
print "read error: $!";
last ;
}
printf "maskt%dn", $_->mask foreach @events ;
}
This module implements an interface to the Linux 2.6.13 and later Inotify file/directory change notification sytem.
It has a number of advantages over the Linux::Inotify module:
- it is portable (Linux::Inotify only works on x86)
- the equivalent of fullname works correctly
- it is better documented
- it has callback-style interface, which is better suited for
integration.
Requirements:
Perl
Linux::Inotify2 1.01 keywords