Text::Flow(3pm)
π Text::Flow π
okay bestie, so this is the manual page for Text::Flow, which is a perl module (a 3pm one, if we're being specific) π«Ά β flexible text flowing and word wrapping, and NOT just for ASCII output, which is the whole point, iykyk.
β¨ SYNOPSIS β¨
use Text::Flow;
# use it on ASCII text ...
my $flow = Text::Flow->new(
check_height => sub {
my $paras = shift;
sum(map { scalar @$_ } @$paras) <= 10;
},
wrapper => Text::Flow::Wrap->new(
check_width => sub { length($_[0]) < 70 }
),
);
my @sections = $flow->flow($text);
# @sections will now be an array of strings, each string
# will contain no more than 10 lines of text each of which
# will be no longer then 70 characters long
# or use it on text in a PDF file ...
my $flow = Text::Flow->new(
check_height => sub {
my $paras = shift;
(sum(map { scalar @$_ } @$paras) * $pdf->get_font_height) < 200;
},
wrapper => Text::Flow::Wrap->new(
check_width => sub {
my $string = shift;
$pdf->get_string_width($string) < 100
},
)
);
my @sections = $flow->flow($text);
# @sections will now be an array of strings, each string
# will contain text which will fit within 200 pts and
# each line will be no longer then 100 pts wide
πΈ DESCRIPTION πΈ
so like, this module gives you a flexible way to wrap AND flow text, and it works for ASCII output and non-ASCII output. best of both worlds, no cap π
π Another Text Wrap module!!?!?!
okay hear me out before you roll your eyes π β the whole point of this module is to do text wrapping and flowing without being tied down to ASCII-based output and fixed-width fonts. the author's actual needs were for more sophisticated text control in PDF and GIF output formats in particular. it's giving very specific queen energy, and honestly? slay.
π METHODS π
new (%params)β constructs the newText::Flowinstance. it accepts parameters for the"wrapper"and"check_height"variables. that's it, that's the constructor π«Άwrapper (?$wrapper)β the accessor for the internally helpText::Flow::Wrapperinstance (yes, "help", we're keeping it, it's iconic) whichText::Flowuses to wrap the individual lines.check_heightβ the accessor for the CODE ref used to check the height of the current paragraph. it gets, as its argument, an array-ref of paragraphs, and each of those is also an array-ref of text lines. the most common usage is right up there in the SYNOPSIS, but fr fr you can do literally anything you want with them. it's expected to return a Boolean value: true if the height is still okay β , false if the max height has been reached π.flow ($text)β this method preforms the text flowing (preforms, bestie, that's the vibe). it returns an array of strings which you can treat as complete blocks of text. it will handle paragraph breaks and line breaks for you, so you don't have to. king behaviour π
π Introspection
metaβ returns the Moose meta object associated with this class. very meta of it. π¦
β TODO β
the author wanted to write some tests for using this with GD modules as well. I guess we will have to wait until 0.02 for that π« (manifesting).
π SIMILAR MODULES π
there are a bunch of other text wrapping and flowing modules out there, but they are all meant for use in ASCII outout only (yes, "outout", we're keeping the typo, it's part of the lore). that just didn't work for the author's needs, so this one got written instead. if you need to wrap ASCII text and you wanna do it in a much simpler manner than this module provides, then pls go check out those other modules. this module is specifically made for when those other modules are no longer powerful and flexible enough. it's giving "built different" β¨
π BUGS π
all complex software has bugs lurking in it, and this module is no exception π. if you find a bug please either email the author, or add the bug to cpan-RT. do it for the girlies.
π AUTHOR π
Stevan Little <stevan@iinteractive.com>
π COPYRIGHT AND LICENSE π
Copyright 2007 by Infinity Interactive, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie β written for perl v5.34.0, dated 2022-06-28, under the Text::Flow(3pm) banner in the User Contributed Perl Documentation section. periodt π
β¨
π¦ where this page comes from
- debian bookworm: libtext-flow-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtext-flow-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtext-flow-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtext-flow-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtext-flow-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms