r1616@llin: dpavlin | 2007-11-12 13:13:55 +0100
[webpac2] / lib / WebPAC / Normalize / MARC.pm
index bddde1e..5fe3e94 100644 (file)
@@ -58,6 +58,8 @@ Returns number of records produced.
 
 =cut
 
+my $created_with_marc_template;
+
 sub marc_template {
        my $args = {@_};
        warn "## marc_template(",dump($args),")",$/ if $debug;
@@ -134,7 +136,10 @@ sub marc_template {
 
                my $i1 = $r->{i1} || ' ';
                my $i2 = $r->{i2} || ' ';
-               $m = [ $args->{to}, $i1, $i2 ];
+               my $to = $args->{to};
+               $m = [ $to, $i1, $i2 ];
+
+               $created_with_marc_template->{ $to }++;
 
                warn "### r = ",dump( $r ),$/ if $debug;
 
@@ -610,6 +615,8 @@ sub marc_count {
        return $#{ $marc_record };
 }
 
+=head1 PRIVATE FUNCTIONS
+
 =head2 _marc_push
 
  _marc_push( $marc );
@@ -621,8 +628,6 @@ sub _marc_push {
        push @{ $marc_record->[ $marc_record_offset ] }, $marc;
 }
 
-=head1 PRIVATE FUNCTIONS
-
 =head2 _clean
 
 Clean internal structures
@@ -630,7 +635,7 @@ Clean internal structures
 =cut
 
 sub _clean {
-       ($marc_record, $marc_encoding, $marc_repeatable_subfield, $marc_indicators, $marc_leader) = ();
+       ($marc_record, $marc_encoding, $marc_repeatable_subfield, $marc_indicators, $marc_leader, $created_with_marc_template) = ();
        ($marc_record_offset, $marc_fetch_offset) = (0,0);
 }
 
@@ -644,6 +649,8 @@ Get all fields defined by calls to C<marc>
 We are using I<magic> which detect repeatable fields only from
 sequence of field/subfield data generated by normalization.
 
+This magic is disabled for all records created with C<marc_template>.
+
 Repeatable field is created when there is second occurence of same subfield or
 if any of indicators are different.
 
@@ -715,9 +722,9 @@ sub _get_marc_fields {
 
        # first, sort all existing fields 
        # XXX might not be needed, but modern perl might randomize elements in hash
-       my @sorted_marc_record = sort {
-               $a->[0] . ( $a->[3] || '' ) cmp $b->[0] . ( $b->[3] || '')
-       } @{ $marc_rec };
+#      my @sorted_marc_record = sort {
+#              $a->[0] . ( $a->[3] || '' ) cmp $b->[0] . ( $b->[3] || '')
+#      } @{ $marc_rec };
 
        @sorted_marc_record = @{ $marc_rec };   ### FIXME disable sorting
        
@@ -752,6 +759,11 @@ sub _get_marc_fields {
 
                my $row = dclone( $sorted_marc_record[$i] );
 
+               if ( $created_with_marc_template->{ $row->[0] } ) {
+                       push @m, $row;
+                       warn "## copied marc_template created ", dump( $row ),$/ if $debug;
+                       next;
+               }
                # field and subfield which is key for
                # marc_repeatable_subfield and u
                my $fsf = $row->[0] . ( $row->[3] || '' );