support for repeatable subfields, version bump to 0.20
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 7 Jul 2006 21:11:01 +0000 (21:11 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 7 Jul 2006 21:11:01 +0000 (21:11 +0000)
THIS MIGHT BE INCOMPATIBILE CHANGE for old programs if they always expect to
get scalar for values in hash generated by to_hash.

git-svn-id: file:///home/dpavlin/svn/Biblio-Isis/trunk@50 4670fa4d-42ec-0310-ab5b-a66af6943492

lib/Biblio/Isis.pm
scripts/dump_isisdb.pl

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;
index d923ba7..c2f5227 100755 (executable)
@@ -1,11 +1,20 @@
 #!/usr/bin/perl -w
 
 use strict;
-#use blib;
+use blib;
 
 use Biblio::Isis;
 use Getopt::Std;
-use Data::Dumper;
+
+BEGIN {
+       eval "use Data::Dump";
+
+       if (! $@) {
+               *Dumper = *Data::Dump::dump;
+       } else {
+               use Data::Dumper;
+       }
+}
 
 my %opt;
 getopts('dn:', \%opt);
@@ -14,7 +23,7 @@ my $isisdb = shift @ARGV || die "usage: $0 [-n number] [-d] /path/to/isis/BIBL\n
 
 my $isis = Biblio::Isis->new (
        isisdb => $isisdb,
-       debug => $opt{'d'},
+       debug => $opt{'d'} ? 2 : 0,
        include_deleted => 1,
 #      read_fdt => 1,
 );