16 |
|
|
17 |
=head1 VERSION |
=head1 VERSION |
18 |
|
|
19 |
Version 0.12 |
Version 0.13 |
20 |
|
|
21 |
=cut |
=cut |
22 |
|
|
23 |
our $VERSION = '0.12'; |
our $VERSION = '0.13'; |
24 |
|
|
25 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
26 |
|
|
107 |
#eval $self->{module} .'->import'; |
#eval $self->{module} .'->import'; |
108 |
|
|
109 |
# check if required subclasses are implemented |
# check if required subclasses are implemented |
110 |
foreach my $subclass (qw/open_db fetch_rec init/) { |
foreach my $subclass (qw/open_db fetch_rec init dump_rec/) { |
111 |
my $n = $self->{module} . '::' . $subclass; |
my $n = $self->{module} . '::' . $subclass; |
112 |
if (! defined &{ $n }) { |
if (! defined &{ $n }) { |
113 |
my $missing = "missing $subclass in $self->{module}"; |
my $missing = "missing $subclass in $self->{module}"; |
162 |
code_page => 'cp852', |
code_page => 'cp852', |
163 |
limit => 500, |
limit => 500, |
164 |
offset => 6000, |
offset => 6000, |
|
lookup => $lookup_obj, |
|
165 |
stats => 1, |
stats => 1, |
166 |
lookup_ref => sub { |
lookup_coderef => sub { |
167 |
my ($k,$v) = @_; |
my $rec = shift; |
168 |
# store lookup $k => $v |
# store lookups |
169 |
}, |
}, |
170 |
modify_records => { |
modify_records => { |
171 |
900 => { '^a' => { ' : ' => '^b' } }, |
900 => { '^a' => { ' : ' => '^b' } }, |
182 |
|
|
183 |
C<stats> create optional report about usage of fields and subfields |
C<stats> create optional report about usage of fields and subfields |
184 |
|
|
185 |
C<lookup_coderef> is closure to call when adding C<< key => 'value' >> combinations to |
C<lookup_coderef> is closure to called to save data into lookups |
|
lookup. |
|
186 |
|
|
187 |
C<modify_records> specify mapping from subfields to delimiters or from |
C<modify_records> specify mapping from subfields to delimiters or from |
188 |
delimiters to subfields, as well as oprations on fields (if subfield is |
delimiters to subfields, as well as oprations on fields (if subfield is |
207 |
$log->logconfess("lookup_coderef must be CODE, not ",ref($arg->{lookup_coderef})) |
$log->logconfess("lookup_coderef must be CODE, not ",ref($arg->{lookup_coderef})) |
208 |
if ($arg->{lookup_coderef} && ref($arg->{lookup_coderef}) ne 'CODE'); |
if ($arg->{lookup_coderef} && ref($arg->{lookup_coderef}) ne 'CODE'); |
209 |
|
|
210 |
|
$log->debug( $arg->{lookup_coderef} ? '' : 'not ', "using lookup_coderef"); |
211 |
|
|
212 |
$log->logcroak("need path") if (! $arg->{'path'}); |
$log->logcroak("need path") if (! $arg->{'path'}); |
213 |
my $code_page = $arg->{'code_page'} || 'cp852'; |
my $code_page = $arg->{'code_page'} || 'cp852'; |
214 |
|
|
298 |
|
|
299 |
$log->debug("position: $pos\n"); |
$log->debug("position: $pos\n"); |
300 |
|
|
301 |
my $rec = $self->{fetch_rec}->($self, $db, $pos, sub { |
my $rec = $self->{fetch_rec}->($self, $pos, sub { |
302 |
my ($l,$f_nr) = @_; |
my ($l,$f_nr) = @_; |
303 |
# return unless defined($l); |
# return unless defined($l); |
304 |
# return $l unless ($rec_regex && $f_nr); |
# return $l unless ($rec_regex && $f_nr); |
348 |
if ($self->{stats}) { |
if ($self->{stats}) { |
349 |
|
|
350 |
# fetch clean record with regexpes applied for statistics |
# fetch clean record with regexpes applied for statistics |
351 |
my $rec = $self->{fetch_rec}->($self, $db, $pos); |
my $rec = $self->{fetch_rec}->($self, $pos); |
352 |
|
|
353 |
foreach my $fld (keys %{ $rec }) { |
foreach my $fld (keys %{ $rec }) { |
354 |
$self->{_stats}->{fld}->{ $fld }++; |
$self->{_stats}->{fld}->{ $fld }++; |
546 |
return $out; |
return $out; |
547 |
} |
} |
548 |
|
|
549 |
|
=head2 dump |
550 |
|
|
551 |
|
Display humanly readable dump of record |
552 |
|
|
553 |
|
=cut |
554 |
|
|
555 |
|
sub dump { |
556 |
|
my $self = shift; |
557 |
|
|
558 |
|
return $self->{dump_rec}->($self, $self->{pos}); |
559 |
|
|
560 |
|
} |
561 |
|
|
562 |
=head2 modify_record_regexps |
=head2 modify_record_regexps |
563 |
|
|
564 |
Generate hash with regexpes to be applied using l<filter>. |
Generate hash with regexpes to be applied using l<filter>. |
640 |
|
|
641 |
my $regexpes; |
my $regexpes; |
642 |
|
|
643 |
CORE::open(my $fh, $modify_path) || $log->die("can't open modify file $modify_path: $!"); |
CORE::open(my $fh, $modify_path) || $log->logdie("can't open modify file $modify_path: $!"); |
644 |
|
|
645 |
my ($f,$sf); |
my ($f,$sf); |
646 |
|
|