--- trunk/lib/WebPAC/Input.pm 2005/12/18 21:06:51 287 +++ trunk/lib/WebPAC/Input.pm 2005/12/20 19:01:22 308 @@ -3,11 +3,10 @@ use warnings; use strict; -use blib; - use WebPAC::Common; use base qw/WebPAC::Common/; use Text::Iconv; +use Data::Dumper; =head1 NAME @@ -92,21 +91,24 @@ $module =~ s#::#/#g; $module .= '.pm'; $log->debug("require low-level module $self->{module} from $module"); + require $module; - eval $self->{module} .'->import'; + #eval $self->{module} .'->import'; # check if required subclasses are implemented - foreach my $subclass (qw/open_db fetch_rec/) { - if ( $self->can($subclass) ) { - $log->debug("imported $subclass"); + foreach my $subclass (qw/open_db fetch_rec init/) { + my $n = $self->{module} . '::' . $subclass; + if (! defined &{ $n }) { + my $missing = "missing $subclass in $self->{module}"; + $self->{$subclass} = sub { $log->logwarn($missing) }; } else { - $log->warn("missing $subclass in $self->{module}"); + $self->{$subclass} = \&{ $n }; } } - if ($self->can('init')) { + if ($self->{init}) { $log->debug("calling init"); - $self->init(@_); + $self->{init}->($self, @_); } $self->{'code_page'} ||= 'ISO-8859-2'; @@ -173,7 +175,7 @@ my $code_page = $arg->{'code_page'} || '852'; # store data in object - $self->{'code_page'} = $code_page; + $self->{'input_code_page'} = $code_page; foreach my $v (qw/path offset limit/) { $self->{$v} = $arg->{$v} if ($arg->{$v}); } @@ -181,7 +183,7 @@ # create Text::Iconv object $self->{iconv} = Text::Iconv->new($code_page,$self->{'code_page'}); - my ($db, $size) = $self->open_db( + my ($db, $size) = $self->{open_db}->( $self, path => $arg->{path}, ); @@ -206,7 +208,7 @@ } if ($self->{limit}) { - $log->info("limiting to ",$self->{limit}," records"); + $log->debug("limiting to ",$self->{limit}," records"); $limit = $offset + $self->{limit} - 1; $limit = $size if ($limit > $size); } @@ -221,7 +223,9 @@ $log->debug("position: $pos\n"); - my $rec = $self->fetch_rec( $db, $pos ); + my $rec = $self->{fetch_rec}->($self, $db, $pos ); + + $log->debug(sub { Dumper($rec) }); if (! $rec) { $log->warn("record $pos empty? skipping...");