/[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 4 by dpavlin, Sat Jul 16 12:37:18 2005 UTC revision 7 by dpavlin, Sat Jul 16 16:00:19 2005 UTC
# Line 9  use base qw/WebPAC::Common/; Line 9  use base qw/WebPAC::Common/;
9  use File::Slurp;  use File::Slurp;
10  use Data::Dumper;  use Data::Dumper;
11    
12    my $LOOKUP_REGEX = 'lookup{[^\{\}]+}';
13    my $LOOKUP_REGEX_SAVE = 'lookup{([^\{\}]+)}';
14    
15  =head1 NAME  =head1 NAME
16    
17  WebPAC::Lookup - simple normalisation plugin to produce lookup  WebPAC::Lookup - simple normalisation plugin to produce lookup
# Line 81  sub new { Line 84  sub new {
84    
85  Create lookup from record using lookup definition.  Create lookup from record using lookup definition.
86    
87   $self->create_lookup($rec);   $self->add($rec);
88    
89  Returns true if this record produced lookup.  Returns true if this record produced lookup.
90    
# Line 124  sub add($) { Line 127  sub add($) {
127          return $n;          return $n;
128  }  }
129    
130    =head2 lookup
131    
132    Perform lookups on format supplied to it.
133    
134     my $text = $lookup->lookup('[v900]');
135    
136    Lookups can be nested (like C<[d:[a:[v900]]]>).
137    
138    =cut
139    
140    sub lookup {
141            my $self = shift;
142    
143            my $log = $self->_get_logger();
144    
145            my $tmp = shift || $log->logconfess("need format");
146    
147            if ($tmp =~ /$LOOKUP_REGEX/o) {
148                    my @in = ( $tmp );
149    
150                    $log->debug("lookup for: ",$tmp);
151    
152                    my @out;
153                    while (my $f = shift @in) {
154                            if ($f =~ /$LOOKUP_REGEX_SAVE/o) {
155                                    my $k = $1;
156                                    if ($self->{'lookup'}->{$k}) {
157                                            foreach my $nv (@{$self->{'lookup'}->{$k}}) {
158                                                    my $tmp2 = $f;
159                                                    $tmp2 =~ s/lookup{$k}/$nv/g;
160                                                    push @in, $tmp2;
161                                            }
162                                    } else {
163                                            undef $f;
164                                    }
165                            } elsif ($f) {
166                                    push @out, $f;
167                            }
168                    }
169                    $log->logconfess("return is array and it's not expected!") unless wantarray;
170                    return @out;
171            } else {
172                    return $tmp;
173            }
174    }
175    
176  =head1 AUTHOR  =head1 AUTHOR
177    
178  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>

Legend:
Removed from v.4  
changed lines
  Added in v.7

  ViewVC Help
Powered by ViewVC 1.1.26