/[webpac2]/trunk/lib/WebPAC/Normalize/MARC.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/Normalize/MARC.pm

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

revision 1029 by dpavlin, Sun Nov 11 17:11:33 2007 UTC revision 1031 by dpavlin, Sun Nov 11 19:58:57 2007 UTC
# Line 12  use Carp qw/confess/; Line 12  use Carp qw/confess/;
12    
13  use WebPAC::Normalize;  use WebPAC::Normalize;
14    
15  my $debug = 1;  my $debug = 0;
16    
17  =head1 NAME  =head1 NAME
18    
# Line 164  sub marc_template { Line 164  sub marc_template {
164                          my $template = $_template->{$name}->{pos}->{ $ckey } || next;                          my $template = $_template->{$name}->{pos}->{ $ckey } || next;
165                          $processed_templates++;                          $processed_templates++;
166    
167                          warn "### traverse $name $count_name selected template: |$template|\n",$/ if $debug;                          warn "### traverse $name $count_name selected template: |$template|\n" if $debug;
168    
169                          our $fill_in = {};                          our $fill_in = {};
170    
171                          my @templates = split(/\|/, $template );                          my @templates = split(/\|/, $template );
172                          @templates = ( $template );                          @templates = ( $template ) unless @templates;
173    
174                            warn "### templates = ",dump( @templates );
175    
176                          foreach my $sf ( @templates ) {                          foreach my $sf ( @templates ) {
177                                  sub fill_in {                                  sub fill_in {
178                                          my ( $name, $r, $sf, $nr ) = @_;                                          my ( $name, $r, $pre, $sf, $nr, $post ) = @_;
179                                            warn "#### fill_in( $name, r, '$pre', $sf, $nr, '$post' )\n" if $debug;
180                                          my ( $from_sf, $from_nr );                                          my ( $from_sf, $from_nr );
181                                          if ( $name eq 'marc' ) {                                          if ( $name eq 'marc' ) {
182                                                  die "no $sf/$nr in to_mapping: ",dump( $to_mapping ), " form record ",dump( $r ) unless defined $to_mapping->{$sf}->[$nr];                                                  die "no $sf/$nr in to_mapping: ",dump( $to_mapping ), " form record ",dump( $r ) unless defined $to_mapping->{$sf}->[$nr];
# Line 182  sub marc_template { Line 185  sub marc_template {
185                                                  ( $from_sf, $from_nr ) = ( $sf, $nr );                                                  ( $from_sf, $from_nr ) = ( $sf, $nr );
186                                          }                                          }
187                                          my $v = $r->{ $from_sf }; # || die "no $from_sf/$from_nr";                                          my $v = $r->{ $from_sf }; # || die "no $from_sf/$from_nr";
                                         warn "#### fill_in( $sf, $nr ) = $from_sf/$from_nr >>>> ",dump( $v ),$/ if $debug;  
188                                          if ( ref( $v ) eq 'ARRAY' ) {                                          if ( ref( $v ) eq 'ARRAY' ) {
189                                                  $fill_in->{$sf}->[$nr] = $v->[$from_nr];                                                  $v = $pre . $v->[$from_nr] . $post;
                                                 return $v->[$from_nr];  
190                                          } elsif ( $from_nr == 0 ) {                                          } elsif ( $from_nr == 0 ) {
191                                                  $fill_in->{$sf}->[$nr] = $v;                                                  $v = $pre . $v . $post;
                                                 return $v;  
192                                          } else {                                          } else {
193                                                  die "requested subfield $from_sf/$from_nr but it's ",dump( $v );                                                  die "requested subfield $from_sf/$from_nr but it's ",dump( $v );
194                                          }                                          }
195                                            warn "#### fill_in( $sf, $nr ) = $from_sf/$from_nr >>>> ",dump( $v ),$/ if $debug;
196                                            $fill_in->{$sf}->[$nr] = $v;
197                                            return $v;
198                                  }                                  }
199                                  my $fields_re = $_template->{$name}->{fields_re} || die "can't find $name in ",dump( $_template->{$name}->{fields_re} );                                  my $fields_re = $_template->{$name}->{fields_re} || die "can't find $name in ",dump( $_template->{$name}->{fields_re} );
200                                  warn "#### $sf <<<< $fields_re\n",$/ if $debug;                                  warn "#### $sf <<<< $fields_re\n" if $debug;
201                                  $sf =~ s/($fields_re)(\d+)/fill_in($name,$r,$1,$2)/ge;                                  $sf =~ s/^(.*?)($fields_re)(\d+)(.*?)$/fill_in($name,$r,$1,$2,$3,$4)/ge;
202                                  warn "#### >>>> $sf with fill_in = ",dump( $fill_in ),$/ if $debug;                                  warn "#### >>>> $sf with fill_in = ",dump( $fill_in ),$/ if $debug;
203                          }                          }
204    

Legend:
Removed from v.1029  
changed lines
  Added in v.1031

  ViewVC Help
Powered by ViewVC 1.1.26