4 |
use strict; |
use strict; |
5 |
|
|
6 |
use WebPAC::Input; |
use WebPAC::Input; |
7 |
|
use Biblio::Isis 0.23; |
8 |
|
use base qw/WebPAC::Common/; |
9 |
|
|
10 |
=head1 NAME |
=head1 NAME |
11 |
|
|
13 |
|
|
14 |
=head1 VERSION |
=head1 VERSION |
15 |
|
|
16 |
Version 0.04 |
Version 0.08 |
17 |
|
|
18 |
=cut |
=cut |
19 |
|
|
20 |
our $VERSION = '0.04'; |
our $VERSION = '0.08'; |
21 |
|
|
22 |
|
|
23 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
24 |
|
|
25 |
Open CDS/ISIS, WinISIS or IsisMarc database using C<Biblio::Isis> or |
Open CDS/ISIS, WinISIS or IsisMarc database using C<Biblio::Isis> |
26 |
C<OpenIsis> module and read all records to memory. |
and read all records to memory. |
27 |
|
|
28 |
my $isis = new WebPAC::Input::ISIS(); |
my $isis = new WebPAC::Input::ISIS( |
29 |
$isis->open( path => '/path/to/ISIS/ISIS' ); |
path => '/path/to/ISIS/ISIS', |
30 |
|
); |
31 |
|
|
32 |
=head1 FUNCTIONS |
=head1 FUNCTIONS |
33 |
|
|
34 |
=head2 init |
=head2 new |
35 |
|
|
36 |
Autoconfigure this module to use C<Biblio::Isis> or C<OpenIsis>. |
Returns new low-level input API object |
37 |
|
|
38 |
=cut |
my $isis = new WebPAC::Input::ISIS( |
|
|
|
|
sub init { |
|
|
my $self = shift; |
|
|
|
|
|
eval "use Biblio::Isis;"; |
|
|
unless ($@) { |
|
|
$self->{have_biblio_isis} = 1 |
|
|
} else { |
|
|
eval "use OpenIsis;"; |
|
|
$self->{have_openisis} = 1 unless ($@); |
|
|
} |
|
|
} |
|
|
|
|
|
=head2 open_db |
|
|
|
|
|
Returns handle to database and size in records |
|
|
|
|
|
my ($db,$size) = $isis->open_db( |
|
39 |
path => '/path/to/LIBRI' |
path => '/path/to/LIBRI' |
40 |
filter => sub { |
filter => sub { |
41 |
my ($l,$field_nr) = @_; |
my ($l,$field_nr) = @_; |
56 |
|
|
57 |
=cut |
=cut |
58 |
|
|
59 |
sub open_db { |
sub new { |
60 |
my $self = shift; |
my $class = shift; |
61 |
|
my $self = {@_}; |
62 |
|
bless($self, $class); |
63 |
|
|
64 |
my $arg = {@_}; |
my $arg = {@_}; |
65 |
|
|
67 |
|
|
68 |
$log->info("opening ISIS database '$arg->{path}'"); |
$log->info("opening ISIS database '$arg->{path}'"); |
69 |
|
|
70 |
my ($isis_db,$db_size); |
$log->debug("using Biblio::Isis"); |
71 |
|
my $isis_db = new Biblio::Isis( |
72 |
|
isisdb => $arg->{path}, |
73 |
|
include_deleted => 1, |
74 |
|
hash_filter => $arg->{filter} ? sub { return $arg->{filter}->(@_); } : undef, |
75 |
|
) or $log->logdie("can't find database $arg->{path}"); |
76 |
|
|
77 |
if ($self->{have_openisis}) { |
$self->{_isis_db} = $isis_db; |
|
$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 => $arg->{filter} ? sub { return $arg->{filter}->(@_); } : undef, |
|
|
) 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."); |
|
|
} |
|
78 |
|
|
79 |
return ($isis_db, $db_size); |
$self ? return $self : return undef; |
80 |
} |
} |
81 |
|
|
82 |
=head2 fetch_rec |
=head2 fetch_rec |
83 |
|
|
84 |
Return record with ID C<$mfn> from database |
Return record with ID C<$mfn> from database |
85 |
|
|
86 |
my $rec = $self->fetch_rec( $db, $mfn ); |
my $rec = $isis->fetch_rec( $mfn, $filter_coderef); |
87 |
|
|
88 |
=cut |
=cut |
89 |
|
|
90 |
sub fetch_rec { |
sub fetch_rec { |
91 |
my $self = shift; |
my $self = shift; |
92 |
|
|
93 |
my ($isis_db, $mfn) = @_; |
my ($mfn, $filter_coderef) = @_; |
94 |
|
|
95 |
|
my $rec = $self->{_isis_db}->to_hash({ |
96 |
|
mfn => $mfn, |
97 |
|
include_subfields => 1, |
98 |
|
hash_filter => $filter_coderef, |
99 |
|
# hash_filter => sub { |
100 |
|
# my ($l,$f) = @_; |
101 |
|
# warn "## in hash_filter ($l,$f)\n"; |
102 |
|
# my $o = $filter_coderef->($l,$f) if ($filter_coderef); |
103 |
|
# warn "## out hash_filter = $o\n"; |
104 |
|
# return $o; |
105 |
|
# }, |
106 |
|
}); |
107 |
|
|
108 |
my $rec; |
return $rec; |
109 |
|
} |
110 |
|
|
111 |
if ($self->{have_openisis}) { |
=head2 dump_rec |
112 |
|
|
113 |
# read record using OpenIsis |
Return dump of record ID C<$mfn> from database |
|
my $row = OpenIsis::read( $isis_db, $mfn ); |
|
114 |
|
|
115 |
# convert record to hash |
my $rec = $isis->dump_rec( $db, $mfn ); |
|
foreach my $k (keys %{$row}) { |
|
|
if ($k ne "mfn") { |
|
|
foreach my $l (@{$row->{$k}}) { |
|
|
$l = $self->{iconv}->convert($l) if ($self->{iconv}); |
|
|
# has subfields? |
|
|
my $val; |
|
|
if ($l =~ m/\^/) { |
|
|
foreach my $t (split(/\^/,$l)) { |
|
|
next if (! $t); |
|
|
$val->{substr($t,0,1)} = substr($t,1); |
|
|
} |
|
|
} else { |
|
|
$val = $l; |
|
|
} |
|
|
push @{$rec->{"$k"}}, $val; |
|
|
} |
|
|
} else { |
|
|
push @{$rec->{'000'}}, $mfn; |
|
|
} |
|
|
} |
|
|
|
|
|
} elsif ($self->{have_biblio_isis}) { |
|
|
$rec = $isis_db->to_hash({ |
|
|
mfn => $mfn, |
|
|
include_subfields => 1 |
|
|
}); |
|
|
} else { |
|
|
$self->_get_logger()->logdie("hum? implementation missing?"); |
|
|
} |
|
116 |
|
|
117 |
return $rec; |
=cut |
118 |
|
|
119 |
|
sub dump_rec { |
120 |
|
my $self = shift; |
121 |
|
|
122 |
|
my $mfn = shift; |
123 |
|
|
124 |
|
return $self->{_isis_db}->to_ascii( $mfn ); |
125 |
|
} |
126 |
|
|
127 |
|
=head2 size |
128 |
|
|
129 |
|
Return number of records in database |
130 |
|
|
131 |
|
my $size = $isis->size; |
132 |
|
|
133 |
|
=cut |
134 |
|
|
135 |
|
sub size { |
136 |
|
my $self = shift; |
137 |
|
return $self->{_isis_db}->count; |
138 |
} |
} |
139 |
|
|
140 |
=head1 AUTHOR |
=head1 AUTHOR |