# Copyright (C) all contributors
# License: AGPL-3.0+
# wrap Linux::Inotify2 XS module, support pure Perl via `syscall' someday
package PublicInbox::Inotify;
use v5.12;
our @ISA;
BEGIN { # prefer pure Perl since it works out-of-the-box
my $isa;
for my $m (qw(PublicInbox::Inotify3 Linux::Inotify2)) {
eval "require $m";
next if $@;
$isa = $m;
}
if ($isa) {
push @ISA, $isa;
my $buf = '';
for (qw(IN_MOVED_TO IN_CREATE IN_DELETE IN_DELETE_SELF
IN_MOVE_SELF IN_MOVED_FROM IN_MODIFY)) {
$buf .= "*$_ = \\&PublicInbox::Inotify3::$_;\n";
}
eval $buf;
die $@ if $@;
} else {
die <SUPER::new // do {
my $msg = $!{EMFILE} ? <new: $!\n";
inotify_init/inotify_init1: $!
You may need to raise the `fs.inotify.max_user_instances' sysctl limit.
Consult your OS documentation and/or sysctl(8) + sysctl.conf(5) manpages.
EOM
$msg =~ s/^/E: /smg;
require Carp;
Carp::croak($msg);
}
}
1;