3 use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION $columns $debug);
10 @EXPORT_OK = qw($columns $tabstop fill);
12 use Text::Tabs qw(expand unexpand $tabstop);
16 $columns = 76; # <= screen width
22 my ($ip, $xp, @t) = @_;
25 my $t = expand(join(" ",@t));
28 my $ll = $columns - length(expand($lead)) - 1;
32 while(length($t) > $ll) {
33 # remove up to a line length of things that
34 # aren't new lines and tabs.
35 if ($t =~ s/^([^\n]{0,$ll})(\s|\Z(?!\n))//) {
38 print "WRAP $lead$l..($r)\n" if $debug;
39 push @rv, unexpand($lead . $l), "\n";
41 } elsif ($t =~ s/^([^\n]{$ll})//) {
42 print "SPLIT $lead$1..\n" if $debug;
43 push @rv, unexpand($lead . $1),"\n";
45 # recompute the leader
47 $ll = $columns - length(expand($lead)) - 1;
50 print "TAIL $lead$t\n" if $debug;
51 push @rv, $lead.$t if $t ne "";
58 my ($ip, $xp, @raw) = @_;
62 for $pp (split(/\n\s+/, join("\n",@raw))) {
64 my $x = wrap($ip, $xp, $pp);
68 # if paragraph_indent is the same as line_indent,
69 # separate paragraphs with blank lines
71 return join ($ip eq $xp ? "\n\n" : "\n", @para);
79 Text::Wrap - line wrapping to form simple paragraphs
85 print wrap($initial_tab, $subsequent_tab, @text);
87 use Text::Wrap qw(wrap $columns $tabstop fill);
92 print fill($initial_tab, $subsequent_tab, @text);
93 print fill("", "", `cat book`);
97 Text::Wrap::wrap() is a very simple paragraph formatter. It formats a
98 single paragraph at a time by breaking lines at word boundries.
99 Indentation is controlled for the first line ($initial_tab) and
100 all subsquent lines ($subsequent_tab) independently. $Text::Wrap::columns
101 should be set to the full width of your output device.
103 Text::Wrap::fill() is a simple multi-paragraph formatter. It formats
104 each paragraph separately and then joins them together when it's done. It
105 will destory any whitespace in the original text. It breaks text into
106 paragraphs by looking for whitespace after a newline. In other respects
111 print wrap("\t","","This is a bit of text that forms
112 a normal book-style paragraph");
116 It's not clear what the correct behavior should be when Wrap() is
117 presented with a word that is longer than a line. The previous
118 behavior was to die. Now the word is now split at line-length.
122 David Muir Sharnoff <muir@idiom.com> with help from Tim Pierce and
123 others. Updated by Jacqui Caren.