/[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 619 - (show annotations)
Fri Aug 25 12:31:06 2006 UTC (17 years, 7 months ago) by dpavlin
File size: 3247 byte(s)
 r867@llin:  dpavlin | 2006-08-25 14:32:05 +0200
 statistics now show data before modify_records

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

  ViewVC Help
Powered by ViewVC 1.1.26