[Bps-public-commit] Text-Quoted branch, set-quote-char, created. d80716bfa36340fc76698fa4e7a2eee40fccd6da

? sunnavy sunnavy at bestpractical.com
Thu Mar 22 01:19:18 EDT 2012


The branch, set-quote-char has been created
        at  d80716bfa36340fc76698fa4e7a2eee40fccd6da (commit)

- Log -----------------------------------------------------------------
commit d80716bfa36340fc76698fa4e7a2eee40fccd6da
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Mar 22 13:18:12 2012 +0800

    add sub set_quote_car so we can customize quote chars

diff --git a/Quoted.pm b/Quoted.pm
index a0fb459..8cecf2d 100644
--- a/Quoted.pm
+++ b/Quoted.pm
@@ -18,6 +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
     my $structure = extract($text);
 
 =head1 DESCRIPTION
@@ -166,7 +167,7 @@ sub classify {
     # PARSE EACH LINE
     foreach (splice @lines) {
         my %line = ( raw => $_ );
-        @line{'quoter', 'text'} = (/\A *($quoter?) *(.*?)\s*\Z/o);
+        @line{'quoter', 'text'} = (/\A *($quoter?) *(.*?)\s*\Z/);
         $line{hang}      = Hang->new( $line{'text'} );
         $line{empty}     = 1 if $line{hang}->empty() && $line{'text'} !~ /\S/;
         $line{separator} = 1 if $line{text} =~ /\A *$separator *\Z/o;
@@ -241,4 +242,12 @@ sub expand_tabs {
     return @_;
 }
 
+sub set_quote_char {
+    my $regex = shift;
+    $quotechar = $regex;
+    $quotechunk = qr/(?!$separator *\z)(?:$quotechar(?!\w)|\w*>+)/;
+    $quoter     = qr/$quotechunk(?:[ \t]*$quotechunk)*/;
+}
+
+
 1;
diff --git a/t/basics.t b/t/basics.t
index ba03a1e..5526079 100644
--- a/t/basics.t
+++ b/t/basics.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 8;
+use Test::More tests => 9;
 BEGIN { use_ok('Text::Quoted') };
 
 use Data::Dumper;
@@ -148,3 +148,28 @@ $a_dump =
 
 is_deeply(extract($a),$a_dump,"correctly handles a non-delimiter");
 
+Text::Quoted::set_quote_char( qr/[!]/ );
+$a = <<'EOF';
+a
+# b
+c
+! d
+EOF
+
+$a_dump = [
+    {
+        'text'   => "a\n# b\nc",
+        'quoter' => '',
+        'raw'    => "a\n# b\nc"
+    },
+    [
+        {
+            'text'   => "d",
+            'quoter' => '!',
+            'raw'    => "! d"
+        },
+    ]
+];
+
+is_deeply(extract($a),$a_dump,"customize quote char");
+

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



More information about the Bps-public-commit mailing list