3 use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION $columns $debug $min_wrap_width);
10 @EXPORT_OK = qw($columns $tabstop $min_wrap_width fill);
12 use Text::Tabs qw(expand unexpand $tabstop);
16 $columns = 76; # <= screen width
18 # minimum wrap width (leaders will be shortened to accomodate this)
19 $min_wrap_width = int($columns/5);
24 my ($ip, $xp, @t) = @_;
27 my $t = expand(join(" ",@t));
29 my $xll = $columns - length(expand($xp)) - 1;
30 while ($xll < $min_wrap_width) {
32 $xll = $columns - length(expand($xp)) - 1;
35 my $ll = $columns - length(expand($ip)) - 1;
36 while ($ll < $min_wrap_width) {
38 $ll = $columns - length(expand($ip)) - 1;
44 while(length($t) > $ll) {
45 # remove up to a line length of things that
46 # aren't new lines and tabs.
47 if ($t =~ s/^([^\n]{0,$ll})(\s|\Z(?!\n))//) {
50 print "WRAP $lead$l..($r)\n" if $debug;
51 push @rv, unexpand($lead . $l), "\n";
53 } elsif ($t =~ s/^([^\n]{$ll})//) {
54 print "SPLIT $lead$1..\n" if $debug;
55 push @rv, unexpand($lead . $1),"\n";
62 print "TAIL $lead$t\n" if $debug;
63 push @rv, $lead.$t if $t ne "";
70 my ($ip, $xp, @raw) = @_;
74 for $pp (split(/\n\s+/, join("\n",@raw))) {
76 my $x = wrap($ip, $xp, $pp);
80 # if paragraph_indent is the same as line_indent,
81 # separate paragraphs with blank lines
83 return join ($ip eq $xp ? "\n\n" : "\n", @para);
91 Text::Wrap - line wrapping to form simple paragraphs
97 print wrap($initial_tab, $subsequent_tab, @text);
99 use Text::Wrap qw(wrap $columns $tabstop fill);
104 print fill($initial_tab, $subsequent_tab, @text);
105 print fill("", "", `cat book`);
109 Text::Wrap::wrap() is a very simple paragraph formatter. It formats a
110 single paragraph at a time by breaking lines at word boundries.
111 Indentation is controlled for the first line ($initial_tab) and
112 all subsquent lines ($subsequent_tab) independently. $Text::Wrap::columns
113 should be set to the full width of your output device (default is 76).
114 $Text::Wrap::min_wrap_width controls the minimum number of columns that
115 are reserved for the wrapped text (default is 15). Indentation will
116 be reduced to accomodate this value.
118 Text::Wrap::fill() is a simple multi-paragraph formatter. It formats
119 each paragraph separately and then joins them together when it's done. It
120 will destory any whitespace in the original text. It breaks text into
121 paragraphs by looking for whitespace after a newline. In other respects
126 print wrap("\t","","This is a bit of text that forms
127 a normal book-style paragraph");
131 It's not clear what the correct behavior should be when Wrap() is
132 presented with a word that is longer than a line. The previous
133 behavior was to die. Now the word is now split at line-length.
137 David Muir Sharnoff <muir@idiom.com> with help from Tim Pierce and
138 others. Updated by Jacqui Caren.