/[webpac]/trunk2/lib/WebPAC.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 /trunk2/lib/WebPAC.pm

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

revision 355 by dpavlin, Wed Jun 16 11:41:50 2004 UTC revision 356 by dpavlin, Wed Jun 16 13:41:54 2004 UTC
# Line 195  sub create_lookup { Line 195  sub create_lookup {
195          }          }
196  }  }
197    
198    =head2 get_data
199    
200    Returns value from record.
201    
202     $self->get_data(\$rec,$f,$sf,$i,\$found);
203    
204    Arguments are:
205    record reference C<$rec>,
206    field C<$f>,
207    optional subfiled C<$sf>,
208    index for repeatable values C<$i>.
209    
210    Optinal variable C<$found> will be incremeted if thre
211    is field.
212    
213    Returns value or empty string.
214    
215    =cut
216    
217    sub get_data {
218            my $self = shift;
219    
220            my ($rec,$f,$sf,$i,$found) = @_;
221            if ($$rec->{$f}) {
222                    if ($sf && $$rec->{$f}->[$i]->{$sf}) {
223                            $$found++ if (defined($$found));
224                            return $$rec->{$f}->[$i]->{$sf};
225                    } elsif ($$rec->{$f}->[$i]) {
226                            $$found++ if (defined($$found));
227                            return $$rec->{$f}->[$i];
228                    }
229            } else {
230                    return '';
231            }
232    }
233    
234  =head2 fill_in  =head2 fill_in
235    
236  Workhourse of all: takes record from in-memory structure of database and  Workhourse of all: takes record from in-memory structure of database and
# Line 228  sub fill_in { Line 264  sub fill_in {
264    
265          my $found = 0;          my $found = 0;
266    
         # get field with subfield  
         sub get_sf {  
                 my ($found,$rec,$f,$sf,$i) = @_;  
                 if ($$rec->{$f} && $$rec->{$f}->[$i]->{$sf}) {  
                         $$found++;  
                         return $$rec->{$f}->[$i]->{$sf};  
                 } else {  
                         return '';  
                 }  
         }  
   
         # get field (without subfield)  
         sub get_nosf {  
                 my ($found,$rec,$f,$i) = @_;  
                 if ($$rec->{$f} && $$rec->{$f}->[$i]) {  
                         $$found++;  
                         return $$rec->{$f}->[$i];  
                 } else {  
                         return '';  
                 }  
         }  
   
267          # do actual replacement of placeholders          # do actual replacement of placeholders
268          $format =~ s/v(\d+)\^(\w)/get_sf(\$found,\$rec,$1,$2,$i)/ges;          $format =~ s/v(\d+)(?:\^(\w))*/$self->get_data(\$rec,$1,$2,$i,\$found)/ges;
         $format =~ s/v(\d+)/get_nosf(\$found,\$rec,$1,$i)/ges;  
269    
270          if ($found) {          if ($found) {
271                  # do we have lookups?                  # do we have lookups?
# Line 310  sub lookup { Line 323  sub lookup {
323          }          }
324  }  }
325    
326    =head2 parse
327    
328    Perform smart parsing of string, skipping delimiters for fields which aren't
329    defined. It can also eval code in format starting with C<eval{...}> and
330    return output or nothing depending on eval code.
331    
332     $webpac->parse($rec,'eval{"v901^a" eq "Deskriptor"}descriptor: v250^a', $i);
333    
334    =cut
335    
336    sub parse {
337            my $self = shift;
338    
339            my ($rec, $format, $i) = @_;
340    
341            my @out;
342    
343            my $eval_code;
344            # remove eval{...} from beginning
345            $eval_code = $1 if ($format =~ s/^eval{([^}]+)}//s);
346    
347            my $prefix = '';
348            $prefix = $1 if ($format =~ s/^(.+)(v\d+(?:\^\w)*)/$2/s);
349    
350            sub f_sf_del {
351                    my ($self,$rec,$out,$f,$sf,$del,$i) = @_;
352    
353                    my $found=0;
354                    my $tmp = $self->get_data($rec,$f,$sf,$i,\$found);
355                    if ($found) {
356                            push @{$$out}, $tmp;
357                            push @{$$out}, $del;
358                    }
359                    return '';
360            }
361    
362            #$format =~ s/(.*)v(\d+)(?:\^(\w))*/f_sf_del($self,\$rec,\@out,$2,$3,$1,$i/ges;
363    
364            print Dumper(@out);
365    
366    }
367    
368  1;  1;

Legend:
Removed from v.355  
changed lines
  Added in v.356

  ViewVC Help
Powered by ViewVC 1.1.26