-#
-# takes the reference to the filter (the first argument) and applies
-# it to the subsequent arguments and returns the action specified.
-#
-sub it
-{
- my $filter = shift;
- my ($action, $field, $fieldsort, $comp, $actiondata);
- my $ref;
-
- # default action is 1
- $action = 1;
- $actiondata = "";
- return ($action, $actiondata) if !$filter;
-
- for $ref (@{$filter}) {
- ($action, $field, $fieldsort, $comp, $actiondata) = @{$ref};
- if ($fieldsort eq 'n') {
- my $val = $_[$field];
- 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, $actiondata) if $val >= $range[$i] && $val <= $range[$i+1];
- }
- } elsif ($fieldsort eq 'a') {
- return ($action, $actiondata) if $_[$field] =~ m{$comp};
- } else {
- return ($action, $actiondata); # the default action
- }
- }
-}