From: Gurusamy Sarathy Date: Sun, 29 Nov 1998 22:50:41 +0000 (+0000) Subject: update to Text::Wrap 98.112901 from David Muir Sharnoff X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0c5a43b5594d04d9dac43d2ebfaeda7a8ef94911;p=p5sagit%2Fp5-mst-13.2.git update to Text::Wrap 98.112901 from David Muir Sharnoff p4raw-id: //depot/perl@2400 --- diff --git a/MANIFEST b/MANIFEST index 3552d94..34d3bcd 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1059,7 +1059,8 @@ t/lib/socket.t See if Socket works t/lib/soundex.t See if Soundex works t/lib/symbol.t See if Symbol works t/lib/texttabs.t See if Text::Tabs works -t/lib/textwrap.t See if Text::Wrap works +t/lib/textfill.t See if Text::Wrap::fill works +t/lib/textwrap.t See if Text::Wrap::wrap works t/lib/thread.t Basic test of threading (skipped if no threads) t/lib/tie-push.t Test for Tie::Array t/lib/tie-stdarray.t Test for Tie::StdArray diff --git a/lib/Text/Wrap.pm b/lib/Text/Wrap.pm index 062354d..a5b16e2 100644 --- a/lib/Text/Wrap.pm +++ b/lib/Text/Wrap.pm @@ -2,11 +2,11 @@ package Text::Wrap; require Exporter; -@ISA = (Exporter); -@EXPORT = qw(wrap); -@EXPORT_OK = qw($columns $wraplong); +@ISA = qw(Exporter); +@EXPORT = qw(wrap fill); +@EXPORT_OK = qw($columns $break $huge); -$VERSION = 98.112801; +$VERSION = 98.112901; use vars qw($VERSION $columns $debug $break $huge); use strict; @@ -61,6 +61,24 @@ sub wrap return $r; } +sub fill +{ + my ($ip, $xp, @raw) = @_; + my @para; + my $pp; + + for $pp (split(/\n\s+/, join("\n",@raw))) { + $pp =~ s/\s+/ /g; + my $x = wrap($ip, $xp, $pp); + push(@para, $x); + } + + # if paragraph_indent is the same as line_indent, + # separate paragraphs with blank lines + + return join ($ip eq $xp ? "\n\n" : "\n", @para); +} + 1; __END__ @@ -73,6 +91,7 @@ Text::Wrap - line wrapping to form simple paragraphs use Text::Wrap print wrap($initial_tab, $subsequent_tab, @text); + print fill($initial_tab, $subsequent_tab, @text); use Text::Wrap qw(wrap $columns $huge); @@ -95,6 +114,12 @@ are broken up. Previous versions of wrap() die()ed instead. To restore the old (dying) behavior, set $Text::Wrap::huge to 'die'. +Text::Wrap::fill() is a simple multi-paragraph formatter. It formats +each paragraph separately and then joins them together when it's done. It +will destory any whitespace in the original text. It breaks text into +paragraphs by looking for whitespace after a newline. In other respects +it acts like wrap(). + =head1 EXAMPLE print wrap("\t","","This is a bit of text that forms @@ -103,5 +128,5 @@ To restore the old (dying) behavior, set $Text::Wrap::huge to =head1 AUTHOR David Muir Sharnoff with help from Tim Pierce and -many others. +many many others. diff --git a/t/lib/textfill.t b/t/lib/textfill.t new file mode 100755 index 0000000..b40aaff --- /dev/null +++ b/t/lib/textfill.t @@ -0,0 +1,94 @@ +#!/usr/bin/perl -w -I. + +@tests = (split(/\nEND\n/s, <