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; |
9 |
|
use Data::Dumper; |
10 |
|
|
11 |
=head1 NAME |
=head1 NAME |
12 |
|
|
100 |
my $n = $self->{module} . '::' . $subclass; |
my $n = $self->{module} . '::' . $subclass; |
101 |
if (! defined &{ $n }) { |
if (! defined &{ $n }) { |
102 |
my $missing = "missing $subclass in $self->{module}"; |
my $missing = "missing $subclass in $self->{module}"; |
103 |
$log->logwarn($missing); |
$self->{$subclass} = sub { $log->logwarn($missing) }; |
|
$self->{$subclass} = sub { warn "$missing\n" }; |
|
104 |
} else { |
} else { |
105 |
$self->{$subclass} = \&{ $n }; |
$self->{$subclass} = \&{ $n }; |
106 |
} |
} |
197 |
return; |
return; |
198 |
} |
} |
199 |
|
|
200 |
my $offset = 1; |
my $from_rec = 1; |
201 |
my $limit = $size; |
my $to_rec = $size; |
202 |
|
|
203 |
if (my $s = $self->{offset}) { |
if (my $s = $self->{offset}) { |
204 |
$log->info("skipping to MFN $s"); |
$log->info("skipping to MFN $s"); |
205 |
$offset = $s; |
$from_rec = $s; |
206 |
} else { |
} else { |
207 |
$self->{offset} = $offset; |
$self->{offset} = $from_rec; |
208 |
} |
} |
209 |
|
|
210 |
if ($self->{limit}) { |
if ($self->{limit}) { |
211 |
$log->info("limiting to ",$self->{limit}," records"); |
$log->debug("limiting to ",$self->{limit}," records"); |
212 |
$limit = $offset + $self->{limit} - 1; |
$to_rec = $from_rec + $self->{limit} - 1; |
213 |
$limit = $size if ($limit > $size); |
$to_rec = $size if ($to_rec > $size); |
214 |
} |
} |
215 |
|
|
216 |
# store size for later |
# store size for later |
217 |
$self->{size} = ($limit - $offset) ? ($limit - $offset + 1) : 0; |
$self->{size} = ($to_rec - $from_rec) ? ($to_rec - $from_rec + 1) : 0; |
218 |
|
|
219 |
$log->info("processing $self->{size} records in $code_page, convert to $self->{code_page}"); |
$log->info("processing $self->{size}/$size records [$from_rec-$to_rec] convert $code_page -> $self->{code_page}"); |
220 |
|
|
221 |
# read database |
# read database |
222 |
for (my $pos = $offset; $pos <= $limit; $pos++) { |
for (my $pos = $from_rec; $pos <= $to_rec; $pos++) { |
223 |
|
|
224 |
$log->debug("position: $pos\n"); |
$log->debug("position: $pos\n"); |
225 |
|
|
226 |
my $rec = $self->{fetch_rec}->($self, $db, $pos ); |
my $rec = $self->{fetch_rec}->($self, $db, $pos ); |
227 |
|
|
228 |
|
$log->debug(sub { Dumper($rec) }); |
229 |
|
|
230 |
if (! $rec) { |
if (! $rec) { |
231 |
$log->warn("record $pos empty? skipping..."); |
$log->warn("record $pos empty? skipping..."); |
232 |
next; |
next; |
242 |
# create lookup |
# create lookup |
243 |
$self->{'lookup'}->add( $rec ) if ($rec && $self->{'lookup'}); |
$self->{'lookup'}->add( $rec ) if ($rec && $self->{'lookup'}); |
244 |
|
|
245 |
$self->progress_bar($pos,$limit); |
$self->progress_bar($pos,$to_rec); |
246 |
|
|
247 |
} |
} |
248 |
|
|
250 |
$self->{last_pcnt} = 0; |
$self->{last_pcnt} = 0; |
251 |
|
|
252 |
# store max mfn and return it. |
# store max mfn and return it. |
253 |
$self->{max_pos} = $limit; |
$self->{max_pos} = $to_rec; |
254 |
$log->debug("max_pos: $limit"); |
$log->debug("max_pos: $to_rec"); |
255 |
|
|
256 |
return $size; |
return $size; |
257 |
} |
} |