NAME

Workflow::Inotify::Handler - base class for creating Linux::Inotify2 handlers

SYNOPSIS

package MyHandler;

use parent qw(Workflow::Inotify::Handler);

sub handler {
  my ($self, $e) = @_;

  print {*STDERR} sprintf("event: %s name: %s\n", $e->mask, $e->fullname); 
}

1;

DESCRIPTION

Base class for creating Linux::Inotify2 event handlers. You can use this base class to implement a handler that responds to events generated by inotify events. Your event handlers can do pretty much anything they want, including fork() a new process. In general however, you want your handlers to be fast and lightweight.

A typical implementation will unload, possibly filter or interpret, then queue the event for another process to handle. This technique encourages a high degree of decoupling of your architecture and ensures your handlers can process all events.

Note that using Workflow::Inotify::Handler as a base class is not strictly required when using the inotify.pl script...as long as your class contains a handler() method. What you get from this class is an object that sub-classes Class::Accessor::Fast and creates accessors for all your configuration values.

new

new( config, [app config] )

The class is instantiated by the inotify.pl script and is passed a Config::IniFiles object. Override the handler() or the new() method if you choose.

HINT: You can add additional application specific values to the configuration file and access their values using the Config::IniFiles object passed in the constructor.

my $user_name = $self->get_config()->val(application => 'user_name');

BONUS: If you add a section to the configuration file using the canonical form (lower and snake cased) of your handler's name, the second argument to the constructor will be a hash containing all of the values in that section which will be used by the default new() method to create accessors for each value. Accessors are named using the best practice of separater setters and getters for each value (e.g. get_foo(), set_foo()).

[workflow_s3_uploader]
bucket        = foo
bucket_prefix = /biz
region        = us-east-1
host          = s3.amazonaws.com

...

sub handler {
  my ($event) = @_;

  my $host = $self->get_host();
  ...
}

INOTIFY EVENTS

....from man 7 inotify...

The inotify_add_watch(2) mask argument and the mask field of the inotify_event structure returned when read(2)ing an inotify file descriptor are both bit masks identifying inotify events. The following bits can be specified in mask when calling inotify_add_watch(2) and may be returned in the mask field returned by read(2):

  • IN_ACCESS (+)

    File was accessed (e.g., read(2), execve(2)).

  • IN_ATTRIB (*)

    Metadata changed for example, permissions (e.g., chmod(2)), timestamps (e.g., utimensat(2)), extended attributes (setxattr(2)), link count (since Linux 2.6.25; e.g., for the target of link(2) and for unlink(2)), and user/group ID (e.g., chown(2)).

  • IN_CLOSE_WRITE (+)

    File opened for writing was closed.

  • IN_CLOSE_NOWRITE (*)

    File or directory not opened for writing was closed.

  • IN_CREATE (+)

    File/directory created in watched directory (e.g., open(2) O_CREAT, mkdir(2), link(2), symlink(2), bind(2) on a UNIX domain socket).

  • IN_DELETE (+)

    File/directory deleted from watched directory.

  • IN_DELETE_SELF

    Watched file/directory was itself deleted. (This event also occurs if an object is moved to another filesystem, since mv(1) in effect copies the file to the other filesystem and then deletes it from the original filesystem.) In addition, an=item * IN_IGNORED event will subsequently begenerated for the watch descriptor.

  • IN_MODIFY (+)

    File was modified (e.g., write(2), truncate(2)).

  • IN_MOVE_SELF

    Watched file/directory was itself moved.

  • IN_MOVED_FROM (+)

    Generated for the directory containing the old filename when a file is renamed.

  • IN_MOVED_TO (+)

    Generated for the directory containing the new filename when a file is renamed.

  • IN_OPEN (*)

    File or directory was opened.

When monitoring a directory:

  • the events marked above with an asterisk (*) can occur both for the directory itself and for objects inside the directory; and

  • the events marked with a plus sign (+) occur only for objects inside the directory (not for the directory itself).

handler

handler( event )

An instance of Linux::Inotify::Event. See Linux::Inotify2

config

The method of your class that will handle the event.

event

An instance of Linux::Inotify::Event. See Linux::Inotify2

get_config

get_config()

Returns a Config::IniFiles object initialized from your configuration file.

AUTHOR

Rob Lauer - <rlauer6@comcast.net>

SEE ALSO

"Linux::Inotify2"

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 134:

Unterminated C<...> sequence

Around line 246:

=back without =over