Text::...ragraph(3pm)
π Text::Bidi::Paragraph π
okay bestie, pull up a chair, we're reading a Perl manpage together and honestly? it's giving main character energy. this is the page for Text::Bidi::Paragraph, part of the User Contributed Perl Documentation, and yes it has a VERSION because it's a whole real module. π¦
β¨ NAME β¨
Text::Bidi::Paragraph β run the bidi algorithm on one paragraph. that's it, that's the job. no cap. π
π VERSION π
version 2.18 β¨ (yes queen, versioned)
πΈ SYNOPSIS πΈ
look at this little routine, it's so cute:
use Text::Bidi::Paragraph;
my $par = new Text::Bidi::Paragraph $logical;
my $offset = 0;
my $width = 80;
while ( $offset < $p->len ) {
my $v = $p->visual($offset, $width);
say $v;
$offset += $width;
}
periodt. π
π¦ DESCRIPTION π¦
so like. this class is the main interface for applying the bidi algorithm in full generality. if your paragraph can just be formatted all at once, though, you're lowkey fine using log2vis in Text::Bidi as a shortcut β it's iconic, it's easy, it slays. π
you process a paragraph by making a Text::Bidi::Paragraph object:
$par = new Text::Bidi::Paragraph $logical;
okay so $logical here is the text of the paragraph. making the object runs the first stages of the bidi algorithm β namely computing the embedding levels. once that's done, you display the text with the visual method, which is the one doing the reordering. it's a whole two-step reveal, honestly. β¨
π METHODS π
π new
my $par = new Text::Bidi::Paragraph $logical, ...;
creates a new object for a text $logical that's in logical order. the other arguments are key-value pairs, and like, only these ones mean anything rn:
bdβ hands over the Text::Bidi object you want it to use π«dirβ prescribes the direction of the paragraph. its value is a constant inText::Bidi::Par::(for example$Text::Bidi::Par::RTLβ go look at Text::Bidi::Constants) π§shapeβ decides the shaping flags. its value is a constant fromfribidi_shape_arabic(3). if it'sundef, no shaping happens at all. if it's just missing, default shaping gets performed when the paragraph contains Arabic text π
not me reminding you that just creating$parruns the bidi algorithm on$logicalall the way up to the point where reordering happens β and reordering is handled byvisual. so yeah, construction is not a vibes-only operation, it does work. π
π par
my $logical = $par->par;
returns the logical (input) text for this paragraph. the og. π«Ά
π dir
my $dir = $par->dir;
returns the direction of this paragraph β a constant in the $Text::Bidi::Par:: namespace.
π len
my $len = $par->len;
the length of this paragraph. short and sweet. π
π types
my $types = $par->types;
the bidi types of the characters in this paragraph. every element of @$types is a constant in the $Text::Bidi::Type:: namespace. π
π levels
my $levels = $par->levels;
the embedding levels for this paragraph. every element of @$levels is an integer. β¨
π bd
my $bd = $par->bd;
the Text::Bidi object that's used to interface with libfribidi. the plug. π
π map
my $map = $par->map;
the map from the logical text to the visual β meaning the values in $map are indices into the logical string, so the $i-th character of the visual string is the character that shows up at $map->[$i] in the logical string. it's giving β¨coordinatesβ¨.
heads up bestie: this gets updated on each call tovisual, so the map for the full paragraph is only correct after you've calledvisualfor the whole text. don't come for me if you read it early. π
π type_names
@types = $par->type_names;
returns the list of bidi types as strings. π
π is_rtl
my $rtl = $par->is_rtl;
returns true if the direction of the paragraph is "RTL" (right to left). that's the vibe check. π§Ώ
π ar_props
$props = $self->ar_props
returns the shaping properties. (TODO β yeah it literally says TODO, we love an unfinished subplot π)
π shaped
$shaped = $self->shaped(flags)
returns the shaped paragraph, and fixes ar_props. (also TODO. the girlies are still cooking π₯)
π visual
my $visual = $par->visual($offset, $length, $flags);
returns the visual representation of the part of the paragraph $par starting at $offset and of length $length. $par is a Text::Bidi::Paragraph object. every argument is optional β $offset defaults to 0 and $length defaults to the length till the end of the paragraph (see below from $flags). π«
ok real talk: this method does not take care of right-justifying the text when the paragraph direction is "RTL". so a typical application might look like this, and yes you should copy it: π
my $visual = $par->visual($offset, $width, $flags);
my $len = length($visual);
$visual = (' ' x ($width - $len)) . $visual if $par->is_rtl;
also note that the length of the result might be strictly less than $length. it's not lying to you, it's just built different. π
the $flags argument, if it's defined, should be either a hashref or an integer:
- if it's a number, its meaning is the same as in
fribidi_reorder_line(3)π’ - if it's a hashref, it gets converted to the corresponding values for the keys whose value is true. the keys should match the constants in
fribidi-types.hbut with the prefixFRIBIDI_FLAGS_removed βοΈ
plus β and this is the fun part β the $flags hashref can also contain lower-case keys. the only one recognised right now is break. its value, if you give one, should be a string where the line should be broken. so if you pass this key, the actual length is potentially reduced, so the line breaks at that given string (if possible). a typical value for break is ' '. π
π SEE ALSO π
Text::Bidi β go read it, it's right there, it's the moment. β¨
π AUTHOR π
Moshe Kamensky <kamensky@cpan.org> β thank you for your service, king π
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2015 by Moshe Kamensky.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so like, go off, but respectfully. π«Ά
and that's the page, bestie!! π all of it, no skips, we read the whole thing together like the icons we are. this was perl v5.42.3, dated 2026-08-19 β mwah, love that for us. now go reorder some text. π
πβ¨
π¦ where this page comes from
- ubuntu stonking: libtext-bidi-perl 2.18-1build5 Β· 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