String::Elide::FromArray - Truncate string containing list of items
This document describes version 0.001 of String::Elide::FromArray (from Perl distribution String-Elide-FromArray), released on 2017-07-28.
use String::Elide::FromArray qw(elide); # 01234567890123456 elide([qw/foo/], 11); # -> "foo" elide([qw/foo bar/], 11); # -> "foo, bar" elide([qw/foo bar baz/], 11); # -> "foo, bar,.." elide([qw/foo bar baz/], 15); # -> "foo, bar, baz" elide([qw/foo bar baz qux/], 15); # -> "foo, bar, baz.." elide([qw/foo bar baz qux/], 15, {max_items => 2}); # -> "foo, bar, .." elide([qw/foo bar baz qux/], 15, {max_items => 2, list_marker => 'etc'}); # -> "foo, bar, etc" elide([qw/foo bar baz/], 11, {sep => '|'}); # -> "foo|bar|baz" elide([qw/foo bar baz/], 11, {marker=>"--"}); # -> "foo, bar,--" elide([qw/aaa bbbbb/], 11, {max_item_len=>4}); # -> "aaa, bb.." elide([qw/aaa bbbbb c d e/], 11, {max_item_len=>4, item_marker=>"*"}); # -> "aaa, bbb*.."
This module provides a single function elide() to truncate a string containing list of items. You provide the array containing the items.
elide()
Join @ary using sep (default is , ), the truncate the resulting string so it has a maximum length of $len. Some options are available:
@ary
sep
,
$len
sep => str (default: ', ')
String used to join the items.
marker => str (default: '..')
String added at the end of elided string.
max_item_len => int
If specified, then each item will be elided first.
item_marker => str (default: '..')
max_items => int
If specified, only join at most this number of items.
list_marker => str (default: '..')
Last item added when number of items exceeds max_items.
max_items
Please visit the project's homepage at https://metacpan.org/release/String-Elide-FromArray.
Source repository is at https://github.com/perlancar/perl-String-Elide-FromArray.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=String-Elide-FromArray
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Text::Elide, String::Truncate, String::Elide::Parts
perlancar <perlancar@cpan.org>
This software is copyright (c) 2017 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install String::Elide::FromArray, copy and paste the appropriate command in to your terminal.
cpanm
cpanm String::Elide::FromArray
CPAN shell
perl -MCPAN -e shell install String::Elide::FromArray
For more information on module installation, please visit the detailed CPAN module installation guide.