MsOffi...n::Text(3pm)
π MsOffice::Word::Surgeon::Text π
okay bestie so this is MsOffice::Word::Surgeon::Text, a lil module from the User Contributed Perl Documentation corner of the world, and she is a 3pm page, iykyk. she's internal, she's lowkey, she's the whole vibe behind storing text. let's get into it π«Ά
β¨ NAME β¨
MsOffice::Word::Surgeon::Text β the internal representation for a node of literal text. she's giving "just a chunk of words" but make it β¨structuralβ¨.
π¦ DESCRIPTION π¦
so basically? this module is used internally by MsOffice::Word::Surgeon for storing a chunk of literal text in a MsWord document. no cap.
she loosely corresponds to a <w:t> node in OOXML β like, vibe-wise, that's her cousin. but she may also contain an anonymous XML fragment which is the part of the document just before the <w:t> node. and why do we care? because that fragment is used for reconstructing the complete document after having changed the contents of some text nodes. iconic behaviour honestly π
π METHODS π
πΈ new πΈ
my $text_node = MsOffice::Word::Surgeon::Text(
xml_before => $xml_string,
literal_text => $text_string,
);
constructor for a brand new text object β¨ arguments are, and listen closely because both of them are required bestie:
xml_beforeβ a string containing arbitrary XML preceding that text node in the complete document. the string may be empty but it must be present. so likeβ¦ show up even if you have nothing to say π«Άliteral_textβ a string of literal text. that's it, that's the tea.
π as_xml π
my $xml = $text_node->as_xml;
returns the XML representation of that text node. and here's the cute lil detail: the attribute xml:space="preserve" is automatically added if the literal text starts of ends with a space character. (yes, the original says "starts of ends", we're keeping it, no editing the source bestie π). so your trailing and leading spaces are protected, periodt.
β merge β
$text_node->merge($next_text_node);
merges the contents of $next_text_node together with the current text node. but β and this is the catch β this is only possible if the next text node has an empty xml_before attribute.
if this condition is not met, an exception is raised. no vibes, no merge, sorry bestie π
π₯ replace π₯
my $xml = $text_node->replace($pattern, $replacement_callback, %args);
replaces all occurrences of $pattern within the text node by a new string computed by $replacement_callback, and returns a new xml string corresponding to the result of all these replacements.
and the lore? this is the internal implementation for the public method "replace" in MsOffice::Word::Surgeon. so she's the backstage queen, the main character working behind the curtain π
π to_uppercase π
puts the literal text within the node into UPPERCASE LETTERS. THAT'S IT. SHE'S LOUD NOW. π’
π AUTHOR π
Laurent Dami, <dami AT cpan DOT org<gt>
π COPYRIGHT AND LICENSE π
Copyright 2019-2024 by Laurent Dami.
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. slay, legally π
and that's the whole page bestie!! πΈπ¦β¨ this was written for perl v5.40.1 and dated 2025-10-05, and it's still called MsOffi...n::Text(3pm) because apparently we're all too cool for full filenames. mwah, bye!! πππ§
π¦ where this page comes from
- ubuntu resolute: libmsoffice-word-surgeon-perl 2.11-1 Β· Artistic-2.0
- ubuntu stonking: libmsoffice-word-surgeon-perl 2.11-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms