/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 726 - (hide annotations)
Fri Sep 29 19:52:17 2006 UTC (17 years, 7 months ago) by dpavlin
File size: 2482 byte(s)
 r1045@llin:  dpavlin | 2006-09-29 21:38:42 +0200
 change low-level API to be OO (and remove various ugly cludges).

1 dpavlin 6 package WebPAC::Input::ISIS;
2    
3     use warnings;
4     use strict;
5    
6 dpavlin 285 use WebPAC::Input;
7 dpavlin 623 use Biblio::Isis 0.23;
8 dpavlin 726 use base qw/WebPAC::Common/;
9 dpavlin 285
10 dpavlin 6 =head1 NAME
11    
12 dpavlin 285 WebPAC::Input::ISIS - support for CDS/ISIS database files
13 dpavlin 6
14     =head1 VERSION
15    
16 dpavlin 726 Version 0.08
17 dpavlin 6
18     =cut
19    
20 dpavlin 726 our $VERSION = '0.08';
21 dpavlin 6
22    
23     =head1 SYNOPSIS
24    
25 dpavlin 623 Open CDS/ISIS, WinISIS or IsisMarc database using C<Biblio::Isis>
26     and read all records to memory.
27 dpavlin 6
28 dpavlin 726 my $isis = new WebPAC::Input::ISIS(
29     path => '/path/to/ISIS/ISIS',
30     );
31 dpavlin 6
32     =head1 FUNCTIONS
33    
34 dpavlin 726 =head2 new
35 dpavlin 6
36 dpavlin 726 Returns new low-level input API object
37 dpavlin 6
38 dpavlin 726 my $isis = new WebPAC::Input::ISIS(
39 dpavlin 285 path => '/path/to/LIBRI'
40 dpavlin 597 filter => sub {
41     my ($l,$field_nr) = @_;
42     # do something with $l which is line of input file
43     return $l;
44     },
45 dpavlin 285 }
46    
47 dpavlin 597 Options:
48    
49     =over 4
50    
51     =item path
52    
53     path to CDS/ISIS database
54    
55     =back
56    
57 dpavlin 6 =cut
58    
59 dpavlin 726 sub new {
60     my $class = shift;
61     my $self = {@_};
62     bless($self, $class);
63 dpavlin 285
64 dpavlin 6 my $arg = {@_};
65    
66     my $log = $self->_get_logger();
67    
68 dpavlin 285 $log->info("opening ISIS database '$arg->{path}'");
69 dpavlin 6
70 dpavlin 623 $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     ) or $log->logdie("can't find database $arg->{path}");
76 dpavlin 6
77 dpavlin 652 $self->{_isis_db} = $isis_db;
78    
79 dpavlin 726 $self ? return $self : return undef;
80 dpavlin 285 }
81 dpavlin 6
82 dpavlin 285 =head2 fetch_rec
83 dpavlin 6
84 dpavlin 285 Return record with ID C<$mfn> from database
85 dpavlin 6
86 dpavlin 726 my $rec = $isis->fetch_rec( $mfn, $filter_coderef);
87 dpavlin 6
88 dpavlin 285 =cut
89 dpavlin 6
90 dpavlin 285 sub fetch_rec {
91     my $self = shift;
92 dpavlin 6
93 dpavlin 652 my ($mfn, $filter_coderef) = @_;
94 dpavlin 6
95 dpavlin 652 my $rec = $self->{_isis_db}->to_hash({
96 dpavlin 623 mfn => $mfn,
97     include_subfields => 1,
98 dpavlin 625 hash_filter => $filter_coderef,
99     # hash_filter => sub {
100     # my ($l,$f) = @_;
101     # warn "## in hash_filter ($l,$f)\n";
102     # my $o = $filter_coderef->($l,$f) if ($filter_coderef);
103     # warn "## out hash_filter = $o\n";
104     # return $o;
105     # },
106 dpavlin 623 });
107 dpavlin 6
108 dpavlin 285 return $rec;
109 dpavlin 6 }
110    
111 dpavlin 652 =head2 dump_rec
112    
113     Return dump of record ID C<$mfn> from database
114    
115 dpavlin 726 my $rec = $isis->dump_rec( $db, $mfn );
116 dpavlin 652
117     =cut
118    
119     sub dump_rec {
120     my $self = shift;
121    
122     my $mfn = shift;
123    
124     return $self->{_isis_db}->to_ascii( $mfn );
125     }
126    
127 dpavlin 726 =head2 size
128    
129     Return number of records in database
130    
131     my $size = $isis->size;
132    
133     =cut
134    
135     sub size {
136     my $self = shift;
137     return $self->{_isis_db}->count;
138     }
139    
140 dpavlin 6 =head1 AUTHOR
141    
142     Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
143    
144     =head1 COPYRIGHT & LICENSE
145    
146     Copyright 2005 Dobrica Pavlinusic, All Rights Reserved.
147    
148     This program is free software; you can redistribute it and/or modify it
149     under the same terms as Perl itself.
150    
151     =cut
152    
153     1; # End of WebPAC::Input::ISIS

  ViewVC Help
Powered by ViewVC 1.1.26