r802@llin: dpavlin | 2006-07-04 13:36:05 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 4 Jul 2006 11:36:21 +0000 (11:36 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 4 Jul 2006 11:36:21 +0000 (11:36 +0000)
 added MARC lint warning summary

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@582 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Output/MARC.pm

index 7d0ea31..8c43371 100644 (file)
@@ -72,8 +72,12 @@ sub new {
        id => $mfn,
        fields => WebPAC::Normalize::_get_marc_fields(),
        leader => WebPAC::Normalize::marc_leader(),
+       row => $row,
   );
 
+C<row> is optional parametar which is used when dumping original row to
+error log.
+
 =cut
 
 sub add {
@@ -110,12 +114,15 @@ sub add {
 
        if ($self->{lint}) {
                $self->{lint}->check_record( $marc );
-               my $err = join( "\n", $self->{lint}->warnings );
-               $log->error("MARC lint detected warning on record $id\n",
-                       "<<<<< Original imput row:\n",dump($arg->{row}), "\n",
-                       ">>>>> Normalized MARC row: leader: [", $marc->leader(), "]\n", dump( $arg->{fields} ), "\n",
-                       "!!!!! MARC lint warnings:\n",$err,"\n"
-               ) if ($err);
+               my @w = $self->{lint}->warnings;
+               if (@w) {
+                       $log->error("MARC lint detected warning on record $id\n",
+                               "<<<<< Original imput row:\n",dump($arg->{row}), "\n",
+                               ">>>>> Normalized MARC row: leader: [", $marc->leader(), "]\n", dump( $arg->{fields} ), "\n",
+                               "!!!!! MARC lint warnings:\n",join("\n",@w),"\n"
+                       );
+                       map { $self->{_marc_lint_warnings}->{$_}++ } @w;
+               }
        }
 
        if ($self->{dump}) {
@@ -135,12 +142,25 @@ Close MARC output file
 
   $marc->finish;
 
+It will also dump MARC lint warnings summary if called with C<lint>.
+
 =cut
 
 sub finish {
        my $self = shift;
 
-       close( $self->{fh} ) or $self->_get_logger->logdie("can't close ", $self->{path}, ": $!");
+       my $log = $self->get_logger;
+
+       close( $self->{fh} ) or $log->logdie("can't close ", $self->{path}, ": $!");
+
+       if (my $w = $self->{_marc_lint_warnings}) {
+               $log->error("MARC lint warnings summary:\n",
+                       join ("\n",
+                               map { $w->{$_} . "\t" . $_ }
+                               sort { $w->{$b} <=> $w->{$a} } keys %$w
+                       )
+               );
+       }
 }
 
 =head1 AUTHOR