line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
################################################################# |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Hook::Filter::Rule - A filter rule |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: Rule.pm,v 1.7 2008/06/09 21:04:08 erwan_lemonnier Exp $ |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# 060301 erwan Created |
8
|
|
|
|
|
|
|
# 070516 erwan Small POD and layout fixes |
9
|
|
|
|
|
|
|
# 070524 erwan Used BEGIN instead of INIT |
10
|
|
|
|
|
|
|
# 080609 erwan Updated POD |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Hook::Filter::Rule; |
14
|
|
|
|
|
|
|
|
15
|
12
|
|
|
12
|
|
202255
|
use 5.006; |
|
12
|
|
|
|
|
54
|
|
|
12
|
|
|
|
|
514
|
|
16
|
12
|
|
|
12
|
|
60
|
use strict; |
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
564
|
|
17
|
12
|
|
|
12
|
|
60
|
use warnings; |
|
12
|
|
|
|
|
27
|
|
|
12
|
|
|
|
|
482
|
|
18
|
12
|
|
|
12
|
|
58
|
use Carp qw(croak); |
|
12
|
|
|
|
|
27
|
|
|
12
|
|
|
|
|
845
|
|
19
|
12
|
|
|
12
|
|
64
|
use Data::Dumper; |
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
707
|
|
20
|
12
|
|
|
12
|
|
9380
|
use Symbol; |
|
12
|
|
|
|
|
15201
|
|
|
12
|
|
|
|
|
978
|
|
21
|
12
|
|
|
12
|
|
1797
|
use Module::Pluggable search_path => ['Hook::Filter::Plugins'], require => 1; |
|
12
|
|
|
|
|
22081
|
|
|
12
|
|
|
|
|
126
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION='0.04'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#---------------------------------------------------------------- |
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
# load test functions from plugins |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
BEGIN { |
31
|
|
|
|
|
|
|
|
32
|
12
|
|
|
12
|
|
5256
|
my %TESTS; |
33
|
|
|
|
|
|
|
|
34
|
12
|
|
|
|
|
263
|
foreach my $plugin (Hook::Filter::Rule->plugins()) { |
35
|
12
|
|
|
|
|
7618
|
my @tests = $plugin->register(); |
36
|
|
|
|
|
|
|
# TODO: test that @tests is an array of strings. die with BUG: |
37
|
|
|
|
|
|
|
|
38
|
12
|
|
|
|
|
62
|
foreach my $test ($plugin->register()) { |
39
|
36
|
50
|
|
|
|
117
|
if (exists $TESTS{$test}) { |
40
|
0
|
|
|
|
|
0
|
croak "invalid plugin function: test function [$test] exported by plugin [$plugin] is already exported by an other plugin."; |
41
|
|
|
|
|
|
|
} |
42
|
36
|
|
|
|
|
68
|
*{ qualify_to_ref($test,"Hook::Filter::Rule") } = *{ qualify_to_ref($test,$plugin) }; |
|
36
|
|
|
|
|
688
|
|
|
36
|
|
|
|
|
111
|
|
43
|
36
|
|
|
|
|
5870
|
$TESTS{$test} = 1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#---------------------------------------------------------------- |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# new - build a new filter rule |
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new { |
54
|
38
|
|
|
38
|
1
|
6624
|
my($pkg,$rule) = @_; |
55
|
38
|
|
33
|
|
|
249
|
$pkg = ref $pkg || $pkg; |
56
|
38
|
|
|
|
|
117
|
my $self = bless({},$pkg); |
57
|
|
|
|
|
|
|
|
58
|
38
|
100
|
100
|
|
|
358
|
if (!defined $rule || ref \$rule ne "SCALAR" || scalar @_ != 2) { |
|
|
|
100
|
|
|
|
|
59
|
4
|
|
|
|
|
5
|
shift @_; |
60
|
4
|
|
|
|
|
16
|
croak "invalid parameter: Hook::Filter::Rule->new expects one string describing a filter rule, but got [".Dumper(@_)."]."; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
34
|
|
|
|
|
130
|
$self->{RULE} = $rule; |
64
|
|
|
|
|
|
|
|
65
|
34
|
|
|
|
|
108
|
return $self; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#---------------------------------------------------------------- |
69
|
|
|
|
|
|
|
# |
70
|
|
|
|
|
|
|
# rule - accessor for the rule |
71
|
|
|
|
|
|
|
# |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub rule { |
74
|
6
|
|
|
6
|
1
|
6072
|
return $_[0]->{RULE}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#---------------------------------------------------------------- |
78
|
|
|
|
|
|
|
# |
79
|
|
|
|
|
|
|
# source - where the rule came from (used in error messages only) |
80
|
|
|
|
|
|
|
# |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub source { |
83
|
30
|
|
|
30
|
1
|
2634
|
my($self,$orig) = @_; |
84
|
|
|
|
|
|
|
|
85
|
30
|
100
|
100
|
|
|
302
|
if (!defined $orig || ref \$orig ne "SCALAR" || scalar @_ != 2) { |
|
|
|
100
|
|
|
|
|
86
|
4
|
|
|
|
|
7
|
shift @_; |
87
|
4
|
|
|
|
|
15
|
croak "invalid parameter: Hook::Filter::Rule->source expects one string, but got [".Dumper(@_)."]."; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
26
|
|
|
|
|
90
|
$self->{SOURCE} = $orig; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#---------------------------------------------------------------- |
94
|
|
|
|
|
|
|
# |
95
|
|
|
|
|
|
|
# eval - evaluate a rule. return either true or false |
96
|
|
|
|
|
|
|
# |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub eval { |
99
|
88
|
|
|
88
|
1
|
1519
|
my $self = shift; |
100
|
88
|
|
|
|
|
171
|
my $rule = $self->{RULE}; |
101
|
|
|
|
|
|
|
|
102
|
88
|
|
|
|
|
6437
|
my $res = eval $rule; |
103
|
88
|
100
|
|
|
|
367
|
if ($@) { |
104
|
|
|
|
|
|
|
# in doubt, let's assume we are not filtering anything, ie allow function calls as if we were not here |
105
|
5
|
100
|
|
|
|
71
|
warn "WARNING: invalid Hook::Filter rule [$rule] ". |
106
|
|
|
|
|
|
|
( (defined $self->{SOURCE})?"from file [".$self->{SOURCE}."] ":"")."caused error:\n". |
107
|
|
|
|
|
|
|
"[".$@."]. Assuming this rule returned true.\n"; |
108
|
5
|
|
|
|
|
1887
|
return 1; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
83
|
100
|
|
|
|
479
|
return ($res)?1:0; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |