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

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

commit 4bd0cdae667e3e1dbe4115770c17cb0368868b3b
Author: Johann Rolschewski <jo...@cpan.org>
Date:   Wed Jan 20 13:50:41 2016 +0100

    GH#213: Support escape characters in CSV import options
---
 lib/Catmandu/Importer/CSV.pm | 10 +++++++++-
 t/Catmandu-Importer-CSV.t    | 13 +++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/lib/Catmandu/Importer/CSV.pm b/lib/Catmandu/Importer/CSV.pm
index 4866b4c..6142fe3 100644
--- a/lib/Catmandu/Importer/CSV.pm
+++ b/lib/Catmandu/Importer/CSV.pm
@@ -12,7 +12,15 @@ use namespace::clean;
 with 'Catmandu::Importer';
 
 has csv => (is => 'ro', lazy => 1, builder => '_build_csv');
-has sep_char => (is => 'ro', default => sub { ',' });
+has sep_char => (
+    is      => 'ro',
+    default => sub {','},
+    coerce  => sub {
+        my $sep_char = $_[0];
+        $sep_char =~ s/(\\[abefnrt])/"qq{$1}"/gee;
+        return $sep_char;
+    }
+);
 has quote_char => (is => 'ro', default => sub { '"' });
 has escape_char => (is => 'ro', default => sub { '"' });
 has allow_loose_quotes => (is => 'ro', default => sub { 0 });
diff --git a/t/Catmandu-Importer-CSV.t b/t/Catmandu-Importer-CSV.t
index 3af6528..3d8494a 100644
--- a/t/Catmandu-Importer-CSV.t
+++ b/t/Catmandu-Importer-CSV.t
@@ -43,5 +43,18 @@ $importer = $pkg->new(file => \$csv, header => 0);
 
 is_deeply $importer->to_array, $data;
 
+$data = [
+   {name=>'Nicolas',age=>'34'},
+];
+
+$csv = <<EOF;
+"name" "age"
+"Nicolas"      "34"
+EOF
+
+$importer = $pkg->new(file => \$csv, sep_char => '\t');
+
+is_deeply $importer->to_array, $data;
+
 done_testing;
 

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

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to