[libcatmandu-marc-perl] 08/208: Fixing Catmandu::Fix::marc_map $append and split #31
Jonas Smedegaard
dr at jones.dk
Sat Oct 28 03:42:30 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 c290bd7c322b53440c2359360c29429d3589c909
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date: Mon Jun 13 16:52:48 2016 +0200
Fixing Catmandu::Fix::marc_map $append and split #31
---
Changes | 1 +
lib/Catmandu/Fix/Inline/marc_map.pm | 4 ++--
lib/Catmandu/Fix/marc_map.pm | 15 ++++++++-------
t/03-marc_map.t | 2 +-
t/07-inline-fix.t | 7 ++++++-
5 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/Changes b/Changes
index 6a772e3..bcaad5e 100644
--- a/Changes
+++ b/Changes
@@ -4,6 +4,7 @@ Revision history for Catmandu-MARC
- Fixed indicator-2 selection bug
- Fixed marc_map value bug
- Support for the value in the inline fixes
+ - Fixing combinations of substring and split
0.215 2016-02-22 09:57:07 CET
- Supporting ISO alias for USMARC importer and exporter
diff --git a/lib/Catmandu/Fix/Inline/marc_map.pm b/lib/Catmandu/Fix/Inline/marc_map.pm
index 09bc303..96c9494 100644
--- a/lib/Catmandu/Fix/Inline/marc_map.pm
+++ b/lib/Catmandu/Fix/Inline/marc_map.pm
@@ -81,7 +81,7 @@ sub marc_map {
my $value_set = $opts{'-value'};
my $attrs = {};
- if ($marc_path =~ /(\S{3})(\[(.)?,?(.)?\])?([_a-z0-9^]+)?(\/(\d+)(-(\d+))?)?/) {
+ if ($marc_path =~ /(\S{3})(\[([^,])?,?([^,])?\])?([_a-z0-9^]+)?(\/(\d+)(-(\d+))?)?/) {
$attrs->{field} = $1;
$attrs->{ind1} = $3;
$attrs->{ind2} = $4;
@@ -143,7 +143,7 @@ sub marc_map {
if ($var->[0] =~ /LDR|00./) {
$v = $add_subfields->($var,3);
}
- elsif (defined $var->[5] && $var->[5] eq '_') {
+ elsif (defined $var->[3] && $var->[3] eq '_') {
$v = $add_subfields->($var,5);
}
else {
diff --git a/lib/Catmandu/Fix/marc_map.pm b/lib/Catmandu/Fix/marc_map.pm
index 4032632..b2c514f 100644
--- a/lib/Catmandu/Fix/marc_map.pm
+++ b/lib/Catmandu/Fix/marc_map.pm
@@ -102,7 +102,7 @@ sub emit {
# Old Catmandu::MARC contained a bug/feature to allow
# for '_' subfields in non-control elements ..for beackwards
# compatibility we ignore them
- $perl .= "} elsif (defined ${var}->[5] && ${var}->[5] eq '_') {";
+ $perl .= "} elsif (defined ${var}->[3] && ${var}->[3] eq '_') {";
$perl .= $add_subfields->(5);
$perl .= "} else {";
$perl .= $add_subfields->(3);
@@ -129,10 +129,11 @@ sub emit {
$perl .= "if (defined ${v}) {";
if ($self->split) {
$perl .=
+ "${v} = [ ${v} ] unless ref ${v} eq 'ARRAY';" .
"if (is_array_ref(${var})) {".
- "push \@{${var}}, ${v};".
+ "push \@{${var}}, \@{${v}};".
"} else {".
- "${var} = [${v}];".
+ "${var} = [\@{${v}}];".
"}";
} else {
$perl .=
@@ -162,10 +163,10 @@ Catmandu::Fix::marc_map - copy marc values of one field to a new field
=head1 SYNOPSIS
- # Append all 245 subfields to my.title
- marc_map('245','my.title')
+ # Append all 245 subfields to my.title field the values are joined into one string
+ marc_map('245','my.title')
- # Append an array of 245 subfields to the my.title array
+ # Append al 245 subfields to the my.title keeping all subfields as an array
marc_map('245','my.title', split:1)
# Copy the 245-$a$b$c subfields into the my.title hash in the order provided in the record
@@ -182,7 +183,7 @@ Catmandu::Fix::marc_map - copy marc values of one field to a new field
# Copy the 600-$x subfields into the my.subjects array while packing each into a genre.text hash
marc_map('600x','my.subjects.$append.genre.text')
-
+
# Copy the 008 characters 35-35 into the my.language hash
marc_map('008/35-35','my.language')
diff --git a/t/03-marc_map.t b/t/03-marc_map.t
index a1f6214..448028c 100644
--- a/t/03-marc_map.t
+++ b/t/03-marc_map.t
@@ -20,7 +20,7 @@ is $records->[0]->{my}{title}, 'ActivePerl with ASP and ADO /', q|fix: marc_map(
is_deeply
$records->[0]->{my}{split_title},
- [['ActivePerl with ASP and ADO /', 'Tobias Martinsson.']],
+ ['ActivePerl with ASP and ADO /', 'Tobias Martinsson.'],
q|fix: marc_map('245','my.split.title','-split', 1);|;
# field 666 does not exist in camel.usmarc
diff --git a/t/07-inline-fix.t b/t/07-inline-fix.t
index de370f2..4b77e9e 100644
--- a/t/07-inline-fix.t
+++ b/t/07-inline-fix.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use Test::More tests => 16;
+use Test::More tests => 17;
use Catmandu::Fix::Inline::marc_map qw(marc_map);
use Catmandu::Fix::Inline::marc_add qw(marc_add);
@@ -83,4 +83,9 @@ ok(@$records == 2 , "Found 2 records");
{
my @arr = marc_map($records->[0],'245a/0-3',-split=>1);
is $arr[0] , q|Acti|;
+}
+
+{
+ my @arr = marc_map($records->[0],'630',-split=>1);
+ ok @arr == 2;
}
\ No newline at end of file
--
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