/[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 10 by dpavlin, Sat Jul 16 20:35:30 2005 UTC revision 265 by dpavlin, Fri Dec 16 16:23:44 2005 UTC
# Line 62  from database (so you can skip beginning Line 62  from database (so you can skip beginning
62  If optional parametar C<limit_mfn> is set, it will read just 500 records  If optional parametar C<limit_mfn> is set, it will read just 500 records
63  from database in example above.  from database in example above.
64    
65  Returns number of last record read into memory (size of database, really).  Returns size of database, regardless of C<start_mfn> and C<limit_mfn>
66    parametars, see also C<$isis->size>.
67    
68  =cut  =cut
69    
# Line 75  sub open { Line 76  sub open {
76          $log->logcroak("need filename") if (! $arg->{'filename'});          $log->logcroak("need filename") if (! $arg->{'filename'});
77          my $code_page = $arg->{'code_page'} || '852';          my $code_page = $arg->{'code_page'} || '852';
78    
         $log->logdie("can't find database ",$arg->{'filename'}) unless (glob($arg->{'filename'}.'.*'));  
   
79          # store data in object          # store data in object
         $self->{'isis_filename'} = $arg->{'filename'};  
80          $self->{'isis_code_page'} = $code_page;          $self->{'isis_code_page'} = $code_page;
81            foreach my $v (qw/isis_filename start_mfn limit_mfn/) {
82          #$self->{'isis_code_page'} = $code_page;                  $self->{$v} = $arg->{$v} if ($arg->{$v});
83            }
84    
85          # create Text::Iconv object          # create Text::Iconv object
86          my $cp = Text::Iconv->new($code_page,$self->{'code_page'});          my $cp = Text::Iconv->new($code_page,$self->{'code_page'});
# Line 89  sub open { Line 88  sub open {
88          $log->info("reading ISIS database '",$arg->{'filename'},"'");          $log->info("reading ISIS database '",$arg->{'filename'},"'");
89          $log->debug("isis code page: $code_page");          $log->debug("isis code page: $code_page");
90    
91          my ($isis_db,$maxmfn);          my ($isis_db,$db_size);
92    
93          if ($have_openisis) {          if ($have_openisis) {
94                  $log->debug("using OpenIsis perl bindings");                  $log->debug("using OpenIsis perl bindings");
95                  $isis_db = OpenIsis::open($arg->{'filename'});                  $isis_db = OpenIsis::open($arg->{'filename'});
96                  $maxmfn = OpenIsis::maxRowid( $isis_db ) || 1;                  $db_size = OpenIsis::maxRowid( $isis_db ) || 1;
97          } elsif ($have_biblio_isis) {          } elsif ($have_biblio_isis) {
98                  $log->debug("using Biblio::Isis");                  $log->debug("using Biblio::Isis");
99                  use Biblio::Isis;                  use Biblio::Isis;
# Line 106  sub open { Line 105  sub open {
105                                  $l = $cp->convert($l);                                  $l = $cp->convert($l);
106                                  return $l;                                  return $l;
107                          },                          },
108                  );                  ) or $log->logdie("can't find database ",$arg->{'filename'});
109                  $maxmfn = $isis_db->count;  
110                    $db_size = $isis_db->count;
111    
112                  unless ($maxmfn) {                  unless ($db_size) {
113                          $log->logwarn("no records in database ", $arg->{'filename'}, ", skipping...");                          $log->logwarn("no records in database ", $arg->{'filename'}, ", skipping...");
114                          return;                          return;
115                  }                  }
# Line 120  sub open { Line 120  sub open {
120    
121    
122          my $startmfn = 1;          my $startmfn = 1;
123            my $maxmfn = $db_size;
124    
125          if (my $s = $self->{'start_mfn'}) {          if (my $s = $self->{'start_mfn'}) {
126                  $log->info("skipping to MFN $s");                  $log->info("skipping to MFN $s");
# Line 128  sub open { Line 129  sub open {
129                  $self->{'start_mfn'} = $startmfn;                  $self->{'start_mfn'} = $startmfn;
130          }          }
131    
132          $maxmfn = $startmfn + $self->{limit_mfn} if ($self->{limit_mfn});          if ($self->{limit_mfn}) {
133                    $log->info("limiting to ",$self->{limit_mfn}," records");
134                    $maxmfn = $startmfn + $self->{limit_mfn} - 1;
135                    $maxmfn = $db_size if ($maxmfn > $db_size);
136            }
137    
138            # store size for later
139            $self->{'size'} = ($maxmfn - $startmfn) ? ($maxmfn - $startmfn + 1) : 0;
140    
141          $log->info("processing ",($maxmfn-$startmfn)." records using ",( $have_openisis ? 'OpenIsis' : 'Biblio::Isis'));          $log->info("processing ",($maxmfn-$startmfn)." records using ",( $have_openisis ? 'OpenIsis' : 'Biblio::Isis'));
142    
# Line 172  sub open { Line 180  sub open {
180                          $log->logdie("hum? implementation missing?");                          $log->logdie("hum? implementation missing?");
181                  }                  }
182    
183                  $log->confess("record $mfn empty?") unless ($rec);                  if (! $rec) {
184                            $log->warn("record $mfn empty? skipping...");
185                            next;
186                    }
187    
188                  # store                  # store
189                  if ($self->{'low_mem'}) {                  if ($self->{'low_mem'}) {
# Line 182  sub open { Line 193  sub open {
193                  }                  }
194    
195                  # create lookup                  # create lookup
196                  $self->{'lookup'}->add( $rec ) if ($self->{'lookup'} && can($self->{'lookup'}->add));                  $self->{'lookup'}->add( $rec ) if ($rec && $self->{'lookup'});
197    
198                  $self->progress_bar($mfn,$maxmfn);                  $self->progress_bar($mfn,$maxmfn);
199    
# Line 194  sub open { Line 205  sub open {
205          $log->debug("max mfn: $maxmfn");          $log->debug("max mfn: $maxmfn");
206    
207          # store max mfn and return it.          # store max mfn and return it.
208          return $self->{'max_mfn'} = $maxmfn;          $self->{'max_mfn'} = $maxmfn;
209    
210            return $db_size;
211  }  }
212    
213  =head2 fetch  =head2 fetch
# Line 231  sub fetch { Line 244  sub fetch {
244    
245          $self->progress_bar($mfn,$self->{'max_mfn'});          $self->progress_bar($mfn,$self->{'max_mfn'});
246    
247            my $rec;
248    
249          if ($self->{'low_mem'}) {          if ($self->{'low_mem'}) {
250                  return $self->{'db'}->get($mfn);                  $rec = $self->{'db'}->get($mfn);
251          } else {          } else {
252                  return $self->{'data'}->{$mfn};                  $rec = $self->{'data'}->{$mfn};
253          }          }
254    
255            $rec ||= 0E0;
256  }  }
257    
258  =head2 pos  =head2 pos
# Line 260  Returns number of records in database Line 277  Returns number of records in database
277    
278   print $isis->size;   print $isis->size;
279    
280    Result from this function can be used to loop through all records
281    
282     foreach my $mfn ( 1 ... $isis->size ) { ... }
283    
284    because it takes into account C<start_mfn> and C<limit_mfn>.
285    
286  =cut  =cut
287    
288  sub size {  sub size {
289          my $self = shift;          my $self = shift;
290          return $self->{'max_mfn'};          return $self->{'size'};
291  }  }
292    
293  =head2 seek  =head2 seek

Legend:
Removed from v.10  
changed lines
  Added in v.265

  ViewVC Help
Powered by ViewVC 1.1.26