HTML::O...t::Event(3)
π NAME π
HTML::Object::Event β HTML Object Event Class
Hiii bestie π This is theHTML::O...t::Event(3)page from the User Contributed Perl Documentation β aka theHTML::Object::Eventmanual β and weβre about to make DOM events make sense. β¨
β¨ SYNOPSIS β¨
use HTML::Object::Event;
my $event = HTML::Object::Event->new ||
die( HTML::Object::Event->error, "\n" );
πΈ VERSION πΈ
v0.2.1
π¦ DESCRIPTION π¦
This module represents an event which takes place in the DOM. π«Ά
Of course, unlike a web browser environment, there is no user interaction here, so all event βfiredβ are triggered programmatically. No cap.
Events are attached to HTML elements.
One element can have several such handlers, even for the exact same event. Yes bestie, the same event can have multiple little handlers hanging out on one element. π
π CONSTRUCTOR π
new
Provided with a type and a hash or hash reference of options, and this creates a new HTML::Object::Event object. An event created in this way is called a "synthetic" event, as opposed to an event fired by the browser, and can be dispatched by a script. π§
It returns the new event object upon success, or upon error, returns undef and sets an error. π
Parameters accepted:
type
This is a string representing the type of the event. β¨
options hash or hash reference
The options can have the following properties. All of them are optional. Each of them can be accessed or modified by their equivalent method listed below. π
bubblesβ A boolean value indicating whether the event bubbles. The default is true. When true, this means the event will be passed on from the element that triggered it on to its parent and its parentβs parent and so on up to the top element. This is the default behaviour. When set to false, the event will not bubble up. π«§cancelableβ A boolean value indicating whether the event can be cancelled. The default is true. It can also be called ascancellablefor non-American speakers. πcomposedβ Because this is a perl environment, this value is always false, and discarded. A boolean value indicating whether the event will trigger listeners outside of a shadow root (seecomposedfor more details). The default isfalse. πdetailβ An optional hash reference of arbitrary key-value pairs that will be stored in the event object and can be later retrieved by the event handlers. π
For example:
Create a look event that bubbles up and cannot be canceled:
my $evt = HTML::Object::Event->new( look => { bubbles => 1, cancelable => 0 } );
$doc->dispatchEvent( $evt );
# event can be dispatched from any element, not only the document
$myDiv->dispatchEvent( $evt );
π PROPERTIES π
bubbles
Read-only
A boolean value indicating whether or not the event bubbles up through the DOM. Default to false.
When true, this means the event will be passed on from the element that triggered it on to its parent and its parentβs parent and so on up to the top element. This is the default behaviour. When set to false, the event will not bubble up. π«§
cancelable
Read-only
A boolean value indicating whether the event is cancelable. Default to true.
It can also be called as cancellable for non-American speakers. π
canceled
Read-only
An integer value indicating whether the event has been canceled. Its value is 1 if it has been cancelled with stopPropagation and 2 if it has been cancelled with stopImmediatePropagation. π
It can also be called as cancelled for non-American speakers.
cancellable
Alias for cancelable. π
cancelled
Alias for canceled. π
composed
Read-only
A boolean indicating whether or not the event can bubble across the boundary between the shadow DOM and the regular DOM. Default to false.
Since this is a perl environment, this is always false, and its value is ignored. π
currentTarget
Read-only
A reference to the currently registered target for the event. This is the object to which the event is currently slated to be sent. Itβs possible this has been changed along the way through retargeting. π―
defaultPrevented
Read-only
Indicates whether or not the call to preventDefault canceled the event. Default to false.
detail
Set or get a hash reference of arbitrary key-value pairs that will be stored in this event. π
eventPhase
Read-only
Returns an integer value which specifies the current evaluation phase of the event flow. Possible values are: NONE (0), CAPTURING_PHASE (1), AT_TARGET (2), BUBBLING_PHASE (3). π
You can export those constants in your namespace by calling HTML::Object::Event like this:
use HTML::Object::Event qw( NONE CAPTURING_PHASE AT_TARGET BUBBLING_PHASE );
or, more simply:
use HTML::Object::Event ':phase';
See for more information https://developer.mozilla.org/en-US/docs/Web/API/Event/eventPhase π
isTrusted
Read-only
Obviously, since this is a perl environment, this is always true, because although it would be script-generated, it is fair to say your own script is trustworthy. π«Ά
Indicates whether or not the event was initiated by the browser (after a user click, for instance) or by a script (using an event creation method, for example).
path
Returns the computed elements path by composedPath, as an array object. π¦
target
Read-only
A reference to the object to which the event was originally dispatched. π―
timeStamp
Read-only
The time at which the event was created (in milliseconds). By specification, this value is time since epoch using Time::HiRes. This is actually a DateTime object. DateTime object supports nanoseconds. β±οΈ
type
Read-only
The case-insensitive type identifying the event. β¨
π METHODS π
composedPath
Returns the eventβs path (an array of objects on which listeners will be invoked). π¦
dispatch
Provided with a node and this will dispatch this event to the given node.
It returns the value returned by HTML::Object::EventTarget/dispatchEvent. π
file
Returns the file path where this event was called from. π
line
Returns the line at which this event was called from. π
package
Returns the package name where this event was called from. π¦
preventDefault
This does nothing under perl, except set the value of defaultPrevented to true. π
Under JavaScript, this method is used to stop the browserβs default behavior when performing an action, such as checking a checkbox upon user click.
setTimestamp
Takes an optional unix timestamp or a DateTime object, and this will set the event timestamp. If no argument is provided, this will resort to set the timestamp using time in Time::HiRes, which provides a timestamp in milliseconds. β±οΈ
It returns a DateTime object.
stopImmediatePropagation
For this particular event, prevent all other listeners from being called. This includes listeners attached to the same element as well as those attached to elements that will be traversed later (during the capture phase, for instance). π
stopPropagation
Stops the propagation of events further along in the DOM. π
subroutine
Returns the subroutine where this event was called from. π§
π CONSTANTS π
NONE (0)
The event is not being processed at this time. π€
CAPTURING_PHASE (1)
The event is being propagated through the targetβs ancestor objects. This process starts with the Document, then the HTML html element, and so on through the elements until the targetβs parent is reached. Event listeners registered for capture mode when addEventListener in HTML::Object::EventTarget was called are triggered during this phase. πͺ
AT_TARGET (2)
The event has arrived at the eventβs target. Event listeners registered for this phase are called at this time. If bubbles is false, processing the event is finished after this phase is complete. π―
BUBBLING_PHASE (3)
The event is propagating back up through the targetβs ancestors in reverse order, starting with the parent, and eventually reaching the containing document. This is known as bubbling, and occurs only if bubbles is true. Event listeners registered for this phase are triggered during this process. π«§
CANCEL_PROPAGATION (1)
State of the propagation being cancelled.
$event->stopPropagation();
$event->cancelled == CANCEL_PROPAGATION;
CANCEL_IMMEDIATE_PROPAGATION (2)
State of immediate propagation being cancelled.
$event->stopImmediatePropagation();
$event->cancelled == CANCEL_IMMEDIATE_PROPAGATION;
π«Ά AUTHOR π«Ά
Jacques Deguest jack@deguest.jp
π₯ SEE ALSO π₯
https://developer.mozilla.org/en-US/docs/Web/API/Eventhttps://developer.mozilla.org/en-US/docs/Web/Events/Creating_and_triggering_eventshttps://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Eventshttps://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
π COPYRIGHT & LICENSE π
Copyright(c) 2021 DEGUEST Pte. Ltd.
All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Okay thatβs the whole manual, bestie π«Ά This page is from perl v5.42.2, dated 2026-02-15, and itβs the HTML::O...t::Event(3) page β go forth and dispatch responsibly π
β¨
π¦ where this page comes from
- alpine 3.24: perl-html-object-doc 0.6.0-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms