/[webpac2]/trunk/lib/WebPAC/Input/ISIS.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/WebPAC/Input/ISIS.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 289 - (show annotations)
Sun Dec 18 22:16:44 2005 UTC (18 years, 4 months ago) by dpavlin
File size: 2990 byte(s)
 r11784@llin:  dpavlin | 2005-12-19 05:17:24 +0100
 don't use Exporter after all

1 package WebPAC::Input::ISIS;
2
3 use warnings;
4 use strict;
5
6 use blib;
7 use WebPAC::Input;
8
9 =head1 NAME
10
11 WebPAC::Input::ISIS - support for CDS/ISIS database files
12
13 =head1 VERSION
14
15 Version 0.03
16
17 =cut
18
19 our $VERSION = '0.03';
20
21
22 =head1 SYNOPSIS
23
24 Open CDS/ISIS, WinISIS or IsisMarc database using C<Biblio::Isis> or
25 C<OpenIsis> module and read all records to memory.
26
27 my $isis = new WebPAC::Input::ISIS();
28 $isis->open( path => '/path/to/ISIS/ISIS' );
29
30 =head1 FUNCTIONS
31
32 =head2 init
33
34 Autoconfigure this module to use C<Biblio::Isis> or C<OpenIsis>.
35
36 =cut
37
38 sub init {
39 my $self = shift;
40
41 eval "use Biblio::Isis 0.13;";
42 unless ($@) {
43 $self->{have_biblio_isis} = 1
44 } else {
45 eval "use OpenIsis;";
46 $self->{have_openisis} = 1 unless ($@);
47 }
48 }
49
50 =head2 open_db
51
52 Returns handle to database
53
54 my $db = $open_db(
55 path => '/path/to/LIBRI'
56 }
57
58 =cut
59
60 sub open_db {
61 my $self = shift;
62
63 my $arg = {@_};
64
65 my $log = $self->_get_logger();
66
67 $log->info("opening ISIS database '$arg->{path}'");
68
69 my ($isis_db,$db_size);
70
71 if ($self->{have_openisis}) {
72 $log->debug("using OpenIsis perl bindings");
73 $isis_db = OpenIsis::open($arg->{path});
74 $db_size = OpenIsis::maxRowid( $isis_db ) || 1;
75 } elsif ($self->{have_biblio_isis}) {
76 $log->debug("using Biblio::Isis");
77 use Biblio::Isis;
78 $isis_db = new Biblio::Isis(
79 isisdb => $arg->{path},
80 include_deleted => 1,
81 hash_filter => sub {
82 my $l = shift || return;
83 $l = $self->{iconv}->convert($l) if ($self->{iconv});
84 return $l;
85 },
86 ) or $log->logdie("can't find database $arg->{path}");
87
88 $db_size = $isis_db->count;
89
90 } else {
91 $log->logdie("Can't find supported ISIS library for perl. I suggent that you install Bilbio::Isis from CPAN.");
92 }
93
94 return ($isis_db, $db_size);
95 }
96
97 =head2 fetch_rec
98
99 Return record with ID C<$mfn> from database
100
101 my $rec = $self->fetch_rec( $db, $mfn );
102
103 }
104
105 =cut
106
107 sub fetch_rec {
108 my $self = shift;
109
110 my ($isis_db, $mfn) = @_;
111
112 my $rec;
113
114 if ($self->{have_openisis}) {
115
116 # read record using OpenIsis
117 my $row = OpenIsis::read( $isis_db, $mfn );
118
119 # convert record to hash
120 foreach my $k (keys %{$row}) {
121 if ($k ne "mfn") {
122 foreach my $l (@{$row->{$k}}) {
123 $l = $self->{iconv}->convert($l) if ($self->{iconv});
124 # has subfields?
125 my $val;
126 if ($l =~ m/\^/) {
127 foreach my $t (split(/\^/,$l)) {
128 next if (! $t);
129 $val->{substr($t,0,1)} = substr($t,1);
130 }
131 } else {
132 $val = $l;
133 }
134 push @{$rec->{$k}}, $val;
135 }
136 } else {
137 push @{$rec->{'000'}}, $mfn;
138 }
139 }
140
141 } elsif ($self->{have_biblio_isis}) {
142 $rec = $isis_db->to_hash($mfn);
143 } else {
144 $self->_get_logger()->logdie("hum? implementation missing?");
145 }
146
147 return $rec;
148 }
149
150 =head1 AUTHOR
151
152 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
153
154 =head1 COPYRIGHT & LICENSE
155
156 Copyright 2005 Dobrica Pavlinusic, All Rights Reserved.
157
158 This program is free software; you can redistribute it and/or modify it
159 under the same terms as Perl itself.
160
161 =cut
162
163 1; # End of WebPAC::Input::ISIS

  ViewVC Help
Powered by ViewVC 1.1.26