7 |
|
|
8 |
use WebPAC::Common; |
use WebPAC::Common; |
9 |
use base qw/WebPAC::Common/; |
use base qw/WebPAC::Common/; |
|
use Text::Iconv; |
|
10 |
use Data::Dumper; |
use Data::Dumper; |
11 |
|
use Encode qw/from_to/; |
12 |
|
|
13 |
=head1 NAME |
=head1 NAME |
14 |
|
|
159 |
|
|
160 |
$input->open( |
$input->open( |
161 |
path => '/path/to/database/file', |
path => '/path/to/database/file', |
162 |
code_page => '852', |
code_page => 'cp852', |
163 |
limit => 500, |
limit => 500, |
164 |
offset => 6000, |
offset => 6000, |
165 |
lookup => $lookup_obj, |
lookup => $lookup_obj, |
174 |
}, |
}, |
175 |
); |
); |
176 |
|
|
177 |
By default, C<code_page> is assumed to be C<852>. |
By default, C<code_page> is assumed to be C<cp852>. |
178 |
|
|
179 |
C<offset> is optional parametar to position at some offset before reading from database. |
C<offset> is optional parametar to position at some offset before reading from database. |
180 |
|
|
205 |
if ($arg->{lookup_coderef} && ref($arg->{lookup_coderef}) ne 'CODE'); |
if ($arg->{lookup_coderef} && ref($arg->{lookup_coderef}) ne 'CODE'); |
206 |
|
|
207 |
$log->logcroak("need path") if (! $arg->{'path'}); |
$log->logcroak("need path") if (! $arg->{'path'}); |
208 |
my $code_page = $arg->{'code_page'} || '852'; |
my $code_page = $arg->{'code_page'} || 'cp852'; |
209 |
|
|
210 |
# store data in object |
# store data in object |
211 |
$self->{'input_code_page'} = $code_page; |
$self->{'input_code_page'} = $code_page; |
213 |
$self->{$v} = $arg->{$v} if ($arg->{$v}); |
$self->{$v} = $arg->{$v} if ($arg->{$v}); |
214 |
} |
} |
215 |
|
|
|
# create Text::Iconv object |
|
|
$self->{iconv} = Text::Iconv->new($code_page,$self->{'encoding'}); ## FIXME remove! |
|
|
|
|
216 |
my $filter_ref; |
my $filter_ref; |
217 |
my $recode_regex; |
my $recode_regex; |
218 |
my $recode_map; |
my $recode_map; |
240 |
|
|
241 |
my ($db, $size) = $self->{open_db}->( $self, |
my ($db, $size) = $self->{open_db}->( $self, |
242 |
path => $arg->{path}, |
path => $arg->{path}, |
243 |
filter => sub { |
# filter => sub { |
244 |
my ($l,$f_nr) = @_; |
# my ($l,$f_nr) = @_; |
245 |
return unless defined($l); |
# return unless defined($l); |
246 |
|
# from_to($l, $code_page, $self->{'encoding'}); |
247 |
## FIXME remove iconv! |
# $l =~ s/($recode_regex)/$recode_map->{$1}/g if ($recode_regex && $recode_map); |
248 |
$l = $self->{iconv}->convert($l) if ($self->{iconv}); |
# return $l; |
249 |
|
# }, |
|
$l =~ s/($recode_regex)/$recode_map->{$1}/g if ($recode_regex && $recode_map); |
|
|
|
|
|
## FIXME remove this warning when we are sure that none of API is calling |
|
|
## this wrongly |
|
|
warn "filter called without field number" unless ($f_nr); |
|
|
|
|
|
return $l; |
|
|
}, |
|
250 |
%{ $arg }, |
%{ $arg }, |
251 |
); |
); |
252 |
|
|
288 |
|
|
289 |
my $rec = $self->{fetch_rec}->($self, $db, $pos, sub { |
my $rec = $self->{fetch_rec}->($self, $db, $pos, sub { |
290 |
my ($l,$f_nr) = @_; |
my ($l,$f_nr) = @_; |
291 |
return unless defined($l); |
# return unless defined($l); |
292 |
return $l unless ($rec_regex && $f_nr); |
# return $l unless ($rec_regex && $f_nr); |
293 |
|
|
294 |
|
$log->debug("-=> $f_nr ## $l"); |
295 |
|
|
296 |
|
# codepage conversion and recode_regex |
297 |
|
# from_to($l, $code_page, $self->{'encoding'}); |
298 |
|
from_to($l, $code_page, 'utf-8'); |
299 |
|
$l =~ s/($recode_regex)/$recode_map->{$1}/g if ($recode_regex && $recode_map); |
300 |
|
|
301 |
# apply regexps |
# apply regexps |
302 |
if ($rec_regex && defined($rec_regex->{$f_nr})) { |
if ($rec_regex && defined($rec_regex->{$f_nr})) { |
309 |
} |
} |
310 |
} |
} |
311 |
|
|
312 |
|
$log->debug("<=- $f_nr ## $l"); |
313 |
return $l; |
return $l; |
314 |
}); |
}); |
315 |
|
|