NAME
POEx::DirNotify - dnotify interface for POE
SYNOPSIS
use strict;
use POE;
use POEx::DirNotify;
POEx::DirNotify->new( alias=>'notify' );
POE::Session->create(
package_states => [
'main' => [ qw(_start notification) ],
],
);
$poe_kernel->run();
exit 0;
sub _start {
my( $kernel, $heap ) = @_[ KERNEL, HEAP ];
$kernel->post( 'notify' => monitor => {
path => '.',
event => 'notification',
args => [ $args ]
} );
return;
}
sub notification {
my( $kernel, $hashref, $args ) = @_[ KERNEL, ARG0, ARG1];
print "Something changed in $hashref->{path}\n";
$kernel->post( notify => 'shutdown' );
return;
}
DESCRIPTION
POEx::DirNotify is a simple interface to the Linux file and directory change notification interface, also called dnotify
.
It can monitor an existing directory for new files, deleted files, new directories and more. It can not detect the monitored directory being deleted. This is a limitation of the underlying dnotify.
METHODS
spawn
POEx::Session->spawn( %options );
Takes a number of arguments, all of which are optional.
- alias
-
The session alias to register with the kernel. Defaults to
dnotify
. - options
-
A hashref of POE::Session options that are passed to the component's session creator.
EVENTS
monitor
$poe_kernel->call( dnotify => 'monitor', $arg );
Starts monitoring the specified path for the specified types of changes.
Accepts one argument, a hashref containing the following keys:
- path
-
The filesystem path to the directory to be monitored. Mandatory.
- event
-
The name of the event handler in the current session to post changes back to. Mandatory.
- args
-
An arrayref of arguments that will be passed to the event handler.
unmonitor
$poe_kernel->call( dnotify => 'unmonitor', $arg );
Ends monitoring of the specified path for the current session.
Accepts one argument, a hashref containing the following keys:
- path
-
The filesystem path to the directory to be unmonitored. Mandatory.
shutdown
$poe_kernel->call( dnotify => 'shutdown' );
# OR
$poe_kernel->signal( $poe_kernel => 'shutdown' );
Shuts down the component gracefully. All monitored paths will be closed. Has no arguments.
SEE ALSO
AUTHOR
Philip Gwyn, <gwyn -at- cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2010 by Philip Gwyn. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.