POEx::DirNotify - dnotify interface for POE
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; }
POEx::DirNotify is a simple interface to the Linux file and directory change notification interface, also called dnotify.
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.
POEx::Session->spawn( %options );
Takes a number of arguments, all of which are optional.
The session alias to register with the kernel. Defaults to dnotify.
A hashref of POE::Session options that are passed to the component's session creator.
$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:
The filesystem path to the directory to be monitored. Mandatory.
The name of the event handler in the current session to post changes back to. Mandatory.
An arrayref of arguments that will be passed to the event handler.
$poe_kernel->call( dnotify => 'unmonitor', $arg );
Ends monitoring of the specified path for the current session.
The filesystem path to the directory to be unmonitored. Mandatory.
$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.
POE, POEx::Inotify.
This module's API was heavily inspired by POE::Component::Win32::ChangeNotify.
Philip Gwyn, <gwyn -at- cpan.org>
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.
To install POEx::DirNotify, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POEx::DirNotify
CPAN shell
perl -MCPAN -e shell install POEx::DirNotify
For more information on module installation, please visit the detailed CPAN module installation guide.