| IO::Async::Notifier - base class for C<IO::Async> event objects |
parent()children()
IO::Async::Notifier - base class for IO::Async event objects
Usually not directly used by a program, but one valid use case may be:
use IO::Async::Notifier;
use IO::Async::Stream; use IO::Async::Signal;
use IO::Async::Loop; my $loop = IO::Async::Loop->new();
my $notifier = IO::Async::Notifier->new();
$notifier->add_child( IO::Async::Stream->new( read_handle => \*STDIN, on_read => sub { my $self = shift; my ( $buffref, $closed ) = @_; $$buffref =~ s/^(.*)\n// or return 0; print "You said $1\n"; return 1; }, ) );
$notifier->add_child( IO::Async::Signal->new( name => 'INT', on_receipt => sub { print "Goodbye!\n"; $loop->loop_stop; }, ) );
$loop->add( $notifier );
$loop->loop_forever;
This object class forms the basis for all the other event objects that an
IO::Async program uses. It provides the lowest level of integration with a
IO::Async::Loop container, and a facility to collect Notifiers together, in
a tree structure, where any Notifier can contain a collection of children.
Normally, objects in this class would not be directly used by an end program, as it performs no actual IO work, and generates no actual events. These are all left to the various subclasses, such as:
the IO::Async::Handle manpage - event callbacks for a non-blocking file descriptor
the IO::Async::Stream manpage - read and write buffers around an IO handle
the IO::Async::Sequencer manpage - handle a serial pipeline of requests / responses (EXPERIMENTAL)
the IO::Async::Timer manpage - event callback after some timed delay
the IO::Async::Signal manpage - event callback on receipt of a POSIX signal
For more detail, see the SYNOPSIS section in one of the above.
One case where this object class would be used, is when a library wishes to
provide a sub-component which consists of multiple other Notifier
subclasses, such as Handles and Timers, but no particular object is
suitable to be the root of a tree. In this case, a plain Notifier object
can be used as the tree root, and all the other notifiers added as children of
it.
A specific subclass of IO::Async::Notifier defines named parameters that
control its behaviour. These may be passed to the new constructor, or to
the configure method. The documentation on each specific subclass will give
details on the parameters that exist, and their uses. Some parameters may only
support being set once at construction time, or only support being changed if
the object is in a particular state.
This function returns a new instance of a IO::Async::Notifier object with
the given initial values of the named parameters.
Up until IO::Async version 0.19, this module used to implement the IO
handle features now found in the IO::Async::Handle subclass. To allow for a
smooth upgrade of existing code, this constructor check for any %params key
which looks like it belongs there instead. These keys are handle,
read_handle, write_handle, on_read_ready and on_write_ready. If
any of these keys are present, then a IO::Async::Handle is returned.
Do not rely on this feature in new code. This logic exists purely to provide
an upgrade path from older code that still expects IO::Async::Notifier to
provide filehandle operations. This will eventually produce a deprecation
warning at some point in the future, and removed at some point beyond that.
Adjust the named parameters of the Notifier as given by the %params
hash.
Returns the IO::Async::Loop that this Notifier is a member of.
During the execution of a program, it may be the case that certain IO handles
cause other handles to be created; for example, new sockets that have been
accept()ed from a listening socket. To facilitate these, a notifier may
contain child notifier objects, that are automatically added to or removed
from the IO::Async::Loop that manages their parent.
parent()Returns the parent of the notifier, or undef if does not have one.
children()Returns a list of the child notifiers contained within this one.
Adds a child notifier. This notifier will be added to the containing loop, if the parent has one. Only a notifier that does not currently have a parent and is not currently a member of any loop may be added as a child. If the child itself has grandchildren, these will be recursively added to the containing loop.
Removes a child notifier. The child will be removed from the containing loop, if the parent has one. If the child itself has grandchildren, these will be recurively removed from the loop.
Paul Evans <leonerd@leonerd.org.uk>
| IO::Async::Notifier - base class for C<IO::Async> event objects |