Synopsis
use Text::Transform;
my $xform = Text::Transform->new(
length => \&sub,
match => qr/regex/,
);
$xform->encode(@args);
$_ = foo(@args);
$xform->decode($_);
Description
This module is currently included in Text::VisualPrintf distribution as Text::VisualPrintf::Transform, and I'm planning to release it as an individual module.
Library using Text::VisualPrintf::Transform
Application using Text::VisualPrintf::Transform
Application using Text::ANSI::Printf intensively
DESCRIPTION
This is a general interface to transform text data into desirable form, and recover the result after the process.
For example, Text::Tabs does not take care of Asian wide characters to calculate string width. So the next program does not work as we wish.
use Text::Tabs;
print expand <>;
In this case, make transform object with length function which understand wide-character width, and the pattern of string to be replaced.
use Text::VisualPrintf::Transform;
use Text::VisualWidth::PP;
my $xform = Text::VisualPrintf::Transform->new(
length => \&Text::VisualWidth::PP::width,
match => qr/\P{ASCII}+/,
);
Then next program encode data, call expand() function, and recover the result into the original text.
my @lines = <>;
$xform->encode(@lines);
my @expanded = expand @lines;
$xform->decode(@expanded);
print @expanded;
Comments
From what I gather, it's purpose is to prepare text to be modified by some external code. And the preparing involves
splitting the text according to length and matching rules. So, a tiny bit more specific would be Text::Split, but that's still too generic.
Splitting is not important. It converts whole text by default, and Text::VisualPrintf is doing so.
Following a series of Text::VisualWidth and Text::VisualPrintf, Text::VisualTransform is an option?
Text::Opacify or Text::Opacate ?
cf. https://english.stackexchange.com/questions/14908/to-make-something-opaque-opaquen
Maybe opacify/deopacify can be used instead of encode/decode.
But, it does remind me of the vim editor's conceal feature (I think emac's equivalent is called overlays).
Since you're already have other Text::Visual* modules, Text::VisualPrint makes sense. But Text::Conceal might also work, since there are a lot of vim users and they'd recognize the term and concept.
https://metacpan.org/release/Text-Conceal
https://github.com/kaz-utashiro/Text-Conceal/discussions
Please sign up to post a review.