/[webpac2]/trunk/lib/WebPAC/Input.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WebPAC/Input.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 800 by dpavlin, Sun Feb 4 23:10:18 2007 UTC revision 868 by dpavlin, Thu Jun 21 21:26:17 2007 UTC
# Line 16  WebPAC::Input - read different file form Line 16  WebPAC::Input - read different file form
16    
17  =head1 VERSION  =head1 VERSION
18    
19  Version 0.17  Version 0.18
20    
21  =cut  =cut
22    
23  our $VERSION = '0.17';  our $VERSION = '0.18';
24    
25  =head1 SYNOPSIS  =head1 SYNOPSIS
26    
# Line 64  Create new input database object. Line 64  Create new input database object.
64          encoding => 'ISO-8859-2',          encoding => 'ISO-8859-2',
65          recode => 'char pairs',          recode => 'char pairs',
66          no_progress_bar => 1,          no_progress_bar => 1,
67            input_config => {
68                    mapping => [ 'foo', 'bar', 'baz' ],
69            },
70    );    );
71    
72  C<module> is low-level file format module. See L<WebPAC::Input::ISIS> and  C<module> is low-level file format module. See L<WebPAC::Input::ISIS> and
# Line 233  sub open { Line 236  sub open {
236    
237          my $ll_db = $class->new(          my $ll_db = $class->new(
238                  path => $arg->{path},                  path => $arg->{path},
239                    input_config => $arg->{input_config},
240  #               filter => sub {  #               filter => sub {
241  #                       my ($l,$f_nr) = @_;  #                       my ($l,$f_nr) = @_;
242  #                       return unless defined($l);  #                       return unless defined($l);
# Line 286  sub open { Line 290  sub open {
290  #                               return unless defined($l);  #                               return unless defined($l);
291  #                               return $l unless ($rec_regex && $f_nr);  #                               return $l unless ($rec_regex && $f_nr);
292    
293                                    return unless ( defined($l) && defined($f_nr) );
294    
295                                  warn "-=> $f_nr ## |$l|\n" if ($debug);                                  warn "-=> $f_nr ## |$l|\n" if ($debug);
296                                  $log->debug("-=> $f_nr ## $l");                                  $log->debug("-=> $f_nr ## $l");
297    
# Line 517  sub stats { Line 523  sub stats {
523    
524          my $out = join("\n",          my $out = join("\n",
525                  map {                  map {
526                          my $f = $_ || die "no field";                          my $f = $_;
527                            die "no field in ", dump( $s->{fld} ) unless defined( $f );
528                          my $v = $s->{fld}->{$f} || die "no s->{fld}->{$f}";                          my $v = $s->{fld}->{$f} || die "no s->{fld}->{$f}";
529                          $max_fld = $v if ($v > $max_fld);                          $max_fld = $v if ($v > $max_fld);
530    
# Line 537  sub stats { Line 544  sub stats {
544                          }                          }
545    
546                          $o;                          $o;
547                  } sort { $a cmp $b } keys %{ $s->{fld} }                  } sort { $a <=> $b } keys %{ $s->{fld} }
548          );          );
549    
550          $log->debug( sub { dump($s) } );          $log->debug( sub { dump($s) } );
# Line 556  sub dump_ascii { Line 563  sub dump_ascii {
563    
564          return unless $self->{ll_db};          return unless $self->{ll_db};
565    
566          if ($self->{ll_db}->can('dump_rec')) {          if ($self->{ll_db}->can('dump_ascii')) {
567                  return $self->{ll_db}->dump_ascii( $self->{pos} );                  return $self->{ll_db}->dump_ascii( $self->{pos} );
568          } else {          } else {
569                  return dump( $self->{ll_db}->fetch_rec( $self->{pos} ) );                  return dump( $self->{ll_db}->fetch_rec( $self->{pos} ) );
570          }          }
571  }  }
572    
573  =head2 modify_record_regexps  =head2 _get_regex
574    
575  Generate hash with regexpes to be applied using L<filter>.  Helper function called which create regexps to be execute on code.
576    
577    my $regexpes = $input->modify_record_regexps(    _get_regex( 900, 'regex:[0-9]+' ,'numbers' );
578                  900 => { '^a' => { ' : ' => '^b' } },    _get_regex( 900, '^b', ' : ^b' );
579                  901 => { '*' => { '^b' => ' ; ' } },  
580    );  It supports perl regexps with C<regex:> prefix to from value and has
581    additional logic to skip empty subfields.
582    
583  =cut  =cut
584    
# Line 587  sub _get_regex { Line 595  sub _get_regex {
595                  $from = '\Q' . $from . '\E';                  $from = '\Q' . $from . '\E';
596          }          }
597          if ($sf =~ /^\^/) {          if ($sf =~ /^\^/) {
598                    my $need_subfield_data = '*';   # no
599                    # if from is also subfield, require some data in between
600                    # to correctly skip empty subfields
601                    $need_subfield_data = '+' if ($from =~ m/^\\Q\^/);
602                  return                  return
603                          's/\Q'. $sf .'\E([^\^]*?)'. $from .'([^\^]*?)/'. $sf .'$1'. $to .'$2/';                          's/\Q'. $sf .'\E([^\^]' . $need_subfield_data . '?)'. $from .'([^\^]*?)/'. $sf .'$1'. $to .'$2/';
604          } else {          } else {
605                  return                  return
606                          's/'. $from .'/'. $to .'/g';                          's/'. $from .'/'. $to .'/g';
607          }          }
608  }  }
609    
610    
611    =head2 modify_record_regexps
612    
613    Generate hash with regexpes to be applied using L<filter>.
614    
615      my $regexpes = $input->modify_record_regexps(
616                    900 => { '^a' => { ' : ' => '^b' } },
617                    901 => { '*' => { '^b' => ' ; ' } },
618      );
619    
620    =cut
621    
622  sub modify_record_regexps {  sub modify_record_regexps {
623          my $self = shift;          my $self = shift;
624          my $modify_record = {@_};          my $modify_record = {@_};

Legend:
Removed from v.800  
changed lines
  Added in v.868

  ViewVC Help
Powered by ViewVC 1.1.26