[libcatmandu-marc-perl] 26/208: Revert the inline handling of arrays back to the original
Jonas Smedegaard
dr at jones.dk
Sat Oct 28 03:42:31 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag upstream/1.19
in repository libcatmandu-marc-perl.
commit a75cb3cc99649a7444499af861e7115848048e63
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date: Wed Jul 6 16:57:04 2016 +0200
Revert the inline handling of arrays back to the original
---
lib/Catmandu/Fix/Inline/marc_map.pm | 2 +-
lib/Catmandu/MARC.pm | 28 +++++++++++++++++++++-------
t/07-inline-fix.t | 13 ++++++++++---
3 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/lib/Catmandu/Fix/Inline/marc_map.pm b/lib/Catmandu/Fix/Inline/marc_map.pm
index 1328570..7668301 100644
--- a/lib/Catmandu/Fix/Inline/marc_map.pm
+++ b/lib/Catmandu/Fix/Inline/marc_map.pm
@@ -69,7 +69,7 @@ our $VERSION = '0.219';
sub marc_map {
my ($data,$marc_path,%opts) = @_;
-
+ $opts{'-nested_arrays'} = 1 unless exists $opts{'-nested_arrays'};
return Catmandu::MARC::marc_map($data,$marc_path,%opts);
}
diff --git a/lib/Catmandu/MARC.pm b/lib/Catmandu/MARC.pm
index f951e4d..20622ee 100644
--- a/lib/Catmandu/MARC.pm
+++ b/lib/Catmandu/MARC.pm
@@ -22,11 +22,12 @@ sub marc_map {
return wantarray ? () : undef;
}
- my $split = $opts{'-split'} // 0;
- my $join_char = $opts{'-join'} // '';
- my $pluck = $opts{'-pluck'};
- my $value_set = $opts{'-value'};
- my $attrs = {};
+ my $split = $opts{'-split'} // 0;
+ my $join_char = $opts{'-join'} // '';
+ my $pluck = $opts{'-pluck'};
+ my $value_set = $opts{'-value'};
+ my $nested_arrays = $opts{'-nested_arrays'} // 0;
+ my $attrs = {};
my $vals;
@@ -67,10 +68,23 @@ sub marc_map {
if ($split) {
$v = [ $v ] unless Catmandu::Util::is_array_ref($v);
if (Catmandu::Util::is_array_ref($vals)) {
- push @$vals , @$v;
+ # With the nested arrays option a split will
+ # always return an array of array of values.
+ # This was the old behavior of Inline marc_map functions
+ if ($nested_arrays == 1) {
+ push @$vals , $v;
+ }
+ else {
+ push @$vals , @$v;
+ }
}
else {
- $vals = [ @$v ];
+ if ($nested_arrays == 1) {
+ $vals = [$v];
+ }
+ else {
+ $vals = [ @$v ];
+ }
}
}
else {
diff --git a/t/07-inline-fix.t b/t/07-inline-fix.t
index bb54e9b..1a95214 100644
--- a/t/07-inline-fix.t
+++ b/t/07-inline-fix.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
use Catmandu::Util;
-use Test::More tests => 18;
+use Test::More tests => 21;
use Catmandu::Fix::Inline::marc_map qw(marc_map);
use Catmandu::Fix::Inline::marc_add qw(marc_add);
@@ -81,15 +81,22 @@ ok(@$records == 2 , "Found 2 records");
{
my @arr = marc_map($records->[0],'245a/0-3',-split=>1);
- is $arr[0] , q|Acti|;
+ is $arr[0][0] , q|Acti|;
}
{
my @arr = marc_map($records->[0],'630',-split=>1);
ok @arr == 2;
+ is ref($arr[0]) , 'ARRAY' , 'got an array of arrays';
+}
+
+{
+ my @arr = marc_map($records->[0],'630',-split=>1, '-nested_arrays' => 0);
+ ok @arr == 2;
+ is ref($arr[0]) , '' , 'got an array of strings';
}
{
my @arr = marc_map($records->[1],'020a',-split=>1);
- ok @arr == 3;
+ ok @arr == 2;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-marc-perl.git
More information about the Pkg-perl-cvs-commits
mailing list