[Bps-public-commit] Text-Quoted branch, set-quote-char, updated. 746bceed078213929e9b642dc18826267f4e98df

Thomas Sibley trs at bestpractical.com
Thu May 16 17:25:13 EDT 2013


The branch, set-quote-char has been updated
       via  746bceed078213929e9b642dc18826267f4e98df (commit)
       via  4e98615024fd74fcfe97c02718559d55d8390366 (commit)
       via  7649477416cf1516a6c64f4085a93be24263e768 (commit)
       via  59813987b7a7ccae29ddd2c7dbdb653a532311db (commit)
      from  363cd4a4467ac78dd4c491a706d4fe1d47ed759c (commit)

Summary of changes:
 Quoted.pm  | 91 ++++++++++++++++++++++++++++++++++++++------------------------
 t/basics.t |  4 +--
 2 files changed, 58 insertions(+), 37 deletions(-)

- Log -----------------------------------------------------------------
commit 59813987b7a7ccae29ddd2c7dbdb653a532311db
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu May 16 13:16:15 2013 -0700

    Use set_quote_char() to set the defaults
    
    This keeps our regexes in one place instead of redefining them in
    multiple places where it would be easy to modify one but not the other.
    The set_quote_char() function itself is moved closer to the variables it
    sets for readability.

diff --git a/Quoted.pm b/Quoted.pm
index d3d98ad..959ef93 100644
--- a/Quoted.pm
+++ b/Quoted.pm
@@ -148,10 +148,18 @@ sub find_below {
 
 # BITS OF A TEXT LINE
 
-my $quotechar  = qr/[!#%=|:]/;
-my $separator  = qr/[-_]{2,} | [=#*]{3,} | [+~]{4,}/x;
-my $quotechunk = qr/(?!$separator *\z)(?:$quotechar(?!\w)|\w*>+)/;
-my $quoter     = qr/$quotechunk(?:[ \t]*$quotechunk)*/;
+my $separator = qr/[-_]{2,} | [=#*]{3,} | [+~]{4,}/x;
+my ($quotechar, $quotechunk, $quoter);
+
+set_quote_char(qr/[!#%=|:]/);
+
+sub set_quote_char {
+    $quotechar  = shift;
+    $quotechunk = $quotechar
+        ? qr/(?!$separator *\z)(?:$quotechar(?!\w)|\w*>+)/
+        : qr/(?!$separator *\z)\w*>+/;
+    $quoter     = qr/$quotechunk(?:[ \t]*$quotechunk)*/;
+}
 
 sub defn($) { return $_[0] if (defined $_[0]); return "" }
 
@@ -242,17 +250,4 @@ sub expand_tabs {
     return @_;
 }
 
-sub set_quote_char {
-    my $regex = shift;
-    $quotechar = $regex;
-    if ($quotechar) {
-        $quotechunk = qr/(?!$separator *\z)(?:$quotechar(?!\w)|\w*>+)/;
-    }
-    else {
-        $quotechunk = qr/(?!$separator *\z)\w*>+/;
-    }
-    $quoter     = qr/$quotechunk(?:[ \t]*$quotechunk)*/;
-}
-
-
 1;

commit 7649477416cf1516a6c64f4085a93be24263e768
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu May 16 13:24:27 2013 -0700

    Rename to set_quote_characters(); no need to use an abbreviated word

diff --git a/Quoted.pm b/Quoted.pm
index 959ef93..799866b 100644
--- a/Quoted.pm
+++ b/Quoted.pm
@@ -18,7 +18,7 @@ Text::Quoted - Extract the structure of a quoted mail message
 =head1 SYNOPSIS
 
     use Text::Quoted;
-    Text::Quoted::set_quote_char( qr/[:]/ ); # customize quote char
+    Text::Quoted::set_quote_characters( qr/[:]/ ); # customize recognized quote characters
     my $structure = extract($text);
 
 =head1 DESCRIPTION
@@ -151,9 +151,9 @@ sub find_below {
 my $separator = qr/[-_]{2,} | [=#*]{3,} | [+~]{4,}/x;
 my ($quotechar, $quotechunk, $quoter);
 
-set_quote_char(qr/[!#%=|:]/);
+set_quote_characters(qr/[!#%=|:]/);
 
-sub set_quote_char {
+sub set_quote_characters {
     $quotechar  = shift;
     $quotechunk = $quotechar
         ? qr/(?!$separator *\z)(?:$quotechar(?!\w)|\w*>+)/
diff --git a/t/basics.t b/t/basics.t
index 61e6772..2ff2d6b 100644
--- a/t/basics.t
+++ b/t/basics.t
@@ -148,7 +148,7 @@ $a_dump =
 
 is_deeply(extract($a),$a_dump,"correctly handles a non-delimiter");
 
-Text::Quoted::set_quote_char( qr/[!]/ );
+Text::Quoted::set_quote_characters( qr/[!]/ );
 $a = <<'EOF';
 a
 # b
@@ -173,7 +173,7 @@ $a_dump = [
 
 is_deeply(extract($a),$a_dump,"customize quote char");
 
-Text::Quoted::set_quote_char( undef );
+Text::Quoted::set_quote_characters( undef );
 $a = <<'EOF';
 a
 # b

commit 4e98615024fd74fcfe97c02718559d55d8390366
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu May 16 13:28:02 2013 -0700

    Move copyright and license POD to end of file so we can write inline function doc

diff --git a/Quoted.pm b/Quoted.pm
index 799866b..e2303d9 100644
--- a/Quoted.pm
+++ b/Quoted.pm
@@ -63,25 +63,6 @@ sub extract {
     return organize( "", classify( @_ ) );
 }
 
-=head1 CREDITS
-
-Most of the heavy lifting is done by a modified version of Damian Conway's
-C<Text::Autoformat>.
-
-=head1 COPYRIGHT
-
-Copyright (C) 2002-2003 Kasei Limited
-Copyright (C) 2003-2004 Simon Cozens
-Copyright (C) 2004 Best Practical Solutions, LLC
-
-This software is distributed WITHOUT ANY WARRANTY; without even the implied
-warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself. 
-
-=cut
-
 sub organize {
     my $top_level = shift;
     my @todo      = @_;
@@ -250,4 +231,23 @@ sub expand_tabs {
     return @_;
 }
 
+=head1 CREDITS
+
+Most of the heavy lifting is done by a modified version of Damian Conway's
+C<Text::Autoformat>.
+
+=head1 COPYRIGHT
+
+Copyright (C) 2002-2003 Kasei Limited
+Copyright (C) 2003-2004 Simon Cozens
+Copyright (C) 2004-2013 Best Practical Solutions, LLC
+
+This software is distributed WITHOUT ANY WARRANTY; without even the implied
+warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself. 
+
+=cut
+
 1;

commit 746bceed078213929e9b642dc18826267f4e98df
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu May 16 13:29:44 2013 -0700

    Document the two publicized functions: extract and set_quote_characters

diff --git a/Quoted.pm b/Quoted.pm
index e2303d9..d47dc72 100644
--- a/Quoted.pm
+++ b/Quoted.pm
@@ -8,6 +8,7 @@ require Exporter;
 
 our @ISA    = qw(Exporter);
 our @EXPORT = qw(extract);
+our @EXPORT_OK = qw(set_quote_characters);
 
 use Text::Autoformat();    # Provides the Hang package, heh, heh.
 
@@ -57,6 +58,15 @@ paragraph of text as it appeared in the original input; C<text> is what
 it looked like when we stripped off the quotation characters, and C<quoter>
 is the quotation string.
 
+=head1 FUNCTIONS
+
+=head2 extract
+
+Takes a single string argument which is the text to extract quote structure
+from.  Returns a nested datastructure as described above.
+
+Exported by default.
+
 =cut
 
 sub extract {
@@ -129,6 +139,22 @@ sub find_below {
 
 # BITS OF A TEXT LINE
 
+=head2 set_quote_characters
+
+Takes a regex (C<qr//>) matching characters that should indicate a quoted line.
+By default, a very liberal set is used:
+
+    set_quote_characters(qr/[!#%=|:]/);
+
+The character C<< E<gt> >> is always recognized as a quoting character.
+
+If C<undef> is provided instead of a regex, only C<< E<gt> >> will remain as a
+quote character.
+
+Not exported by default, but exportable.
+
+=cut
+
 my $separator = qr/[-_]{2,} | [=#*]{3,} | [+~]{4,}/x;
 my ($quotechar, $quotechunk, $quoter);
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list