Make cleanup of encodings, moving webpac closer to having
[webpac2] / lib / WebPAC / Normalize.pm
index 84b5fee..45e3e64 100644 (file)
@@ -7,6 +7,7 @@ our @EXPORT = qw/
        _debug
        _pack_subfields_hash
 
+       to
        search_display search display sorted
 
        rec1 rec2 rec
@@ -52,7 +53,7 @@ WebPAC::Normalize - describe normalisaton rules using sets
 
 =cut
 
-our $VERSION = '0.35';
+our $VERSION = '0.36';
 
 =head1 SYNOPSIS
 
@@ -269,13 +270,30 @@ sub _debug {
 
 Those functions generally have to first in your normalization file.
 
+=head2 to
+
+Generic way to set values for some name
+
+  to('field-name', 'name-value' => rec('200','a') );
+
+There are many helpers defined below which might be easier to use.
+
+=cut
+
+sub to {
+       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}->{$type} = \@o;
+}
+
 =head2 search_display
 
 Define output for L<search> and L<display> at the same time
 
   search_display('Title', rec('200','a') );
 
-
 =cut
 
 sub search_display {
@@ -288,7 +306,7 @@ sub search_display {
 
 =head2 tag
 
-Old name for L<search_display>, but supported
+Old name for L<search_display>, it will probably be removed at one point.
 
 =cut
 
@@ -304,15 +322,7 @@ Define output just for I<display>
 
 =cut
 
-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}->{$type} = \@o;
-}
-
-sub display { _field( 'display', @_ ) }
+sub display { to( 'display', @_ ) }
 
 =head2 search
 
@@ -322,7 +332,7 @@ Prepare values just for I<search>
 
 =cut
 
-sub search { _field( 'search', @_ ) }
+sub search { to( 'search', @_ ) }
 
 =head2 sorted
 
@@ -332,8 +342,7 @@ Insert into lists which will be automatically sorted
 
 =cut
 
-sub sorted { _field( 'sorted', @_ ) }
-
+sub sorted { to( 'sorted', @_ ) }
 
 
 =head1 Functions to extract data from input
@@ -449,7 +458,7 @@ sub rec2 {
                } else {
                        $_->{$sf};
                }
-       } grep { ref($_) eq 'HASH' && $_->{$sf} } @{ $rec->{$f} };
+       } grep { ref($_) eq 'HASH' && defined $_->{$sf} } @{ $rec->{$f} };
 }
 
 =head2 rec