/[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 21 by dpavlin, Sun Jul 17 22:28:11 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 193  sub open { Line 203  sub open {
203          $log->debug("max mfn: $maxmfn");          $log->debug("max mfn: $maxmfn");
204    
205          # store max mfn and return it.          # store max mfn and return it.
206          return $self->{'max_mfn'} = $maxmfn;          $self->{'max_mfn'} = $maxmfn;
207    
208            return $db_size;
209  }  }
210    
211  =head2 fetch_rec  =head2 fetch
212    
213  Fetch next record from database. It will also displays progress bar.  Fetch next record from database. It will also displays progress bar.
214    
215   my $rec = $webpac->fetch_rec;   my $rec = $isis->fetch;
216    
217  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
218  C<fetch_data_structure> which returns normalised data.  normalisation.
219    
220  =cut  =cut
221    
222  sub fetch_rec {  sub fetch {
223          my $self = shift;          my $self = shift;
224    
225          my $log = $self->_get_logger();          my $log = $self->_get_logger();
# Line 237  sub fetch_rec { Line 249  sub fetch_rec {
249          }          }
250  }  }
251    
252  =head2 fetch_data_structure  =head2 pos
253    
254    Returns current record number (MFN).
255    
256  Fetch data structure of next record from database.   print $isis->pos;
257    
258   my @ds = $webpac->fetch_data_structure;  First record in database has position 1.
259    
260  =cut  =cut
261    
262  sub fetch_data_structure {  sub pos {
263          my $self = shift;          my $self = shift;
264            return $self->{'current_mfn'};
265    }
266    
267    
268    =head2 size
269    
270    Returns number of records in database
271    
272     print $isis->size;
273    
274    Result from this function can be used to loop through all records
275    
276          return $self->data_structure(   foreach my $mfn ( 1 ... $isis->size ) { ... }
277                  $self->fetch_rec(@_)  
278          );  because it takes into account C<start_mfn> and C<limit_mfn>.
279    
280    =cut
281    
282    sub size {
283            my $self = shift;
284            return $self->{'size'};
285  }  }
286    
287  =head2 mfn  =head2 seek
288    
289  Returns current record number (MFN).  Seek to specified MFN in file.
290    
291     $isis->seek(42);
292    
293   print $webpac->mfn;  First record in database has position 1.
294    
295  =cut  =cut
296    
297  sub mfn {  sub seek {
298          my $self = shift;          my $self = shift;
299          return $self->{'current_mfn'};          my $pos = shift || return;
300    
301            my $log = $self->_get_logger();
302    
303            if ($pos < 1) {
304                    $log->warn("seek before first record");
305                    $pos = 1;
306            } elsif ($pos > $self->{'max_mfn'}) {
307                    $log->warn("seek beyond last record");
308                    $pos = $self->{'max_mfn'};
309            }
310    
311            return $self->{'current_mfn'} = (($pos - 1) || -1);
312  }  }
313    
314  =head1 AUTHOR  =head1 AUTHOR

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

  ViewVC Help
Powered by ViewVC 1.1.26