X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FFilter.pm;h=aefa922419ee94afac488101b11c184aba45a8eb;hb=638d9efe6fe3d3c4eec08d5e985fce4dd760423b;hp=1e1913a27af1cec13eeed03f51e2962191899521;hpb=8942c27356acc5d5f5a20134461bcf7e6bd6a044;p=spider.git diff --git a/perl/Filter.pm b/perl/Filter.pm index 1e1913a2..aefa9224 100644 --- a/perl/Filter.pm +++ b/perl/Filter.pm @@ -23,7 +23,7 @@ # # # @in = ( -# [ action, fieldno, fieldsort, comparison ], +# [ action, fieldno, fieldsort, comparison, action data ], # ... # ); # @@ -37,7 +37,8 @@ # numeric, 'r' is ranges of pairs of numeric values and 'd' is default. # # Filter::it basically goes thru the list of comparisons from top to -# bottom and when one matches it will return the action. The fields +# bottom and when one matches it will return the action and the action data as a list. +# The fields # are the element nos of the list that is presented to Filter::it. Element # 0 is the first field of the list. # @@ -51,9 +52,10 @@ use Carp; use strict; -use vars qw ($filterbasefn); +use vars qw ($filterbasefn $in); $filterbasefn = "$main::root/filter"; +$in = undef; # initial filter system sub init @@ -68,27 +70,30 @@ sub init sub it { my $filter = shift; + my ($action, $field, $fieldsort, $comp, $actiondata); my $ref; # default action is 1 - return 1 if !$filter; - + $action = 1; + $actiondata = ""; + return ($action, $actiondata) if !$filter; + for $ref (@{$filter}) { - my ($action, $field, $fieldsort, $comp) = @{$ref}; + ($action, $field, $fieldsort, $comp, $actiondata) = @{$ref}; if ($fieldsort eq 'n') { my $val = $_[$field]; - return $action if grep $_ == $val, @{$comp}; + return ($action, $actiondata) if grep $_ == $val, @{$comp}; } elsif ($fieldsort eq 'r') { my $val = $_[$field]; my $i; my @range = @{$comp}; for ($i = 0; $i < @range; $i += 2) { - return $action if $val >= $range[$i] && $val <= $range[$i+1]; + return ($action, $actiondata) if $val >= $range[$i] && $val <= $range[$i+1]; } } elsif ($fieldsort eq 'a') { - return $action if $_[$field] =~ m{$comp}; + return ($action, $actiondata) if $_[$field] =~ m{$comp}; } else { - return $action; # the default action + return ($action, $actiondata); # the default action } } } @@ -101,12 +106,23 @@ sub it # sub read_in { - my ($sort, $call) = @_; - my $fn = "$filterbasefn/$sort/$call.pl"; - my $in; + my ($sort, $call, $flag) = @_; + + # first uppercase + $flag = ($flag) ? "in_" : ""; + $call = uc $call; + my $fn = "$filterbasefn/$sort/$flag$call.pl"; + + # otherwise lowercase + unless (-e $fn) { + $call = lc $call; + $fn = "$filterbasefn/$sort/$flag$call.pl"; + } + # load it if (-e $fn) { - do $fn; + do "$fn"; + dbg('conn', "$@") if $@; return $in; } return undef; @@ -132,7 +148,8 @@ sub write_out } my $today = localtime; - print FILTER "# + print FILTER "#!/usr/bin/perl +# # Filter for $call stored $today # \$in = [ @@ -140,7 +157,7 @@ sub write_out my $ref; for $ref (@_) { - my ($action, $field, $fieldsort, $comp) = @{$ref}; + my ($action, $field, $fieldsort, $comp, $actiondata) = @{$ref}; print FILTER "\t[ $action, $field, $fieldsort,"; if ($fieldsort eq 'n' || $fieldsort eq 'r') { print FILTER "[ ", join (',', $comp), " ],";