--- trunk/IsisDB.pm 2005/01/06 16:27:07 35 +++ trunk/lib/Biblio/Isis.pm 2006/07/07 23:45:12 54 @@ -1,15 +1,13 @@ -package IsisDB; +package Biblio::Isis; 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.09; + $VERSION = 0.20; @ISA = qw (Exporter); #Give a hoot don't pollute, do not export more than needed by default @EXPORT = qw (); @@ -20,13 +18,13 @@ =head1 NAME -IsisDB - Read CDS/ISIS, WinISIS and IsisMarc database +Biblio::Isis - Read CDS/ISIS, WinISIS and IsisMarc database =head1 SYNOPSIS - use IsisDB; + use Biblio::Isis; - my $isis = new IsisDB( + my $isis = new Biblio::Isis( isisdb => './cds/cds', ); @@ -81,7 +79,7 @@ Open ISIS database - my $isis = new IsisDB( + my $isis = new Biblio::Isis( isisdb => './cds/cds', read_fdt => 1, include_deleted => 1, @@ -119,7 +117,7 @@ =item debug -Dump a B of debugging output. +Dump a B of debugging output even at level 1. For even more increase level. =back @@ -147,10 +145,22 @@ push @must_exist, "fdt" if ($self->{read_fdt}); foreach my $ext (@must_exist) { - croak "missing ",uc($ext)," file in ",$self->{isisdb} unless ($self->{$ext."_file"}); + unless ($self->{$ext."_file"}) { + carp "missing ",uc($ext)," file in ",$self->{isisdb}; + return; + } } - 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}) { @@ -199,7 +209,7 @@ 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}': $!"; @@ -261,7 +271,15 @@ # read XRFMFB abd XRFMFP read($self->{'fileXRF'}, $buff, 4); - my $pointer=unpack("V",$buff) || croak "pointer is null"; + my $pointer=unpack("V",$buff); + if (! $pointer) { + if ($self->{include_deleted}) { + return; + } else { + warn "pointer for MFN $mfn is null\n"; + return; + } + } # check for logically deleted record if ($pointer & 0x80000000) { @@ -367,6 +385,24 @@ return $self->{'record'}; } +=head2 mfn + +Returns current MFN position + + my $mfn = $isis->mfn; + +=cut + +# This function should be simple return $self->{current_mfn}, +# but if new is called with _hack_mfn it becomes setter. +# It's useful in tests when setting $isis->{record} directly + +sub mfn { + my $self = shift; + return $self->{current_mfn}; +}; + + =head2 to_ascii Returns ASCII output of record with specified MFN @@ -390,7 +426,7 @@ my $mfn = shift || croak "need MFN"; - my $rec = $self->fetch($mfn); + my $rec = $self->fetch($mfn) || return; my $out = "0\t$mfn"; @@ -446,6 +482,13 @@ } ], +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 @@ -458,13 +501,16 @@ # init record to include MFN as field 000 my $rec = { '000' => [ $mfn ] }; - my $row = $self->fetch($mfn); + my $row = $self->fetch($mfn) || return; foreach my $k (keys %{$row}) { foreach my $l (@{$row->{$k}}) { # filter output - $l = $self->{'hash_filter'}->($l) if ($self->{'hash_filter'}); + if ($self->{'hash_filter'}) { + $l = $self->{'hash_filter'}->($l); + next unless defined($l); + } my $val; @@ -475,7 +521,21 @@ 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)); + # FIXME make this option ! + next unless ($v); +# warn "### $k^$sf:$v",$/ if ($self->{debug} > 1); + + # FIXME array return optional, by default unroll to ' ; ' + 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; @@ -594,6 +654,18 @@ tested this against ouput of one C-based application, but I don't know any details about it's version. +=head1 VERSIONS + +You can find version dependencies documented here + +=over 8 + +=item 0.20 + +Added C<< $isis->mfn >> and support for repeatable subfields + +=back + =head1 AUTHOR Dobrica Pavlinusic