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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 497 by dpavlin, Sun May 14 19:45:36 2006 UTC revision 770 by dpavlin, Fri Nov 3 20:21:14 2006 UTC
# Line 4  use warnings; Line 4  use warnings;
4  use strict;  use strict;
5    
6  use WebPAC::Input;  use WebPAC::Input;
7    use Biblio::Isis 0.23;
8    use base qw/WebPAC::Common/;
9    
10  =head1 NAME  =head1 NAME
11    
# Line 11  WebPAC::Input::ISIS - support for CDS/IS Line 13  WebPAC::Input::ISIS - support for CDS/IS
13    
14  =head1 VERSION  =head1 VERSION
15    
16  Version 0.03  Version 0.08
17    
18  =cut  =cut
19    
20  our $VERSION = '0.03';  our $VERSION = '0.08';
21    
22    
23  =head1 SYNOPSIS  =head1 SYNOPSIS
24    
25  Open CDS/ISIS, WinISIS or IsisMarc database using C<Biblio::Isis> or  Open CDS/ISIS, WinISIS or IsisMarc database using C<Biblio::Isis>
26  C<OpenIsis> module and read all records to memory.  and read all records to memory.
27    
28   my $isis = new WebPAC::Input::ISIS();   my $isis = new WebPAC::Input::ISIS(
29   $isis->open( path => '/path/to/ISIS/ISIS' );          path => '/path/to/ISIS/ISIS',
30     );
31    
32  =head1 FUNCTIONS  =head1 FUNCTIONS
33    
34  =head2 init  =head2 new
35    
36  Autoconfigure this module to use C<Biblio::Isis> or C<OpenIsis>.  Returns new low-level input API object
37    
38  =cut    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  sub init {  Options:
         my $self = shift;  
48    
49          eval "use Biblio::Isis;";  =over 4
         unless ($@) {  
                 $self->{have_biblio_isis} = 1  
         } else {  
                 eval "use OpenIsis;";  
                 $self->{have_openisis} = 1 unless ($@);  
         }  
 }  
50    
51  =head2 open_db  =item path
52    
53  Returns handle to database and size in records  path to CDS/ISIS database
54    
55    my ($db,$size) = $open_db(  =back
         path => '/path/to/LIBRI'  
   }  
56    
57  =cut  =cut
58    
59  sub open_db {  sub new {
60          my $self = shift;          my $class = shift;
61            my $self = {@_};
62            bless($self, $class);
63    
64          my $arg = {@_};          my $arg = {@_};
65    
# Line 65  sub open_db { Line 67  sub open_db {
67    
68          $log->info("opening ISIS database '$arg->{path}'");          $log->info("opening ISIS database '$arg->{path}'");
69    
70          my ($isis_db,$db_size);          $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    
77          if ($self->{have_openisis}) {          $self->{_isis_db} = $isis_db;
                 $log->debug("using OpenIsis perl bindings");  
                 $isis_db = OpenIsis::open($arg->{path});  
                 $db_size = OpenIsis::maxRowid( $isis_db ) || 1;  
         } elsif ($self->{have_biblio_isis}) {  
                 $log->debug("using Biblio::Isis");  
                 use Biblio::Isis;  
                 $isis_db = new Biblio::Isis(  
                         isisdb => $arg->{path},  
                         include_deleted => 1,  
                         hash_filter => sub {  
                                 my $l = shift || return;  
                                 $l = $self->{iconv}->convert($l) if ($self->{iconv});  
                                 return $l;  
                         },  
                 ) or $log->logdie("can't find database $arg->{path}");  
   
                 $db_size = $isis_db->count;  
   
         } else {  
                 $log->logdie("Can't find supported ISIS library for perl. I suggent that you install Bilbio::Isis from CPAN.");  
         }  
78    
79          return ($isis_db, $db_size);          $self ? return $self : return undef;
80  }  }
81    
82  =head2 fetch_rec  =head2 fetch_rec
83    
84  Return record with ID C<$mfn> from database  Return record with ID C<$mfn> from database
85    
86    my $rec = $self->fetch_rec( $db, $mfn );    my $rec = $isis->fetch_rec( $mfn, $filter_coderef);
87    
88    =cut
89    
90    sub fetch_rec {
91            my $self = shift;
92    
93            my ($mfn, $filter_coderef) = @_;
94    
95            my $rec = $self->{_isis_db}->to_hash({
96                    mfn => $mfn,
97                    include_subfields => 1,
98                    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            });
107    
108            return $rec;
109  }  }
110    
111    =head2 dump_rec
112    
113    Return dump of record ID C<$mfn> from database
114    
115      my $rec = $isis->dump_rec( $mfn );
116    
117  =cut  =cut
118    
119  sub fetch_rec {  sub dump_rec {
120          my $self = shift;          my $self = shift;
121    
122          my ($isis_db, $mfn) = @_;          my $mfn = shift;
123    
124          my $rec;          return $self->{_isis_db}->to_ascii( $mfn );
125    }
126    
127          if ($self->{have_openisis}) {  =head2 size
128    
129                  # read record using OpenIsis  Return number of records in database
                 my $row = OpenIsis::read( $isis_db, $mfn );  
130    
131                  # convert record to hash    my $size = $isis->size;
                 foreach my $k (keys %{$row}) {  
                         if ($k ne "mfn") {  
                                 foreach my $l (@{$row->{$k}}) {  
                                         $l = $self->{iconv}->convert($l) if ($self->{iconv});  
                                         # has subfields?  
                                         my $val;  
                                         if ($l =~ m/\^/) {  
                                                 foreach my $t (split(/\^/,$l)) {  
                                                         next if (! $t);  
                                                         $val->{substr($t,0,1)} = substr($t,1);  
                                                 }  
                                         } else {  
                                                 $val = $l;  
                                         }  
                                         push @{$rec->{"$k"}}, $val;  
                                 }  
                         } else {  
                                 push @{$rec->{'000'}}, $mfn;  
                         }  
                 }  
   
         } elsif ($self->{have_biblio_isis}) {  
                 $rec = $isis_db->to_hash($mfn);  
         } else {  
                 $self->_get_logger()->logdie("hum? implementation missing?");  
         }  
132    
133          return $rec;  =cut
134    
135    sub size {
136            my $self = shift;
137            return $self->{_isis_db}->count;
138  }  }
139    
140  =head1 AUTHOR  =head1 AUTHOR

Legend:
Removed from v.497  
changed lines
  Added in v.770

  ViewVC Help
Powered by ViewVC 1.1.26