Text::WrapProp - proportional line wrapping to form simple paragraphs
use Text::WrapProp qw(wrap_prop); my ($output, $status) = wrap_prop($text, $width, $ref_width_table); print $output if !$status;
Text::WrapProp::wrap_prop() is a very simple paragraph formatter for proportional text. It formats a single paragraph at a time by breaking lines at word boundries. You must supply the column width in floating point units which should be set to the full width of your output device. A reference to a character width table must also be supplied. The width units can be any metric you choose, as long as the column width and the width table use the same metric.
Proportional wrapping is commonly used in the publishing industry. In HTML, custom proportional wrapping is less often performed as the browser performs the calculations automatically.
wrap_prop returns a list: (text string, integer status). For invalid parameters, the empty string '' and a non-zero status.
use strict; use diagnostics; use Text::WrapProp qw(wrap_prop); my @width_table = (0.05) x 256; my ($output, $status) = wrap_prop("This is a bit of text that forms a normal book-style paragraph. Supercajafrajalisticexpialadocious!", 4.00, \@width_table); print $output if !$status;
See eg/ for more examples.
It's not clear what the correct behavior should be when WrapProp() is presented with a word that is longer than a line. The previous behavior was to die. Now the word is split at line-length.
James Briggs <email@example.com>. Styled after Text::Wrap.