/[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 652 - (hide annotations)
Thu Sep 7 15:01:45 2006 UTC (17 years, 8 months ago) by dpavlin
File size: 2305 byte(s)
refactored internal WebPAC::Input::* API a bit, added dump_rec,
validate is now more clever and reports all errors from database at end

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

  ViewVC Help
Powered by ViewVC 1.1.26