/[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 8 by dpavlin, Sat Jul 16 16:48:35 2005 UTC revision 113 by dpavlin, Wed Nov 23 00:14:05 2005 UTC
# Line 5  use strict; Line 5  use strict;
5    
6  use WebPAC::Common;  use WebPAC::Common;
7  use base qw/WebPAC::Input WebPAC::Common/;  use base qw/WebPAC::Input WebPAC::Common/;
8    use Text::Iconv;
9    
10  =head1 NAME  =head1 NAME
11    
# Line 61  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 77  sub open { Line 79  sub open {
79          $log->logdie("can't find database ",$arg->{'filename'}) unless (glob($arg->{'filename'}.'.*'));          $log->logdie("can't find database ",$arg->{'filename'}) unless (glob($arg->{'filename'}.'.*'));
80    
81          # store data in object          # store data in object
         $self->{'isis_filename'} = $arg->{'filename'};  
82          $self->{'isis_code_page'} = $code_page;          $self->{'isis_code_page'} = $code_page;
83            foreach my $v (qw/isis_filename start_mfn limit_mfn/) {
84          #$self->{'isis_code_page'} = $code_page;                  $self->{$v} = $arg->{$v} if ($arg->{$v});
85            }
86    
87          # create Text::Iconv object          # create Text::Iconv object
88          my $cp = Text::Iconv->new($code_page,$self->{'code_page'});          my $cp = Text::Iconv->new($code_page,$self->{'code_page'});
# Line 88  sub open { Line 90  sub open {
90          $log->info("reading ISIS database '",$arg->{'filename'},"'");          $log->info("reading ISIS database '",$arg->{'filename'},"'");
91          $log->debug("isis code page: $code_page");          $log->debug("isis code page: $code_page");
92    
93          my ($isis_db,$maxmfn);          my ($isis_db,$db_size);
94    
95          if ($have_openisis) {          if ($have_openisis) {
96                  $log->debug("using OpenIsis perl bindings");                  $log->debug("using OpenIsis perl bindings");
97                  $isis_db = OpenIsis::open($arg->{'filename'});                  $isis_db = OpenIsis::open($arg->{'filename'});
98                  $maxmfn = OpenIsis::maxRowid( $isis_db ) || 1;                  $db_size = OpenIsis::maxRowid( $isis_db ) || 1;
99          } elsif ($have_biblio_isis) {          } elsif ($have_biblio_isis) {
100                  $log->debug("using Biblio::Isis");                  $log->debug("using Biblio::Isis");
101                  use Biblio::Isis;                  use Biblio::Isis;
# Line 106  sub open { Line 108  sub open {
108                                  return $l;                                  return $l;
109                          },                          },
110                  );                  );
111                  $maxmfn = $isis_db->count;                  $db_size = $isis_db->count;
112    
113                  unless ($maxmfn) {                  unless ($db_size) {
114                          $log->logwarn("no records in database ", $arg->{'filename'}, ", skipping...");                          $log->logwarn("no records in database ", $arg->{'filename'}, ", skipping...");
115                          return;                          return;
116                  }                  }
# Line 119  sub open { Line 121  sub open {
121    
122    
123          my $startmfn = 1;          my $startmfn = 1;
124            my $maxmfn = $db_size;
125    
126          if (my $s = $self->{'start_mfn'}) {          if (my $s = $self->{'start_mfn'}) {
127                  $log->info("skipping to MFN $s");                  $log->info("skipping to MFN $s");
# Line 127  sub open { Line 130  sub open {
130                  $self->{'start_mfn'} = $startmfn;                  $self->{'start_mfn'} = $startmfn;
131          }          }
132    
133          $maxmfn = $startmfn + $self->{limit_mfn} if ($self->{limit_mfn});          if ($self->{limit_mfn}) {
134                    $log->info("limiting to ",$self->{limit_mfn}," records");
135                    $maxmfn = $startmfn + $self->{limit_mfn} - 1;
136                    $maxmfn = $db_size if ($maxmfn > $db_size);
137            }
138    
139            # store size for later
140            $self->{'size'} = ($maxmfn - $startmfn) ? ($maxmfn - $startmfn + 1) : 0;
141    
142          $log->info("processing ",($maxmfn-$startmfn)." records using ",( $have_openisis ? 'OpenIsis' : 'Biblio::Isis'));          $log->info("processing ",($maxmfn-$startmfn)." records using ",( $have_openisis ? 'OpenIsis' : 'Biblio::Isis'));
143    
# Line 171  sub open { Line 181  sub open {
181                          $log->logdie("hum? implementation missing?");                          $log->logdie("hum? implementation missing?");
182                  }                  }
183    
184                  $log->confess("record $mfn empty?") unless ($rec);                  if (! $rec) {
185                            $log->warn("record $mfn empty? skipping...");
186                            next;
187                    }
188    
189                  # store                  # store
190                  if ($self->{'low_mem'}) {                  if ($self->{'low_mem'}) {
# Line 193  sub open { Line 206  sub open {
206          $log->debug("max mfn: $maxmfn");          $log->debug("max mfn: $maxmfn");
207    
208          # store max mfn and return it.          # store max mfn and return it.
209          return $self->{'max_mfn'} = $maxmfn;          $self->{'max_mfn'} = $maxmfn;
210    
211            return $db_size;
212  }  }
213    
214  =head2 fetch_rec  =head2 fetch
215    
216  Fetch next record from database. It will also displays progress bar.  Fetch next record from database. It will also displays progress bar.
217    
218   my $rec = $webpac->fetch_rec;   my $rec = $isis->fetch;
219    
220  You should rearly have the need to call this function directly. Instead use  Record from this function should probably go to C<data_structure> for
221  C<fetch_data_structure> which returns normalised data.  normalisation.
222    
223  =cut  =cut
224    
225  sub fetch_rec {  sub fetch {
226          my $self = shift;          my $self = shift;
227    
228          my $log = $self->_get_logger();          my $log = $self->_get_logger();
# Line 230  sub fetch_rec { Line 245  sub fetch_rec {
245    
246          $self->progress_bar($mfn,$self->{'max_mfn'});          $self->progress_bar($mfn,$self->{'max_mfn'});
247    
248            my $rec;
249    
250          if ($self->{'low_mem'}) {          if ($self->{'low_mem'}) {
251                  return $self->{'db'}->get($mfn);                  $rec = $self->{'db'}->get($mfn);
252          } else {          } else {
253                  return $self->{'data'}->{$mfn};                  $rec = $self->{'data'}->{$mfn};
254          }          }
255    
256            $rec ||= 0E0;
257  }  }
258    
259  =head2 fetch_data_structure  =head2 pos
260    
261  Fetch data structure of next record from database.  Returns current record number (MFN).
262    
263     print $isis->pos;
264    
265   my @ds = $webpac->fetch_data_structure;  First record in database has position 1.
266    
267  =cut  =cut
268    
269  sub fetch_data_structure {  sub pos {
270          my $self = shift;          my $self = shift;
271            return $self->{'current_mfn'};
272    }
273    
274    
275    =head2 size
276    
277    Returns number of records in database
278    
279          return $self->data_structure(   print $isis->size;
280                  $self->fetch_rec(@_)  
281          );  Result from this function can be used to loop through all records
282    
283     foreach my $mfn ( 1 ... $isis->size ) { ... }
284    
285    because it takes into account C<start_mfn> and C<limit_mfn>.
286    
287    =cut
288    
289    sub size {
290            my $self = shift;
291            return $self->{'size'};
292  }  }
293    
294  =head2 mfn  =head2 seek
295    
296  Returns current record number (MFN).  Seek to specified MFN in file.
297    
298   print $webpac->mfn;   $isis->seek(42);
299    
300    First record in database has position 1.
301    
302  =cut  =cut
303    
304  sub mfn {  sub seek {
305          my $self = shift;          my $self = shift;
306          return $self->{'current_mfn'};          my $pos = shift || return;
307    
308            my $log = $self->_get_logger();
309    
310            if ($pos < 1) {
311                    $log->warn("seek before first record");
312                    $pos = 1;
313            } elsif ($pos > $self->{'max_mfn'}) {
314                    $log->warn("seek beyond last record");
315                    $pos = $self->{'max_mfn'};
316            }
317    
318            return $self->{'current_mfn'} = (($pos - 1) || -1);
319  }  }
320    
321  =head1 AUTHOR  =head1 AUTHOR

Legend:
Removed from v.8  
changed lines
  Added in v.113

  ViewVC Help
Powered by ViewVC 1.1.26