3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
|
use blib; |
|
6 |
use WebPAC::Input; |
use WebPAC::Input; |
7 |
|
use Biblio::Isis 0.23; |
8 |
|
|
9 |
=head1 NAME |
=head1 NAME |
10 |
|
|
12 |
|
|
13 |
=head1 VERSION |
=head1 VERSION |
14 |
|
|
15 |
Version 0.03 |
Version 0.06 |
16 |
|
|
17 |
=cut |
=cut |
18 |
|
|
19 |
our $VERSION = '0.03'; |
our $VERSION = '0.06'; |
20 |
|
|
21 |
|
|
22 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
23 |
|
|
24 |
Open CDS/ISIS, WinISIS or IsisMarc database using C<Biblio::Isis> or |
Open CDS/ISIS, WinISIS or IsisMarc database using C<Biblio::Isis> |
25 |
C<OpenIsis> module and read all records to memory. |
and read all records to memory. |
26 |
|
|
27 |
my $isis = new WebPAC::Input::ISIS(); |
my $isis = new WebPAC::Input::ISIS(); |
28 |
$isis->open( path => '/path/to/ISIS/ISIS' ); |
$isis->open( path => '/path/to/ISIS/ISIS' ); |
29 |
|
|
30 |
=head1 FUNCTIONS |
=head1 FUNCTIONS |
31 |
|
|
32 |
=head2 init |
=head2 open_db |
33 |
|
|
34 |
Autoconfigure this module to use C<Biblio::Isis> or C<OpenIsis>. |
Returns handle to database and size in records |
35 |
|
|
36 |
=cut |
my ($db,$size) = $isis->open_db( |
37 |
|
path => '/path/to/LIBRI' |
38 |
|
filter => sub { |
39 |
|
my ($l,$field_nr) = @_; |
40 |
|
# do something with $l which is line of input file |
41 |
|
return $l; |
42 |
|
}, |
43 |
|
} |
44 |
|
|
45 |
sub init { |
Options: |
|
my $self = shift; |
|
46 |
|
|
47 |
eval "use Biblio::Isis 0.13;"; |
=over 4 |
|
unless ($@) { |
|
|
$self->{have_biblio_isis} = 1 |
|
|
} else { |
|
|
eval "use OpenIsis;"; |
|
|
$self->{have_openisis} = 1 unless ($@); |
|
|
} |
|
|
} |
|
48 |
|
|
49 |
=head2 open_db |
=item path |
50 |
|
|
51 |
Returns handle to database |
path to CDS/ISIS database |
52 |
|
|
53 |
my $db = $open_db( |
=back |
|
path => '/path/to/LIBRI' |
|
|
} |
|
54 |
|
|
55 |
=cut |
=cut |
56 |
|
|
63 |
|
|
64 |
$log->info("opening ISIS database '$arg->{path}'"); |
$log->info("opening ISIS database '$arg->{path}'"); |
65 |
|
|
66 |
my ($isis_db,$db_size); |
$log->debug("using Biblio::Isis"); |
67 |
|
my $isis_db = new Biblio::Isis( |
68 |
|
isisdb => $arg->{path}, |
69 |
|
include_deleted => 1, |
70 |
|
hash_filter => $arg->{filter} ? sub { return $arg->{filter}->(@_); } : undef, |
71 |
|
) or $log->logdie("can't find database $arg->{path}"); |
72 |
|
|
73 |
if ($self->{have_openisis}) { |
my $size = $isis_db->count; |
|
$log->debug("using OpenIsis perl bindings"); |
|
|
$isis_db = OpenIsis::open($arg->{path}); |
|
|
$db_size = OpenIsis::maxRowid( $isis_db ) || 1; |
|
|
} elsif ($self->{have_biblio_isis}) { |
|
|
$log->debug("using Biblio::Isis"); |
|
|
use Biblio::Isis; |
|
|
$isis_db = new Biblio::Isis( |
|
|
isisdb => $arg->{path}, |
|
|
include_deleted => 1, |
|
|
hash_filter => sub { |
|
|
my $l = shift || return; |
|
|
$l = $self->{iconv}->convert($l) if ($self->{iconv}); |
|
|
return $l; |
|
|
}, |
|
|
) or $log->logdie("can't find database $arg->{path}"); |
|
|
|
|
|
$db_size = $isis_db->count; |
|
|
|
|
|
} else { |
|
|
$log->logdie("Can't find supported ISIS library for perl. I suggent that you install Bilbio::Isis from CPAN."); |
|
|
} |
|
74 |
|
|
75 |
return ($isis_db, $db_size); |
return ($isis_db, $size); |
76 |
} |
} |
77 |
|
|
78 |
=head2 fetch_rec |
=head2 fetch_rec |
79 |
|
|
80 |
Return record with ID C<$mfn> from database |
Return record with ID C<$mfn> from database |
81 |
|
|
82 |
my $rec = $self->fetch_rec( $db, $mfn ); |
my $rec = $self->fetch_rec( $db, $mfn, $filter_coderef); |
|
|
|
|
} |
|
83 |
|
|
84 |
=cut |
=cut |
85 |
|
|
86 |
sub fetch_rec { |
sub fetch_rec { |
87 |
my $self = shift; |
my $self = shift; |
88 |
|
|
89 |
my ($isis_db, $mfn) = @_; |
my ($isis_db, $mfn, $filter_coderef) = @_; |
|
|
|
|
my $rec; |
|
|
|
|
|
if ($self->{have_openisis}) { |
|
|
|
|
|
# read record using OpenIsis |
|
|
my $row = OpenIsis::read( $isis_db, $mfn ); |
|
90 |
|
|
91 |
# convert record to hash |
my $rec = $isis_db->to_hash({ |
92 |
foreach my $k (keys %{$row}) { |
mfn => $mfn, |
93 |
if ($k ne "mfn") { |
include_subfields => 1, |
94 |
foreach my $l (@{$row->{$k}}) { |
hash_filter => $filter_coderef, |
95 |
$l = $self->{iconv}->convert($l) if ($self->{iconv}); |
# hash_filter => sub { |
96 |
# has subfields? |
# my ($l,$f) = @_; |
97 |
my $val; |
# warn "## in hash_filter ($l,$f)\n"; |
98 |
if ($l =~ m/\^/) { |
# my $o = $filter_coderef->($l,$f) if ($filter_coderef); |
99 |
foreach my $t (split(/\^/,$l)) { |
# warn "## out hash_filter = $o\n"; |
100 |
next if (! $t); |
# return $o; |
101 |
$val->{substr($t,0,1)} = substr($t,1); |
# }, |
102 |
} |
}); |
|
} else { |
|
|
$val = $l; |
|
|
} |
|
|
push @{$rec->{$k}}, $val; |
|
|
} |
|
|
} else { |
|
|
push @{$rec->{'000'}}, $mfn; |
|
|
} |
|
|
} |
|
|
|
|
|
} elsif ($self->{have_biblio_isis}) { |
|
|
$rec = $isis_db->to_hash($mfn); |
|
|
} else { |
|
|
$self->_get_logger()->logdie("hum? implementation missing?"); |
|
|
} |
|
103 |
|
|
104 |
return $rec; |
return $rec; |
105 |
} |
} |