/[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 515 by dpavlin, Tue May 16 15:23:05 2006 UTC revision 640 by dpavlin, Wed Sep 6 19:52:36 2006 UTC
# Line 69  sub new { Line 69  sub new {
69    
70          foreach my $l (split(/[\n\r]+/, $v_file)) {          foreach my $l (split(/[\n\r]+/, $v_file)) {
71                  $curr_line++;                  $curr_line++;
72                  # skip comments  
73                  next if ($l =~ m/^#/);                  # skip comments and whitespaces
74                    next if ($l =~ /^#/ || $l =~ /^\s*$/);
75    
76                  $l =~ s/^\s+//;                  $l =~ s/^\s+//;
77                  $l =~ s/\s+$//;                  $l =~ s/\s+$//;
78    
79                  my @d = split(/\s+/, $l);                  my @d = split(/\s+/, $l);
80    
81                  my $fld = shift @d || $log->logdie("need field name in line $curr_line: $l");                  my $fld = shift @d;
82    
83                    $log->logdie("need field name in line $curr_line: $l") unless (defined($fld));
84    
85                  if (@d) {                  if (@d) {
86                          $v->{$fld} = \@d;                          $v->{$fld} = \@d;
# Line 91  sub new { Line 94  sub new {
94    
95          $self->{rules} = $v;          $self->{rules} = $v;
96    
97            $log->info("validation uses rules from $self->{path}");
98    
99          $self ? return $self : return undef;          $self ? return $self : return undef;
100  }  }
101    
# Line 118  sub validate_errors { Line 123  sub validate_errors {
123    
124          foreach my $f (keys %{ $rec }) {          foreach my $f (keys %{ $rec }) {
125    
126                  next if (!defined($f) || $f eq '');                  next if (!defined($f) || $f eq '' || $f eq '000');
127    
128                  if (! defined($r->{$f})) {                  if (! defined($r->{$f})) {
129                          push @errors, "field '$f' shouldn't exists";                          push @errors, "field '$f' shouldn't exists";
# Line 141  sub validate_errors { Line 146  sub validate_errors {
146                                          foreach my $sf (keys %{ $v }) {                                          foreach my $sf (keys %{ $v }) {
147                                                  # permited subfield?                                                  # permited subfield?
148                                                  if (! first { $_ eq $sf } @{ $r->{$f} }) {                                                  if (! first { $_ eq $sf } @{ $r->{$f} }) {
149                                                          push @errors, "$f has unknown subfield: $sf";                                                          push @errors, "$f has unknown subfield: $sf" if ($sf ne 'subfields');
150                                                  }                                                  }
151                                          }                                          }
152                                  }                                  }

Legend:
Removed from v.515  
changed lines
  Added in v.640

  ViewVC Help
Powered by ViewVC 1.1.26