92 |
$module =~ s#::#/#g; |
$module =~ s#::#/#g; |
93 |
$module .= '.pm'; |
$module .= '.pm'; |
94 |
$log->debug("require low-level module $self->{module} from $module"); |
$log->debug("require low-level module $self->{module} from $module"); |
95 |
|
|
96 |
require $module; |
require $module; |
97 |
eval $self->{module} .'->import'; |
#eval $self->{module} .'->import'; |
98 |
|
|
99 |
# check if required subclasses are implemented |
# check if required subclasses are implemented |
100 |
foreach my $subclass (qw/open_db fetch_rec/) { |
foreach my $subclass (qw/open_db fetch_rec init/) { |
101 |
if ( $self->can($subclass) ) { |
my $n = $self->{module} . '::' . $subclass; |
102 |
$log->debug("imported $subclass"); |
if (! defined &{ $n }) { |
103 |
|
my $missing = "missing $subclass in $self->{module}"; |
104 |
|
$self->{$subclass} = sub { $log->logwarn($missing) }; |
105 |
} else { |
} else { |
106 |
$log->warn("missing $subclass in $self->{module}"); |
$self->{$subclass} = \&{ $n }; |
107 |
} |
} |
108 |
} |
} |
109 |
|
|
110 |
if ($self->can('init')) { |
if ($self->{init}) { |
111 |
$log->debug("calling init"); |
$log->debug("calling init"); |
112 |
$self->init(@_); |
$self->{init}->($self, @_); |
113 |
} |
} |
114 |
|
|
115 |
$self->{'code_page'} ||= 'ISO-8859-2'; |
$self->{'code_page'} ||= 'ISO-8859-2'; |
176 |
my $code_page = $arg->{'code_page'} || '852'; |
my $code_page = $arg->{'code_page'} || '852'; |
177 |
|
|
178 |
# store data in object |
# store data in object |
179 |
$self->{'code_page'} = $code_page; |
$self->{'input_code_page'} = $code_page; |
180 |
foreach my $v (qw/path offset limit/) { |
foreach my $v (qw/path offset limit/) { |
181 |
$self->{$v} = $arg->{$v} if ($arg->{$v}); |
$self->{$v} = $arg->{$v} if ($arg->{$v}); |
182 |
} |
} |
184 |
# create Text::Iconv object |
# create Text::Iconv object |
185 |
$self->{iconv} = Text::Iconv->new($code_page,$self->{'code_page'}); |
$self->{iconv} = Text::Iconv->new($code_page,$self->{'code_page'}); |
186 |
|
|
187 |
my ($db, $size) = $self->open_db( |
my ($db, $size) = $self->{open_db}->( $self, |
188 |
path => $arg->{path}, |
path => $arg->{path}, |
189 |
); |
); |
190 |
|
|
209 |
} |
} |
210 |
|
|
211 |
if ($self->{limit}) { |
if ($self->{limit}) { |
212 |
$log->info("limiting to ",$self->{limit}," records"); |
$log->debug("limiting to ",$self->{limit}," records"); |
213 |
$limit = $offset + $self->{limit} - 1; |
$limit = $offset + $self->{limit} - 1; |
214 |
$limit = $size if ($limit > $size); |
$limit = $size if ($limit > $size); |
215 |
} |
} |
220 |
$log->info("processing $self->{size} records in $code_page, convert to $self->{code_page}"); |
$log->info("processing $self->{size} records in $code_page, convert to $self->{code_page}"); |
221 |
|
|
222 |
# read database |
# read database |
223 |
for (my $pos = $offset; $pos <= $limit; $mfn++) { |
for (my $pos = $offset; $pos <= $limit; $pos++) { |
224 |
|
|
225 |
$log->debug("position: $pos\n"); |
$log->debug("position: $pos\n"); |
226 |
|
|
227 |
my $rec = $self->fetch_rec( $db, $pos ); |
my $rec = $self->{fetch_rec}->($self, $db, $pos ); |
228 |
|
|
229 |
if (! $rec) { |
if (! $rec) { |
230 |
$log->warn("record $pos empty? skipping..."); |
$log->warn("record $pos empty? skipping..."); |