/[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 619 by dpavlin, Fri Aug 25 12:31:06 2006 UTC revision 623 by dpavlin, Sat Aug 26 12:00:25 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    
9  =head1 NAME  =head1 NAME
10    
# Line 11  WebPAC::Input::ISIS - support for CDS/IS Line 12  WebPAC::Input::ISIS - support for CDS/IS
12    
13  =head1 VERSION  =head1 VERSION
14    
15  Version 0.05  Version 0.06
16    
17  =cut  =cut
18    
19  our $VERSION = '0.05';  our $VERSION = '0.06';
20    
21    
22  =head1 SYNOPSIS  =head1 SYNOPSIS
23    
24  Open CDS/ISIS, WinISIS or IsisMarc database using C<Biblio::Isis> or  Open CDS/ISIS, WinISIS or IsisMarc database using C<Biblio::Isis>
25  C<OpenIsis> module and read all records to memory.  and read all records to memory.
26    
27   my $isis = new WebPAC::Input::ISIS();   my $isis = new WebPAC::Input::ISIS();
28   $isis->open( path => '/path/to/ISIS/ISIS' );   $isis->open( path => '/path/to/ISIS/ISIS' );
29    
30  =head1 FUNCTIONS  =head1 FUNCTIONS
31    
 =head2 init  
   
 Autoconfigure this module to use C<Biblio::Isis> or C<OpenIsis>.  
   
 =cut  
   
 sub init {  
         my $self = shift;  
   
         eval "use Biblio::Isis;";  
         unless ($@) {  
                 $self->{have_biblio_isis} = 1  
         } else {  
                 eval "use OpenIsis;";  
                 $self->{have_openisis} = 1 unless ($@);  
         }  
 }  
   
32  =head2 open_db  =head2 open_db
33    
34  Returns handle to database and size in records  Returns handle to database and size in records
# Line 80  sub open_db { Line 63  sub open_db {
63    
64          $log->info("opening ISIS database '$arg->{path}'");          $log->info("opening ISIS database '$arg->{path}'");
65    
66          my ($isis_db,$db_size);          $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    
73          if ($self->{have_openisis}) {          my $size = $isis_db->count;
                 $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 => $arg->{filter} ? sub { return $arg->{filter}->(@_); } : undef,  
                 ) 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.");  
         }  
74    
75          return ($isis_db, $db_size);          return ($isis_db, $size);
76  }  }
77    
78  =head2 fetch_rec  =head2 fetch_rec
# Line 117  sub fetch_rec { Line 88  sub fetch_rec {
88    
89          my ($isis_db, $mfn, $filter_coderef) = @_;          my ($isis_db, $mfn, $filter_coderef) = @_;
90    
91          my $rec;  use Data::Dump qw/dump/;
92    warn "fetch_rec filter_coderef = ", dump($filter_coderef), $/;
         if ($self->{have_openisis}) {  
   
                 # read record using OpenIsis  
                 my $row = OpenIsis::read( $isis_db, $mfn );  
93    
94                  # convert record to hash          my $rec = $isis_db->to_hash({
95                  foreach my $k (keys %{$row}) {                  mfn => $mfn,
96                          if ($k ne "mfn") {                  include_subfields => 1,
97                                  foreach my $l (@{$row->{$k}}) {                  hash_filter => sub {
98                                          $l = $self->{iconv}->convert($l) if ($self->{iconv});                          my ($l,$f) = @_;
99                                          # has subfields?                          warn "## in hash_filter ($l,$f)\n";
100                                          my $val;                          my $o = $filter_coderef->($l,$f);
101                                          if ($l =~ m/\^/) {                          warn "## out hash_filter = $o\n";
102                                                  foreach my $t (split(/\^/,$l)) {                          return $o;
103                                                          next if (! $t);                  },
104                                                          $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 => $mfn,  
                         include_subfields => 1,  
                         hash_filter => $filter_coderef,  
                 });  
         } else {  
                 $self->_get_logger()->logdie("hum? implementation missing?");  
         }  
105    
106          return $rec;          return $rec;
107  }  }

Legend:
Removed from v.619  
changed lines
  Added in v.623

  ViewVC Help
Powered by ViewVC 1.1.26