Text::BlockLayout - Generate text blocks from a mixture of wrappable and protected lines
use 5.010; use strict; use warnings; use Text::BlockLayout; my $tb = Text::BlockLayout->new( max_width => 30, separator => '. ', ); $tb->add_text('This text will be wrapped if longer than 30 characters,' . ' and potentially be joined with other lines, separted by ". "'); $tb->add_text('Same here'); $tb->add_line('This will also be wrapped, but never be joined with other lines'); say $tb->formatted;
Text::BlockLayout can wrap and format chunks of text for you. For each piece of text you add, you can chose whether it remains on lines on its own (when added with the add_line method), or whether it might be joined with other lines (when added with the add_text method). If the latter is the case, the pieces of text are joined by a customizable separator.
add_line
add_text
Attributes can be passed as named arguments to the constructor, and later set and get with methods of the same name as the attribute.
The maximal number of characters in a line (not counting the newline character).
Required. Must be a positive integer.
The separator with which two chunks of text are joined if they are put on the same line.
Optional. Will be used as a string. Default: the empty string.
The number of characters after which a line is considered full, i.e. no extra chunks of text will be added to this line.
Optional. Defaults to two thirds of max_width, rounded to the nearest integer.
max_width
A callback that receives the max_width and text to be wrapped as arguments, and must return a wrapped string.
Optional. Defaults to a Text::Wrapper-based wrapper.
If set to a false value, text added with add_line will not be line-wrapped.
Optional. Defaults to True.
True
Returns the formatted text.
Moritz Lenz (moritz@faui2k3.org) for the noris network AG.
This module is under version control. You can find its repository at https://github.com/noris-network/perl5-Text-BlockLayout.
This module and its accompanying files may be used, distributed and modified under the same terms as perl itself.
There is no warranty for this software, to the extend permitted by applicable law. Use it at your own risk.
To install Text::BlockLayout, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::BlockLayout
CPAN shell
perl -MCPAN -e shell install Text::BlockLayout
For more information on module installation, please visit the detailed CPAN module installation guide.