r1393@llin: dpavlin | 2007-10-31 00:52:52 +0100
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 31 Oct 2007 00:26:43 +0000 (00:26 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 31 Oct 2007 00:26:43 +0000 (00:26 +0000)
 added sorted to WebPAC::Normalize to define values which should go
 into sorted lists

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@923 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Normalize.pm
t/3-normalize.t

index 48768a2..548cd63 100644 (file)
@@ -7,7 +7,7 @@ use Exporter 'import';
        _debug
        _pack_subfields_hash
 
        _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
 
        marc marc_indicators marc_repeatable_subfield
        marc_compose marc_leader marc_fixed
@@ -41,13 +41,9 @@ my $debug = 0;
 
 WebPAC::Normalize - describe normalisaton rules using sets
 
 
 WebPAC::Normalize - describe normalisaton rules using sets
 
-=head1 VERSION
-
-Version 0.30
-
 =cut
 
 =cut
 
-our $VERSION = '0.30';
+our $VERSION = '0.31';
 
 =head1 SYNOPSIS
 
 
 =head1 SYNOPSIS
 
@@ -478,13 +474,16 @@ Define output just for I<display>
 
 =cut
 
 
 =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);
        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<search>
 =head2 search
 
 Prepare values just for I<search>
@@ -493,12 +492,18 @@ Prepare values just for I<search>
 
 =cut
 
 
 =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
 
 
 =head2 marc_leader
 
index b01e89f..363797f 100755 (executable)
@@ -2,7 +2,7 @@
 
 use strict;
 
 
 use strict;
 
-use Test::More tests => 341;
+use Test::More tests => 347;
 use Test::Exception;
 use Cwd qw/abs_path/;
 use blib;
 use Test::Exception;
 use Cwd qw/abs_path/;
 use blib;
@@ -436,6 +436,11 @@ sub test_s {
        test_check_ds('search');
        test_check_ds('display');
 
        test_check_ds('search');
        test_check_ds('display');
 
+       _clean_ds();
+       test_s(qq{ sorted('something', '42'); });
+       test_s(qq{ sorted('empty', ''); });
+       test_check_ds('sorted');
+
        _clean_ds();
        my $n = read_file( "$abs_path/data/normalize.pl" );
        $n .= "\n1;\n";
        _clean_ds();
        my $n = read_file( "$abs_path/data/normalize.pl" );
        $n .= "\n1;\n";