[libcatmandu-marc-perl] 121/208: Fixing again the $append bug $49 now with support for $prepend, $last, $first, ....

Jonas Smedegaard dr at jones.dk
Sat Oct 28 03:42:42 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 553bf8eb777567e57ca620bf141740e0b0c742a8
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date:   Mon Mar 27 11:27:29 2017 +0200

    Fixing again the $append bug $49 now with support for $prepend, $last,
    $first, ....
---
 Changes                             |  1 +
 lib/Catmandu/Fix/Inline/marc_map.pm |  2 ++
 lib/Catmandu/Fix/marc_map.pm        | 10 +++++-----
 lib/Catmandu/Fix/marc_spec.pm       | 13 +++++++------
 lib/Catmandu/MARC.pm                |  4 ++--
 t/07-inline-fix.t                   |  8 +++++++-
 6 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/Changes b/Changes
index 3921ab0..9af4de0 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
 Revision history for Catmandu-MARC
 
 {{$NEXT}}
+  - Supporting forced arrays for $prepend, $append, $first, $last and any digits in the path
 
 1.08  2017-03-06 09:55:53 CET
   - Fixed broken $append mapping and added many more tests
diff --git a/lib/Catmandu/Fix/Inline/marc_map.pm b/lib/Catmandu/Fix/Inline/marc_map.pm
index 57f575c..1c18fb8 100644
--- a/lib/Catmandu/Fix/Inline/marc_map.pm
+++ b/lib/Catmandu/Fix/Inline/marc_map.pm
@@ -75,6 +75,8 @@ sub marc_map {
     $opts{'-pluck'} = 0         unless exists $opts{'-pluck'};
     $opts{'-nested_arrays'} = 1 unless exists $opts{'-nested_arrays'};
 
+    $opts{'-force_array'} = 1 if (wantarray);
+
     my $vals = Catmandu::MARC->instance->marc_map(
                 $data,
                 $marc_path,
diff --git a/lib/Catmandu/Fix/marc_map.pm b/lib/Catmandu/Fix/marc_map.pm
index 35bae0c..d5a88de 100644
--- a/lib/Catmandu/Fix/marc_map.pm
+++ b/lib/Catmandu/Fix/marc_map.pm
@@ -28,12 +28,12 @@ sub emit {
     my $marc         = $fixer->capture($marc_obj);
     my $marc_path    = $fixer->capture($marc_context);
     my $marc_opt     = $fixer->capture({
-                            '-join'       => $self->join   // '' ,
-                            '-split'      => $self->split  // 0 ,
-                            '-pluck'      => $self->pluck  // 0 ,
+                            '-join'          => $self->join   // '' ,
+                            '-split'         => $self->split  // 0 ,
+                            '-pluck'         => $self->pluck  // 0 ,
                             '-nested_arrays' => $self->nested_arrays // 0 ,
-                            '-value'      => $self->value ,
-                            '-append'     => $key eq '$append'
+                            '-value'         => $self->value ,
+                            '-force_array'   => ($key =~ /^(\$.*|\d+)$/) ? 1 : 0
                         });
 
     my $var           = $fixer->var;
diff --git a/lib/Catmandu/Fix/marc_spec.pm b/lib/Catmandu/Fix/marc_spec.pm
index 3999542..82ea7b3 100644
--- a/lib/Catmandu/Fix/marc_spec.pm
+++ b/lib/Catmandu/Fix/marc_spec.pm
@@ -28,13 +28,14 @@ sub emit {
     my $marc         = $fixer->capture($marc_obj);
     my $marc_spec    = $fixer->capture($spec);
     my $marc_opt     = $fixer->capture({
-                            '-join'   => $self->join   // '' ,
-                            '-split'  => $self->split  // 0 ,
-                            '-pluck'  => $self->pluck  // 0 ,
-                            '-invert' => $self->invert // 0 ,
-                            '-value'  => $self->value ,
-                            '-append' => $key eq '$append'
+                            '-join'        => $self->join   // '' ,
+                            '-split'       => $self->split  // 0 ,
+                            '-pluck'       => $self->pluck  // 0 ,
+                            '-invert'      => $self->invert // 0 ,
+                            '-value'       => $self->value ,
+                            '-force_array' => ($key =~ /^(\$.*|\d+)$/) ? 1 : 0
                         });
+
     my $var          = $fixer->var;
     my $result       = $fixer->generate_var;
     my $current_value = $fixer->generate_var;
diff --git a/lib/Catmandu/MARC.pm b/lib/Catmandu/MARC.pm
index b63f445..cc3d522 100644
--- a/lib/Catmandu/MARC.pm
+++ b/lib/Catmandu/MARC.pm
@@ -36,7 +36,7 @@ sub marc_map {
     my $pluck          = $_[3]->{'-pluck'} // 0;
     my $value_set      = $_[3]->{'-value'} // undef;
     my $nested_arrays  = $_[3]->{'-nested_arrays'} // 0;
-    my $append         = $_[3]->{'-append'} // undef;
+    my $append         = $_[3]->{'-force_array'} // undef;
 
     my $vals;
 
@@ -350,7 +350,7 @@ sub marc_spec {
     my $pluck          = $_[3]->{'-pluck'} // 0;
     my $value_set      = $_[3]->{'-value'} // undef;
     my $invert         = $_[3]->{'-invert'} // 0;
-    my $append         = $_[3]->{'-append'} // undef;
+    my $append         = $_[3]->{'-force_array'} // undef;
 
     my $vals;
 
diff --git a/t/07-inline-fix.t b/t/07-inline-fix.t
index ff2124c..80fc702 100644
--- a/t/07-inline-fix.t
+++ b/t/07-inline-fix.t
@@ -31,7 +31,13 @@ ok(@$records == 2 , "Found 2 records");
 
 {
 	my @res = marc_map($records->[0],'630');
-	ok(@res == 1 , q|marc_map(630)|);
+	is_deeply \@res , [ 'Active server pages.' , 'ActiveX.' ] , q|marc_map(630) as array|;
+
+    my $res = marc_map($records->[0],'630');
+    is $res , 'Active server pages.ActiveX.' , q|marc_map(630) as string|;
+
+    my $res2 = marc_map($records->[0],'630', -join => "; ");
+    is $res2 , 'Active server pages.; ActiveX.' , q|marc_map(630) as string joined|;
 }
 
 {

-- 
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