make test less chatty without debug
[Biblio-Isis] / lib / Biblio / Isis.pm
index 5461657..76f20ba 100644 (file)
@@ -4,12 +4,10 @@ use strict;
 use Carp;
 use File::Glob qw(:globally :nocase);
 
-use Data::Dumper;
-
 BEGIN {
        use Exporter ();
        use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
-       $VERSION     = 0.13;
+       $VERSION     = 0.20;
        @ISA         = qw (Exporter);
        #Give a hoot don't pollute, do not export more than needed by default
        @EXPORT      = qw ();
@@ -153,7 +151,16 @@ sub new {
                }
        }
 
-       print STDERR "## using files: ",join(" ",@isis_files),"\n" if ($self->{debug});
+       if ($self->{debug}) {
+               print STDERR "## using files: ",join(" ",@isis_files),"\n";
+               eval "use Data::Dump";
+
+               if (! $@) {
+                       *Dumper = *Data::Dump::dump;
+               } else {
+                       use Data::Dumper;
+               }
+       }
 
        # if you want to read .FDT file use read_fdt argument when creating class!
        if ($self->{read_fdt} && -e $self->{fdt_file}) {
@@ -202,7 +209,7 @@ sub new {
        read($self->{'fileMST'}, $buff, 4) || croak "can't read NXTMFN from MST: $!";
        $self->{'NXTMFN'}=unpack("V",$buff) || croak "NXTNFN is zero";
 
-       print STDERR Dumper($self),"\n" if ($self->{debug});
+       print STDERR "## self ",Dumper($self),"\n" if ($self->{debug});
 
        # open files for later
        open($self->{'fileXRF'}, $self->{xrf_file}) || croak "can't open '$self->{xrf_file}': $!";
@@ -457,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
@@ -489,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;