use strict;
use warnings;
use XML::LibXML;
use Linux::Inotify2;
my $drop_dir = "/foo/bar";
my $inotify = Linux::Inotify2->new
or die "unable to create new inotify object: $!";
$inotify->watch($drop_dir, IN_CREATE, sub {
my $e = shift;
my $name = $e->fullname;
process_drop_file($name);
});
1 while $inotify->poll;
sub process_drop_file {
my $file = Path::Class::File->new(shift);
-f $file or croak "'$file' is not a file";
my $doc = XML::LibXML->new->parse_file("$file");
# Do stuff with it...
$file->remove or croak "Couldn't remove '$file'";
}
####
/foo/bar/test.xml:1: parser error : Start tag expected, '<' not found
####
$inotify->watch($drop_dir, IN_CREATE, sub {
my $e = shift;
my $name = $e->fullname;
$inotify->watch($name, IN_CLOSE, sub {
process_drop_file($name);
});
});