/[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 259 by dpavlin, Thu Dec 15 17:01:10 2005 UTC revision 260 by dpavlin, Fri Dec 16 14:40:55 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.05  Version 0.06
15    
16  =cut  =cut
17    
18  our $VERSION = '0.05';  our $VERSION = '0.06';
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 119  sub new { Line 123  sub new {
123    
124          $log->debug("using lookup regex: ", $self->{lookup_regex}) if ($r && $l);          $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 278  return output or nothing depending on ev Line 291  return output or nothing depending on ev
291    
292   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);
293    
294    Filters are implemented here. While simple form of filters looks like this:
295    
296      filter{name_of_filter}
297    
298    but, filters can also have variable number of parametars like this:
299    
300      filter{name_of_filter(param,param,param)}
301    
302  =cut  =cut
303    
304  sub parse {  sub parse {
# Line 349  sub parse { Line 370  sub parse {
370                  return if (! $self->_eval($eval));                  return if (! $self->_eval($eval));
371          }          }
372                    
373          if ($filter_name && $self->{'filter'}->{$filter_name}) {          if ($filter_name) {
374                  $log->debug("about to filter{$filter_name} format: $out");                  my @filter_args;
375                  $out = $self->{'filter'}->{$filter_name}->($out);                  if ($filter_name =~ s/(\w+)\((.*)\)/$1/) {
376                  return unless(defined($out));                          @filter_args = split(/,/, $2);
377                  $log->debug("filter result: $out");                  }
378                    if ($self->{'filter'}->{$filter_name}) {
379                            $log->debug("about to filter{$filter_name} format: $out with arguments: ", join(",", @filter_args));
380                            unshift @filter_args, $out;
381                            $out = $self->{'filter'}->{$filter_name}->(@filter_args);
382                            return unless(defined($out));
383                            $log->debug("filter result: $out");
384                    } else {
385                            $log->warn("trying to use undefined filter $filter_name");
386                    }
387          }          }
388    
389          return $out;          return $out;

Legend:
Removed from v.259  
changed lines
  Added in v.260

  ViewVC Help
Powered by ViewVC 1.1.26