From 589fdca1033ccd8ce1328db72e94aa0e84dd2bfc Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 19 Nov 2007 15:56:05 +0000 Subject: [PATCH] r1631@llin: dpavlin | 2007-11-19 16:56:04 +0100 marc_template now respect marc_indicators, code cleanup git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@1047 07558da8-63fa-0310-ba24-9fe276d99e06 --- TODO | 2 +- lib/WebPAC/Normalize/MARC.pm | 14 +++++++++----- t/3-normalize-marc.t | 24 ++++++++++++++---------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/TODO b/TODO index d847c05..d814ef3 100644 --- a/TODO +++ b/TODO @@ -45,7 +45,7 @@ + show i1 and i2 in statistcs specially (sorted first) + ISBN support in normalize + marc_template (WebPAC v1 in a command) [2.31] -- marc_template must use marc_indicators data ++ marc_template must use marc_indicators data - indicator(field,nr) nr=1|2 for MARC input -> rec(field,'i1') - rewrite WebPAC::Input to be based on Module::Pluggable - check usage of config in normalize file (database, input name?) diff --git a/lib/WebPAC/Normalize/MARC.pm b/lib/WebPAC/Normalize/MARC.pm index 38a6267..1f5896c 100644 --- a/lib/WebPAC/Normalize/MARC.pm +++ b/lib/WebPAC/Normalize/MARC.pm @@ -136,9 +136,8 @@ sub marc_template { foreach my $r ( @$from_rec ) { - my $i1 = $r->{i1} || ' '; - my $i2 = $r->{i2} || ' '; my $to = $args->{to}; + my ($i1,$i2) = _get_marc_indicators( $to ); $m = [ $to, $i1, $i2 ]; $created_with_marc_template->{ $to }++; @@ -346,7 +345,7 @@ sub marc { foreach (@_) { my $v = $_; # make var read-write for Encode next unless (defined($v) && $v !~ /^\s*$/); - my ($i1,$i2) = defined($marc_indicators->{$f}) ? @{ $marc_indicators->{$f} } : (' ',' '); + my ($i1,$i2) = _get_marc_indicators( $f ); if (defined $sf) { push @{ $marc_record->[ $marc_record_offset ] }, [ $f, $i1, $i2, $sf => $v ]; } else { @@ -391,6 +390,11 @@ sub marc_indicators { @{ $marc_indicators->{$f} } = ($i1,$i2); } +sub _get_marc_indicators { + my $f = shift || confess "need field!\n"; + return defined($marc_indicators->{$f}) ? @{ $marc_indicators->{$f} } : (' ',' '); +} + =head2 marc_compose Save values for each MARC subfield explicitly @@ -411,7 +415,7 @@ sub marc_compose { my $f = shift or die "marc_compose needs field"; die "marc_compose field must be numer" unless ($f =~ /^\d+$/); - my ($i1,$i2) = defined($marc_indicators->{$f}) ? @{ $marc_indicators->{$f} } : (' ',' '); + my ($i1,$i2) = _get_marc_indicators( $f ); my $m = [ $f, $i1, $i2 ]; warn "### marc_compose input subfields = ", dump(@_),$/ if ($debug > 2); @@ -562,7 +566,7 @@ sub marc_original_order { my $r = $rec->{$from}; die "record field $from isn't array ",dump( $rec ) unless (ref($r) eq 'ARRAY'); - my ($i1,$i2) = defined($marc_indicators->{$to}) ? @{ $marc_indicators->{$to} } : (' ',' '); + my ($i1,$i2) = _get_marc_indicators( $to ); warn "## marc_original_order($to,$from) source = ", dump( $r ),$/ if ($debug > 1); foreach my $d (@$r) { diff --git a/t/3-normalize-marc.t b/t/3-normalize-marc.t index dc82d81..1ed57dc 100755 --- a/t/3-normalize-marc.t +++ b/t/3-normalize-marc.t @@ -3,7 +3,7 @@ use strict; use blib; -use Test::More tests => 188; +use Test::More tests => 262; BEGIN { use_ok( 'WebPAC::Test' ); @@ -58,6 +58,8 @@ sub test_marc_template { ok( _clean_ds(), '_clean_ds' ); ok( _set_ds( $rec ), '_set_ds' ); + ok( marc_indicators( 440, '0', '1' ), 'marc_indicators' ); + ok( marc_template( from => 225, to => 440, subfields_rename => [ @@ -85,19 +87,21 @@ sub test_marc_template { ok(my $marc = WebPAC::Normalize::MARC::_get_marc_fields(), "_get_marc_fields"); diag " _get_marc_fields = ",dump( $marc ) if $debug; + ok( marc_indicators( 440, 'x', 'y' ), 'marc_indicators' ); + return $marc; } my $marc_out = [ - [440, " ", " ", "a", "a-1-1, ", "x", "x-1-1 ; ", "v", "v-1-1. ", "n", "h-1-1, ", "p", "i-1-1 ; ", "v", "w-1-1"], - [440, " ", " ", "a", "a-2-1 ; ", "v", "v-2-1. ", "p", "i-2-1"], - [440, " ", " ", "a", "a-3-1 ; ", "v", "v-3-1. ", "p", "i-3-1"], - [440, " ", " ", "a", "a-4-1 ; ", "v", "v-4-1. ", "p", "i-4-1 ; ", "v", "w-4-1"], - [440, " ", " ", "a", "a-5-1 ; ", "v", "v-5-1. ", "p", "i-5-1"], - [440, " ", " ", "a", "a-6-1. ", "p", "i-6-1 ; ", "v", "w-6-1"], - [440, " ", " ", "a", "a-7-1"], - [440, " ", " ", "a", "a-8-1 ;", "v", "v-8-1"], - [440, " ", " ", "v", "v-9-1"], + [440, "0", "1", "a", "a-1-1, ", "x", "x-1-1 ; ", "v", "v-1-1. ", "n", "h-1-1, ", "p", "i-1-1 ; ", "v", "w-1-1"], + [440, "0", "1", "a", "a-2-1 ; ", "v", "v-2-1. ", "p", "i-2-1"], + [440, "0", "1", "a", "a-3-1 ; ", "v", "v-3-1. ", "p", "i-3-1"], + [440, "0", "1", "a", "a-4-1 ; ", "v", "v-4-1. ", "p", "i-4-1 ; ", "v", "w-4-1"], + [440, "0", "1", "a", "a-5-1 ; ", "v", "v-5-1. ", "p", "i-5-1"], + [440, "0", "1", "a", "a-6-1. ", "p", "i-6-1 ; ", "v", "w-6-1"], + [440, "0", "1", "a", "a-7-1"], + [440, "0", "1", "a", "a-8-1 ;", "v", "v-8-1"], + [440, "0", "1", "v", "v-9-1"], ]; is_deeply( test_marc_template($rec), $marc_out , 'is_deeply'); -- 2.20.1