/[webpac2]/trunk/lib/WebPAC/Lookup.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/Lookup.pm

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

revision 234 by dpavlin, Tue Dec 6 19:41:17 2005 UTC revision 393 by dpavlin, Wed Feb 15 14:49:48 2006 UTC
# Line 59  Create new lookup object. Line 59  Create new lookup object.
59  =cut  =cut
60    
61  sub new {  sub new {
62          my $class = shift;          my $class = shift;
63          my $self = {@_};          my $self = {@_};
64          bless($self, $class);          bless($self, $class);
65    
66          my $log = $self->_get_logger();          my $log = $self->_get_logger();
# Line 79  sub new { Line 79  sub new {
79          } else {          } else {
80                  $log->logide("unsupported lookup file $lookup_file");                  $log->logide("unsupported lookup file $lookup_file");
81          }          }
82            $log->debug("lookup_def: " . Dumper( $self->{lookup_def} ));
83    
84          $log->logconfess("lookup config file isn't ARRAY but ", sub { Dumper( $self->{'lookup_def'} ) }) if ($self->{'lookup_def'} !~ /ARRAY/o);          $log->logconfess("lookup config file isn't ARRAY but ", sub { Dumper( $self->{'lookup_def'} ) }) if ($self->{'lookup_def'} !~ /ARRAY/o);
85    
# Line 89  sub new { Line 90  sub new {
90          $self->{'LOOKUP_REGEX'} = qr/$self->{'is_lookup_regex'}/;          $self->{'LOOKUP_REGEX'} = qr/$self->{'is_lookup_regex'}/;
91          $self->{'LOOKUP_REGEX_SAVE'} = qr/$self->{'save_lookup_regex'}/;          $self->{'LOOKUP_REGEX_SAVE'} = qr/$self->{'save_lookup_regex'}/;
92    
93          $log->debug("regexps: ", $self->{'LOOKUP_REGEX'}, " ", $self->{'LOOKUP_REGEX_SAVE'});          $log->debug("regexps lookup:", $self->{'LOOKUP_REGEX'}, " save:", $self->{'LOOKUP_REGEX_SAVE'});
94    
95          $self ? return $self : return undef;          $self ? return $self : return undef;
96  }  }
# Line 104  Returns true if this record produced loo Line 105  Returns true if this record produced loo
105    
106  =cut  =cut
107    
108  sub add($) {  sub add {
109          my $self = shift;          my $self = shift;
110    
111          my $log = $self->_get_logger();          my $log = $self->_get_logger();
# Line 116  sub add($) { Line 117  sub add($) {
117          my $n = 0;          my $n = 0;
118    
119          foreach my $i (@{ $self->{'lookup_def'} }) {          foreach my $i (@{ $self->{'lookup_def'} }) {
120                  $log->logconfess("need key") unless defined($i->{'key'});                  $log->logconfess("need key in ", Dumper($i) ) unless defined($i->{'key'});
121                  $log->logconfess("need val") unless defined($i->{'val'});                  $log->logconfess("need val in ", Dumper($i) ) unless defined($i->{'val'});
122    
123                  $n++;                  $n++;
124    
# Line 145  sub add($) { Line 146  sub add($) {
146    
147  Perform lookups on format supplied to it.  Perform lookups on format supplied to it.
148    
149   my $text = $lookup->lookup('[v900]');   my $text = $lookup->lookup('lookup{v900}');
150    
151  Lookups can be nested (like C<[d:[a:[v900]]]>).  Lookups can be nested (like lookup{B<d:>lookup{B<a:>lookup{B<v900>}}}).
152    
153  =cut  =cut
154    
# Line 161  sub lookup { Line 162  sub lookup {
162          if ($tmp =~ $self->{'LOOKUP_REGEX'}) {          if ($tmp =~ $self->{'LOOKUP_REGEX'}) {
163                  my @in = ( $tmp );                  my @in = ( $tmp );
164    
                 $log->debug("lookup for: ",$tmp);  
   
165                  my @out;                  my @out;
166                  while (my $f = shift @in) {                  while (my $f = shift @in) {
167                          if ($f =~ $self->{'LOOKUP_REGEX_SAVE'}) {                          if ($f =~ $self->{'LOOKUP_REGEX_SAVE'}) {
# Line 180  sub lookup { Line 179  sub lookup {
179                                  push @out, $f;                                  push @out, $f;
180                          }                          }
181                  }                  }
182                    $log->debug("lookup for: ",$tmp, " returned: ", join(", ",@out));
183    
184                  $log->logconfess("return is array and it's not expected!") unless wantarray;                  $log->logconfess("return is array and it's not expected!") unless wantarray;
185    
186                  return @out;                  return @out;
187          } else {          } else {
188                  return $tmp;                  return $tmp;

Legend:
Removed from v.234  
changed lines
  Added in v.393

  ViewVC Help
Powered by ViewVC 1.1.26