6 @EXPORT = qw(wrap fill);
7 @EXPORT_OK = qw($columns $break $huge);
11 use vars qw($VERSION $columns $debug $break $huge);
15 $columns = 76; # <= screen width
18 $huge = 'wrap'; # alternatively: 'die'
21 use Text::Tabs qw(expand unexpand);
25 my ($ip, $xp, @t) = @_;
28 my $t = expand(join(" ",@t));
30 my $ll = $columns - length(expand($ip)) - 1;
31 my $nll = $columns - length(expand($xp)) - 1;
35 while ($t !~ /^\s*$/) {
36 if ($t =~ s/^([^\n]{0,$ll})($break|\Z(?!\n))//xm) {
37 $r .= unexpand($nl . $lead . $1);
39 } elsif ($huge eq 'wrap' && $t =~ s/^([^\n]{$ll})//) {
40 $r .= unexpand($nl . $lead . $1);
42 } elsif ($huge eq 'die') {
43 die "couldn't wrap '$t'";
45 die "This shouldn't happen";
54 print "-----------$r---------\n" if $debug;
56 print "Finish up with '$lead', '$t'\n" if $debug;
58 $r .= $lead . $t if $t ne "";
60 print "-----------$r---------\n" if $debug;;
66 my ($ip, $xp, @raw) = @_;
70 for $pp (split(/\n\s+/, join("\n",@raw))) {
72 my $x = wrap($ip, $xp, $pp);
76 # if paragraph_indent is the same as line_indent,
77 # separate paragraphs with blank lines
79 return join ($ip eq $xp ? "\n\n" : "\n", @para);
87 Text::Wrap - line wrapping to form simple paragraphs
93 print wrap($initial_tab, $subsequent_tab, @text);
94 print fill($initial_tab, $subsequent_tab, @text);
96 use Text::Wrap qw(wrap $columns $huge);
104 Text::Wrap::wrap() is a very simple paragraph formatter. It formats a
105 single paragraph at a time by breaking lines at word boundries.
106 Indentation is controlled for the first line ($initial_tab) and
107 all subsquent lines ($subsequent_tab) independently.
109 Lines are wrapped at $Text::Wrap::columns columns.
110 $Text::Wrap::columns should be set to the full width of your output device.
112 When words that are longer than $columns are encountered, they
113 are broken up. Previous versions of wrap() die()ed instead.
114 To restore the old (dying) behavior, set $Text::Wrap::huge to
117 Text::Wrap::fill() is a simple multi-paragraph formatter. It formats
118 each paragraph separately and then joins them together when it's done. It
119 will destory any whitespace in the original text. It breaks text into
120 paragraphs by looking for whitespace after a newline. In other respects
125 print wrap("\t","","This is a bit of text that forms
126 a normal book-style paragraph");
130 David Muir Sharnoff <muir@idiom.com> with help from Tim Pierce and