/[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 219 by dpavlin, Mon Dec 5 17:48:08 2005 UTC revision 295 by dpavlin, Mon Dec 19 15:34:47 2005 UTC
# Line 11  WebPAC::Normalize - data mungling for no Line 11  WebPAC::Normalize - data mungling for no
11    
12  =head1 VERSION  =head1 VERSION
13    
14  Version 0.04  Version 0.07
15    
16  =cut  =cut
17    
18  our $VERSION = '0.04';  our $VERSION = '0.07';
19    
20  =head1 SYNOPSIS  =head1 SYNOPSIS
21    
# Line 47  optional C<filter{filter_name}> at B<beg Line 47  optional C<filter{filter_name}> at B<beg
47  code defined as code ref on format after field substitution to producing  code defined as code ref on format after field substitution to producing
48  output  output
49    
50    There is one built-in filter called C<regex> which can be use like this:
51    
52      filter{regex(s/foo/bar/)}
53    
54  =item *  =item *
55    
56  optional C<lookup{...}> will be then performed. See C<WebPAC::Lookups>.  optional C<lookup{...}> will be then performed. See C<WebPAC::Lookups>.
# Line 117  sub new { Line 121  sub new {
121    
122          $log->warn("no prefix defined. please check that!") unless ($self->{'prefix'});          $log->warn("no prefix defined. please check that!") unless ($self->{'prefix'});
123    
124            $log->debug("using lookup regex: ", $self->{lookup_regex}) if ($r && $l);
125    
126            if (! $self->{filter} || ! $self->{filter}->{regex}) {
127                    $log->debug("adding built-in filter regex");
128                    $self->{filter}->{regex} = sub {
129                            my ($val, $regex) = @_;
130                            eval "\$val =~ $regex";
131                            return $val;
132                    };
133            }
134    
135          $self ? return $self : return undef;          $self ? return $self : return undef;
136  }  }
137    
# Line 155  sub data_structure { Line 170  sub data_structure {
170                  $log->debug("cache miss, creating");                  $log->debug("cache miss, creating");
171          }          }
172    
         undef $self->{'currnet_filename'};  
         undef $self->{'headline'};  
   
173          my @sorted_tags;          my @sorted_tags;
174          if ($self->{tags_by_order}) {          if ($self->{tags_by_order}) {
175                  @sorted_tags = @{$self->{tags_by_order}};                  @sorted_tags = @{$self->{tags_by_order}};
# Line 213  sub data_structure { Line 225  sub data_structure {
225    
226                          foreach my $type (@types) {                          foreach my $type (@types) {
227                                  # append to previous line?                                  # append to previous line?
228                                  $log->debug("type: $type ",sub { join(" ",@v) }, $row->{'append'} || 'no append');                                  $log->debug("type: $type ",sub { join(" ",@v) }, " ", $row->{'append'} || 'no append');
229                                  if ($tag->{'append'}) {                                  if ($tag->{'append'}) {
230    
231                                          # I will delimit appended part with                                          # I will delimit appended part with
# Line 276  return output or nothing depending on ev Line 288  return output or nothing depending on ev
288    
289   my $text = $webpac->parse($rec,'eval{"v901^a" eq "Deskriptor"}descriptor: v250^a', $i);   my $text = $webpac->parse($rec,'eval{"v901^a" eq "Deskriptor"}descriptor: v250^a', $i);
290    
291    Filters are implemented here. While simple form of filters looks like this:
292    
293      filter{name_of_filter}
294    
295    but, filters can also have variable number of parametars like this:
296    
297      filter{name_of_filter(param,param,param)}
298    
299  =cut  =cut
300    
301    my $warn_once;
302    
303  sub parse {  sub parse {
304          my $self = shift;          my $self = shift;
305    
# Line 347  sub parse { Line 369  sub parse {
369                  return if (! $self->_eval($eval));                  return if (! $self->_eval($eval));
370          }          }
371                    
372          if ($filter_name && $self->{'filter'}->{$filter_name}) {          if ($filter_name) {
373                  $log->debug("about to filter{$filter_name} format: $out");                  my @filter_args;
374                  $out = $self->{'filter'}->{$filter_name}->($out);                  if ($filter_name =~ s/(\w+)\((.*)\)/$1/) {
375                  return unless(defined($out));                          @filter_args = split(/,/, $2);
376                  $log->debug("filter result: $out");                  }
377                    if ($self->{'filter'}->{$filter_name}) {
378                            $log->debug("about to filter{$filter_name} format: $out with arguments: ", join(",", @filter_args));
379                            unshift @filter_args, $out;
380                            $out = $self->{'filter'}->{$filter_name}->(@filter_args);
381                            return unless(defined($out));
382                            $log->debug("filter result: $out");
383                    } elsif (! $warn_once->{$filter_name}) {
384                            $log->warn("trying to use undefined filter $filter_name");
385                            $warn_once->{$filter_name}++;
386                    }
387          }          }
388    
389          return $out;          return $out;
# Line 461  sub fill_in { Line 493  sub fill_in {
493                  # do we have lookups?                  # do we have lookups?
494                  if ($self->{'lookup'}) {                  if ($self->{'lookup'}) {
495                          if ($self->{'lookup'}->can('lookup')) {                          if ($self->{'lookup'}->can('lookup')) {
496                                  return $self->{'lookup'}->lookup($format);                                  my @lookup = $self->{lookup}->lookup($format);
497                                    $log->debug("lookup $format", join(", ", @lookup));
498                                    return @lookup;
499                          } else {                          } else {
500                                  $log->warn("Have lookup object but can't invoke lookup method");                                  $log->warn("Have lookup object but can't invoke lookup method");
501                          }                          }

Legend:
Removed from v.219  
changed lines
  Added in v.295

  ViewVC Help
Powered by ViewVC 1.1.26