NAME
Linux::Event::Watcher - Mutable watcher handle for Linux::Event::Loop
SYNOPSIS
use v5.36;
use Linux::Event;
my $loop = Linux::Event->new;
my $conn = My::Conn->new(...);
my $w = $loop->watch($fh,
read => \&My::Conn::on_read,
write => \&My::Conn::on_write,
error => \&My::Conn::on_error, # optional
data => $conn, # optional
);
$w->disable_write;
# later...
$w->enable_write;
# stop watching (does not close the fh)
$w->cancel;
DESCRIPTION
A watcher is a lightweight mutable handle owned by the loop. It stores callbacks, enable/disable state, and optional user data. The loop manages backend polling and dispatch.
Watchers do not own the underlying filehandle; user code is responsible for closing resources. Recommended teardown order is $w->cancel; close $fh;.
METHODS
loop / fh / fd
Accessors for the owning loop, the watched filehandle, and its file descriptor.
data
Get/set the user data slot:
my $data = $w->data;
$w->data($new);
on_read / on_write / on_error
Install or replace handlers. Passing undef removes the handler and disables it.
enable_read / disable_read =head2 enable_write / disable_write =head2 enable_error / disable_error
Toggle dispatch. Interest masks are inferred from installed handlers and enable state. Note: epoll reports errors regardless of interest; enable/disable only controls dispatch of error.
edge_triggered / oneshot
Advanced epoll behaviors. These update the backend registration immediately.
cancel
Remove the watcher from the loop/backend. This operation is idempotent.
CALLBACK SIGNATURES
Handlers are invoked as:
read => sub ($loop, $fh, $watcher) { ... }
write => sub ($loop, $fh, $watcher) { ... }
error => sub ($loop, $fh, $watcher) { ... }
DISPATCH SEMANTICS
On EPOLLERR, the loop calls error first (if installed+enabled) and returns. If no error handler is installed, EPOLLERR behaves like both readable and writable.
On EPOLLHUP, read readiness is triggered (EOF detection via read() returning 0).
VERSION
0.003_001
LICENSE
Same terms as Perl itself.