/[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 645 by dpavlin, Wed Sep 6 22:07:21 2006 UTC revision 646 by dpavlin, Wed Sep 6 22:42:37 2006 UTC
# Line 18  WebPAC::Validate - provide simple valida Line 18  WebPAC::Validate - provide simple valida
18    
19  =head1 VERSION  =head1 VERSION
20    
21  Version 0.03  Version 0.04
22    
23  =cut  =cut
24    
25  our $VERSION = '0.03';  our $VERSION = '0.04';
26    
27  =head1 SYNOPSIS  =head1 SYNOPSIS
28    
# Line 91  sub new { Line 91  sub new {
91                  $log->logdie("need field name in line $curr_line: $l") unless (defined($fld));                  $log->logdie("need field name in line $curr_line: $l") unless (defined($fld));
92    
93                  if (@d) {                  if (@d) {
94                          $v->{$fld} = \@d;                          $v->{$fld} = [ map {
95                                    my $sf = $_;
96                                    if ( $sf =~ s/!(\*)?$/$1/ ) {
97                                            $self->{must_exist_sf}->{ $fld }->{ $sf }++;
98                                    };
99                                    $sf;
100                            } @d ];
101                  } else {                  } else {
102                          $v->{$fld} = 1;                          $v->{$fld} = 1;
103                  }                  }
# Line 163  sub validate_errors { Line 169  sub validate_errors {
169    
170                                          delete($v->{subfields}) if (defined($v->{subfields}));                                          delete($v->{subfields}) if (defined($v->{subfields}));
171    
172                                            my $subfields;
173    
174                                          foreach my $sf (keys %{ $v }) {                                          foreach my $sf (keys %{ $v }) {
175    
176                                                    $subfields->{ $sf }++;
177    
178                                                  # is non-repeatable but with multiple values?                                                  # is non-repeatable but with multiple values?
179                                                  if ( ! first { $_ eq $sf.'*' } @{$r->{$f}} ) {                                                  if ( ! first { $_ eq $sf.'*' } @{$r->{$f}} ) {
180                                                          if ( ref($v->{$sf}) eq 'ARRAY' ) {                                                          if ( ref($v->{$sf}) eq 'ARRAY' ) {
# Line 186  sub validate_errors { Line 196  sub validate_errors {
196                                                  'repeatable in: ' .                                                  'repeatable in: ' .
197                                                  join('', _pack_subfields_hash( $h, 1) );                                                  join('', _pack_subfields_hash( $h, 1) );
198                                          }                                          }
199    
200                                            if ( defined( $self->{must_exist_sf}->{$f} ) ) {
201                                                    foreach my $sf (sort keys %{ $self->{must_exist_sf}->{$f} }) {
202    warn "====> $f $sf must exist\n";
203                                                            push @errors, "$f missing required subfield $sf"
204                                                                    unless (
205                                                                            defined( $subfields->{$f} ) &&
206                                                                            defined( $subfields->{$f}->{$sf} )
207                                                                    )
208                                                    }
209                                            }
210    
211                                  }                                  }
212                          } elsif (ref($v) eq 'HASH') {                          } elsif (ref($v) eq 'HASH') {
213                                  push @errors, "$f has subfields which is not valid";                                  push @errors, "$f has subfields which is not valid";

Legend:
Removed from v.645  
changed lines
  Added in v.646

  ViewVC Help
Powered by ViewVC 1.1.26