4 |
use strict; |
use strict; |
5 |
|
|
6 |
use WebPAC::Input; |
use WebPAC::Input; |
7 |
|
use Biblio::Isis; |
8 |
|
use base qw/WebPAC::Common/; |
9 |
|
|
10 |
=head1 NAME |
=head1 NAME |
11 |
|
|
13 |
|
|
14 |
=head1 VERSION |
=head1 VERSION |
15 |
|
|
16 |
Version 0.03 |
Version 0.09 |
17 |
|
|
18 |
=cut |
=cut |
19 |
|
|
20 |
our $VERSION = '0.03'; |
our $VERSION = '0.09'; |
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( |
39 |
|
path => '/path/to/LIBRI' |
40 |
|
filter => sub { |
41 |
|
my ($l,$field_nr) = @_; |
42 |
|
# do something with $l which is line of input file |
43 |
|
return $l; |
44 |
|
}, |
45 |
|
} |
46 |
|
|
47 |
sub init { |
Options: |
|
my $self = shift; |
|
48 |
|
|
49 |
eval "use Biblio::Isis;"; |
=over 4 |
|
unless ($@) { |
|
|
$self->{have_biblio_isis} = 1 |
|
|
} else { |
|
|
eval "use OpenIsis;"; |
|
|
$self->{have_openisis} = 1 unless ($@); |
|
|
} |
|
|
} |
|
50 |
|
|
51 |
=head2 open_db |
=item path |
52 |
|
|
53 |
Returns handle to database |
path to CDS/ISIS database |
54 |
|
|
55 |
my $db = $open_db( |
=back |
|
path => '/path/to/LIBRI' |
|
|
} |
|
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 |
|
ignore_empty_subfields => 1, |
76 |
|
) or $log->logdie("can't find database $arg->{path}"); |
77 |
|
|
78 |
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 => 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."); |
|
|
} |
|
79 |
|
|
80 |
return ($isis_db, $db_size); |
$self ? return $self : return undef; |
81 |
} |
} |
82 |
|
|
83 |
=head2 fetch_rec |
=head2 fetch_rec |
84 |
|
|
85 |
Return record with ID C<$mfn> from database |
Return record with ID C<$mfn> from database |
86 |
|
|
87 |
my $rec = $self->fetch_rec( $db, $mfn ); |
my $rec = $isis->fetch_rec( $mfn, $filter_coderef); |
88 |
|
|
89 |
|
=cut |
90 |
|
|
91 |
|
sub fetch_rec { |
92 |
|
my $self = shift; |
93 |
|
|
94 |
|
my ($mfn, $filter_coderef) = @_; |
95 |
|
|
96 |
|
my $rec = $self->{_isis_db}->to_hash({ |
97 |
|
mfn => $mfn, |
98 |
|
include_subfields => 1, |
99 |
|
hash_filter => $filter_coderef, |
100 |
|
# hash_filter => sub { |
101 |
|
# my ($l,$f) = @_; |
102 |
|
# warn "## in hash_filter ($l,$f)\n"; |
103 |
|
# my $o = $filter_coderef->($l,$f) if ($filter_coderef); |
104 |
|
# warn "## out hash_filter = $o\n"; |
105 |
|
# return $o; |
106 |
|
# }, |
107 |
|
}); |
108 |
|
|
109 |
|
return $rec; |
110 |
} |
} |
111 |
|
|
112 |
|
=head2 dump_ascii |
113 |
|
|
114 |
|
Return dump of record ID C<$mfn> from database |
115 |
|
|
116 |
|
my $rec = $isis->dump_ascii( $mfn ); |
117 |
|
|
118 |
=cut |
=cut |
119 |
|
|
120 |
sub fetch_rec { |
sub dump_ascii { |
121 |
my $self = shift; |
my $self = shift; |
122 |
|
|
123 |
my ($isis_db, $mfn) = @_; |
my $mfn = shift; |
124 |
|
|
125 |
my $rec; |
return $self->{_isis_db}->to_ascii( $mfn ); |
126 |
|
} |
127 |
|
|
128 |
if ($self->{have_openisis}) { |
=head2 size |
129 |
|
|
130 |
# read record using OpenIsis |
Return number of records in database |
|
my $row = OpenIsis::read( $isis_db, $mfn ); |
|
131 |
|
|
132 |
# convert record to hash |
my $size = $isis->size; |
|
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); |
|
|
} else { |
|
|
$self->_get_logger()->logdie("hum? implementation missing?"); |
|
|
} |
|
133 |
|
|
134 |
return $rec; |
=cut |
135 |
|
|
136 |
|
sub size { |
137 |
|
my $self = shift; |
138 |
|
return $self->{_isis_db}->count; |
139 |
} |
} |
140 |
|
|
141 |
=head1 AUTHOR |
=head1 AUTHOR |