--- trunk/lib/WebPAC/Normalize.pm 2006/09/29 20:18:30 729 +++ trunk/lib/WebPAC/Normalize.pm 2006/10/07 16:33:37 740 @@ -2,7 +2,7 @@ use Exporter 'import'; @EXPORT = qw/ _set_rec _set_lookup - _set_load_ds + _set_load_row _get_ds _clean_ds _debug _pack_subfields_hash @@ -39,11 +39,11 @@ =head1 VERSION -Version 0.21 +Version 0.22 =cut -our $VERSION = '0.21'; +our $VERSION = '0.22'; =head1 SYNOPSIS @@ -74,16 +74,16 @@ rules => $normalize_pl_config, marc_encoding => 'utf-8', config => $config, - load_ds_coderef => sub { + load_row_coderef => sub { my ($database,$input,$mfn) = shift; - $store->load_ds( database => $database, input => $input, id => $mfn ); + $store->load_row( database => $database, input => $input, id => $mfn ); }, ); Options C, C and C are mandatory while all other are optional. -C is closure only used when executing lookups, so they will +C is closure only used when executing lookups, so they will die if it's not defined. This function will B if normalizastion can't be evaled. @@ -93,7 +93,7 @@ =cut -my $load_ds_coderef; +my $load_row_coderef; sub data_structure { my $arg = {@_}; @@ -102,11 +102,11 @@ die "need normalisation argument" unless ($arg->{rules}); no strict 'subs'; - _set_lookup( $arg->{lookup} ); + _set_lookup( $arg->{lookup} ) if defined($arg->{lookup}); _set_rec( $arg->{row} ); - _set_config( $arg->{config} ); + _set_config( $arg->{config} ) if defined($arg->{config}); _clean_ds( %{ $arg } ); - $load_ds_coderef = $arg->{load_ds_coderef}; + $load_row_coderef = $arg->{load_row_coderef}; eval "$arg->{rules}"; die "error evaling $arg->{rules}: $@\n" if ($@); @@ -212,23 +212,23 @@ return $lookup; } -=head2 _set_load_ds +=head2 _set_load_row Setup code reference which will return L from L - _set_load_ds(sub { + _set_load_row(sub { my ($database,$input,$mfn) = @_; - $store->load_ds( database => $database, input => $input, id => $mfn ); + $store->load_row( database => $database, input => $input, id => $mfn ); }); =cut -sub _set_load_ds { +sub _set_load_row { my $coderef = shift; confess "argument isn't CODE" unless ref($coderef) eq 'CODE'; - $load_ds_coderef = $coderef; + $load_row_coderef = $coderef; } =head2 _get_marc_fields @@ -1022,7 +1022,7 @@ warn "## lookup ($database, $input, $key)", $/ if ($debug > 1); return unless (defined($lookup->{$database}->{$input}->{$key})); - confess "lookup really need load_ds_coderef added to data_structure\n" unless ($load_ds_coderef); + confess "lookup really need load_row_coderef added to data_structure\n" unless ($load_row_coderef); my $mfns; my @having = $having->(); @@ -1046,7 +1046,7 @@ my @out; foreach my $mfn (@mfns) { - $rec = $load_ds_coderef->( $database, $input, $mfn ); + $rec = $load_row_coderef->( $database, $input, $mfn ); warn "got $database/$input/$mfn = ", dump($rec), $/; @@ -1067,7 +1067,11 @@ warn "## lookup returns = ", dump(@out), $/; - return @out; + if ($#out == 0) { + return $out[0]; + } else { + return @out; + } } =head2 save_into_lookup