/[webpac2]/trunk/lib/WebPAC/Normalize.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WebPAC/Normalize.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 729 by dpavlin, Fri Sep 29 20:18:30 2006 UTC revision 915 by dpavlin, Tue Oct 30 20:27:20 2007 UTC
# Line 2  package WebPAC::Normalize; Line 2  package WebPAC::Normalize;
2  use Exporter 'import';  use Exporter 'import';
3  @EXPORT = qw/  @EXPORT = qw/
4          _set_rec _set_lookup          _set_rec _set_lookup
5          _set_load_ds          _set_load_row
6          _get_ds _clean_ds          _get_ds _clean_ds
7          _debug          _debug
8          _pack_subfields_hash          _pack_subfields_hash
9    
10          tag search display          search_display search display
11    
12          marc marc_indicators marc_repeatable_subfield          marc marc_indicators marc_repeatable_subfield
13          marc_compose marc_leader          marc_compose marc_leader marc_fixed
14          marc_duplicate marc_remove          marc_duplicate marc_remove marc_count
15          marc_original_order          marc_original_order
16    
17          rec1 rec2 rec          rec1 rec2 rec
# Line 19  use Exporter 'import'; Line 20  use Exporter 'import';
20          save_into_lookup          save_into_lookup
21    
22          split_rec_on          split_rec_on
23    
24            get set
25            count
26  /;  /;
27    
28  use warnings;  use warnings;
# Line 39  WebPAC::Normalize - describe normalisato Line 43  WebPAC::Normalize - describe normalisato
43    
44  =head1 VERSION  =head1 VERSION
45    
46  Version 0.21  Version 0.30
47    
48  =cut  =cut
49    
50  our $VERSION = '0.21';  our $VERSION = '0.30';
51    
52  =head1 SYNOPSIS  =head1 SYNOPSIS
53    
# Line 56  means that you check it's validity befor Line 60  means that you check it's validity befor
60  C<perl -c normalize.pl>.  C<perl -c normalize.pl>.
61    
62  Normalisation can generate multiple output normalized data. For now, supported output  Normalisation can generate multiple output normalized data. For now, supported output
63  types (on the left side of definition) are: C<tag>, C<display>, C<search> and  types (on the left side of definition) are: C<search_display>, C<display>, C<search> and
64  C<marc>.  C<marc>.
65    
66  =head1 FUNCTIONS  =head1 FUNCTIONS
# Line 74  Return data structure Line 78  Return data structure
78          rules => $normalize_pl_config,          rules => $normalize_pl_config,
79          marc_encoding => 'utf-8',          marc_encoding => 'utf-8',
80          config => $config,          config => $config,
81          load_ds_coderef => sub {          load_row_coderef => sub {
82                  my ($database,$input,$mfn) = shift;                  my ($database,$input,$mfn) = shift;
83                  $store->load_ds( database => $database, input => $input, id => $mfn );                  $store->load_row( database => $database, input => $input, id => $mfn );
84          },          },
85    );    );
86    
87  Options C<row>, C<rules> and C<log> are mandatory while all  Options C<row>, C<rules> and C<log> are mandatory while all
88  other are optional.  other are optional.
89    
90  C<load_ds_coderef> is closure only used when executing lookups, so they will  C<load_row_coderef> is closure only used when executing lookups, so they will
91  die if it's not defined.  die if it's not defined.
92    
93  This function will B<die> if normalizastion can't be evaled.  This function will B<die> if normalizastion can't be evaled.
# Line 93  C<WebPAC::Normalize::data_structure>. Line 97  C<WebPAC::Normalize::data_structure>.
97    
98  =cut  =cut
99    
100  my $load_ds_coderef;  my $load_row_coderef;
101    
102  sub data_structure {  sub data_structure {
103          my $arg = {@_};          my $arg = {@_};
# Line 102  sub data_structure { Line 106  sub data_structure {
106          die "need normalisation argument" unless ($arg->{rules});          die "need normalisation argument" unless ($arg->{rules});
107    
108          no strict 'subs';          no strict 'subs';
109          _set_lookup( $arg->{lookup} );          _set_lookup( $arg->{lookup} ) if defined($arg->{lookup});
110          _set_rec( $arg->{row} );          _set_rec( $arg->{row} );
111          _set_config( $arg->{config} );          _set_config( $arg->{config} ) if defined($arg->{config});
112          _clean_ds( %{ $arg } );          _clean_ds( %{ $arg } );
113          $load_ds_coderef = $arg->{load_ds_coderef};          $load_row_coderef = $arg->{load_row_coderef};
114    
115          eval "$arg->{rules}";          eval "$arg->{rules}";
116          die "error evaling $arg->{rules}: $@\n" if ($@);          die "error evaling $arg->{rules}: $@\n" if ($@);
# Line 164  Return hash formatted as data structure Line 168  Return hash formatted as data structure
168    
169  =cut  =cut
170    
171  my ($out, $marc_record, $marc_encoding, $marc_repeatable_subfield, $marc_indicators);  my ($out, $marc_record, $marc_encoding, $marc_repeatable_subfield, $marc_indicators, $marc_leader);
172  my ($marc_record_offset, $marc_fetch_offset) = (0, 0);  my ($marc_record_offset, $marc_fetch_offset) = (0, 0);
173    
174  sub _get_ds {  sub _get_ds {
# Line 181  Clean data structure hash for next recor Line 185  Clean data structure hash for next recor
185    
186  sub _clean_ds {  sub _clean_ds {
187          my $a = {@_};          my $a = {@_};
188          ($out,$marc_record, $marc_encoding, $marc_repeatable_subfield, $marc_indicators) = ();          ($out,$marc_record, $marc_encoding, $marc_repeatable_subfield, $marc_indicators, $marc_leader) = ();
189          ($marc_record_offset, $marc_fetch_offset) = (0,0);          ($marc_record_offset, $marc_fetch_offset) = (0,0);
190          $marc_encoding = $a->{marc_encoding};          $marc_encoding = $a->{marc_encoding};
191  }  }
# Line 212  sub _get_lookup { Line 216  sub _get_lookup {
216          return $lookup;          return $lookup;
217  }  }
218    
219  =head2 _set_load_ds  =head2 _set_load_row
220    
221  Setup code reference which will return L<data_structure> from  Setup code reference which will return L<data_structure> from
222  L<WebPAC::Store>  L<WebPAC::Store>
223    
224    _set_load_ds(sub {    _set_load_row(sub {
225                  my ($database,$input,$mfn) = @_;                  my ($database,$input,$mfn) = @_;
226                  $store->load_ds( database => $database, input => $input, id => $mfn );                  $store->load_row( database => $database, input => $input, id => $mfn );
227    });    });
228    
229  =cut  =cut
230    
231  sub _set_load_ds {  sub _set_load_row {
232          my $coderef = shift;          my $coderef = shift;
233          confess "argument isn't CODE" unless ref($coderef) eq 'CODE';          confess "argument isn't CODE" unless ref($coderef) eq 'CODE';
234    
235          $load_ds_coderef = $coderef;          $load_row_coderef = $coderef;
236  }  }
237    
238  =head2 _get_marc_fields  =head2 _get_marc_fields
# Line 286  will return 42th copy record (if it exis Line 290  will return 42th copy record (if it exis
290    
291  =cut  =cut
292    
293    my $fetch_pos;
294    
295  sub _get_marc_fields {  sub _get_marc_fields {
296    
297          my $arg = {@_};          my $arg = {@_};
298          warn "### _get_marc_fields arg: ", dump($arg), $/ if ($debug > 2);          warn "### _get_marc_fields arg: ", dump($arg), $/ if ($debug > 2);
299          my $offset = $marc_fetch_offset;          $fetch_pos = $marc_fetch_offset;
300          if ($arg->{offset}) {          if ($arg->{offset}) {
301                  $offset = $arg->{offset};                  $fetch_pos = $arg->{offset};
302          } elsif($arg->{fetch_next}) {          } elsif($arg->{fetch_next}) {
303                  $marc_fetch_offset++;                  $marc_fetch_offset++;
304          }          }
# Line 301  sub _get_marc_fields { Line 307  sub _get_marc_fields {
307    
308          warn "### full marc_record = ", dump( @{ $marc_record }), $/ if ($debug > 2);          warn "### full marc_record = ", dump( @{ $marc_record }), $/ if ($debug > 2);
309    
310          my $marc_rec = $marc_record->[ $offset ];          my $marc_rec = $marc_record->[ $fetch_pos ];
311    
312          warn "## _get_marc_fields (at offset: $offset) -- marc_record = ", dump( @$marc_rec ), $/ if ($debug > 1);          warn "## _get_marc_fields (at offset: $fetch_pos) -- marc_record = ", dump( @$marc_rec ), $/ if ($debug > 1);
313    
314          return if (! $marc_rec || ref($marc_rec) ne 'ARRAY' || $#{ $marc_rec } < 0);          return if (! $marc_rec || ref($marc_rec) ne 'ARRAY' || $#{ $marc_rec } < 0);
315    
# Line 324  sub _get_marc_fields { Line 330  sub _get_marc_fields {
330    
331          if ($debug) {          if ($debug) {
332                  warn "## marc_repeatable_subfield = ", dump( $marc_repeatable_subfield ), $/ if ( $marc_repeatable_subfield );                  warn "## marc_repeatable_subfield = ", dump( $marc_repeatable_subfield ), $/ if ( $marc_repeatable_subfield );
333                  warn "## marc_record[$offset] = ", dump( $marc_rec ), $/;                  warn "## marc_record[$fetch_pos] = ", dump( $marc_rec ), $/;
334                  warn "## sorted_marc_record = ", dump( \@sorted_marc_record ), $/;                  warn "## sorted_marc_record = ", dump( \@sorted_marc_record ), $/;
335                  warn "## subfield count = ", dump( $u ), $/;                  warn "## subfield count = ", dump( $u ), $/;
336          }          }
# Line 405  sub _get_marc_fields { Line 411  sub _get_marc_fields {
411          return \@m;          return \@m;
412  }  }
413    
414    =head2 _get_marc_leader
415    
416    Return leader from currently fetched record by L</_get_marc_fields>
417    
418      print WebPAC::Normalize::_get_marc_leader();
419    
420    =cut
421    
422    sub _get_marc_leader {
423            die "no fetch_pos, did you called _get_marc_fields first?" unless ( defined( $fetch_pos ) );
424            return $marc_leader->[ $fetch_pos ];
425    }
426    
427  =head2 _debug  =head2 _debug
428    
429  Change level of debug warnings  Change level of debug warnings
# Line 424  sub _debug { Line 443  sub _debug {
443    
444  Those functions generally have to first in your normalization file.  Those functions generally have to first in your normalization file.
445    
446  =head2 tag  =head2 search_display
447    
448  Define new tag for I<search> and I<display>.  Define output for L<search> and L<display> at the same time
449    
450    tag('Title', rec('200','a') );    search_display('Title', rec('200','a') );
451    
452    
453  =cut  =cut
454    
455  sub tag {  sub search_display {
456          my $name = shift or die "tag needs name as first argument";          my $name = shift or die "search_display needs name as first argument";
457          my @o = grep { defined($_) && $_ ne '' } @_;          my @o = grep { defined($_) && $_ ne '' } @_;
458          return unless (@o);          return unless (@o);
         $out->{$name}->{tag} = $name;  
459          $out->{$name}->{search} = \@o;          $out->{$name}->{search} = \@o;
460          $out->{$name}->{display} = \@o;          $out->{$name}->{display} = \@o;
461  }  }
462    
463    =head2 tag
464    
465    Old name for L<search_display>, but supported
466    
467    =cut
468    
469    sub tag {
470            search_display( @_ );
471    }
472    
473  =head2 display  =head2 display
474    
475  Define tag just for I<display>  Define output just for I<display>
476    
477    @v = display('Title', rec('200','a') );    @v = display('Title', rec('200','a') );
478    
# Line 454  sub display { Line 482  sub display {
482          my $name = shift or die "display needs name as first argument";          my $name = shift or die "display needs name as first argument";
483          my @o = grep { defined($_) && $_ ne '' } @_;          my @o = grep { defined($_) && $_ ne '' } @_;
484          return unless (@o);          return unless (@o);
         $out->{$name}->{tag} = $name;  
485          $out->{$name}->{display} = \@o;          $out->{$name}->{display} = \@o;
486  }  }
487    
# Line 470  sub search { Line 497  sub search {
497          my $name = shift or die "search needs name as first argument";          my $name = shift or die "search needs name as first argument";
498          my @o = grep { defined($_) && $_ ne '' } @_;          my @o = grep { defined($_) && $_ ne '' } @_;
499          return unless (@o);          return unless (@o);
         $out->{$name}->{tag} = $name;  
500          $out->{$name}->{search} = \@o;          $out->{$name}->{search} = \@o;
501  }  }
502    
# Line 487  sub marc_leader { Line 513  sub marc_leader {
513          my ($offset,$value) = @_;          my ($offset,$value) = @_;
514    
515          if ($offset) {          if ($offset) {
516                  $out->{' leader'}->{ $offset } = $value;                  $marc_leader->[ $marc_record_offset ]->{ $offset } = $value;
517          } else {          } else {
518                  return $out->{' leader'};                  
519                    if (defined($marc_leader)) {
520                            die "marc_leader not array = ", dump( $marc_leader ) unless (ref($marc_leader) eq 'ARRAY');
521                            return $marc_leader->[ $marc_record_offset ];
522                    } else {
523                            return;
524                    }
525            }
526    }
527    
528    =head2 marc_fixed
529    
530    Create control/indentifier fields with values in fixed positions
531    
532      marc_fixed('008', 00, '070402');
533      marc_fixed('008', 39, '|');
534    
535    Positions not specified will be filled with spaces (C<0x20>).
536    
537    There will be no effort to extend last specified value to full length of
538    field in standard.
539    
540    =cut
541    
542    sub marc_fixed {
543            my ($f, $pos, $val) = @_;
544            die "need marc(field, position, value)" unless defined($f) && defined($pos);
545    
546            confess "need val" unless defined $val;
547    
548            my $update = 0;
549    
550            map {
551                    if ($_->[0] eq $f) {
552                            my $old = $_->[1];
553                            if (length($old) <= $pos) {
554                                    $_->[1] .= ' ' x ( $pos - length($old) ) . $val;
555                                    warn "## marc_fixed($f,$pos,'$val') append '$old' -> '$_->[1]'\n" if ($debug > 1);
556                            } else {
557                                    $_->[1] = substr($old, 0, $pos) . $val . substr($old, $pos + length($val));
558                                    warn "## marc_fixed($f,$pos,'$val') update '$old' -> '$_->[1]'\n" if ($debug > 1);
559                            }
560                            $update++;
561                    }
562            } @{ $marc_record->[ $marc_record_offset ] };
563    
564            if (! $update) {
565                    my $v = ' ' x $pos . $val;
566                    push @{ $marc_record->[ $marc_record_offset ] }, [ $f, $v ];
567                    warn "## marc_fixed($f,$pos,'val') created '$v'\n" if ($debug > 1);
568          }          }
569  }  }
570    
# Line 621  sub marc_duplicate { Line 696  sub marc_duplicate {
696           my $m = $marc_record->[ -1 ];           my $m = $marc_record->[ -1 ];
697           die "can't duplicate record which isn't defined" unless ($m);           die "can't duplicate record which isn't defined" unless ($m);
698           push @{ $marc_record }, dclone( $m );           push @{ $marc_record }, dclone( $m );
699           warn "## marc_duplicate = ", dump(@$marc_record), $/ if ($debug > 1);           push @{ $marc_leader }, dclone( marc_leader() );
700             warn "## marc_duplicate = ", dump(@$marc_leader, @$marc_record), $/ if ($debug > 1);
701           $marc_record_offset = $#{ $marc_record };           $marc_record_offset = $#{ $marc_record };
702           warn "## marc_record_offset = $marc_record_offset", $/ if ($debug > 1);           warn "## marc_record_offset = $marc_record_offset", $/ if ($debug > 1);
703    
704  }  }
705    
706  =head2 marc_remove  =head2 marc_remove
# Line 635  Remove some field or subfield from MARC Line 712  Remove some field or subfield from MARC
712    
713  This will erase field C<200> or C<200^a> from current MARC record.  This will erase field C<200> or C<200^a> from current MARC record.
714    
715      marc_remove('*');
716    
717    Will remove all fields in current MARC record.
718    
719  This is useful after calling C<marc_duplicate> or on it's own (but, you  This is useful after calling C<marc_duplicate> or on it's own (but, you
720  should probably just remove that subfield definition if you are not  should probably just remove that subfield definition if you are not
721  using C<marc_duplicate>).  using C<marc_duplicate>).
# Line 652  sub marc_remove { Line 733  sub marc_remove {
733    
734          warn "### marc_remove before = ", dump( $marc ), $/ if ($debug > 2);          warn "### marc_remove before = ", dump( $marc ), $/ if ($debug > 2);
735    
736          my $i = 0;          if ($f eq '*') {
737          foreach ( 0 .. $#{ $marc } ) {  
738                  last unless (defined $marc->[$i]);                  delete( $marc_record->[ $marc_record_offset ] );
739                  warn "#### working on ",dump( @{ $marc->[$i] }), $/ if ($debug > 3);                  warn "## full marc_record = ", dump( @{ $marc_record }), $/ if ($debug > 1);
740                  if ($marc->[$i]->[0] eq $f) {  
741                          if (! defined $sf) {          } else {
742                                  # remove whole field  
743                                  splice @$marc, $i, 1;                  my $i = 0;
744                                  warn "#### slice \@\$marc, $i, 1 = ",dump( @{ $marc }), $/ if ($debug > 3);                  foreach ( 0 .. $#{ $marc } ) {
745                                  $i--;                          last unless (defined $marc->[$i]);
746                          } else {                          warn "#### working on ",dump( @{ $marc->[$i] }), $/ if ($debug > 3);
747                                  foreach my $j ( 0 .. (( $#{ $marc->[$i] } - 3 ) / 2) ) {                          if ($marc->[$i]->[0] eq $f) {
748                                          my $o = ($j * 2) + 3;                                  if (! defined $sf) {
749                                          if ($marc->[$i]->[$o] eq $sf) {                                          # remove whole field
750                                                  # remove subfield                                          splice @$marc, $i, 1;
751                                                  splice @{$marc->[$i]}, $o, 2;                                          warn "#### slice \@\$marc, $i, 1 = ",dump( @{ $marc }), $/ if ($debug > 3);
752                                                  warn "#### slice \@{\$marc->[$i]}, $o, 2 = ", dump( @{ $marc }), $/ if ($debug > 3);                                          $i--;
753                                                  # is record now empty?                                  } else {
754                                                  if ($#{ $marc->[$i] } == 2) {                                          foreach my $j ( 0 .. (( $#{ $marc->[$i] } - 3 ) / 2) ) {
755                                                          splice @$marc, $i, 1;                                                  my $o = ($j * 2) + 3;
756                                                          warn "#### slice \@\$marc, $i, 1 = ", dump( @{ $marc }), $/ if ($debug > 3);                                                  if ($marc->[$i]->[$o] eq $sf) {
757                                                          $i--;                                                          # remove subfield
758                                                  };                                                          splice @{$marc->[$i]}, $o, 2;
759                                                            warn "#### slice \@{\$marc->[$i]}, $o, 2 = ", dump( @{ $marc }), $/ if ($debug > 3);
760                                                            # is record now empty?
761                                                            if ($#{ $marc->[$i] } == 2) {
762                                                                    splice @$marc, $i, 1;
763                                                                    warn "#### slice \@\$marc, $i, 1 = ", dump( @{ $marc }), $/ if ($debug > 3);
764                                                                    $i--;
765                                                            };
766                                                    }
767                                          }                                          }
768                                  }                                  }
769                          }                          }
770                            $i++;
771                  }                  }
                 $i++;  
         }  
772    
773          warn "### marc_remove($f", $sf ? ",$sf" : "", ") after = ", dump( $marc ), $/ if ($debug > 2);                  warn "### marc_remove($f", $sf ? ",$sf" : "", ") after = ", dump( $marc ), $/ if ($debug > 2);
774    
775          $marc_record->[ $marc_record_offset ] = $marc;                  $marc_record->[ $marc_record_offset ] = $marc;
776            }
777    
778          warn "## full marc_record = ", dump( @{ $marc_record }), $/ if ($debug > 1);          warn "## full marc_record = ", dump( @{ $marc_record }), $/ if ($debug > 1);
779  }  }
# Line 759  sub marc_original_order { Line 848  sub marc_original_order {
848          warn "## marc_record = ", dump( $marc_record ),$/ if ($debug > 1);          warn "## marc_record = ", dump( $marc_record ),$/ if ($debug > 1);
849  }  }
850    
851    =head2 marc_count
852    
853    Return number of MARC records created using L</marc_duplicate>.
854    
855      print "created ", marc_count(), " records";
856    
857    =cut
858    
859    sub marc_count {
860            return $#{ $marc_record };
861    }
862    
863    
864  =head1 Functions to extract data from input  =head1 Functions to extract data from input
865    
# Line 781  sub _pack_subfields_hash { Line 882  sub _pack_subfields_hash {
882    
883          my ($h,$include_subfields) = @_;          my ($h,$include_subfields) = @_;
884    
885            # sanity and ease of use
886            return $h if (ref($h) ne 'HASH');
887    
888          if ( defined($h->{subfields}) ) {          if ( defined($h->{subfields}) ) {
889                  my $sfs = delete $h->{subfields} || die "no subfields?";                  my $sfs = delete $h->{subfields} || die "no subfields?";
890                  my @out;                  my @out;
# Line 880  syntaxtic sugar for Line 984  syntaxtic sugar for
984    @v = rec('200')    @v = rec('200')
985    @v = rec('200','a')    @v = rec('200','a')
986    
987    If rec() returns just single value, it will
988    return scalar, not array.
989    
990  =cut  =cut
991    
992  sub rec {  sub rec {
# Line 889  sub rec { Line 996  sub rec {
996          } elsif ($#_ == 1) {          } elsif ($#_ == 1) {
997                  @out = rec2(@_);                  @out = rec2(@_);
998          }          }
999          if (@out) {          if ($#out == 0 && ! wantarray) {
1000                    return $out[0];
1001            } elsif (@out) {
1002                  return @out;                  return @out;
1003          } else {          } else {
1004                  return '';                  return '';
# Line 925  Prefix all values with a string Line 1034  Prefix all values with a string
1034  =cut  =cut
1035    
1036  sub prefix {  sub prefix {
1037          my $p = shift or return;          my $p = shift;
1038            return @_ unless defined( $p );
1039          return map { $p . $_ } grep { defined($_) } @_;          return map { $p . $_ } grep { defined($_) } @_;
1040  }  }
1041    
# Line 938  suffix all values with a string Line 1048  suffix all values with a string
1048  =cut  =cut
1049    
1050  sub suffix {  sub suffix {
1051          my $s = shift or die "suffix needs string as first argument";          my $s = shift;
1052            return @_ unless defined( $s );
1053          return map { $_ . $s } grep { defined($_) } @_;          return map { $_ . $s } grep { defined($_) } @_;
1054  }  }
1055    
# Line 951  surround all values with a two strings Line 1062  surround all values with a two strings
1062  =cut  =cut
1063    
1064  sub surround {  sub surround {
1065          my $p = shift or die "surround need prefix as first argument";          my $p = shift;
1066          my $s = shift or die "surround needs suffix as second argument";          my $s = shift;
1067            $p = '' unless defined( $p );
1068            $s = '' unless defined( $s );
1069          return map { $p . $_ . $s } grep { defined($_) } @_;          return map { $p . $_ . $s } grep { defined($_) } @_;
1070  }  }
1071    
# Line 1017  Easy as pie, right? Line 1130  Easy as pie, right?
1130  sub lookup {  sub lookup {
1131          my ($what, $database, $input, $key, $having) = @_;          my ($what, $database, $input, $key, $having) = @_;
1132    
1133          confess "lookup needs 5 arguments: what, database, input, key, having" unless ($#_ == 4);          confess "lookup needs 5 arguments: what, database, input, key, having\n" unless ($#_ == 4);
1134    
1135          warn "## lookup ($database, $input, $key)", $/ if ($debug > 1);          warn "## lookup ($database, $input, $key)", $/ if ($debug > 1);
1136          return unless (defined($lookup->{$database}->{$input}->{$key}));          return unless (defined($lookup->{$database}->{$input}->{$key}));
1137    
1138          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);
1139    
1140          my $mfns;          my $mfns;
1141          my @having = $having->();          my @having = $having->();
# Line 1031  sub lookup { Line 1144  sub lookup {
1144    
1145          foreach my $h ( @having ) {          foreach my $h ( @having ) {
1146                  if (defined($lookup->{$database}->{$input}->{$key}->{$h})) {                  if (defined($lookup->{$database}->{$input}->{$key}->{$h})) {
1147                          warn "lookup for $database/$input/$key/$h return ",dump($lookup->{$database}->{$input}->{$key}->{$h}),"\n";                          warn "lookup for $database/$input/$key/$h return ",dump($lookup->{$database}->{$input}->{$key}->{$h}),"\n" if ($debug);
1148                          $mfns->{$_}++ foreach keys %{ $lookup->{$database}->{$input}->{$key}->{$h} };                          $mfns->{$_}++ foreach keys %{ $lookup->{$database}->{$input}->{$key}->{$h} };
1149                  }                  }
1150          }          }
# Line 1040  sub lookup { Line 1153  sub lookup {
1153    
1154          my @mfns = sort keys %$mfns;          my @mfns = sort keys %$mfns;
1155    
1156          warn "# lookup loading $database/$input/$key mfn ", join(",",@mfns)," having ",dump(@having),"\n";          warn "# lookup loading $database/$input/$key mfn ", join(",",@mfns)," having ",dump(@having),"\n" if ($debug);
1157    
1158          my $old_rec = $rec;          my $old_rec = $rec;
1159          my @out;          my @out;
1160    
1161          foreach my $mfn (@mfns) {          foreach my $mfn (@mfns) {
1162                  $rec = $load_ds_coderef->( $database, $input, $mfn );                  $rec = $load_row_coderef->( $database, $input, $mfn );
1163    
1164                  warn "got $database/$input/$mfn = ", dump($rec), $/;                  warn "got $database/$input/$mfn = ", dump($rec), $/ if ($debug);
1165    
1166                  my @vals = $what->();                  my @vals = $what->();
1167    
1168                  push @out, ( @vals );                  push @out, ( @vals );
1169    
1170                  warn "lookup for mfn $mfn returned ", dump(@vals), $/;                  warn "lookup for mfn $mfn returned ", dump(@vals), $/ if ($debug);
1171          }          }
1172    
1173  #       if (ref($lookup->{$k}) eq 'ARRAY') {  #       if (ref($lookup->{$k}) eq 'ARRAY') {
# Line 1065  sub lookup { Line 1178  sub lookup {
1178    
1179          $rec = $old_rec;          $rec = $old_rec;
1180    
1181          warn "## lookup returns = ", dump(@out), $/;          warn "## lookup returns = ", dump(@out), $/ if ($debug);
1182    
1183          return @out;          if ($#out == 0) {
1184                    return $out[0];
1185            } else {
1186                    return @out;
1187            }
1188  }  }
1189    
1190  =head2 save_into_lookup  =head2 save_into_lookup
# Line 1123  Consult config values stored in C<config Line 1240  Consult config values stored in C<config
1240    $database_code = config();    # use _ from hash    $database_code = config();    # use _ from hash
1241    $database_name = config('name');    $database_name = config('name');
1242    $database_input_name = config('input name');    $database_input_name = config('input name');
   $tag = config('input normalize tag');  
1243    
1244  Up to three levels are supported.  Up to three levels are supported.
1245    
# Line 1239  sub split_rec_on { Line 1355  sub split_rec_on {
1355          }          }
1356  }  }
1357    
1358    my $hash;
1359    
1360    =head2 set
1361    
1362      set( key => 'value' );
1363    
1364    =cut
1365    
1366    sub set {
1367            my ($k,$v) = @_;
1368            warn "## set ( $k => ", dump($v), " )", $/ if ( $debug );
1369            $hash->{$k} = $v;
1370    };
1371    
1372    =head2 get
1373    
1374      get( 'key' );
1375    
1376    =cut
1377    
1378    sub get {
1379            my $k = shift || return;
1380            my $v = $hash->{$k};
1381            warn "## get $k = ", dump( $v ), $/ if ( $debug );
1382            return $v;
1383    }
1384    
1385    =head2 count
1386    
1387      if ( count( @result ) == 1 ) {
1388            # do something if only 1 result is there
1389      }
1390    
1391    =cut
1392    
1393    sub count {
1394            warn "## count ",dump(@_),$/ if ( $debug );
1395            return @_ . '';
1396    }
1397    
1398  # END  # END
1399  1;  1;

Legend:
Removed from v.729  
changed lines
  Added in v.915

  ViewVC Help
Powered by ViewVC 1.1.26