/[webpac2]/trunk/lib/WebPAC/Input.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.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 287 by dpavlin, Sun Dec 18 21:06:51 2005 UTC revision 307 by dpavlin, Tue Dec 20 00:03:04 2005 UTC
# Line 3  package WebPAC::Input; Line 3  package WebPAC::Input;
3  use warnings;  use warnings;
4  use strict;  use strict;
5    
 use blib;  
   
6  use WebPAC::Common;  use WebPAC::Common;
7  use base qw/WebPAC::Common/;  use base qw/WebPAC::Common/;
8  use Text::Iconv;  use Text::Iconv;
# Line 92  sub new { Line 90  sub new {
90          $module =~ s#::#/#g;          $module =~ s#::#/#g;
91          $module .= '.pm';          $module .= '.pm';
92          $log->debug("require low-level module $self->{module} from $module");          $log->debug("require low-level module $self->{module} from $module");
93    
94          require $module;          require $module;
95          eval $self->{module} .'->import';          #eval $self->{module} .'->import';
96    
97          # check if required subclasses are implemented          # check if required subclasses are implemented
98          foreach my $subclass (qw/open_db fetch_rec/) {          foreach my $subclass (qw/open_db fetch_rec init/) {
99                  if ( $self->can($subclass) ) {                  my $n = $self->{module} . '::' . $subclass;
100                          $log->debug("imported $subclass");                  if (! defined &{ $n }) {
101                            my $missing = "missing $subclass in $self->{module}";
102                            $self->{$subclass} = sub { $log->logwarn($missing) };
103                  } else {                  } else {
104                          $log->warn("missing $subclass in $self->{module}");                          $self->{$subclass} = \&{ $n };
105                  }                  }
106          }          }
107    
108          if ($self->can('init')) {          if ($self->{init}) {
109                  $log->debug("calling init");                  $log->debug("calling init");
110                  $self->init(@_);                  $self->{init}->($self, @_);
111          }          }
112    
113          $self->{'code_page'} ||= 'ISO-8859-2';          $self->{'code_page'} ||= 'ISO-8859-2';
# Line 173  sub open { Line 174  sub open {
174          my $code_page = $arg->{'code_page'} || '852';          my $code_page = $arg->{'code_page'} || '852';
175    
176          # store data in object          # store data in object
177          $self->{'code_page'} = $code_page;          $self->{'input_code_page'} = $code_page;
178          foreach my $v (qw/path offset limit/) {          foreach my $v (qw/path offset limit/) {
179                  $self->{$v} = $arg->{$v} if ($arg->{$v});                  $self->{$v} = $arg->{$v} if ($arg->{$v});
180          }          }
# Line 181  sub open { Line 182  sub open {
182          # create Text::Iconv object          # create Text::Iconv object
183          $self->{iconv} = Text::Iconv->new($code_page,$self->{'code_page'});          $self->{iconv} = Text::Iconv->new($code_page,$self->{'code_page'});
184    
185          my ($db, $size) = $self->open_db(          my ($db, $size) = $self->{open_db}->( $self,
186                  path => $arg->{path},                  path => $arg->{path},
187          );          );
188    
# Line 206  sub open { Line 207  sub open {
207          }          }
208    
209          if ($self->{limit}) {          if ($self->{limit}) {
210                  $log->info("limiting to ",$self->{limit}," records");                  $log->debug("limiting to ",$self->{limit}," records");
211                  $limit = $offset + $self->{limit} - 1;                  $limit = $offset + $self->{limit} - 1;
212                  $limit = $size if ($limit > $size);                  $limit = $size if ($limit > $size);
213          }          }
# Line 221  sub open { Line 222  sub open {
222    
223                  $log->debug("position: $pos\n");                  $log->debug("position: $pos\n");
224    
225                  my $rec = $self->fetch_rec( $db, $pos );                  my $rec = $self->{fetch_rec}->($self, $db, $pos );
226    
227                  if (! $rec) {                  if (! $rec) {
228                          $log->warn("record $pos empty? skipping...");                          $log->warn("record $pos empty? skipping...");

Legend:
Removed from v.287  
changed lines
  Added in v.307

  ViewVC Help
Powered by ViewVC 1.1.26