--- trunk/lib/WebPAC/Normalize.pm 2007/10/30 17:40:13 912 +++ trunk/lib/WebPAC/Normalize.pm 2007/11/04 11:12:38 983 @@ -1,13 +1,14 @@ package WebPAC::Normalize; use Exporter 'import'; -@EXPORT = qw/ - _set_rec _set_lookup +our @EXPORT = qw/ + _set_ds _set_lookup + get_ds _set_load_row _get_ds _clean_ds _debug _pack_subfields_hash - search_display search display + search_display search display sorted marc marc_indicators marc_repeatable_subfield marc_compose marc_leader marc_fixed @@ -15,6 +16,7 @@ marc_original_order rec1 rec2 rec + frec regex prefix suffix surround first lookup join_with save_into_lookup @@ -23,6 +25,7 @@ get set count + /; use warnings; @@ -36,18 +39,16 @@ # debugging warn(s) my $debug = 0; +use WebPAC::Normalize::ISBN; +push @EXPORT, ( 'isbn_10', 'isbn_13' ); =head1 NAME WebPAC::Normalize - describe normalisaton rules using sets -=head1 VERSION - -Version 0.30 - =cut -our $VERSION = '0.30'; +our $VERSION = '0.32'; =head1 SYNOPSIS @@ -79,7 +80,7 @@ marc_encoding => 'utf-8', config => $config, load_row_coderef => sub { - my ($database,$input,$mfn) = shift; + my ($database,$input,$mfn) = @_; $store->load_row( database => $database, input => $input, id => $mfn ); }, ); @@ -107,7 +108,7 @@ no strict 'subs'; _set_lookup( $arg->{lookup} ) if defined($arg->{lookup}); - _set_rec( $arg->{row} ); + _set_ds( $arg->{row} ); _set_config( $arg->{config} ) if defined($arg->{config}); _clean_ds( %{ $arg } ); $load_row_coderef = $arg->{load_row_coderef}; @@ -118,20 +119,32 @@ return _get_ds(); } -=head2 _set_rec +=head2 _set_ds Set current record hash - _set_rec( $rec ); + _set_ds( $rec ); =cut my $rec; -sub _set_rec { +sub _set_ds { $rec = shift or die "no record hash"; } +=head2 get_ds + +Access to original record from input module + + my $ds = get_rec; + +=cut + +sub get_ds { + return $rec; +} + =head2 _set_config Set current config hash @@ -172,6 +185,7 @@ my ($marc_record_offset, $marc_fetch_offset) = (0, 0); sub _get_ds { +#warn "## out = ",dump($out); return $out; } @@ -460,6 +474,16 @@ $out->{$name}->{display} = \@o; } +=head2 tag + +Old name for L, but supported + +=cut + +sub tag { + search_display( @_ ); +} + =head2 display Define output just for I @@ -468,13 +492,16 @@ =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}->{display} = \@o; + $out->{$name}->{$type} = \@o; } +sub display { _field( 'display', @_ ) } + =head2 search Prepare values just for I @@ -483,12 +510,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}->{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 @@ -979,6 +1012,12 @@ =cut +sub frec { + my @out = rec(@_); + warn "rec(",dump(@_),") has more than one return value, ignoring\n" if $#out > 0; + return shift @out; +} + sub rec { my @out; if ($#_ == 0) {