7 |
|
|
8 |
use WebPAC::Common; |
use WebPAC::Common; |
9 |
use base qw/WebPAC::Common/; |
use base qw/WebPAC::Common/; |
10 |
use Data::Dumper; |
use Data::Dump qw/dump/; |
11 |
use Encode qw/from_to/; |
use Encode qw/from_to/; |
12 |
|
|
13 |
=head1 NAME |
=head1 NAME |
16 |
|
|
17 |
=head1 VERSION |
=head1 VERSION |
18 |
|
|
19 |
Version 0.14 |
Version 0.17 |
20 |
|
|
21 |
=cut |
=cut |
22 |
|
|
23 |
our $VERSION = '0.14'; |
our $VERSION = '0.17'; |
24 |
|
|
25 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
26 |
|
|
102 |
|
|
103 |
require $module_path; |
require $module_path; |
104 |
|
|
|
# check if required subclasses are implemented |
|
|
foreach my $subclass (qw/open_db fetch_rec init dump_rec/) { |
|
|
# FIXME |
|
|
} |
|
|
|
|
105 |
$self->{'encoding'} ||= 'ISO-8859-2'; |
$self->{'encoding'} ||= 'ISO-8859-2'; |
106 |
|
|
107 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
224 |
$log->debug("using modify_file $p"); |
$log->debug("using modify_file $p"); |
225 |
$rec_regex = $self->modify_file_regexps( $p ); |
$rec_regex = $self->modify_file_regexps( $p ); |
226 |
} elsif (my $h = $arg->{modify_records}) { |
} elsif (my $h = $arg->{modify_records}) { |
227 |
$log->debug("using modify_records ", Dumper( $h )); |
$log->debug("using modify_records ", sub { dump( $h ) }); |
228 |
$rec_regex = $self->modify_record_regexps(%{ $h }); |
$rec_regex = $self->modify_record_regexps(%{ $h }); |
229 |
} |
} |
230 |
$log->debug("rec_regex: ", Dumper($rec_regex)) if ($rec_regex); |
$log->debug("rec_regex: ", sub { dump($rec_regex) }) if ($rec_regex); |
231 |
|
|
232 |
my $class = $self->{module} || $log->logconfess("can't get low-level module name!"); |
my $class = $self->{module} || $log->logconfess("can't get low-level module name!"); |
233 |
|
|
310 |
return $l; |
return $l; |
311 |
}); |
}); |
312 |
|
|
313 |
$log->debug(sub { Dumper($rec) }); |
$log->debug(sub { dump($rec) }); |
314 |
|
|
315 |
if (! $rec) { |
if (! $rec) { |
316 |
$log->warn("record $pos empty? skipping..."); |
$log->warn("record $pos empty? skipping..."); |
469 |
|
|
470 |
sub seek { |
sub seek { |
471 |
my $self = shift; |
my $self = shift; |
472 |
my $pos = shift || return; |
my $pos = shift; |
473 |
|
|
474 |
my $log = $self->_get_logger(); |
my $log = $self->_get_logger(); |
475 |
|
|
476 |
|
$log->logconfess("called without pos") unless defined($pos); |
477 |
|
|
478 |
if ($pos < 1) { |
if ($pos < 1) { |
479 |
$log->warn("seek before first record"); |
$log->warn("seek before first record"); |
480 |
$pos = 1; |
$pos = 1; |
532 |
} sort { $a cmp $b } keys %{ $s->{fld} } |
} sort { $a cmp $b } keys %{ $s->{fld} } |
533 |
); |
); |
534 |
|
|
535 |
$log->debug( sub { Dumper($s) } ); |
$log->debug( sub { dump($s) } ); |
536 |
|
|
537 |
return $out; |
return $out; |
538 |
} |
} |
539 |
|
|
540 |
=head2 dump |
=head2 dump_ascii |
541 |
|
|
542 |
Display humanly readable dump of record |
Display humanly readable dump of record |
543 |
|
|
544 |
=cut |
=cut |
545 |
|
|
546 |
sub dump { |
sub dump_ascii { |
547 |
my $self = shift; |
my $self = shift; |
548 |
|
|
549 |
return $self->{ll_db}->dump_rec( $self->{pos} ); |
return unless $self->{ll_db}; |
550 |
|
|
551 |
|
if ($self->{ll_db}->can('dump_rec')) { |
552 |
|
return $self->{ll_db}->dump_ascii( $self->{pos} ); |
553 |
|
} else { |
554 |
|
return dump( $self->{ll_db}->fetch_rec( $self->{pos} ) ); |
555 |
|
} |
556 |
} |
} |
557 |
|
|
558 |
=head2 modify_record_regexps |
=head2 modify_record_regexps |
568 |
|
|
569 |
sub _get_regex { |
sub _get_regex { |
570 |
my ($sf,$from,$to) = @_; |
my ($sf,$from,$to) = @_; |
571 |
|
|
572 |
|
# protect / |
573 |
|
$from =~ s!/!\\/!gs; |
574 |
|
$to =~ s!/!\\/!gs; |
575 |
|
|
576 |
|
if ($from =~ m/^regex:(.+)$/) { |
577 |
|
$from = $1; |
578 |
|
} else { |
579 |
|
$from = '\Q' . $from . '\E'; |
580 |
|
} |
581 |
if ($sf =~ /^\^/) { |
if ($sf =~ /^\^/) { |
582 |
return |
return |
583 |
's/\Q'. $sf .'\E([^\^]*?)\Q'. $from .'\E([^\^]*?)/'. $sf .'$1'. $to .'$2/'; |
's/\Q'. $sf .'\E([^\^]*?)'. $from .'([^\^]*?)/'. $sf .'$1'. $to .'$2/'; |
584 |
} else { |
} else { |
585 |
return |
return |
586 |
's/\Q'. $from .'\E/'. $to .'/g'; |
's/'. $from .'/'. $to .'/g'; |
587 |
} |
} |
588 |
} |
} |
589 |
|
|