The manakai project

Web::DOM::EventTarget

DOM EventTarget object

DESCRIPTION

The Web::DOM::EventTarget class implements the DOM EventTarget interface. The EventTarget object does not exist by itself, it is used as a superclass of other classes, such as Web::DOM::Node.

METHODS

Following methods are available:

$et->add_event_listener ($type, $code, {capture => $boolean, passive => $boolean, once => $boolean})

Register a callback function as event listener for the event target. The first argument identifies the type of the event to listen, e.g. click or resize. The second argument is a code reference, which is invoked when an event is dispatched. [DOM] [DOMPERL]

The optional third argument can specify following options as a hash reference: capture represents whether the code should be invoked in the capturing phase; passive rerepsents whether the event listener is passive (i.e. prevent_default is not allowed) or not; once represents whether the event listener should be automatically removed just after it is invoked for the first time.

When an event of the specified type is dispatched, the code of the second argument is invoked with two arguments: $self and $event. The second argument, $event, is the event object in question. The first argument, $self, is equal to the context object ($et) or the current target object $event->current_target.

Please be aware to not create circular reference to the event target object through the callback. The reference to the callback is holded by the event target object until it is explicitly unregistered. The event target object can be accessed as the first argument in the callback, as mentioned above.

$boolean = $et->dispatch_event ($event)

Dispatch the specified event object at the event target object. The method returns whether the event's default action has not been cancelled. [DOM]

Note that the event is dispatched synchronously, such that any event listener callback is invoked synchronously.

$et->remove_event_listener ($type, $code, {capture => $boolean, passive => $boolean})

Unregister a callback function as event listener, if it is registered. [DOM]

SPECIFICATIONS

DOM

DOM Standard <https://dom.spec.whatwg.org/#interface-eventtarget>.

DOMPERL

manakai's DOM Perl Binding <https://suika.suikawiki.org/~wakaba/wiki/sw/n/manakai%27s%20DOM%20Perl%20Binding>.

SEE ALSO

Web::DOM::Event, Web::DOM::Node.

AUTHOR

Wakaba <wakaba@suikawiki.org>.

LICENSE

Copyright 2013-2016 Wakaba <wakaba@suikawiki.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.