HTML::O...DataMap(3)

πŸ“¦ version 0.6.0, in alpine 3.24

πŸ’… 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:

  1. Lowercase all ASCII capital letters (A to Z);
  2. Remove the prefix data- (including the dash);
  3. For any dash (U+002D) followed by an ASCII lowercase letter a to z, remove the dash and uppercase the letter;
  4. 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:

  1. Restriction: Before transformation, a dash must not be immediately followed by an ASCII lowercase letter a to z;
  2. Add the data- prefix;
  3. Add a dash before any ASCII uppercase letter A to Z, then lowercase the letter;
  4. 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 removeAttribute in HTML::Object::Element method: "$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(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