/[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 285 - (show annotations)
Sun Dec 18 21:06:39 2005 UTC (18 years, 4 months ago) by dpavlin
File size: 3019 byte(s)
 r11777@llin:  dpavlin | 2005-12-19 00:02:47 +0100
 refactor Input::ISIS::* [0.02]

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

  ViewVC Help
Powered by ViewVC 1.1.26