support for repeatable subfields, version bump to 0.20
[Biblio-Isis] / lib / Biblio / Isis.pm
index da1fcd7..76f20ba 100644 (file)
@@ -7,7 +7,7 @@ use File::Glob qw(:globally :nocase);
 BEGIN {
        use Exporter ();
        use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
-       $VERSION     = 0.14;
+       $VERSION     = 0.20;
        @ISA         = qw (Exporter);
        #Give a hoot don't pollute, do not export more than needed by default
        @EXPORT      = qw ();
@@ -464,6 +464,13 @@ which will be used for identifiers, C<i1> and C<i2> like this:
              }
            ],
 
+In case there are repeatable subfields in record, this will create
+following structure:
+
+  '900' => [ {
+       'a' => [ 'foo', 'bar', 'baz' ],
+  }]
+
 This method will also create additional field C<000> with MFN.
 
 =cut
@@ -496,7 +503,16 @@ sub to_hash {
                        if ($l =~ m/\^/) {
                                foreach my $t (split(/\^/,$l)) {
                                        next if (! $t);
-                                       $val->{substr($t,0,1)} = substr($t,1);
+                                       my ($sf,$v) = (substr($t,0,1), substr($t,1));
+                                       warn "### $k^$sf:$v",$/ if ($self->{debug} > 1);
+                                       if (ref( $val->{$sf} ) eq 'ARRAY') {
+                                               push @{ $val->{$sf} }, $v;
+                                       } elsif (defined( $val->{$sf} )) {
+                                               # convert scalar field to array
+                                               $val->{$sf} = [ $val->{$sf}, $v ];
+                                       } else {
+                                               $val->{$sf} = $v;
+                                       }
                                }
                        } else {
                                $val = $l;