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

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

revision 832 by dpavlin, Wed May 23 20:03:16 2007 UTC revision 836 by dpavlin, Thu May 24 12:44:43 2007 UTC
# Line 160  sub validate_rec { Line 160  sub validate_rec {
160                  if ( my $regex = $self->{delimiters_regex} ) {                  if ( my $regex = $self->{delimiters_regex} ) {
161    
162                          foreach my $v (@{ $rec->{$f} }) {                          foreach my $v (@{ $rec->{$f} }) {
163                                          my $l = _pack_subfields_hash( $v, 1 );                                  my $l = _pack_subfields_hash( $v, 1 );
164                                          my $template = '';                                  my $subfield_dump = $l;
165                                          $l =~ s/$regex/$template.=$1/eg;                                  my $template = '';
166  #                                       warn "## template: $template\n";                                  $l =~ s/$regex/$template.=$1/eg;
167                                          $self->{_delimiters_templates}->{$f}->{$template}++ if ( $template );                                  #warn "## template: $template\n";
168    
169                                    if ( $template ) {
170                                            $self->{_delimiters_templates}->{$f}->{$template}++;
171    
172                                            if ( my $v = $self->{_validate_delimiters_templates} ) {
173                                                    if ( ! defined( $v->{$template} ) ) {
174                                                            $errors->{$f}->{invalid_delimiters_combination} = $template;
175                                                            $errors->{$f}->{dump} = $subfield_dump;
176                                                    } else {
177                                                            warn "## $f $template ok\n";
178                                                    }
179                                            }
180                                    }
181                          }                          }
   
182                  }                  }
183    
184                  next if (defined( $self->{dont_validate}->{$f} ));                  next if (defined( $self->{dont_validate}->{$f} ));
# Line 326  sub report_error { Line 338  sub report_error {
338    
339                          if ($k eq 'dump') {                          if ($k eq 'dump') {
340                                  $dump = $tree->{dump};                                  $dump = $tree->{dump};
341  #                               warn "## dump: ",dump($dump),"\n";                                  #warn "## dump ",dump($dump),"\n";
342                                  next;                                  next;
343                          }                          }
344    
# Line 360  sub report_error { Line 372  sub report_error {
372          sub _reformat {          sub _reformat {
373                  my $l = shift;                  my $l = shift;
374                  $l =~ s/\t/ /g;                  $l =~ s/\t/ /g;
375                  $l =~ s/_/ /;                  $l =~ s/_/ /g;
376                  return $l;                  return $l;
377          }          }
378    
# Line 407  sub report { Line 419  sub report {
419    
420  =head2 delimiters_templates  =head2 delimiters_templates
421    
422    Generate report of delimiter tamplates
423    
424      my $report = $validate->delimiter_teplates(
425            report => 1,
426      );
427    
428    Options:
429    
430    =over 4
431    
432    =item report
433    
434    Generate humanly readable report with single fields
435    
436    =back
437    
438  =cut  =cut
439    
440  sub delimiters_templates {  sub delimiters_templates {
441          my $self = shift;          my $self = shift;
442    
443            my $args = {@_};
444    
445          my $t = $self->{_delimiters_templates};          my $t = $self->{_delimiters_templates};
446    
447          my $log = $self->_get_logger;          my $log = $self->_get_logger;
448    
449          unless ($t) {          unless ($t) {
450                  $log->warn("called without delimiters");                  $log->error("called without delimiters");
451                  return;                  return;
452          }          }
453    
454          my $out;          my $out;
455    
456          foreach my $f (sort { $a <=> $b } keys %$t) {          foreach my $f (sort { $a <=> $b } keys %$t) {
457                  $out .= "$f\n";                  $out .= "$f\n" if ( $args->{report} );
458                  foreach my $sft (sort { $a cmp $b } keys %{ $t->{$f} }) {                  foreach my $template (sort { $a cmp $b } keys %{ $t->{$f} }) {
459                          $out .= "\t" . $t->{$f}->{$sft} . "\t$sft\n";                          my $count = $t->{$f}->{$template};
460                            $out .=
461                                    ( $count ? "" : "# " ) .
462                                    ( $args->{report} ? "" : "$f" ) .
463                                    "\t$count\t$template\n";
464                  }                  }
465          }          }
466    

Legend:
Removed from v.832  
changed lines
  Added in v.836

  ViewVC Help
Powered by ViewVC 1.1.26