The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

UniEvent::FsEvent - cross-platform file/dir monitoring

SYNOPSIS

    use UniEvent::FsEvent; # imports constants

    my $h = UniEvent::FsEvent->new;
    $h->start("/tmp/", RECURSIVE, sub {
        my ($handle, $filename, $events, $error_code) = @_;
            if ($events & RENAME) {
            say "file $filename has been renamed";
        }
    });
    UE::Loop->default->run;

DESCRIPTION

The FsEvent is useful for monitoring individual file events , e.g. when file is renamed, created or when its content was changed. It works on major operational systems, including Windows; however the order of events might be system dependent. This handle uses the best backend for the job on each platform.

The UniEvent::FsEvent is inherited from UniEvent::Handle.

METHODS

All methods of UniEvent::Handle also apply.

create($path, $flags, $callback, [$loop = default])

    my $handle = UniEvent::FsEvent->create("my/file", 0, sub { say "hi" });

Creates and starts an fs event handle. Alias for new($loop) + start($path, $flags, $callback).

new([$loop = default])

Constructs new FsEvent handle and binds it to the specified event loop

start($path, [$flags], [$callback])

Starts monitoring file system events on the specified $path, i.e. makes it active for the next even loop iteration. The $path can point to file as well as to directory.

The $flags is a bitmask of (in UE::FsEvent::*):

RECURSIVE

Watch for changes recursively (might not be available on all operating systems)

May return error

stop()

Stops monitoring file system events.

May return error

callback($sub)

event()

Callback signature:

    my ($handle, $filename, $events, $error) = @_;

Where $handle is the FsEvent handle object itself.

$filename is path to the triggered file. If the handle was started with a directory the filename parameter will be a relative path to a file contained in the directory.

The $events parameter is an ORed mask of these flags (in UE::FsEvent::*):

RENAME

When file was moved

CHANGE

When file data (content) or metadata changes (e.g. mtime).

The $error parameter will be an XS::ErrorCode object if any.

See "EVENT CALLBACKS" in UniEvent

event_listener($delegate, [$weak])

Method on_fs_event will be called.

See "EVENT LISTENER" in UniEvent

path()

Returns the currently monitored path.

CONSTANTS