Sign in to PrePAN

Text::Transform transform and recover interface for text processing



use Text::Transform;
my $xform = Text::Transform->new(
    length => \&sub,
    match => qr/regex/,
$_ = foo(@args);


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


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 = <>;
my @expanded = expand @lines;
print @expanded;


I think Transform is a way too general verb to use- it's equivalent to Change, Modify, Alter, etc. The majority of modules on CPAN transform text in one fashion or another. It doesn't really indicate the specifics of what the module is trying to do. It's only a step above naming it Do::Something.

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.
Thanks for comment. Since it does not define what and how (much), text transformation itself is core of this module. But I agree it is too general.

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?
Another idea is choosing a word for making something opaque.
Text::Opacify or Text::Opacate ?


Maybe opacify/deopacify can be used instead of encode/decode.
Those words are rarely seen in common use and would likely confuse users. My rule of thumb is to be clear in naming as possible, if you choose something that requires people to look it up, you might as well use wacky names like Mojolicious or Moose, etc. ;-)

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.
copypasta, s{Text::VisualPrint}{Text::VisualTransform/}
Actually, I've never seen those words until I found the article. I was planning to use Text::Opacifier after some thought, but Text::Conceal looks good too. Thanks for your suggestions.
Released to CPAN and update Text::VisualPrintf and Text::ANSI::Printf to use Text::Conceal.
Opened github [discussions](

Please sign up to post a review.