/[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 20 by dpavlin, Sat Jul 16 20:35:30 2005 UTC revision 21 by dpavlin, Sun Jul 17 22:28:11 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 78  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 89  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 107  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 120  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 128  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 194  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  =head2 fetch
# Line 260  Returns number of records in database Line 271  Returns number of records in database
271    
272   print $isis->size;   print $isis->size;
273    
274    Result from this function can be used to loop through all records
275    
276     foreach my $mfn ( 1 ... $isis->size ) { ... }
277    
278    because it takes into account C<start_mfn> and C<limit_mfn>.
279    
280  =cut  =cut
281    
282  sub size {  sub size {
283          my $self = shift;          my $self = shift;
284          return $self->{'max_mfn'};          return $self->{'size'};
285  }  }
286    
287  =head2 seek  =head2 seek

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

  ViewVC Help
Powered by ViewVC 1.1.26