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

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

revision 340 by dpavlin, Mon Jan 2 10:58:26 2006 UTC revision 364 by dpavlin, Sun Jan 8 20:27:11 2006 UTC
# Line 194  sub data_structure { Line 194  sub data_structure {
194                          $log->logdie("expected tag HASH and got $tag") unless (ref($tag) eq 'HASH');                          $log->logdie("expected tag HASH and got $tag") unless (ref($tag) eq 'HASH');
195                          $format = $tag->{'value'} || $tag->{'content'};                          $format = $tag->{'value'} || $tag->{'content'};
196    
                         $log->debug("format: $format");  
   
197                          my @v;                          my @v;
198                          if ($self->{'lookup_regex'} && $format =~ $self->{'lookup_regex'}) {                          if ($self->{'lookup_regex'} && $format =~ $self->{'lookup_regex'}) {
199                                  @v = $self->fill_in_to_arr($rec,$format);                                  @v = $self->fill_in_to_arr($rec,$format);
200                          } else {                          } else {
201                                  @v = $self->parse_to_arr($rec,$format);                                  @v = $self->parse_to_arr($rec,$format);
202                          }                          }
203                          next if (! @v);                          if (! @v) {
204                                    $log->debug("$field <",$self->{tag},"> format: $format no values");
205    #                               next;
206                            } else {
207                                    $log->debug("$field <",$self->{tag},"> format: $format values: ", join(",", @v));
208                            }
209    
210                          if ($tag->{'sort'}) {                          if ($tag->{'sort'}) {
211                                  @v = $self->sort_arr(@v);                                  @v = $self->sort_arr(@v);
# Line 225  sub data_structure { Line 228  sub data_structure {
228    
229                          foreach my $type (@types) {                          foreach my $type (@types) {
230                                  # append to previous line?                                  # append to previous line?
231                                  $log->debug("type: $type ",sub { join(" ",@v) }, " ", $row->{'append'} || 'no append');                                  $log->debug("tag $field / $type [",sub { join(",",@v) }, "] ", $row->{'append'} || 'no append');
232                                  if ($tag->{'append'}) {                                  if ($tag->{'append'}) {
233    
234                                          # I will delimit appended part with                                          # I will delimit appended part with
# Line 358  sub parse { Line 361  sub parse {
361                          $found_any->{$fld_type} += $found;                          $found_any->{$fld_type} += $found;
362    
363                          # we will skip delimiter before first occurence of field!                          # we will skip delimiter before first occurence of field!
364                          push @out, $del unless($found_any == 1);                          push @out, $del unless($found_any->{$fld_type} == 1);
365                          push @out, $tmp;                          push @out, $tmp;
366                  }                  }
367                  $f_step++;                  $f_step++;
# Line 494  sub fill_in { Line 497  sub fill_in {
497          if ($format =~ s/v(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,$i,\$found)/ges) {          if ($format =~ s/v(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,$i,\$found)/ges) {
498                  $just_single = 0;                  $just_single = 0;
499          }          }
500            
501          # non-repeatable fields          # non-repeatable fields
502          if ($format =~ s/s(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,0,\$found)/ges) {          if ($format =~ s/s(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,0,\$found)/ges) {
503                  return if ($i > 0 && $just_single);                  return if ($i > 0 && $just_single);
# Line 553  sub fill_in_to_arr { Line 556  sub fill_in_to_arr {
556          my $i = 0;          my $i = 0;
557          my @arr;          my @arr;
558    
559          while (my @v = $self->fill_in($rec,$format_utf8,$i++)) {          while (my $v = $self->fill_in($rec,$format_utf8,$i++)) {
560                  push @arr, @v;                  push @arr, $v;
561          }          }
562    
563          $log->debug("format '$format_utf8' returned ",--$i," elements: ", sub { join(" | ",@arr) }) if (@arr);          $log->debug("format '$format_utf8' returned ",--$i," elements: ", sub { join(" | ",@arr) }) if (@arr);
# Line 600  sub get_data { Line 603  sub get_data {
603                          if ($$rec->{$f}->[$i] =~ /HASH/o) {                          if ($$rec->{$f}->[$i] =~ /HASH/o) {
604                                  my $out;                                  my $out;
605                                  foreach my $k (keys %{$$rec->{$f}->[$i]}) {                                  foreach my $k (keys %{$$rec->{$f}->[$i]}) {
606                                          $out .= $$rec->{$f}->[$i]->{$k}." ";                                          my $v = $$rec->{$f}->[$i]->{$k};
607                                            $out .= "$v " if ($v);
608                                  }                                  }
609                                  return $out;                                  return $out;
610                          } else {                          } else {

Legend:
Removed from v.340  
changed lines
  Added in v.364

  ViewVC Help
Powered by ViewVC 1.1.26