---
name: "MsOffice::Word::Surgeon::Text"
section: "3pm"
platform: "linux"
package: "libmsoffice-word-surgeon-perl"
version: "2.10-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/MsOffice::Word::Surgeon::Text"
---

# MsOffice::Word::Surgeon::Text(3pm)

internal representation for a node of literal text

## NAME

MsOffice::Word::Surgeon::Text - internal representation for a node of literal text

## DESCRIPTION

This is used internally by MsOffice::Word::Surgeon for storing a chunk of literal text in a MsWord document. It loosely corresponds to a `"<w:t>"` node in OOXML, but may also contain an anonymous XML fragment which is the part of the document just before the `"<w:t>"`  node -- used for reconstructing the complete document after having changed the contents of some text nodes.

## METHODS

### new

```
  my $text_node = MsOffice::Word::Surgeon::Text(
    xml_before   => $xml_string,
    literal_text => $text_string,
  );
```

Constructor for a new text object. Arguments are :

- xml\_before

  A string containing arbitrary XML preceding that text node in the complete document. The string may be empty but must be present.

- literal\_text

  A string of literal text.

### as\_xml

```
  my $xml = $text_node->as_xml;
```

Returns the XML representation of that text node. The attribute `"xml:space="preserve""` is automatically added if the literal text starts of ends with a space character.

### merge

```
  $text_node->merge($next_text_node);
```

Merge the contents of `$next_text_node` together with the current text node. 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.

### 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. This is the internal implementation for public method "replace" in MsOffice::Word::Surgeon.

### to\_uppercase

Puts the literal text within the node into uppercase letters.

## 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.
