package Equinox::Migration::SubfieldMapper;
+# Copyright 2009-2012, Equinox Software, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
use warnings;
use strict;
=head1 VERSION
-Version 1.004
+Version 1.005
=cut
-our $VERSION = '1.004';
+our $VERSION = '1.005';
=head1 SYNOPSIS
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.
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;
- $tok =~ s/^'//;
+ $tok =~ s/'//;
$tok =~ s/'$//;
}
if ($tok =~ m/^m:/)
{ push @{$map->{mods}}, $tok }
elsif ($tok =~ m/^f:/)
{ push @{$map->{filt}}, $tok }
- elsif ($tok =~ m/^[a-z0-9]$/)
+ elsif ($tok =~ m/^[a-zA-Z0-9]$/)
{ $map->{sub} = $tok }
+ elsif ($tok =~ /^c:(.*)$/)
+ { $map->{sep} = $1 }
else
{ die "Unknown chunk '$tok' at line $.\n" }
}
$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};