HTML::O...DataMap(3)
π NAME
okay so bestie, this is the manual page for HTML::O...DataMap(3) β the HTML::Object::ElementDataMap, aka the HTML Object Element Data Map Class. It's a User Contributed Perl Documentation page, and it's giving βtiny map object for data-* attributesβ main character energy. π
β¨ SYNOPSIS
Here's the code vibe check, fr fr:
use HTML::Object::ElementDataMap;
my $map = HTML::Object::ElementDataMap->new( $html_element_object ) ||
die( HTML::Object::ElementDataMap->error, "\n" );
$map->dateOfBirth( '1989-12-01' );
# Related html element would now have an attribute data-date-of-birth set to 1989-12-01
β VERSION
v0.2.0 β that's the version, periodt. It ate. π
πΈ DESCRIPTION
This module implements a data map for HTML element objects β the MDN reference is literally right here: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset. π¦
It provides read/write access to custom data attributes (data-*) on elements. It provides a map of strings with an entry for each data-* attribute. lowkey the whole point, and honestly? obsessed.
Those class objects are instantiated from dataset in HTML::Object::Element.
π Name conversion
bestie, the naming rules are a whole transformation arc and highkey you need to pay attention:
π¦ dash-style to camelCase conversion
A custom data attribute name is transformed to a key for the element data entry by the following:
- Lowercase all ASCII capital letters (A to Z);
- Remove the prefix
data-(including the dash); - For any dash (
U+002D) followed by an ASCII lowercase letteratoz, remove the dash and uppercase the letter; - Other characters (including other dashes) are left unchanged.
π camelCase to dash-style conversion
The opposite transformation, which maps a key to an attribute name, uses the following:
- Restriction: Before transformation, a dash must not be immediately followed by an ASCII lowercase letter
atoz; - Add the
data-prefix; - Add a dash before any ASCII uppercase letter
AtoZ, then lowercase the letter; - Other characters are left unchanged.
For example, a data-abc-def attribute corresponds to dataset.abcDef. The way that works? iconic. β¨
π Accessing values
not me giving you the exact access snippets:
- Attributes can be set and read by the camelCase name/key as an object property of the dataset:
"$element-"dataset->keyname> - Attributes can also be set and read using variable:
"$element-"dataset->$keyname> - You can check if a given attribute exists like so:
"$element-"attributes->exists( 'data-keyname' )>
π¦ Setting values
- When the attribute is set, its value is always stored as is, which means you can set reference and access them later.
- To remove an attribute, you can use the
removeAttributeinHTML::Object::Elementmethod:"$element-"removeAttribute( 'data-keyname' )>
π AUTHOR
Written by the iconic Jacques Deguest <jack@deguest.jp>. π
π₯ SEE ALSO
Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset β ngl, go read it, iykyk. π
π 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.
π cute little sign-off: this page is from perl v5.42.2, dated 2026-02-15, and it's the HTML::O...DataMap(3) manual page. slay, bye bestie! πβ¨
π¦ 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