[Bps-public-commit] Text-Quoted branch, master, updated. 2.09-2-g34e180f
Jesse Vincent
jesse at bestpractical.com
Fri Apr 10 14:59:59 EDT 2015
The branch, master has been updated
via 34e180f1c436f8a8ef5d5f65fab3603e43bbf197 (commit)
via 273c713270f1a5bd4e1362789bc0ab7d29bd9aff (commit)
from 9cce0e0fa8fdd80427f486c6a298e725e2346c6a (commit)
Summary of changes:
lib/Text/Quoted.pm | 17 ++++++++++++++---
t/separator.t | 17 ++++++++++++++++-
2 files changed, 30 insertions(+), 4 deletions(-)
- Log -----------------------------------------------------------------
commit 273c713270f1a5bd4e1362789bc0ab7d29bd9aff
Author: Ricardo Signes <rjbs at cpan.org>
Date: Fri Apr 10 13:28:27 2015 -0400
add no_separators option
diff --git a/lib/Text/Quoted.pm b/lib/Text/Quoted.pm
index 317929b..4e4f814 100644
--- a/lib/Text/Quoted.pm
+++ b/lib/Text/Quoted.pm
@@ -69,9 +69,16 @@ C<quoter> is the quotation string.
=head2 extract
+ my $struct = extract($text, \%arg);
+
Takes a single string argument which is the text to extract quote
structure from. Returns a nested datastructure as described above.
+Second argument is optional: a hashref of options. The only valid
+argument at present is:
+
+ no_separators - never mark paragraphs as "separators"
+
Exported by default.
=cut
@@ -187,10 +194,13 @@ sub combine_hunks {
}
sub _classify {
- my $text = shift;
+ my ($text, $arg) = @_;
+ $arg ||= {};
+
+ # If the user passes in a null string, we really want to end up with
+ # _something_
return { raw => undef, text => undef, quoter => undef }
unless defined $text && length $text;
- # If the user passes in a null string, we really want to end up with _something_
# DETABIFY
my @lines = Text::Tabs::expand( split /\n/, $text );
@@ -201,7 +211,8 @@ sub _classify {
@line{'quoter', 'text'} = (/\A *($quoter?) *(.*?)\s*\Z/);
$line{hang} = $hang_package->new( $line{'text'} );
$line{empty} = 1 if $line{hang}->empty() && $line{'text'} !~ /\S/;
- $line{separator} = 1 if $line{text} =~ /\A *$separator *\Z/o;
+ $line{separator} = 1 if $line{text} =~ /\A *$separator *\Z/o
+ and ! $arg->{no_separators};
push @lines, \%line;
}
commit 34e180f1c436f8a8ef5d5f65fab3603e43bbf197
Author: Ricardo Signes <rjbs at cpan.org>
Date: Fri Apr 10 14:00:43 2015 -0400
add no_separator tests
diff --git a/t/separator.t b/t/separator.t
index 1e347e8..0125746 100644
--- a/t/separator.t
+++ b/t/separator.t
@@ -1,5 +1,5 @@
-use Test::More tests => 3;
+use Test::More tests => 5;
BEGIN { use_ok('Text::Quoted') };
use Data::Dumper;
@@ -22,6 +22,12 @@ is_deeply(extract($text), [
"Sample text is organized properly"
) or diag Dumper(extract($text));
+is_deeply(extract($text, { no_separators => 1 }), [
+ {text => "foo\n============\nbar\n============\nbaz", quoter => '', raw => "foo\n============\nbar\n============\nbaz"},
+ ],
+ "Sample text is organized properly (no separators)"
+) or diag Dumper(extract($text, { no_separators => 1 }));
+
$text = <<EOF;
foo
> bar
@@ -42,3 +48,12 @@ is_deeply(extract($text), [
"Sample text is organized properly"
) or diag Dumper(extract($text));
+is_deeply(extract($text, { no_separators => 1 }), [
+ {text => 'foo', quoter => '', raw => 'foo'},
+ [
+ {text => "bar\n============\nbaz\n============", quoter => '>', raw => "> bar\n> ============\n> baz\n> ============"},
+ ],
+ ],
+ "Sample text is organized properly (no separators)"
+) or diag Dumper(extract($text, { no_separators => 1 }));
+
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list