r772@llin: dpavlin | 2006-07-02 22:14:37 +0200
[webpac2] / run.pl
diff --git a/run.pl b/run.pl
index 3ac7fb2..f374abf 100755 (executable)
--- a/run.pl
+++ b/run.pl
@@ -77,6 +77,10 @@ Optional path to output file
 By default turned on if C<--marc-normalize> is used. You can disable lint
 messages with C<--no-marc-lint>.
 
+=item --marc-dump
+
+Force dump or input and marc record for debugging.
+
 =back
 
 =cut
@@ -92,6 +96,7 @@ my $stats = 0;
 my $validate_path;
 my ($marc_normalize, $marc_output);
 my $marc_lint = 1;
+my $marc_dump = 0;
 
 GetOptions(
        "limit=i" => \$limit,
@@ -100,12 +105,13 @@ GetOptions(
        "one=s" => \$only_filter,
        "only=s" => \$only_filter,
        "config" => \$config,
-       "debug" => \$debug,
+       "debug+" => \$debug,
        "stats" => \$stats,
        "validate=s" => \$validate_path,
        "marc-normalize=s" => \$marc_normalize,
        "marc-output=s" => \$marc_output,
        "marc-lint!" => \$marc_lint,
+       "marc-dump!" => \$marc_dump,
 );
 
 $config = LoadFile($config);
@@ -294,7 +300,6 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) {
                                        $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);
                                }
 
-                                       
                                my $ds = WebPAC::Normalize::data_structure(
                                        row => $row,
                                        rules => $rules,
@@ -322,6 +327,20 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) {
                                                $log->warn("MARC record $mfn is empty, skipping");
                                        } else {
                                                $marc->add_fields( @marc_fields );
+
+                                               # tweak leader
+                                               if (my $new_l = WebPAC::Normalize::marc_leader()) {
+
+                                                       my $leader = $marc->leader;
+
+                                                       foreach my $o ( keys %$new_l ) {
+                                                               my $insert = $new_l->{$o};
+                                                               $leader = substr($leader, 0, $o) .
+                                                                       $insert . substr($leader, $o+length($insert));
+                                                       }
+                                                       $marc->leader( $leader );
+                                               }
+
                                                if ($marc_lint) {
                                                        $lint->check_record( $marc );
                                                        my $err = join( "\n", $lint->warnings );
@@ -331,6 +350,14 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) {
                                                                "MARC lint warnings: ",$err,"\n"
                                                        ) if ($err);
                                                }
+
+                                               if ($marc_dump) {
+                                                       $log->info("MARC record on MFN $mfn\tleader:", $marc->leader(), "\n",
+                                                               "Original imput row: ",dump($row), "\n",
+                                                               "Normalized MARC row: ",dump(@marc_fields), "\n",
+                                                       );
+                                               }
+
                                                print $marc_fh $marc->as_usmarc;
                                        }
                                }