r1185@llin: dpavlin | 2007-04-01 23:47:05 +0200
[webpac2] / lib / WebPAC / Output / MARC.pm
index 33f5ace..f8c17c4 100644 (file)
@@ -16,11 +16,11 @@ WebPAC::Output::MARC - Create MARC records from C<marc_*> normalisation rules
 
 =head1 VERSION
 
-Version 0.02
+Version 0.04
 
 =cut
 
-our $VERSION = '0.02';
+our $VERSION = '0.04';
 
 =head1 SYNOPSIS
 
@@ -57,6 +57,7 @@ sub new {
        if (my $path = $self->{path}) {
                open($self->{fh}, '>', $path) ||
                        $log->logdie("can't open MARC output $path: $!");
+               binmode($self->{fh}, ':utf8');
 
                $log->info("Creating MARC export file $path", $self->{lint} ? ' (with lint)' : '', "\n");
        } else {
@@ -74,7 +75,7 @@ sub new {
   $marc->add(
        id => $mfn,
        fields => WebPAC::Normalize::_get_marc_fields(),
-       leader => WebPAC::Normalize::marc_leader(),
+       leader => WebPAC::Normalize::_get_marc_leader(),
        row => $row,
   );
 
@@ -113,6 +114,9 @@ sub add {
                }
        }
 
+       # sort fields
+       @$fields = sort { $a->[0] <=> $b->[0] } @$fields;
+
        $log->debug("recode fields = ", sub { dump( $fields ) });
 
        $marc->add_fields( @$fields );
@@ -136,7 +140,7 @@ sub add {
                if (@w) {
                        $log->error("MARC lint detected warning on record $id\n",
                                "<<<<< Original input row:\n",dump($arg->{row}), "\n",
-                               ">>>>> Normalized MARC row: leader: [", $marc->leader(), "]\n", dump( $arg->{fields} ), "\n",
+                               ">>>>> Normalized MARC row: leader: [", $marc->leader(), "]\n", dump( $fields ), "\n",
                                "!!!!! MARC lint warnings:\n",join("\n",@w),"\n"
                        );
                        map { $self->{_marc_lint_warnings}->{$_}++ } @w;
@@ -146,14 +150,11 @@ sub add {
        if ($self->{dump}) {
                $log->info("MARC record on record $id\n",
                        "<<<<< Original imput row:\n",dump($arg->{row}), "\n",
-                       ">>>>> Normalized MARC row: leader: [", $marc->leader(), "]\n", dump( $arg->{fields} ), "\n",
+                       ">>>>> Normalized MARC row: leader: [", $marc->leader(), "]\n", dump( $fields ), "\n",
                );
        }
 
-       {
-               use bytes;
-               print {$self->{fh}} $marc->as_usmarc;
-       }
+       print {$self->{fh}} $marc->as_usmarc;
 
 }