The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Text::BlockLayout - Generate text blocks from a mixture of wrappable and protected lines

SYNOPSIS

    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;

DESCRIPTION

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.

Attributes

Attributes can be passed as named arguments to the constructor, and later set and get with methods of the same name as the attribute.

max_width

The maximal number of characters in a line (not counting the newline character).

Required. Must be a positive integer.

separator

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.

line_continuation_threshold

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.

wrapper

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.

wrap_predefined_lines

If set to a false value, text added with add_line will not be line-wrapped.

Optional. Defaults to True.

Methods

formatted

Returns the formatted text.

AUTHOR

Moritz Lenz (moritz@faui2k3.org) for the noris network AG.

DEVELOPMENT

This module is under version control. You can find its repository at https://github.com/noris-network/perl5-Text-BlockLayout.

LICENSE

This module and its accompanying files may be used, distributed and modified under the same terms as perl itself.

WARRANTY

There is no warranty for this software, to the extend permitted by applicable law. Use it at your own risk.