r1192@llin: dpavlin | 2007-04-02 19:20:01 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 2 Apr 2007 17:20:01 +0000 (17:20 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 2 Apr 2007 17:20:01 +0000 (17:20 +0000)
 added support for fix-length fields using marc_fixed [2.29]

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

TODO
lib/WebPAC.pm
lib/WebPAC/Normalize.pm
t/3-normalize.t

diff --git a/TODO b/TODO
index e0879ef..c86d699 100644 (file)
--- a/TODO
+++ b/TODO
@@ -37,9 +37,9 @@
 + support splitting of config yml to multiple files
 + add set and get to create in-memory lookup
 + support marc_remove('*')
++ fix-length fields (<100) support [2.29]
 - load_ds/save_ds should use on-disk hash to preserve inodes
 - leader(position,...), indicator(field,nr) nr=1|2 for MARC input
-- fix-length fields (<100) support
 - validate should ignore modify_file
 - add option to specify output marc path in config.yml
 - add dBase input format
index ec8837d..9269c05 100644 (file)
@@ -9,11 +9,11 @@ WebPAC - core module
 
 =head1 VERSION
 
-Version 2.28
+Version 2.29
 
 =cut
 
-our $VERSION = '2.28';
+our $VERSION = '2.29';
 
 =head1 SYNOPSIS
 
index 2a13b11..13548fe 100644 (file)
@@ -9,7 +9,7 @@ use Exporter 'import';
 
        tag search display
        marc marc_indicators marc_repeatable_subfield
-       marc_compose marc_leader
+       marc_compose marc_leader marc_fixed
        marc_duplicate marc_remove marc_count
        marc_original_order
 
@@ -42,11 +42,11 @@ WebPAC::Normalize - describe normalisaton rules using sets
 
 =head1 VERSION
 
-Version 0.27
+Version 0.28
 
 =cut
 
-our $VERSION = '0.27';
+our $VERSION = '0.28';
 
 =head1 SYNOPSIS
 
@@ -517,6 +517,47 @@ sub marc_leader {
        }
 }
 
+=head2 marc_fixed
+
+Create control/indentifier fields with values in fixed positions
+
+  marc_fixed('008', 00, '070402');
+  marc_fixed('008', 39, '|');
+
+Positions not specified will be filled with spaces (C<0x20>).
+
+There will be no effort to extend last specified value to full length of
+field in standard.
+
+=cut
+
+sub marc_fixed {
+       my ($f, $pos, $val) = @_;
+       die "need marc(field, position, value)" unless defined($f) && defined($pos);
+
+       my $update = 0;
+
+       map {
+               if ($_->[0] eq $f) {
+                       my $old = $_->[1];
+                       if (length($old) < $pos) {
+                               $_->[1] .= ' ' x ( $pos - length($old) ) . $val;
+                               warn "## marc_fixed($f,$pos,'$val') append '$old' -> '$_->[1]'\n";
+                       } else {
+                               $_->[1] = substr($old, 0, $pos) . $val . substr($old, $pos + length($val));
+                               warn "## marc_fixed($f,$pos,'$val') update '$old' -> '$_->[1]'\n";
+                       }
+                       $update++;
+               }
+       } @{ $marc_record->[ $marc_record_offset ] };
+
+       if (! $update) {
+               my $v = ' ' x $pos . $val;
+               push @{ $marc_record->[ $marc_record_offset ] }, [ $f, $v ];
+               warn "## marc_fixed($f,$pos,'val') created '$v'\n";
+       }
+}
+
 =head2 marc
 
 Save value for MARC field
index 225c227..c152770 100755 (executable)
@@ -2,7 +2,7 @@
 
 use strict;
 
-use Test::More tests => 332;
+use Test::More tests => 335;
 use Test::Exception;
 use Cwd qw/abs_path/;
 use blib;
@@ -835,5 +835,22 @@ sub test_s {
                '^aa1^bb1^aa2^bb2^cc1^cc2',
                '_pack_subfields_hash( $h, 1 )'
        );
+
+       _clean_ds();
+       test_s(qq{
+               marc_fixed('008', 0, 'abcdef');
+               marc_fixed('000', 5, '5');
+               marc_fixed('000', 10, 'A');
+               marc_fixed('000', 0, '0');
+       });
+       ok( my $m = WebPAC::Normalize::_get_marc_fields(), '_get_marc_fields');
+       diag dump( $m );
+       is_deeply( WebPAC::Normalize::_get_marc_fields(),
+               [
+                       ["008", "abcdef"], 
+                       #        0....5....10
+                       ["000", "0    5    A"]
+               ]
+       );
 }