--- trunk/lib/WebPAC/Normalize.pm 2007/04/11 10:09:34 819 +++ trunk/lib/WebPAC/Normalize.pm 2007/11/02 14:59:12 973 @@ -7,7 +7,8 @@ _debug _pack_subfields_hash - tag search display + search_display search display sorted + marc marc_indicators marc_repeatable_subfield marc_compose marc_leader marc_fixed marc_duplicate marc_remove marc_count @@ -40,13 +41,9 @@ WebPAC::Normalize - describe normalisaton rules using sets -=head1 VERSION - -Version 0.29 - =cut -our $VERSION = '0.29'; +our $VERSION = '0.31'; =head1 SYNOPSIS @@ -59,7 +56,7 @@ C. Normalisation can generate multiple output normalized data. For now, supported output -types (on the left side of definition) are: C, C, C and +types (on the left side of definition) are: C, C, C and C. =head1 FUNCTIONS @@ -111,6 +108,9 @@ _clean_ds( %{ $arg } ); $load_row_coderef = $arg->{load_row_coderef}; + # FIXME load this conditionally + use WebPAC::Normalize::ISBN; + eval "$arg->{rules}"; die "error evaling $arg->{rules}: $@\n" if ($@); @@ -442,40 +442,51 @@ Those functions generally have to first in your normalization file. -=head2 tag +=head2 search_display -Define new tag for I and I. +Define output for L and L at the same time - tag('Title', rec('200','a') ); + search_display('Title', rec('200','a') ); =cut -sub tag { - my $name = shift or die "tag needs name as first argument"; +sub search_display { + my $name = shift or die "search_display needs name as first argument"; my @o = grep { defined($_) && $_ ne '' } @_; return unless (@o); - $out->{$name}->{tag} = $name; $out->{$name}->{search} = \@o; $out->{$name}->{display} = \@o; } +=head2 tag + +Old name for L, but supported + +=cut + +sub tag { + search_display( @_ ); +} + =head2 display -Define tag just for I +Define output just for I @v = display('Title', rec('200','a') ); =cut -sub display { - my $name = shift or die "display needs name as first argument"; +sub _field { + my $type = shift or confess "need type -- BUG?"; + my $name = shift or confess "needs name as first argument"; my @o = grep { defined($_) && $_ ne '' } @_; return unless (@o); - $out->{$name}->{tag} = $name; - $out->{$name}->{display} = \@o; + $out->{$name}->{$type} = \@o; } +sub display { _field( 'display', @_ ) } + =head2 search Prepare values just for I @@ -484,13 +495,18 @@ =cut -sub search { - my $name = shift or die "search needs name as first argument"; - my @o = grep { defined($_) && $_ ne '' } @_; - return unless (@o); - $out->{$name}->{tag} = $name; - $out->{$name}->{search} = \@o; -} +sub search { _field( 'search', @_ ) } + +=head2 sorted + +Insert into lists which will be automatically sorted + + sorted('Title', rec('200','a') ); + +=cut + +sub sorted { _field( 'sorted', @_ ) } + =head2 marc_leader @@ -535,12 +551,14 @@ my ($f, $pos, $val) = @_; die "need marc(field, position, value)" unless defined($f) && defined($pos); + confess "need val" unless defined $val; + my $update = 0; map { if ($_->[0] eq $f) { my $old = $_->[1]; - if (length($old) < $pos) { + if (length($old) <= $pos) { $_->[1] .= ' ' x ( $pos - length($old) ) . $val; warn "## marc_fixed($f,$pos,'$val') append '$old' -> '$_->[1]'\n" if ($debug > 1); } else { @@ -872,6 +890,9 @@ my ($h,$include_subfields) = @_; + # sanity and ease of use + return $h if (ref($h) ne 'HASH'); + if ( defined($h->{subfields}) ) { my $sfs = delete $h->{subfields} || die "no subfields?"; my @out; @@ -1227,7 +1248,6 @@ $database_code = config(); # use _ from hash $database_name = config('name'); $database_input_name = config('input name'); - $tag = config('input normalize tag'); Up to three levels are supported.