String...:Parts(3pm)
π String::Elide::Parts π
okay bestie, so we're doing String::Elide::Parts today β she's the elide module that gets priorities, and honestly? she ate. it's "Elide a string with multiple parts of different priorities" and the manual name is String::Elide::Parts(3pm) if you need to look her up later π
β¨ VERSION β¨
this doc describes version 0.07 of String::Elide::Parts (she lives in the Perl distribution String-Elide-Parts), released on 2017-01-29. vintage queen π
πΈ SYNOPSIS πΈ
first you gotta bring her in, no cap:
use String::Elide::Parts qw(elide);
eliding a string with no parts at all (just vibes):
my $text = "this is your brain";
# 0----5---10---15---20
elide($text, 16); # -> "this is your ..."
elide($text, 16, {truncate=>"left"}); # -> "...is your brain"
elide($text, 16, {truncate=>"middle"}); # -> "this is... brain"
elide($text, 16, {truncate=>"ends"}); # -> "... is your b..."
elide($text, 16, {marker=>"--"}); # -> "this is your b--"
eliding a string with multiple parts marked with markup β free the URL first (prio=3), then the "Downloading" text (prio=2), then the speed (prio=1, which is the default). watch her cook:
$text = "<elspan prio=2>Downloading</elspan> <elspan prio=3 truncate=middle>http://www.example.com/somefile</elspan> 320.0k/5.5M";
# 0----5---10---15---20---25---30---35---40---45---50---55---60
elide($text, 56); # -> "Downloading http://www.example.com/somefile 320.0k/5.5M"
elide($text, 55); # -> "Downloading http://www.example.com/somefile 320.0k/5.5M"
elide($text, 50); # -> "Downloading http://www.e..com/somefile 320.0k/5.5M"
elide($text, 45); # -> "Downloading http://ww..m/somefile 320.0k/5.5M"
elide($text, 40); # -> "Downloading http://..omefile 320.0k/5.5M"
elide($text, 35); # -> "Downloading http..efile 320.0k/5.5M"
elide($text, 30); # -> "Downloading ht..le 320.0k/5.5M"
elide($text, 25); # -> "Downloading . 320.0k/5.5M"
elide($text, 24); # -> "Downloading 320.0k/5.5M"
elide($text, 23); # -> "Download.. 320.0k/5.5M"
elide($text, 20); # -> "Downl.. 320.0k/5.5M"
elide($text, 15); # -> ".. 320.0k/5.5M"
elide($text, 13); # -> " 320.0k/5.5M"
elide($text, 10); # -> " 320.0k/.."
elide($text, 5); # -> " 32.."
# 0----5---10---15---20---25---30---35---40---45---50---55---60
look at the little ruler comments, they're giving very much graph paper energy πβ¨
π DESCRIPTION π
String::Elide::Parts is like all the other string eliding modules you know, except β and this is the whole main character moment β she accepts strings marked up with parts that have different priorities. the goal? keep the important stuff alive for as long as possible while the length shrinks. prioritize correctly and she will simply not let the good info go first. it's giving self-care honestly π«Ά
π¦ FUNCTIONS π¦
elide($str, $len[, \%opts]) => str
Elide a string if length exceeds $len.
your string can be marked up like "<elspan prio=N truncate=T marker=M>...</elspan>", which is how you get multiple parts with different priorities and different truncate directions. the default priority is 1. so: tag the less important strings with a higher priority and she'll elide those first, no cap. heads up though β the markup gets removed from the string before the eliding happens, so what you get back is clean β¨
Known options (the lore):
marker => strβ default:'..'truncate => 'left'|'middle'|'middle'|'ends'β default:'right'default_prio => intβ default:1
not me pointing out that the truncate list says 'middle' twice π i'm not fixing it, bestie, i'm reporting exactly what the page says. facts are facts.
π HOMEPAGE π
go visit the project's homepage, it's cute: <https://metacpan.org/release/String-Elide-Parts>
β SOURCE β
the source repo lives at: <https://github.com/perlancar/perl-String-Elide-Parts>
like, go star it, that's the whole ask π
π BUGS π
got a bug or a feature request? drop it on the bugtracker: <https://rt.cpan.org/Public/Dist/Display.html?Name=String-Elide-Parts>
and when you submit a bug or a request, please include a test-file (or a patch to an existing test-file) that illustrates the bug or the desired feature. a vague "it's broken" is not the vibe check, bestie, we need receipts π§Ύ
π SEE ALSO π
Similar elide modules
Text::Elideβ simple, doesn't have many options, and elides at word boundaries.String::Truncateβ has a similar interface toString::Elide::Partsand has some options.String::Elide::Linesβ based on this module, but works on a line-basis.
squad goals fr fr πΈ
π AUTHOR π
perlancar <perlancar@cpan.org> β thank you for your service, icon π«‘
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2017 by perlancar@cpan.org.
it's free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. periodt π
okay that's the whole page and every single flag, default, example and link survived the vibe check β¨ go elide something responsibly, bestie.
this was page String...:Parts(3pm), perl v5.36.0, dated 2022-10-16. mwah, love u, bye π¦π
π¦ where this page comes from
- ubuntu noble: libstring-elide-parts-perl 0.07-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libstring-elide-parts-perl 0.07-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libstring-elide-parts-perl 0.07-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