--- trunk/lib/WebPAC/Normalize.pm 2006/06/29 15:29:19 538 +++ trunk/lib/WebPAC/Normalize.pm 2006/06/29 15:29:41 540 @@ -5,6 +5,8 @@ _get_ds _clean_ds tag search display + marc21 + rec1 rec2 rec regex prefix suffix surround first lookup join_with @@ -39,7 +41,8 @@ C. Normalisation can generate multiple output normalized data. For now, supported output -types (on the left side of definition) are: C, C and C. +types (on the left side of definition) are: C, C, C and +C. =head1 FUNCTIONS @@ -56,6 +59,9 @@ rules => $normalize_pl_config, ); +Options C, C, C and C are mandatory while all +other are optional. + This function will B if normalizastion can't be evaled. Since this function isn't exported you have to call it with @@ -73,8 +79,10 @@ _set_lookup( $arg->{lookup} ); _set_rec( $arg->{row} ); _clean_ds(); + eval "$arg->{rules}"; die "error evaling $arg->{rules}: $@\n" if ($@); + return _get_ds(); } @@ -101,6 +109,7 @@ =cut my $out; +my $marc21; sub _get_ds { return $out; @@ -116,6 +125,7 @@ sub _clean_ds { $out = undef; + $marc21 = undef; } =head2 _set_lookup @@ -132,6 +142,22 @@ $lookup = shift; } +=head2 _get_marc21_fields + +Get all fields defined by calls to C + + $marc->add_fields( WebPAC::Normalize:_get_marc21_fields() ); + +=cut + +sub _get_marc21_fields { + return @{$marc21}; +} + +=head1 Functions to create C + +Those functions generally have to first in your normalization file. + =head2 tag Define new tag for I and I. @@ -182,6 +208,30 @@ $out->{$name}->{search} = \@o; } +=head2 marc21 + +Save value for MARC field + + marc21('900','a', rec('200','a') ); + +=cut + +sub marc21 { + my $f = shift or die "marc21 needs field"; + die "marc21 field must be numer" unless ($f =~ /^\d+$/); + + my $sf = shift or die "marc21 needs subfield"; + + foreach my $v (@_) { + push @{ $marc21 }, [ $f, ' ', ' ', $sf => $v ]; + } +} + +=head1 Functions to extract data from input + +This function should be used inside functions to create C described +above. + =head2 rec1 Return all values in some field