request Biblio::Isis 0.24 to ignore empty subfields
[webpac2] / lib / WebPAC / Input / ISIS.pm
1 package WebPAC::Input::ISIS;
2
3 use warnings;
4 use strict;
5
6 use WebPAC::Input;
7 use Biblio::Isis;
8 use base qw/WebPAC::Common/;
9
10 =head1 NAME
11
12 WebPAC::Input::ISIS - support for CDS/ISIS database files
13
14 =head1 VERSION
15
16 Version 0.09
17
18 =cut
19
20 our $VERSION = '0.09';
21
22
23 =head1 SYNOPSIS
24
25 Open CDS/ISIS, WinISIS or IsisMarc database using C<Biblio::Isis>
26 and read all records to memory.
27
28  my $isis = new WebPAC::Input::ISIS(
29         path => '/path/to/ISIS/ISIS',
30  );
31
32 =head1 FUNCTIONS
33
34 =head2 new
35
36 Returns new low-level input API object
37
38   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 Options:
48
49 =over 4
50
51 =item path
52
53 path to CDS/ISIS database
54
55 =back
56
57 =cut
58
59 sub new {
60         my $class = shift;
61         my $self = {@_};
62         bless($self, $class);
63
64         my $arg = {@_};
65
66         my $log = $self->_get_logger();
67
68         $log->info("opening ISIS database '$arg->{path}'");
69
70         $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         $self->{_isis_db} = $isis_db;
79
80         $self ? return $self : return undef;
81 }
82
83 =head2 fetch_rec
84
85 Return record with ID C<$mfn> from database
86
87   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
119
120 sub dump_ascii {
121         my $self = shift;
122
123         my $mfn = shift;
124
125         return $self->{_isis_db}->to_ascii( $mfn );
126 }
127
128 =head2 size
129
130 Return number of records in database
131
132   my $size = $isis->size;
133
134 =cut
135
136 sub size {
137         my $self = shift;
138         return $self->{_isis_db}->count;
139 }
140
141 =head1 AUTHOR
142
143 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
144
145 =head1 COPYRIGHT & LICENSE
146
147 Copyright 2005 Dobrica Pavlinusic, All Rights Reserved.
148
149 This program is free software; you can redistribute it and/or modify it
150 under the same terms as Perl itself.
151
152 =cut
153
154 1; # End of WebPAC::Input::ISIS