Now handles subfield codes A-Z in addition to a-z (this is strictly speaking not...
[migration-tools.git] / Equinox-Migration / lib / Equinox / Migration / SubfieldMapper.pm
index 68a545c..8716b18 100644 (file)
@@ -9,11 +9,11 @@ Equinox::Migration::SubfieldMapper - Generate named-field to MARC tag map from f
 
 =head1 VERSION
 
-Version 1.004
+Version 1.005
 
 =cut
 
-our $VERSION = '1.004';
+our $VERSION = '1.005';
 
 
 =head1 SYNOPSIS
@@ -206,6 +206,19 @@ sub filters {
     return $self->{fields}{$field}{filt};
 }
 
+=head2 sep
+
+Returns the separator string set on a mapping.  Used only
+if concatenating.
+
+=cut
+
+sub sep {
+    my ($self, $field) = @_;
+    return undef unless $self->has($field);
+    return $self->{fields}{$field}{sep};
+}
+
 =head1 MAP CONSTRUCTION METHODS
 
 These methods are not generally accessed from user code.
@@ -227,12 +240,12 @@ sub generate {
         chomp;
         my @tokens = split /\s+/;
 
-        my $map = { mods => [], filt => [] };
+        my $map = { mods => [], filt => [], sep => ' ' };
         $map->{field} = shift @tokens;
         $map->{tag}   = shift @tokens;
-        while (my $tok = shift @tokens) {
+        while (defined (my $tok = shift @tokens)) {
             last if ($tok =~ m/^#/);
-            if ($tok =~ m/^[a-z]:'/ and $tok !~ /'$/) {
+            if ($tok =~ m/^[a-zA-Z]:'/ and $tok !~ /^'$/) {
                 $tok .= ' ' . shift @tokens
                   until ($tokens[0] =~ m/'$/);
                 $tok .= ' ' . shift @tokens;
@@ -245,6 +258,8 @@ sub generate {
               { push @{$map->{filt}}, $tok }
             elsif ($tok =~ m/^[a-z0-9]$/)
               { $map->{sub} = $tok }
+            elsif ($tok =~ /^c:(.*)$/)
+              { $map->{sep} = $1 }
             else
               { die "Unknown chunk '$tok' at line $.\n" }
         }
@@ -296,7 +311,8 @@ sub add {
     $self->{fields}{ $map->{field} } = { tag => $map->{tag},
                                          sub => $map->{sub},
                                          mods => $map->{mods},
-                                         filt => $map->{filt}
+                                         filt => $map->{filt},
+                                         sep => $map->{sep},
                                        };
     # and to the tags hash
     $self->{tags}{ $map->{tag} }{ $map->{sub} } = $map->{field};