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::Handle - Base abstract class for all handle types

SYNOPSIS

    # since Handle is abstract, only certain class can be instantiated
    my $h = UniEvent::Timer->new;
    $h->loop; # event loop is returned, the default one in the case
    $h->type; # UniEvent::Timer::TYPE

    say $h->active; # => false
    $h->start;
    say $h->active; # => true

    $h->weak(1); # make it weak

    $h->reset;
    $h->clear;

DESCRIPTION

The class contains methods common for all hanlde types.

METHODS

loop()

Returns assigned to the handle event loop instance.

type()

Returns an integer, which uniquely identifies handle type. You can check it against constants in handle classes (like UniEvent::Timer::TYPE).

    if ($handle->type == UE::Tcp::TYPE) {
        # $handle is TCP handle
    }

Every handle class has TYPE constant.

active()

Returns true if the handle is "active". What "active" means depends on the concrete handle type, i.e. for timer handle active means, that it was started, for pipe, tcp etc. handle types "active" means that I/O operations will be performed or watched for.

Usually, if there is a start() method, then handle is active afther the invokation of the method, and vise versa, stop() method deactivates handle.

weak([$value])

If no argument is passed, returns true if handle is weak, false otherwise.

With argument, marks the handle as weak (if $value is true) or unmarks it (if false).

Weak handles do not keep the loop from bailing out of run() method (regardless of whether handle is active or not). That means that if all the handles left in the loop are weak, it will return from it's run() method.

The freshly created handle instance is non-weak by default.

reset()

Stops the handle, making it inactive, resetting it to initial state, with the exception, that assigned callbacks and event listener are kept.

clear()

Resets everything, including assigned callbacks and event listener, as if the hanle has been created anew.