--- trunk/lib/WebPAC/Validate.pm 2006/09/11 14:29:08 670 +++ trunk/lib/WebPAC/Validate.pm 2006/09/11 15:59:35 671 @@ -222,7 +222,7 @@ } if ($errors) { - $log->debug("errors: ", sub { dump( $errors ) } ); + $log->debug("errors: ", $self->report_error( $errors ) ); my $mfn = $rec->{'000'}->[0] || $log->logconfess("record ", dump( $rec ), " doesn't have MFN"); $self->{errors}->{$mfn} = $errors; @@ -259,18 +259,20 @@ return $self->{errors}; } -=head2 report +=head2 report_error -Produce nice humanly readable report of errors +Produce nice humanly readable report of single error - print $validate->report; + print $validate->report_error( $error_hash ); =cut -sub report { +sub report_error { my $self = shift; - sub unroll { + my $h = shift || die "no hash?"; + + sub _unroll { my ($self, $tree, $accumulated) = @_; my $log = $self->_get_logger(); @@ -298,7 +300,7 @@ $log->debug("current: $k"); - my ($new_results, $new_dump) = $self->unroll($tree->{$k}, + my ($new_results, $new_dump) = $self->_unroll($tree->{$k}, $accumulated ? "$accumulated\t$k" : $k ); @@ -322,37 +324,53 @@ } } - my $log = $self->_get_logger(); - - my $out = ''; - my $e = $self->{errors} || return; - sub reformat { + sub _reformat { my $l = shift; $l =~ s/\t/ /g; $l =~ s/_/ /; return $l; } - foreach my $mfn (sort keys %$e) { - $out .= "MFN $mfn\n"; + my $out = ''; - for my $f (sort keys %{ $e->{$mfn} }) { - my ($r, $d) = $self->unroll( $e->{$mfn}->{$f} ); - my $e = $f . ': '; - if (ref($r) eq 'ARRAY') { - $e .= join(", ", map { reformat( $_ ) } @$r); - } else { - $e .= reformat( $r ); - } - $e .= "\n\t$d" if ($d); - $e .= "\n"; - $log->debug("MFN $mfn | $e"); - $out .= $e; + for my $f (sort keys %{ $h }) { + $out .= "$f: "; + + my ($r, $d) = $self->_unroll( $h->{$f} ); + my $e; + if (ref($r) eq 'ARRAY') { + $e .= join(", ", map { _reformat( $_ ) } @$r); + } else { + $e .= _reformat( $r ); } + $e .= "\n\t$d" if ($d); + + $out .= $e . "\n"; + } + return $out; +} + + +=head2 report + +Produce nice humanly readable report of errors + + print $validate->report; + +=cut + +sub report { + my $self = shift; + my $e = $self->{errors} || return; + + my $out; + foreach my $mfn (sort { $a <=> $b } keys %$e) { + $out .= "MFN $mfn\n" . $self->report_error( $e->{$mfn} ) . "\n"; } return $out; + } =head1 AUTHOR