--- trunk/lib/WebPAC/Validate.pm 2006/09/07 15:01:45 652 +++ trunk/lib/WebPAC/Validate.pm 2006/09/07 15:57:48 653 @@ -117,7 +117,7 @@ Validate record and return errors - my @errors = $validate->validate_errors( $rec ); + my @errors = $validate->validate_errors( $rec, $rec_dump ); =cut @@ -127,6 +127,7 @@ my $log = $self->_get_logger(); my $rec = shift || $log->logdie("validate_errors need record"); + my $rec_dump = shift; $log->logdie("rec isn't HASH") unless (ref($rec) eq 'HASH'); $log->logdie("can't find validation rules") unless (my $r = $self->{rules}); @@ -160,9 +161,9 @@ # are values hashes? (has subfields) if (! defined($v)) { $errors->{field}->{$f}->{empty} = undef; - $errors->{dump}->{record}++; + $errors->{dump} = $rec_dump if ($rec_dump); } elsif (ref($v) ne 'HASH') { - $errors->{field}->{$f}->{missing_subfield} = "value without subfields: $v"; + $errors->{field}->{$f}->{missing_subfield} = "subfields required for this field"; next; } else { @@ -184,7 +185,7 @@ $sf_repeatable->{$sf}++; }; if (! first { $_ eq $sf } @{ $r->{$f} }) { - $errors->{field}->{ $f }->{subfield}->{$sf} = "unknown"; + $errors->{field}->{ $f }->{subfield}->{$sf} = "found extra subfield $sf which shouldn't exist"; } } @@ -193,7 +194,7 @@ foreach my $sf (@r_sf) { $errors->{field}->{$f}->{subfield}->{$sf} = "repeatable"; - $errors->{dump}->{field}->{$f} = + $errors->{field}->{$f}->{dump}->{$f} = join('', _pack_subfields_hash( $h, 1 ) ); } @@ -210,7 +211,7 @@ } } elsif (ref($v) eq 'HASH') { $errors->{field}->{$f}->{unexpected_subfields}++; - $errors->{dump}->{field}->{$f} = + $errors->{field}->{$f}->{dump} = join('', _pack_subfields_hash( $v, 1 ) ); } } @@ -219,13 +220,13 @@ foreach my $must (sort keys %{ $self->{must_exist} }) { next if ($fields->{$must}); $errors->{field}->{$must}->{missing}++; - $errors->{dump}->{record}++; + $errors->{dump} = $rec_dump if ($rec_dump); } if ($errors) { $log->debug("errors: ", sub { dump( $errors ) } ); - my $mfn = $rec->{'000'}->[0]; + my $mfn = $rec->{'000'}->[0] || $log->logconfess("record ", dump( $rec ), " doesn't have MFN"); $self->{errors}->{$mfn} = $errors; } @@ -234,6 +235,32 @@ return $errors; } +=head2 reset_errors + +Clean all accumulated errors for this input + + $validate->reset_errors; + +=cut + +sub reset_errors { + my $self = shift; + delete ($self->{errors}); +} + +=head2 all_errors + +Return hash with all errors + + print dump( $validate->all_errors ); + +=cut + +sub all_errors { + my $self = shift; + return $self->{errors}; +} + =head1 AUTHOR Dobrica Pavlinusic, C<< >>