MDOM::...tespace(3pm)

πŸ“¦
version 0.008 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ MDOM::Token::Whitespace β€” the manual, but make it cute ✨

okay bestie, so this is MDOM::Token::Whitespace (from the User Contributed Perl Documentation corner of the world) and it's literally just… the tokens that represent ordinary white space. that's it. that's the whole vibe. πŸ’…


🌸 INHERITANCE 🌸

the family tree, and yes it's giving royalty:

MDOM::Token::Whitespace
isa MDOM::Token
    isa MDOM::Element

so she inherits from MDOM::Token, which inherits from MDOM::Element. generational excellence fr fr πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so MDOM is a full "round-trip" parser, meaning it records every last byte in a file and makes sure every single one of them ends up inside the MDOM::Document object. no byte left behind. periodt.

and that includes whitespace. like, especially whitespace. Perl documents are basically "floating in a sea of whitespace", so any document is gonna contain a vast quantity of MDOM::Token::Whitespace objects. they're everywhere. they're the background characters with main character energy. 🌊

for the most part? you shouldn't notice them. or at least β€” and this is the important part β€” you shouldn't have to notice them. πŸ™ˆ

so what that means practically is: consistently use the "S for significant" series of MDOM::Node and MDOM::Element methods to do your thing.

like, if you want the *n*th child element, use schild instead of child. same deal with snext_sibling, sprevious_sibling, and so on and so forth. the "s" is your bestie here. 🫢


πŸŽ€ METHODS πŸŽ€

again β€” for the most part you should really not need to do anything very significant with whitespace. it's just vibing.

but there are a couple of convenience methods provided, on top of the ones you already get from the parent MDOM::Token and MDOM::Element classes. πŸ’–

null

because MDOM sees documents as sitting on a sort of substrate made of whitespace, there are a couple of corner cases that get particularly nasty if they don't find whitespace in certain places.

imagine walking down the beach to go into the ocean and then quite unexpectedly falling off the side of the planet. yeah. it's somewhat equivalent to that. including the whole screaming death bit. πŸ’€πŸ˜­

the null method is a convenience provided to get some internals out of some of these corner cases.

specifically, it creates a whitespace token that represents nothing β€” or at least, the null string ''. it's a handy way to have some "whitespace" right where you need it, without having to have any actual characters. iconic honestly ✨

tidy

tidy is a convenience method for removing unneeded whitespace.

specifically, it removes any whitespace from the end of a line.

heads up bestie: this doesn't include POD, where you may well need to keep certain types of whitespace. the entire POD chunk lives in its own MDOM::Token::Pod object. so don't go tidying your POD, okay? πŸŽ€

πŸ’œ SUPPORT πŸ’œ

see the support section in the main module. (short and sweet, we love a delegation moment)


🌈 AUTHOR 🌈

Adam Kennedy <adamk@cpan.org>


Copyright 2001 - 2006 Adam Kennedy.

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

The full text of the license can be found in the LICENSE file included with this module.


and that's the whole page, bestie β€” perl v5.34.0, dated 2022-06-15, brought to you by the MDOM::...tespace(3pm) girlies. slay, stay hydrated, and remember: the whitespace was there the whole time. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from