[libcatmandu-perl] 02/101: Change default line_sep of Text exporter (#204)

Jonas Smedegaard dr at jones.dk
Tue Feb 23 13:43:48 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libcatmandu-perl.

commit 2558cc339e6a3c796dc93151aae778c082406c90
Author: Jakob Voss <voss at gbv.de>
Date:   Sat Dec 5 08:07:19 2015 +0100

    Change default line_sep of Text exporter (#204)
---
 lib/Catmandu/Exporter/Text.pm | 18 +++++++++++-------
 t/Catmandu-Exporter-Text.t    | 19 ++++++-------------
 2 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/lib/Catmandu/Exporter/Text.pm b/lib/Catmandu/Exporter/Text.pm
index 6524e4f..814a4a2 100644
--- a/lib/Catmandu/Exporter/Text.pm
+++ b/lib/Catmandu/Exporter/Text.pm
@@ -33,12 +33,16 @@ sub unbackslash ($) {
 }
 # End from String::Escape
 
-has line_sep  => (is => 'ro', default => sub { undef }, coerce => sub {
-    unbackslash($_[0]);
-});
-has field_sep => (is => 'ro', default => sub { undef }, coerce => sub {
-    unbackslash($_[0]);
-});
+has line_sep  => (
+    is => 'ro', 
+    default => sub { "\n" }, 
+    coerce => sub { unbackslash($_[0]); }
+);
+has field_sep => (
+    is => 'ro', 
+    default => sub { undef }, 
+    coerce => sub { unbackslash($_[0]) }
+);
 
 sub add {
     my ($self, $data) = @_;
@@ -146,7 +150,7 @@ Binmode of the output stream C<fh>. Set to "C<:utf8>" by default.
 
 =item line_sep STR
 
-Use the STR at each end of line.
+Use the STR at each end of line. Set to "C<\n>" by default.
 
 =item field_sep STR
 
diff --git a/t/Catmandu-Exporter-Text.t b/t/Catmandu-Exporter-Text.t
index 5677343..2885998 100644
--- a/t/Catmandu-Exporter-Text.t
+++ b/t/Catmandu-Exporter-Text.t
@@ -12,7 +12,7 @@ require_ok 'Catmandu::Exporter::Text';
     my $data = [{'a' => 'moose'}, {'a' => 'pony'}, {'a' => ['shrimp','lobster']}];
     my $file = "";
 
-    my $exporter = Catmandu::Exporter::Text->new(file => \$file, line_sep => '\n' , field_sep => ',');
+    my $exporter = Catmandu::Exporter::Text->new(file => \$file, field_sep => ',');
     isa_ok $exporter, 'Catmandu::Exporter::Text';
 
     $exporter->add($_) for @$data;
@@ -26,28 +26,21 @@ pony
 shrimp,lobster
 EOF
 
-    is $file, $text, 'Text doc hash';
+    is $file, $text, 'Text doc hash, default line_sep';
 }
 
 {
     my $data = [{'a' => 'moose'}, {'a' => 'pony'}, {'a' => ['shrimp','lobster']}];
     my $file = "";
 
-    my $exporter = Catmandu::Exporter::Text->new(file => \$file, line_sep => '\n' , field_sep => ',');
+    my $exporter = Catmandu::Exporter::Text->new(file => \$file, line_sep => '\t' , field_sep => ',');
     isa_ok $exporter, 'Catmandu::Exporter::Text';
 
     $exporter->add_many($data);
-    $exporter->commit;
+    # don't call commit to test streaming output
 
     is $exporter->count, 3, 'Count ok';
-
-    my $text =<<EOF;
-moose
-pony
-shrimp,lobster
-EOF
-
-    is $file, $text, 'Text doc array';
+    is $file, "moose\tpony\tshrimp,lobster\t", 'Text doc array';
 }
 
-done_testing;
\ No newline at end of file
+done_testing;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-perl.git



More information about the Pkg-perl-cvs-commits mailing list