- add support for repeatable fields (so all hash values becomed arrays, even
with single element)
- scripts to dump CDS/ISIS database using this module and OpenIsis
- to_ascii method which dumps ascii output of record
git-svn-id: file:///home/dpavlin/svn/Biblio-Isis/trunk@2
4670fa4d-42ec-0310-ab5b-
a66af6943492
+Options are described below:
+
+=over 5
+
=item isisdb
Prefix path to CDS/ISIS. It should contain full or relative path to database
=item isisdb
Prefix path to CDS/ISIS. It should contain full or relative path to database
Dump a C<lot> of debugging output.
Dump a C<lot> of debugging output.
+=back
+
+It will also set C<$isis-E<gt>{'maxmfn'}> which is maximum MFN stored in database.
+
$self->{isisdb} = {@_}->{isisdb} || croak "new needs database name as argument!";
$self->{isisdb} = {@_}->{isisdb} || croak "new needs database name as argument!";
- $self->{debug} = {@_}->{debug} || 1; # XXX remove debug always!
+ $self->{debug} = {@_}->{debug};
# if you want to read .FDT file use read_fdt argument when creating class!
if ({@_}->{read_fdt} && -e $self->{isisdb}.".FDT") {
# if you want to read .FDT file use read_fdt argument when creating class!
if ({@_}->{read_fdt} && -e $self->{isisdb}.".FDT") {
seek(fileMST,4,0);
$self->{'NXTMFN'}=$self->Read32(\*fileMST) || carp "NXTNFN is zero";
seek(fileMST,4,0);
$self->{'NXTMFN'}=$self->Read32(\*fileMST) || carp "NXTNFN is zero";
+ # save maximum MFN
+ $self->{'maxmfn'} = $self->{'NXTMFN'} - 1;
+
close(fileMST);
# Get the index information from $db.CNT
close(fileMST);
# Get the index information from $db.CNT
$self ? return $self : return undef;
}
$self ? return $self : return undef;
}
+=head2 GetMFN
+
+Read record with selected MFN
+
+ my $rec = $isis->GetMFN(55);
-# Get a record from the MFN
-# Return the number of fields in the record.
-# Return -1 if the record is marked for deletion
-# The record is then extracted with call to GETs
+Returns hash with keys which are field names and values are unpacked values
+for that field.
+
+=cut
sub GetMFN {
my $self = shift;
sub GetMFN {
my $self = shift;
+ delete $self->{record};
+
for (my $i = 0 ; $i < $NVF ; $i++) {
my $rec;
read(fileMST,$rec,$FieldLEN[$i]);
for (my $i = 0 ; $i < $NVF ; $i++) {
my $rec;
read(fileMST,$rec,$FieldLEN[$i]);
- $self->{record}->{$FieldTAG[$i]} = $rec;
+ push @{$self->{record}->{$FieldTAG[$i]}}, $rec;
print Dumper($self) if ($self->{debug});
print Dumper($self) if ($self->{debug});
+ return $self->{'record'};
+=head2 to_ascii
+
+Dump ascii output of selected MFN
+
+ print $isis->to_ascii(55);
+
+=cut
+
+sub to_ascii {
+ my $self = shift;
+
+ my $mfn = shift || croak "need MFN";
+
+ my $rec = $self->GetMFN($mfn);
+
+print STDERR Dumper($rec);
+
+ my $out = "0\t$mfn";
+
+ foreach my $f (sort keys %{$rec}) {
+ $out .= "\n$f\t".join("\n$f\t",@{$self->{record}->{$f}});
+ }
+
+ $out .= "\n";
+
+ return $out;
+}
+
+################# old cruft which is not ported from php to perl
+
=begin php
# Load the dictionary from the $db.L0x files.
=begin php
# Load the dictionary from the $db.L0x files.
Changes
IsisDB.pm
t/001_load.t
Makefile.PL
Changes
IsisDB.pm
t/001_load.t
Makefile.PL
+scripts/dump_isis.pl
+scripts/dump_openisis.pl
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use blib;
+
+use IsisDB;
+use Data::Dumper;
+
+my $isis = IsisDB->new (
+ isisdb => '/data/isis_data/ps/LIBRI/LIBRI',
+);
+
+for(my $mfn = 1; $mfn <= $isis->{'maxmfn'}; $mfn++) {
+ print $isis->to_ascii($mfn),"\n";
+
+}
+
--- /dev/null
+#!/usr/bin/perl -w
+
+# this utility emulates output of openisis -db "database"
+# so you can test if perl can read your isis file
+
+#use strict;
+use OpenIsis;
+
+my $db = OpenIsis::open( shift @ARGV || '/data/isis_data/ps/LIBRI/LIBRI' );
+my $maxmfn = OpenIsis::maxRowid( $db ) || 1;
+
+print "rows: $maxmfn\n\n";
+
+for (my $mfn = 1; $mfn <= $maxmfn; $mfn++) {
+ print "0\t$mfn\n";
+ my $row = OpenIsis::read( $db, $mfn );
+ foreach my $k (sort keys %{$row}) {
+ next if ($k eq 'mfn');
+ print "$k\t",join("\n$k\t",@{$row->{$k}}),"\n";
+ }
+ print "\n";
+}
+
my $object = IsisDB->new (
isisdb => '/data/isis_data/ps/LIBRI/LIBRI',
my $object = IsisDB->new (
isisdb => '/data/isis_data/ps/LIBRI/LIBRI',
isa_ok ($object, 'IsisDB');
isa_ok ($object, 'IsisDB');