Linux::Perl::inotify
my $inf = Linux::Perl::inotify->new(); my $wd = $inf->add( path => $path, events => ['CREATE', 'ONLYDIR'] ); my @events = $inf->read(); $inf->remove($wd);
This is an interface to Linux’s “inotify” feature.
A hash reference of event names to numeric values. The member keys are:
ACCESS, MODIFY, ATTRIB
ACCESS
MODIFY
ATTRIB
OPEN, CLOSE, CLOSE_WRITE, CLOSE_NOWRITE
OPEN
CLOSE
CLOSE_WRITE
CLOSE_NOWRITE
MOVE, MOVED_FROM, MOVED_TO, MOVE_SELF
MOVE
MOVED_FROM
MOVED_TO
MOVE_SELF
CREATE, DELETE, DELETE_SELF
CREATE
DELETE
DELETE_SELF
UNMOUNT, Q_OVERFLOW, IGNORED, ISDIR
UNMOUNT
Q_OVERFLOW
IGNORED
ISDIR
See man 7 inotify for details of what these mean. This is useful to parse the return from read() (below).
man 7 inotify
read()
Instantiates a new inotify instance.
%OPTS is:
flags - Optional, an array reference of either or both of NONBLOCK and/or CLOEXEC.
flags
NONBLOCK
CLOEXEC
Adds to an inotify instance and returns a watch descriptor. See man 2 inotify_add_watch for more information.
man 2 inotify_add_watch
path - The filesystem path to monitor.
path
events - An array reference of events to monitor for. Recognized events are:
events
ALL_EVENTS
ONLYDIR, DONT_FOLLOW, EXCL_UNLINK, MASK_CREATE, MASK_ADD, ONESHOT
ONLYDIR
DONT_FOLLOW
EXCL_UNLINK
MASK_CREATE
MASK_ADD
ONESHOT
Note that your kernel may not recognize all of these.
Returns the inotify instance’s file descriptor number.
Reads events from the inotify instance. Each event is returned as a hash reference with members wd, mask, cookie, and name. See man 7 inotify for details about what these mean. (Use the members of EVENT_NUMBER() above to parse mask.)
wd
mask
cookie
name
EVENT_NUMBER()
Note that if the underlying inotify object is not set NONBLOCK then this call will block until there is an inotify event to read.
In scalar context this returns the number of events that happened.
An empty return here indicates a read failure; $! will contain the usual information about the failure.
$!
Analogous to man 2 inotify_rm_watch.
man 2 inotify_rm_watch
To install Linux::Perl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Linux::Perl
CPAN shell
perl -MCPAN -e shell install Linux::Perl
For more information on module installation, please visit the detailed CPAN module installation guide.