[perl #40272] subroutine call with & in perlop example
[p5sagit/p5-mst-13.2.git] / lib / Text / Wrap.pm
index de21d2a..b0e15a7 100644 (file)
@@ -6,7 +6,7 @@ require Exporter;
 @EXPORT = qw(wrap fill);
 @EXPORT_OK = qw($columns $break $huge);
 
-$VERSION = 2005.0824_01;
+$VERSION = 2006.0711;
 
 use vars qw($VERSION $columns $debug $break $huge $unexpand $tabstop
        $separator $separator2);
@@ -43,8 +43,8 @@ sub wrap
        use re 'taint';
 
        pos($t) = 0;
-       while ($t !~ /\G\s*\Z/gc) {
-               if ($t =~ /\G([^\n]{0,$ll})($break|\n*\z)/xmgc) {
+       while ($t !~ /\G(?:$break)*\Z/gc) {
+               if ($t =~ /\G([^\n]{0,$ll})($break|\n+|\z)/xmgc) {
                        $r .= $unexpand 
                                ? unexpand($nl . $lead . $1)
                                : $nl . $lead . $1;
@@ -54,13 +54,17 @@ sub wrap
                                ? unexpand($nl . $lead . $1)
                                : $nl . $lead . $1;
                        $remainder = defined($separator2) ? $separator2 : $separator;
-               } elsif ($huge eq 'overflow' && $t =~ /\G([^\n]*?)($break|\z)/xmgc) {
+               } elsif ($huge eq 'overflow' && $t =~ /\G([^\n]*?)($break|\n+|\z)/xmgc) {
                        $r .= $unexpand 
                                ? unexpand($nl . $lead . $1)
                                : $nl . $lead . $1;
                        $remainder = $2;
                } elsif ($huge eq 'die') {
                        die "couldn't wrap '$t'";
+               } elsif ($columns < 2) {
+                       warn "Increasing \$Text::Wrap::columns from $columns to 2";
+                       $columns = 2;
+                       return ($ip, $xp, @t);
                } else {
                        die "This shouldn't happen";
                }
@@ -139,7 +143,7 @@ B<Example 2>
        $huge = 'overflow';
 
 B<Example 3>
-
+       
        use Text::Wrap
 
        $Text::Wrap::columns = 72;
@@ -160,6 +164,8 @@ will destroy 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().
 
+Both C<wrap()> and C<fill()> return a single string.
+
 =head1 OVERRIDES
 
 C<Text::Wrap::wrap()> has a number of variables that control its behavior.
@@ -208,15 +214,35 @@ left intact.
 Historical notes: 'die' used to be the default value of
 C<$huge>.  Now, 'wrap' is the default value.
 
-=head1 EXAMPLE
+=head1 EXAMPLES
+
+Code:
+
+  print wrap("\t","",<<END);
+  This is a bit of text that forms 
+  a normal book-style indented paragraph
+  END
+
+Result:
+
+  "    This is a bit of text that forms
+  a normal book-style indented paragraph   
+  "
+
+Code:
+
+  $Text::Wrap::columns=20;
+  $Text::Wrap::separator="|";
+  print wrap("","","This is a bit of text that forms a normal book-style paragraph");
+
+Result:
 
-       print wrap("\t","","This is a bit of text that forms 
-               a normal book-style paragraph");
+  "This is a bit of|text that forms a|normal book-style|paragraph"
 
 =head1 LICENSE
 
 David Muir Sharnoff <muir@idiom.com> with help from Tim Pierce and
-many many others.  Copyright (C) 1996-2002 David Muir Sharnoff.  
+many many others.  Copyright (C) 1996-2006 David Muir Sharnoff.  
 This module may be modified, used, copied, and redistributed at
 your own risk.  Publicly redistributed modified versions must use 
 a different name.